batching is gone.
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 Aug 2002 12:26:23 +0000 (12:26 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 Aug 2002 12:26:23 +0000 (12:26 +0000)
if you forget to call R_Mesh_Render after each mesh the backend system will yell at you.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2284 d7cf8633-e32d-0410-b094-e92efae38249

cl_particles.c
gl_backend.c
gl_models.c
gl_rmain.c
gl_rsurf.c
r_crosshairs.c
r_explosion.c
r_light.c
r_sky.c

index fd4bade..15f78ca 100644 (file)
@@ -1323,6 +1323,7 @@ void R_DrawParticles (void)
                        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();
                }
        }
 }
index e972323..1dff96e 100644 (file)
@@ -2,7 +2,6 @@
 #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"};
@@ -87,7 +86,6 @@ void SCR_ScreenShot_f (void);
 
 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
@@ -274,13 +272,6 @@ static void gl_backend_bufferchanges(int init)
        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;
@@ -313,7 +304,6 @@ void gl_backend_init(void)
 
        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);
@@ -777,12 +767,8 @@ void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *in
 // 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");
@@ -819,17 +805,7 @@ void R_Mesh_Render(void)
                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
                }
        }
 
@@ -994,11 +970,9 @@ void R_Mesh_AddTransparent(void)
                }
        }
 
+       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
 
@@ -1018,6 +992,7 @@ void R_Mesh_AddTransparent(void)
                        currenttriangle++;
                }
                mesh->triangles = currenttriangle - mesh->firsttriangle;
+               R_Mesh_Render();
        }
 
        currenttransmesh = 0;
@@ -1120,8 +1095,11 @@ void R_Mesh_Draw(const rmeshinfo_t *m)
        }
        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;
@@ -1233,9 +1211,6 @@ void R_Mesh_Draw(const rmeshinfo_t *m)
                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
@@ -1304,8 +1279,11 @@ int R_Mesh_Draw_GetBuffer(rmeshbufferinfo_t *m, int wantoverbright)
        }
        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;
index e5852f9..47efa6d 100644 (file)
@@ -214,6 +214,7 @@ void R_DrawModelMesh(rtexture_t *skin, float *colors, float cred, float cgreen,
 
        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;
@@ -372,6 +373,7 @@ void R_DrawQ1Q2AliasModel (float fog)
 
                c_alias_polys += aliasmeshinfo.numtriangles;
                R_Mesh_Draw(&aliasmeshinfo);
+               R_Mesh_Render();
        }
        else if (currentrenderentity->colormap >= 0 || !skinframe->merged || skinframe->glow || !r_quickmodels.integer)
        {
@@ -494,6 +496,7 @@ void R_DrawQ1Q2AliasModel (float fog)
 
                aliasvert = aliasvertbuf;
                aliasvertcolor = aliasvertcolorbuf;
+               R_Mesh_Render();
        }
 }
 
@@ -798,6 +801,7 @@ void R_DrawZymoticModelMesh(zymtype1header_t *m)
                aliasmeshinfo.index = renderlist;
                c_alias_polys += aliasmeshinfo.numtriangles;
                R_Mesh_Draw(&aliasmeshinfo);
+               R_Mesh_Render();
                renderlist += aliasmeshinfo.numtriangles * 3;
        }
 }
@@ -824,6 +828,7 @@ void R_DrawZymoticModelMeshFog(vec3_t org, zymtype1header_t *m, float fog)
                aliasmeshinfo.index = renderlist;
                c_alias_polys += aliasmeshinfo.numtriangles;
                R_Mesh_Draw(&aliasmeshinfo);
+               R_Mesh_Render();
                renderlist += aliasmeshinfo.numtriangles * 3;
        }
 }
index 226de36..ad66314 100644 (file)
@@ -556,6 +556,7 @@ static void R_BlendView(void)
                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();
        }
 }
 
index 9fe860b..dbe515c 100644 (file)
@@ -676,6 +676,7 @@ static void RSurfShader_Sky(msurface_t *firstsurf)
                                        outc[2] = cb;
                                        outc[3] = ca;
                                }
+                               R_Mesh_Render();
                        }
                }
        }
@@ -788,6 +789,7 @@ static void RSurfShader_Water_Pass_Base(msurface_t *surf)
                                                VectorScale(outc, f, outc);
                                        }
                                }
+                               R_Mesh_Render();
                        }
                }
        }
@@ -850,6 +852,7 @@ static void RSurfShader_Water_Pass_Base(msurface_t *surf)
                                        else
                                                VectorScale(outc, cl, outc);
                                }
+                               R_Mesh_Render();
                        }
                }
        }
@@ -896,6 +899,7 @@ static void RSurfShader_Water_Pass_Fog(msurface_t *surf)
                                        outst[1] = v->st[1];
                                }
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1021,6 +1025,7 @@ static void RSurfShader_Wall_Pass_BaseVertex(msurface_t *surf)
                                                VectorScale(outc, cl, outc);
                                }
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1079,6 +1084,7 @@ static void RSurfShader_Wall_Pass_BaseFullbright(msurface_t *surf)
                                outst[0] = v->st[0];
                                outst[1] = v->st[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1120,6 +1126,7 @@ static void RSurfShader_Wall_Pass_Glow(msurface_t *surf)
                                outst[0] = v->st[0];
                                outst[1] = v->st[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1156,6 +1163,7 @@ static void RSurfShader_Wall_Pass_Fog(msurface_t *surf)
                                outst[0] = v->st[0];
                                outst[1] = v->st[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1201,6 +1209,7 @@ static void RSurfShader_OpaqueWall_Pass_TripleTexCombine(msurface_t *surf)
                                outab[0] = v->ab[0];
                                outab[1] = v->ab[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1240,6 +1249,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseMTex(msurface_t *surf)
                                outuv[0] = v->uv[0];
                                outuv[1] = v->uv[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1276,6 +1286,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseTexture(msurface_t *surf)
                                outst[0] = v->st[0];
                                outst[1] = v->st[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1312,6 +1323,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseLightmap(msurface_t *surf)
                                outuv[0] = v->uv[0];
                                outuv[1] = v->uv[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1360,6 +1372,7 @@ static void RSurfShader_OpaqueWall_Pass_Light(msurface_t *surf)
                                if (cl != 1)
                                        for (i = 0, outc = m.color;i < m.numverts;i++, outc += 4)
                                                VectorScale(outc, cl, outc);
+                               R_Mesh_Render();
                        }
                }
        }
@@ -1394,6 +1407,7 @@ static void RSurfShader_OpaqueWall_Pass_Fog(msurface_t *surf)
                                VectorSubtract(outv, r_origin, diff);
                                outc[3] = exp(fogdensity/DotProduct(diff, diff));
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1428,6 +1442,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseDetail(msurface_t *surf)
                                outst[0] = v->ab[0];
                                outst[1] = v->ab[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1462,6 +1477,7 @@ static void RSurfShader_OpaqueWall_Pass_Glow(msurface_t *surf)
                                outst[0] = v->st[0];
                                outst[1] = v->st[1];
                        }
+                       R_Mesh_Render();
                }
        }
 }
@@ -1910,6 +1926,7 @@ void R_DrawPortals(void)
                                                VectorCopy(point[i].position, portalpointbuffer[i]);
                                }
                                R_Mesh_DrawPolygon(&m, portal->numpoints);
+                               R_Mesh_Render();
                        }
                }
        }
index 158734b..a4466ce 100644 (file)
@@ -205,6 +205,7 @@ void R_DrawCrosshairSprite(rtexture_t *texture, vec3_t origin, vec_t scale, floa
                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();
        }
 }
 
index 3f8daa4..507f1f7 100644 (file)
@@ -238,6 +238,7 @@ void R_DrawExplosion(explosion_t *e)
                                c[3] = 1;
                        }
                }
+               R_Mesh_Render();
        }
 }
 
index da977bf..e1207de 100644 (file)
--- a/r_light.c
+++ b/r_light.c
@@ -193,6 +193,7 @@ void R_DrawCoronas(void)
                                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();
                        }
                }
        }
diff --git a/r_sky.c b/r_sky.c
index 497d7f7..7e21135 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -182,6 +182,7 @@ static void R_SkyBox(void)
                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))
@@ -195,6 +196,7 @@ static void R_SkyBox(void)
                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))
@@ -208,6 +210,7 @@ static void R_SkyBox(void)
                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))
@@ -221,6 +224,7 @@ static void R_SkyBox(void)
                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))
@@ -234,6 +238,7 @@ static void R_SkyBox(void)
                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))
@@ -247,6 +252,7 @@ static void R_SkyBox(void)
                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();
        }
 }
 
@@ -345,6 +351,7 @@ static void R_SkySphere(void)
        {
                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;
@@ -353,6 +360,7 @@ static void R_SkySphere(void)
        {
                memcpy(m.index, skysphereindices, m.numtriangles * sizeof(int[3]));
                skyspherearrays(m.vertex, m.texcoords[0], m.color, skysphere, speedscale2, m.colorscale);
+               R_Mesh_Render();
        }
 }