m.color[1] = m.color[5] = m.color[9] = m.color[13] = cg * m.colorscale;
m.color[2] = m.color[6] = m.color[10] = m.color[14] = cb * m.colorscale;
m.color[3] = m.color[7] = m.color[11] = m.color[15] = ca;
+ R_Mesh_Render();
}
}
}
#include "quakedef.h"
cvar_t gl_mesh_maxtriangles = {0, "gl_mesh_maxtriangles", "1024"};
-cvar_t gl_mesh_batchtriangles = {0, "gl_mesh_batchtriangles", "0"};
cvar_t gl_mesh_transtriangles = {0, "gl_mesh_transtriangles", "16384"};
cvar_t gl_mesh_floatcolors = {0, "gl_mesh_floatcolors", "1"};
cvar_t gl_mesh_drawmode = {CVAR_SAVE, "gl_mesh_drawmode", "3"};
static int max_meshs;
static int max_transmeshs;
-static int max_batch;
static int max_verts; // always max_meshs * 3
static int max_transverts; // always max_transmeshs * 3
#define TRANSDEPTHRES 4096
if (gl_mesh_transtriangles.integer > 65536)
Cvar_SetValueQuick(&gl_mesh_transtriangles, 65536);
- if (gl_mesh_batchtriangles.integer < 1)
- Cvar_SetValueQuick(&gl_mesh_batchtriangles, 1);
- if (gl_mesh_batchtriangles.integer > gl_mesh_maxtriangles.integer)
- Cvar_SetValueQuick(&gl_mesh_batchtriangles, gl_mesh_maxtriangles.integer);
-
- max_batch = gl_mesh_batchtriangles.integer;
-
if (max_meshs != gl_mesh_maxtriangles.integer || max_transmeshs != gl_mesh_transtriangles.integer)
{
max_meshs = gl_mesh_maxtriangles.integer;
Cvar_RegisterVariable(&gl_mesh_maxtriangles);
Cvar_RegisterVariable(&gl_mesh_transtriangles);
- Cvar_RegisterVariable(&gl_mesh_batchtriangles);
Cvar_RegisterVariable(&gl_mesh_floatcolors);
Cvar_RegisterVariable(&gl_mesh_drawmode);
R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap);
// renders mesh buffers, called to flush buffers when full
void R_Mesh_Render(void)
{
- int i;
int k;
- int indexcount;
- int firstvert;
buf_mesh_t *mesh;
- unsigned int *index;
if (!backendactive)
Sys_Error("R_Mesh_Render: called when backend is not active\n");
for (k = 1, mesh = buf_mesh + k;k < currentmesh;k++, mesh++)
{
GL_MeshState(mesh);
-
- firstvert = mesh->firstvert;
- indexcount = mesh->triangles * 3;
- index = (unsigned int *)&buf_tri[mesh->firsttriangle].index[0];
-
- // if not using batching, skip the index adjustment
- if (firstvert != 0)
- for (i = 0;i < indexcount;i++)
- index[i] += firstvert;
-
- GL_DrawRangeElements(firstvert, firstvert + mesh->verts, indexcount, index);CHECKGLERROR
+ GL_DrawRangeElements(mesh->firstvert, mesh->firstvert + mesh->verts, mesh->triangles * 3, buf_tri[mesh->firsttriangle].index);CHECKGLERROR
}
}
}
}
+ R_Mesh_Render();
for (;transmesh;transmesh = transmesh->chain)
{
- if (currentmesh >= max_meshs || currenttriangle + transmesh->triangles > max_batch || currenttriangle + transmesh->triangles > 1024 || currentvertex + transmesh->verts > max_verts)
- R_Mesh_Render();
-
mesh = &buf_mesh[currentmesh++];
*mesh = *transmesh; // copy mesh properties
currenttriangle++;
}
mesh->triangles = currenttriangle - mesh->firsttriangle;
+ R_Mesh_Render();
}
currenttransmesh = 0;
}
else
{
- if (currentmesh >= max_meshs || (currenttriangle + m->numtriangles) > max_batch || (currentvertex + m->numverts) > max_verts)
+ if (currentmesh)
+ {
R_Mesh_Render();
+ Con_Printf("mesh queue not empty, flushing.\n");
+ }
c_meshs++;
c_meshtris += m->numtriangles;
else
memcpy(&texcoord[j][0].t[0], m->texcoords[j], m->numverts * sizeof(buf_texcoord_t));
}
-
- if (currenttriangle >= max_batch)
- R_Mesh_Render();
}
// allocates space in geometry buffers, and fills in pointers to the buffers in passsed struct
}
else
{
- if (currentmesh >= max_meshs || (currenttriangle + m->numtriangles) > max_batch || (currentvertex + m->numverts) > max_verts)
+ if (currentmesh)
+ {
R_Mesh_Render();
+ Con_Printf("mesh queue not empty, flushing.\n");
+ }
c_meshs++;
c_meshtris += m->numtriangles;
c_alias_polys += aliasmeshinfo.numtriangles;
R_Mesh_Draw(&aliasmeshinfo);
+ R_Mesh_Render();
// leave it in a state for additional passes
aliasmeshinfo.blendfunc1 = GL_SRC_ALPHA;
c_alias_polys += aliasmeshinfo.numtriangles;
R_Mesh_Draw(&aliasmeshinfo);
+ R_Mesh_Render();
}
else if (currentrenderentity->colormap >= 0 || !skinframe->merged || skinframe->glow || !r_quickmodels.integer)
{
aliasvert = aliasvertbuf;
aliasvertcolor = aliasvertcolorbuf;
+ R_Mesh_Render();
}
}
aliasmeshinfo.index = renderlist;
c_alias_polys += aliasmeshinfo.numtriangles;
R_Mesh_Draw(&aliasmeshinfo);
+ R_Mesh_Render();
renderlist += aliasmeshinfo.numtriangles * 3;
}
}
aliasmeshinfo.index = renderlist;
c_alias_polys += aliasmeshinfo.numtriangles;
R_Mesh_Draw(&aliasmeshinfo);
+ R_Mesh_Render();
renderlist += aliasmeshinfo.numtriangles * 3;
}
}
m.vertex[8] = m.vertex[0] + vright[0] * r;
m.vertex[9] = m.vertex[1] + vright[1] * r;
m.vertex[10] = m.vertex[2] + vright[2] * r;
+ R_Mesh_Render();
}
}
outc[2] = cb;
outc[3] = ca;
}
+ R_Mesh_Render();
}
}
}
VectorScale(outc, f, outc);
}
}
+ R_Mesh_Render();
}
}
}
else
VectorScale(outc, cl, outc);
}
+ R_Mesh_Render();
}
}
}
outst[1] = v->st[1];
}
}
+ R_Mesh_Render();
}
}
}
VectorScale(outc, cl, outc);
}
}
+ R_Mesh_Render();
}
}
}
outst[0] = v->st[0];
outst[1] = v->st[1];
}
+ R_Mesh_Render();
}
}
}
outst[0] = v->st[0];
outst[1] = v->st[1];
}
+ R_Mesh_Render();
}
}
}
outst[0] = v->st[0];
outst[1] = v->st[1];
}
+ R_Mesh_Render();
}
}
}
outab[0] = v->ab[0];
outab[1] = v->ab[1];
}
+ R_Mesh_Render();
}
}
}
outuv[0] = v->uv[0];
outuv[1] = v->uv[1];
}
+ R_Mesh_Render();
}
}
}
outst[0] = v->st[0];
outst[1] = v->st[1];
}
+ R_Mesh_Render();
}
}
}
outuv[0] = v->uv[0];
outuv[1] = v->uv[1];
}
+ R_Mesh_Render();
}
}
}
if (cl != 1)
for (i = 0, outc = m.color;i < m.numverts;i++, outc += 4)
VectorScale(outc, cl, outc);
+ R_Mesh_Render();
}
}
}
VectorSubtract(outv, r_origin, diff);
outc[3] = exp(fogdensity/DotProduct(diff, diff));
}
+ R_Mesh_Render();
}
}
}
outst[0] = v->ab[0];
outst[1] = v->ab[1];
}
+ R_Mesh_Render();
}
}
}
outst[0] = v->st[0];
outst[1] = v->st[1];
}
+ R_Mesh_Render();
}
}
}
VectorCopy(point[i].position, portalpointbuffer[i]);
}
R_Mesh_DrawPolygon(&m, portal->numpoints);
+ R_Mesh_Render();
}
}
}
m.vertex[12] = origin[0] + vright[0] * scale - vup[0] * scale;
m.vertex[13] = origin[1] + vright[1] * scale - vup[1] * scale;
m.vertex[14] = origin[2] + vright[2] * scale - vup[2] * scale;
+ R_Mesh_Render();
}
}
c[3] = 1;
}
}
+ R_Mesh_Render();
}
}
m.vertex[12] = rd->origin[0] + vright[0] * scale - vup[0] * scale;
m.vertex[13] = rd->origin[1] + vright[1] * scale - vup[1] * scale;
m.vertex[14] = rd->origin[2] + vright[2] * scale - vup[2] * scale;
+ R_Mesh_Render();
}
}
}
R_SkyBoxPolyVec(1, 1, 1, 1, -1, -1);
R_SkyBoxPolyVec(2, 0, 1, 1, 1, -1);
R_SkyBoxPolyVec(3, 0, 0, 1, 1, 1);
+ R_Mesh_Render();
}
m.tex[0] = R_GetTexture(skyboxside[1]); // back
if (R_Mesh_Draw_GetBuffer(&m, false))
R_SkyBoxPolyVec(1, 1, 1, -1, 1, -1);
R_SkyBoxPolyVec(2, 0, 1, -1, -1, -1);
R_SkyBoxPolyVec(3, 0, 0, -1, -1, 1);
+ R_Mesh_Render();
}
m.tex[0] = R_GetTexture(skyboxside[0]); // right
if (R_Mesh_Draw_GetBuffer(&m, false))
R_SkyBoxPolyVec(1, 1, 1, 1, 1, -1);
R_SkyBoxPolyVec(2, 0, 1, -1, 1, -1);
R_SkyBoxPolyVec(3, 0, 0, -1, 1, 1);
+ R_Mesh_Render();
}
m.tex[0] = R_GetTexture(skyboxside[2]); // left
if (R_Mesh_Draw_GetBuffer(&m, false))
R_SkyBoxPolyVec(1, 1, 1, -1, -1, -1);
R_SkyBoxPolyVec(2, 0, 1, 1, -1, -1);
R_SkyBoxPolyVec(3, 0, 0, 1, -1, 1);
+ R_Mesh_Render();
}
m.tex[0] = R_GetTexture(skyboxside[4]); // up
if (R_Mesh_Draw_GetBuffer(&m, false))
R_SkyBoxPolyVec(1, 1, 1, 1, 1, 1);
R_SkyBoxPolyVec(2, 0, 1, -1, 1, 1);
R_SkyBoxPolyVec(3, 0, 0, -1, -1, 1);
+ R_Mesh_Render();
}
m.tex[0] = R_GetTexture(skyboxside[5]); // down
if (R_Mesh_Draw_GetBuffer(&m, false))
R_SkyBoxPolyVec(1, 1, 1, 1, -1, -1);
R_SkyBoxPolyVec(2, 0, 1, -1, -1, -1);
R_SkyBoxPolyVec(3, 0, 0, -1, 1, -1);
+ R_Mesh_Render();
}
}
{
memcpy(m.index, skysphereindices, m.numtriangles * sizeof(int[3]));
skyspherearrays(m.vertex, m.texcoords[0], m.color, skysphere, speedscale, m.colorscale);
+ R_Mesh_Render();
}
m.blendfunc1 = GL_SRC_ALPHA;
m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
{
memcpy(m.index, skysphereindices, m.numtriangles * sizeof(int[3]));
skyspherearrays(m.vertex, m.texcoords[0], m.color, skysphere, speedscale2, m.colorscale);
+ R_Mesh_Render();
}
}