eliminated rmeshstate_t .pointer_vertex and .pointer_color (now must use R_Mesh_Verte...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 16 Apr 2006 09:21:17 +0000 (09:21 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 16 Apr 2006 09:21:17 +0000 (09:21 +0000)
renamed R_Mesh_State to R_Mesh_TextureState
made an alternate variant of R_Mesh_TextureState called R_Mesh_ResetTextureState which acts like it was given an empty rmeshstate_t (but is faster than R_Mesh_TextureState)
moved R_Mesh_VertexPointer and R_Mesh_TexCoordPointer calls out of the inner loops of the GLSL surface path
other related cleanups

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

cl_particles.c
cl_screen.c
gl_backend.c
gl_backend.h
gl_draw.c
gl_rmain.c
gl_rsurf.c
r_explosion.c
r_lightning.c
r_shadow.c
r_sky.c

index 435981a..922302a 100644 (file)
@@ -2004,11 +2004,12 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, int surfacen
 
        R_Mesh_Matrix(&identitymatrix);
 
+       R_Mesh_VertexPointer(particle_vertex3f);
+       R_Mesh_ColorPointer(NULL);
        memset(&m, 0, sizeof(m));
        m.tex[0] = R_GetTexture(tex->texture);
        m.pointer_texcoord[0] = particle_texcoord2f;
-       m.pointer_vertex = particle_vertex3f;
-       R_Mesh_State(&m);
+       R_Mesh_TextureState(&m);
 
        GL_Color(cr, cg, cb, ca);
 
index 63b8e94..5d9544b 100644 (file)
@@ -1290,7 +1290,6 @@ void SCR_UpdateLoadingScreen (void)
 {
        float x, y;
        cachepic_t *pic;
-       rmeshstate_t m;
        float vertex3f[12];
        float texcoord2f[8];
        // don't do anything if not initialized yet
@@ -1316,11 +1315,11 @@ void SCR_UpdateLoadingScreen (void)
        GL_Color(1,1,1,1);
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthTest(false);
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = vertex3f;
-       m.pointer_texcoord[0] = texcoord2f;
-       m.tex[0] = R_GetTexture(pic->tex);
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(vertex3f);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
+       R_Mesh_TexBind(0, R_GetTexture(pic->tex));
+       R_Mesh_TexCoordPointer(0, 2, texcoord2f);
        vertex3f[2] = vertex3f[5] = vertex3f[8] = vertex3f[11] = 0;
        vertex3f[0] = vertex3f[9] = x;
        vertex3f[1] = vertex3f[4] = y;
index aa1f23c..7d608d3 100644 (file)
@@ -1575,15 +1575,12 @@ void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, i
        }
 }
 
-void R_Mesh_State(const rmeshstate_t *m)
+void R_Mesh_TextureState(const rmeshstate_t *m)
 {
        unsigned int i;
 
        BACKENDACTIVECHECK
 
-       R_Mesh_VertexPointer(m->pointer_vertex);
-       R_Mesh_ColorPointer(m->pointer_color);
-
        if (gl_backend_rebindtextures)
        {
                gl_backend_rebindtextures = false;
@@ -1606,6 +1603,124 @@ void R_Mesh_State(const rmeshstate_t *m)
        }
 }
 
+void R_Mesh_ResetTextureState(void)
+{
+       unsigned int unitnum;
+
+       BACKENDACTIVECHECK
+
+       if (gl_backend_rebindtextures)
+       {
+               gl_backend_rebindtextures = false;
+               GL_SetupTextureState();
+       }
+
+       for (unitnum = 0;unitnum < backendimageunits;unitnum++)
+       {
+               gltextureunit_t *unit = gl_state.units + unitnum;
+               // update 1d texture binding
+               if (unit->t1d)
+               {
+                       GL_ActiveTexture(unitnum);
+                       if (unitnum < backendunits)
+                               qglDisable(GL_TEXTURE_1D);
+                       unit->t1d = 0;
+                       qglBindTexture(GL_TEXTURE_1D, unit->t1d);
+                       CHECKGLERROR
+               }
+               // update 2d texture binding
+               if (unit->t2d)
+               {
+                       GL_ActiveTexture(unitnum);
+                       if (unitnum < backendunits)
+                               qglDisable(GL_TEXTURE_2D);
+                       unit->t2d = 0;
+                       qglBindTexture(GL_TEXTURE_2D, unit->t2d);
+                       CHECKGLERROR
+               }
+               // update 3d texture binding
+               if (unit->t3d)
+               {
+                       GL_ActiveTexture(unitnum);
+                       if (unitnum < backendunits)
+                               qglDisable(GL_TEXTURE_3D);
+                       unit->t3d = 0;
+                       qglBindTexture(GL_TEXTURE_3D, unit->t3d);
+                       CHECKGLERROR
+               }
+               // update cubemap texture binding
+               if (unit->tcubemap)
+               {
+                       GL_ActiveTexture(unitnum);
+                       if (unitnum < backendunits)
+                               qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
+                       unit->tcubemap = 0;
+                       qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
+                       CHECKGLERROR
+               }
+       }
+       for (unitnum = 0;unitnum < backendarrayunits;unitnum++)
+       {
+               gltextureunit_t *unit = gl_state.units + unitnum;
+               // texture array unit is disabled, disable the array
+               if (unit->arrayenabled)
+               {
+                       unit->arrayenabled = false;
+                       GL_ClientActiveTexture(unitnum);
+                       qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
+               }
+       }
+       for (unitnum = 0;unitnum < backendunits;unitnum++)
+       {
+               gltextureunit_t *unit = gl_state.units + unitnum;
+               // no texmatrix specified, revert to identity
+               if (unit->texmatrixenabled)
+               {
+                       unit->texmatrixenabled = false;
+                       qglMatrixMode(GL_TEXTURE);
+                       GL_ActiveTexture(unitnum);
+                       qglLoadIdentity();
+                       qglMatrixMode(GL_MODELVIEW);
+               }
+               if (gl_combine.integer)
+               {
+                       // GL_ARB_texture_env_combine
+                       if (unit->combinergb != GL_MODULATE)
+                       {
+                               unit->combinergb = GL_MODULATE;
+                               GL_ActiveTexture(unitnum);
+                               qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, unit->combinergb);CHECKGLERROR
+                       }
+                       if (unit->combinealpha != GL_MODULATE)
+                       {
+                               unit->combinealpha = GL_MODULATE;
+                               GL_ActiveTexture(unitnum);
+                               qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, unit->combinealpha);CHECKGLERROR
+                       }
+                       if (unit->rgbscale != 1)
+                       {
+                               GL_ActiveTexture(unitnum);
+                               qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (unit->rgbscale = 1));CHECKGLERROR
+                       }
+                       if (unit->alphascale != 1)
+                       {
+                               GL_ActiveTexture(unitnum);
+                               qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, (unit->alphascale = 1));CHECKGLERROR
+                       }
+               }
+               else
+               {
+                       // normal GL texenv
+                       if (unit->combinergb != GL_MODULATE)
+                       {
+                               unit->combinergb = GL_MODULATE;
+                               GL_ActiveTexture(unitnum);
+                               qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->combinergb);CHECKGLERROR
+                       }
+               }
+       }
+}
+
 void R_Mesh_Draw_ShowTris(int firstvertex, int numvertices, int numtriangles, const int *elements)
 {
        qglBegin(GL_LINES);
index f494b44..c7fba5e 100644 (file)
@@ -35,7 +35,7 @@ extern cvar_t gl_mesh_copyarrays;
 extern cvar_t gl_paranoid;
 extern cvar_t gl_printcheckerror;
 
-//input to R_Mesh_State
+//input to R_Mesh_TextureState
 typedef struct rmeshstate_s
 {
        // textures
@@ -53,10 +53,6 @@ typedef struct rmeshstate_s
        // pointers
        const float *pointer_texcoord[MAX_TEXTUREUNITS]; // 2D
        const float *pointer_texcoord3f[MAX_TEXTUREUNITS]; // 3D
-
-       // other state set by this
-       const float *pointer_vertex;
-       const float *pointer_color;
 }
 rmeshstate_t;
 
@@ -90,8 +86,10 @@ void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum);
 void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix);
 // sets the combine state for a texenv unit
 void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, int rgbscale, int alphascale);
-// set up the requested entire rendering state
-void R_Mesh_State(const rmeshstate_t *m);
+// set up the requested texture state
+void R_Mesh_TextureState(const rmeshstate_t *m);
+// set up a blank texture state (faster/easier specialized version of R_Mesh_TextureState)
+void R_Mesh_ResetTextureState(void);
 
 // renders a mesh
 void R_Mesh_Draw(int firstvertex, int numvertices, int numtriangles, const int *elements);
index d4339ca..1d448ac 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -529,7 +529,6 @@ void DrawQ_String_Real(float x, float y, const char *string, int maxlen, float w
        int i, num;
        float *av, *at;
        int batchcount;
-       rmeshstate_t m;
        float vertex3f[QUADELEMENTS_MAXQUADS*4*3];
        float texcoord2f[QUADELEMENTS_MAXQUADS*4*2];
 
@@ -556,12 +555,11 @@ void DrawQ_String_Real(float x, float y, const char *string, int maxlen, float w
 
        GL_Color(red, green, blue, alpha);
 
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = vertex3f;
-       m.pointer_color = NULL;
-       m.pointer_texcoord[0] = texcoord2f;
-       m.tex[0] = R_GetTexture(char_texture);
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(vertex3f);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
+       R_Mesh_TexBind(0, R_GetTexture(char_texture));
+       R_Mesh_TexCoordPointer(0, 2, texcoord2f);
 
        at = texcoord2f;
        av = vertex3f;
@@ -736,7 +734,6 @@ void DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float
 
 void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height, float s1, float t1, float r1, float g1, float b1, float a1, float s2, float t2, float r2, float g2, float b2, float a2, float s3, float t3, float r3, float g3, float b3, float a3, float s4, float t4, float r4, float g4, float b4, float a4, int flags)
 {
-       rmeshstate_t m;
        float floats[36];
 
        if (!r_refdef.draw2dstage)
@@ -757,23 +754,22 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
        else
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = floats;
-       m.pointer_color = floats + 20;
+       R_Mesh_VertexPointer(floats);
+       R_Mesh_ColorPointer(floats + 20);
+       R_Mesh_ResetTextureState();
        if (pic)
        {
                if (width == 0)
                        width = pic->width;
                if (height == 0)
                        height = pic->height;
-               m.tex[0] = R_GetTexture(pic->tex);
-               m.pointer_texcoord[0] = floats + 12;
+               R_Mesh_TexBind(0, R_GetTexture(pic->tex));
+               R_Mesh_TexCoordPointer(0, 2, floats + 12);
                floats[12] = s1;floats[13] = t1;
                floats[14] = s2;floats[15] = t2;
                floats[16] = s4;floats[17] = t4;
                floats[18] = s3;floats[19] = t3;
        }
-       R_Mesh_State(&m);
 
        floats[2] = floats[5] = floats[8] = floats[11] = 0;
        floats[0] = floats[9] = x;
@@ -790,8 +786,6 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
 
 void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags)
 {
-       rmeshstate_t m;
-
        if (!r_refdef.draw2dstage)
        {
                Con_Printf("DrawQ_Mesh: not in 2d rendering stage!\n");
@@ -810,13 +804,11 @@ void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags)
        else
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = mesh->data_vertex3f;
-       m.pointer_color = mesh->data_color4f;
-       m.tex[0] = R_GetTexture(mesh->texture);
-       if (m.tex[0])
-               m.pointer_texcoord[0] = mesh->data_texcoord2f;
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(mesh->data_vertex3f);
+       R_Mesh_ColorPointer(mesh->data_color4f);
+       R_Mesh_ResetTextureState();
+       R_Mesh_TexBind(0, R_GetTexture(mesh->texture));
+       R_Mesh_TexCoordPointer(0, 2, mesh->data_texcoord2f);
 
        GL_LockArrays(0, mesh->num_vertices);
        R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
@@ -937,14 +929,13 @@ void DrawQ_Finish(void)
 static float blendvertex3f[9] = {-5000, -5000, 10, 10000, -5000, 10, -5000, 10000, 10};
 void R_DrawGamma(void)
 {
-       rmeshstate_t m;
        float c[4];
        if (!vid_usinghwgamma)
        {
                // all the blends ignore depth
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = blendvertex3f;
-               R_Mesh_State(&m);
+               R_Mesh_VertexPointer(blendvertex3f);
+               R_Mesh_ColorPointer(NULL);
+               R_Mesh_ResetTextureState();
                GL_DepthMask(true);
                GL_DepthTest(false);
                if (v_color_enable.integer)
index dbcd18c..44bf341 100644 (file)
@@ -952,9 +952,12 @@ void R_SetupSurfaceShader(const entity_render_t *ent, const texture_t *texture,
        if (r_glsl_permutation->loc_Texture_Normal >= 0) R_Mesh_TexBind(0, R_GetTexture(texture->skin.nmap));
        if (r_glsl_permutation->loc_Texture_Color >= 0) R_Mesh_TexBind(1, R_GetTexture(texture->basetexture));
        if (r_glsl_permutation->loc_Texture_Gloss >= 0) R_Mesh_TexBind(2, R_GetTexture(texture->glosstexture));
-       if (r_glsl_permutation->loc_Texture_FogMask >= 0) R_Mesh_TexBind(4, R_GetTexture(r_texture_fogattenuation));
+       //if (r_glsl_permutation->loc_Texture_Cube >= 0 && permutation & SHADERPERMUTATION_MODE_LIGHTSOURCE) R_Mesh_TexBindCubeMap(3, R_GetTexture(r_shadow_rtlight->currentcubemap));
+       //if (r_glsl_permutation->loc_Texture_FogMask >= 0) R_Mesh_TexBind(4, R_GetTexture(r_texture_fogattenuation));
        if (r_glsl_permutation->loc_Texture_Pants >= 0) R_Mesh_TexBind(5, R_GetTexture(texture->skin.pants));
        if (r_glsl_permutation->loc_Texture_Shirt >= 0) R_Mesh_TexBind(6, R_GetTexture(texture->skin.shirt));
+       //if (r_glsl_permutation->loc_Texture_Lightmap >= 0) R_Mesh_TexBind(7, R_GetTexture(r_texture_white));
+       //if (r_glsl_permutation->loc_Texture_Deluxemap >= 0) R_Mesh_TexBind(8, R_GetTexture(r_texture_blanknormalmap));
        if (r_glsl_permutation->loc_Texture_Glow >= 0) R_Mesh_TexBind(9, R_GetTexture(texture->skin.glow));
        if (r_glsl_permutation->loc_FogColor >= 0)
        {
@@ -1464,7 +1467,6 @@ static void R_BlendView(void)
        int screenwidth, screenheight;
        qboolean dobloom;
        qboolean doblend;
-       rmeshstate_t m;
        float vertex3f[12];
        float texcoord2f[3][8];
 
@@ -1489,9 +1491,12 @@ static void R_BlendView(void)
        vertex3f[3] = 1;vertex3f[4] = 0;vertex3f[5] = 0;
        vertex3f[6] = 1;vertex3f[7] = 1;vertex3f[8] = 0;
        vertex3f[9] = 0;vertex3f[10] = 1;vertex3f[11] = 0;
+       R_Mesh_VertexPointer(vertex3f);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
        if (dobloom)
        {
-               int bloomwidth, bloomheight, x, dobloomblend, range;
+               int bloomwidth, bloomheight, x, range;
                float xoffset, yoffset, r;
                renderstats.bloom++;
                // allocate textures as needed
@@ -1523,11 +1528,8 @@ static void R_BlendView(void)
                texcoord2f[1][5] = 0;
                texcoord2f[1][6] = 0;
                texcoord2f[1][7] = 0;
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = vertex3f;
-               m.pointer_texcoord[0] = texcoord2f[0];
-               m.tex[0] = R_GetTexture(r_bloom_texture_screen);
-               R_Mesh_State(&m);
+               R_Mesh_TexCoordPointer(0, 2, texcoord2f[0]);
+               R_Mesh_TexBind(0, R_GetTexture(r_bloom_texture_screen));
                // copy view into the full resolution screen image texture
                GL_ActiveTexture(0);
                qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.height - (r_view_y + r_view_height), r_view_width, r_view_height);
@@ -1550,11 +1552,8 @@ static void R_BlendView(void)
                }
                // we now have a darkened bloom image in the framebuffer, copy it into
                // the bloom image texture for more processing
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = vertex3f;
-               m.tex[0] = R_GetTexture(r_bloom_texture_bloom);
-               m.pointer_texcoord[0] = texcoord2f[2];
-               R_Mesh_State(&m);
+               R_Mesh_TexBind(0, R_GetTexture(r_bloom_texture_bloom));
+               R_Mesh_TexCoordPointer(0, 2, texcoord2f[2]);
                GL_ActiveTexture(0);
                qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.height - (r_view_y + bloomheight), bloomwidth, bloomheight);
                renderstats.bloom_copypixels += bloomwidth * bloomheight;
@@ -1627,49 +1626,33 @@ static void R_BlendView(void)
                qglViewport(r_view_x, vid.height - (r_view_y + r_view_height), r_view_width, r_view_height);
                // put the original screen image back in place and blend the bloom
                // texture on it
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = vertex3f;
-               m.tex[0] = R_GetTexture(r_bloom_texture_screen);
-               m.pointer_texcoord[0] = texcoord2f[0];
-#if 0
-               dobloomblend = false;
-#else
+               GL_Color(1,1,1,1);
+               GL_BlendFunc(GL_ONE, GL_ZERO);
                // do both in one pass if possible
+               R_Mesh_TexBind(0, R_GetTexture(r_bloom_texture_screen));
+               R_Mesh_TexCoordPointer(0, 2, texcoord2f[0]);
                if (r_textureunits.integer >= 2 && gl_combine.integer)
                {
-                       dobloomblend = false;
-                       m.texcombinergb[1] = GL_ADD;
-                       m.tex[1] = R_GetTexture(r_bloom_texture_bloom);
-                       m.pointer_texcoord[1] = texcoord2f[1];
+                       R_Mesh_TexCombine(1, GL_ADD, GL_ADD, 1, 1);
+                       R_Mesh_TexBind(1, R_GetTexture(r_bloom_texture_bloom));
+                       R_Mesh_TexCoordPointer(1, 2, texcoord2f[1]);
                }
                else
-                       dobloomblend = true;
-#endif
-               R_Mesh_State(&m);
-               GL_BlendFunc(GL_ONE, GL_ZERO);
-               GL_Color(1,1,1,1);
-               R_Mesh_Draw(0, 4, 2, polygonelements);
-               renderstats.bloom_drawpixels += r_view_width * r_view_height;
-               // now blend on the bloom texture if multipass
-               if (dobloomblend)
                {
-                       memset(&m, 0, sizeof(m));
-                       m.pointer_vertex = vertex3f;
-                       m.tex[0] = R_GetTexture(r_bloom_texture_bloom);
-                       m.pointer_texcoord[0] = texcoord2f[1];
-                       R_Mesh_State(&m);
-                       GL_BlendFunc(GL_ONE, GL_ONE);
-                       GL_Color(1,1,1,1);
                        R_Mesh_Draw(0, 4, 2, polygonelements);
                        renderstats.bloom_drawpixels += r_view_width * r_view_height;
+                       // now blend on the bloom texture
+                       GL_BlendFunc(GL_ONE, GL_ONE);
+                       R_Mesh_TexBind(0, R_GetTexture(r_bloom_texture_bloom));
+                       R_Mesh_TexCoordPointer(0, 2, texcoord2f[1]);
                }
+               R_Mesh_Draw(0, 4, 2, polygonelements);
+               renderstats.bloom_drawpixels += r_view_width * r_view_height;
        }
        if (doblend)
        {
                // apply a color tint to the whole view
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = vertex3f;
-               R_Mesh_State(&m);
+               R_Mesh_ResetTextureState();
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                GL_Color(r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
                R_Mesh_Draw(0, 4, 2, polygonelements);
@@ -1946,7 +1929,6 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
 {
        int i;
        float *v, *c, f1, f2, diff[3], vertex3f[8*3], color4f[8*4];
-       rmeshstate_t m;
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthTest(true);
@@ -1972,10 +1954,9 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
                        c[2] = c[2] * f1 + fogcolor[2] * f2;
                }
        }
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = vertex3f;
-       m.pointer_color = color;
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(vertex3f);
+       R_Mesh_ColorPointer(color);
+       R_Mesh_ResetTextureState();
        R_Mesh_Draw(8, 12);
 }
 */
@@ -2017,12 +1998,8 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, int surfacenu
        int i;
        float f1, f2, *c;
        float color4f[6*4];
-       rmeshstate_t m;
        R_Mesh_Matrix(&ent->matrix);
 
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = nomodelvertex3f;
-
        if (ent->flags & EF_ADDITIVE)
        {
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
@@ -2039,10 +2016,11 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, int surfacenu
                GL_DepthMask(true);
        }
        GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
+       R_Mesh_VertexPointer(nomodelvertex3f);
        if (fogenabled)
        {
                memcpy(color4f, nomodelcolor4f, sizeof(float[6*4]));
-               m.pointer_color = color4f;
+               R_Mesh_ColorPointer(color4f);
                f2 = VERTEXFOGTABLE(VectorDistance(ent->origin, r_vieworigin));
                f1 = 1 - f2;
                for (i = 0, c = color4f;i < 6;i++, c += 4)
@@ -2056,13 +2034,13 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, int surfacenu
        else if (ent->alpha != 1)
        {
                memcpy(color4f, nomodelcolor4f, sizeof(float[6*4]));
-               m.pointer_color = color4f;
+               R_Mesh_ColorPointer(color4f);
                for (i = 0, c = color4f;i < 6;i++, c += 4)
                        c[3] *= ent->alpha;
        }
        else
-               m.pointer_color = nomodelcolor4f;
-       R_Mesh_State(&m);
+               R_Mesh_ColorPointer(nomodelcolor4f);
+       R_Mesh_ResetTextureState();
        R_Mesh_Draw(0, 6, 8, nomodelelements);
 }
 
@@ -2109,7 +2087,6 @@ float spritetexcoord2f[4*2] = {0, 1, 0, 0, 1, 0, 1, 1};
 void R_DrawSprite(int blendfunc1, int blendfunc2, rtexture_t *texture, rtexture_t *fogtexture, int depthdisable, const vec3_t origin, const vec3_t left, const vec3_t up, float scalex1, float scalex2, float scaley1, float scaley2, float cr, float cg, float cb, float ca)
 {
        float fog = 0.0f, ifog;
-       rmeshstate_t m;
        float vertex3f[12];
 
        if (fogenabled)
@@ -2134,11 +2111,11 @@ void R_DrawSprite(int blendfunc1, int blendfunc2, rtexture_t *texture, rtexture_
        vertex3f[10] = origin[1] + left[1] * scalex1 + up[1] * scaley1;
        vertex3f[11] = origin[2] + left[2] * scalex1 + up[2] * scaley1;
 
-       memset(&m, 0, sizeof(m));
-       m.tex[0] = R_GetTexture(texture);
-       m.pointer_texcoord[0] = spritetexcoord2f;
-       m.pointer_vertex = vertex3f;
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(vertex3f);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
+       R_Mesh_TexBind(0, R_GetTexture(texture));
+       R_Mesh_TexCoordPointer(0, 2, spritetexcoord2f);
        GL_Color(cr * ifog, cg * ifog, cb * ifog, ca);
        R_Mesh_Draw(0, 4, 2, polygonelements);
 
@@ -2221,10 +2198,7 @@ void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *plane
 static void R_DrawCollisionBrush(colbrushf_t *brush)
 {
        int i;
-       rmeshstate_t m;
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = brush->points->v;
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(brush->points->v);
        i = (int)(((size_t)brush) / sizeof(colbrushf_t));
        GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
        GL_LockArrays(0, brush->numpoints);
@@ -2235,12 +2209,9 @@ static void R_DrawCollisionBrush(colbrushf_t *brush)
 static void R_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
 {
        int i;
-       rmeshstate_t m;
        if (!surface->num_collisiontriangles)
                return;
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = surface->data_collisionvertex3f;
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(surface->data_collisionvertex3f);
        i = (int)(((size_t)surface) / sizeof(msurface_t));
        GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
        GL_LockArrays(0, surface->num_collisionvertices);
@@ -2553,7 +2524,6 @@ static void RSurf_Draw(const msurface_t *surface)
 {
        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
        R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface_model->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
-       GL_LockArrays(0, 0);
 }
 
 static void RSurf_DrawLightmap(const msurface_t *surface, float r, float g, float b, float a, int lightmode, qboolean applycolor, qboolean applyfog)
@@ -2709,8 +2679,8 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
        {
                GL_DepthMask(true);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               memset(&m, 0, sizeof(m));
-               R_Mesh_State(&m);
+               R_Mesh_ColorPointer(NULL);
+               R_Mesh_ResetTextureState();
                RSurf_PrepareVerticesForBatch(ent, texture, modelorg, false, false, texturenumsurfaces, texturesurfacelist);
                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                {
@@ -2742,8 +2712,8 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        if (model->type == mod_brushq1 && r_q1bsp_skymasking.integer && !r_worldnovis)
                        {
                                GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
-                               memset(&m, 0, sizeof(m));
-                               R_Mesh_State(&m);
+                               R_Mesh_ColorPointer(NULL);
+                               R_Mesh_ResetTextureState();
                                if (skyrendermasked)
                                {
                                        // depth-only (masking)
@@ -2786,35 +2756,31 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_DepthMask(true);
                }
 
-               memset(&m, 0, sizeof(m));
-               R_Mesh_State(&m);
+               R_Mesh_ColorPointer(NULL);
+               R_Mesh_ResetTextureState();
                GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], texture->currentalpha);
                R_SetupSurfaceShader(ent, texture, modelorg, vec3_origin, lightmode == 2);
                if (!r_glsl_permutation)
                        return;
                RSurf_PrepareVerticesForBatch(ent, texture, modelorg, true, true, texturenumsurfaces, texturesurfacelist);
+               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
+               R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
+               R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
+               R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
                if (lightmode == 2)
                {
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
                                surface = texturesurfacelist[texturesurfaceindex];
-                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
-                               R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
-                               R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
-                               R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
                                RSurf_Draw(surface);
                        }
                }
                else
                {
+                       R_Mesh_TexCoordPointer(4, 2, model->surfmesh.data_texcoordlightmap2f);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
                                surface = texturesurfacelist[texturesurfaceindex];
-                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
-                               R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
-                               R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
-                               R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
-                               R_Mesh_TexCoordPointer(4, 2, model->surfmesh.data_texcoordlightmap2f);
                                if (surface->lightmaptexture)
                                {
                                        R_Mesh_TexBind(7, R_GetTexture(surface->lightmaptexture));
@@ -2861,6 +2827,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                VectorScale(layer->color, 1.0f, layercolor);
                        }
                        layercolor[3] = layer->color[3];
+                       R_Mesh_ColorPointer(NULL);
                        GL_Color(layercolor[0], layercolor[1], layercolor[2], layercolor[3]);
                        applycolor = layercolor[0] != 1 || layercolor[1] != 1 || layercolor[2] != 1 || layercolor[3] != 1;
                        applyfog = (layer->flags & TEXTURELAYERFLAG_FOGDARKEN) != 0;
@@ -2868,19 +2835,17 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        {
                        case TEXTURELAYERTYPE_LITTEXTURE_COMBINE:
                                memset(&m, 0, sizeof(m));
+                               m.pointer_texcoord[0] = model->surfmesh.data_texcoordlightmap2f;
                                m.tex[1] = R_GetTexture(layer->texture);
                                m.texmatrix[1] = layer->texmatrix;
                                m.texrgbscale[1] = layertexrgbscale;
-                               m.pointer_color = rsurface_array_color4f;
-                               m.pointer_vertex = rsurface_vertex3f;
-                               R_Mesh_State(&m);
+                               m.pointer_texcoord[1] = model->surfmesh.data_texcoordtexture2f;
+                               R_Mesh_TextureState(&m);
                                if (lightmode == 2)
                                {
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
-                                               R_Mesh_TexCoordPointer(1, 2, model->surfmesh.data_texcoordtexture2f);
                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                RSurf_DrawLightmap(surface, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 2, applycolor, applyfog);
                                        }
@@ -2890,8 +2855,6 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
-                                               R_Mesh_TexCoordPointer(1, 2, model->surfmesh.data_texcoordtexture2f);
                                                if (surface->lightmaptexture)
                                                {
                                                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -2909,16 +2872,14 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                memset(&m, 0, sizeof(m));
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
-                               m.pointer_color = rsurface_array_color4f;
                                m.texrgbscale[0] = layertexrgbscale;
-                               m.pointer_vertex = rsurface_vertex3f;
-                               R_Mesh_State(&m);
+                               m.pointer_texcoord[0] = model->surfmesh.data_texcoordlightmap2f;
+                               R_Mesh_TextureState(&m);
                                if (lightmode == 2)
                                {
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                RSurf_DrawLightmap(surface, 1, 1, 1, 1, 2, false, false);
                                        }
@@ -2928,7 +2889,6 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
                                                if (surface->lightmaptexture)
                                                {
                                                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -2941,18 +2901,17 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                                }
                                        }
                                }
+                               GL_LockArrays(0, 0);
                                GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
                                memset(&m, 0, sizeof(m));
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
-                               m.pointer_color = rsurface_array_color4f;
                                m.texrgbscale[0] = layertexrgbscale;
-                               m.pointer_vertex = rsurface_vertex3f;
-                               R_Mesh_State(&m);
+                               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
+                               R_Mesh_TextureState(&m);
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
-                                       R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                        RSurf_DrawLightmap(surface, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 0, applycolor, false);
                                }
                                break;
@@ -2961,15 +2920,13 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
                                m.texrgbscale[0] = layertexrgbscale;
-                               m.pointer_color = rsurface_array_color4f;
-                               m.pointer_vertex = rsurface_vertex3f;
-                               R_Mesh_State(&m);
+                               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
+                               R_Mesh_TextureState(&m);
                                if (lightmode == 2)
                                {
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                                RSurf_DrawLightmap(surface, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 2, applycolor, applyfog);
                                        }
                                }
@@ -2978,7 +2935,6 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                                RSurf_DrawLightmap(surface, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 1, applycolor, applyfog);
                                        }
                                }
@@ -2987,34 +2943,32 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                memset(&m, 0, sizeof(m));
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
-                               m.pointer_color = rsurface_array_color4f;
                                m.texrgbscale[0] = layertexrgbscale;
-                               m.pointer_vertex = rsurface_vertex3f;
-                               R_Mesh_State(&m);
+                               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
+                               R_Mesh_TextureState(&m);
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
-                                       R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                        RSurf_DrawLightmap(surface, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 0, applycolor, applyfog);
                                }
                                break;
                        case TEXTURELAYERTYPE_FOG:
-                               memset(&m, 0, sizeof(m));
+                               R_Mesh_ColorPointer(rsurface_array_color4f);
                                if (layer->texture)
                                {
+                                       memset(&m, 0, sizeof(m));
                                        m.tex[0] = R_GetTexture(layer->texture);
                                        m.texmatrix[0] = layer->texmatrix;
+                                       m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
+                                       R_Mesh_TextureState(&m);
                                }
-                               m.pointer_vertex = rsurface_vertex3f;
-                               R_Mesh_State(&m);
+                               else
+                                       R_Mesh_ResetTextureState();
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        int i;
                                        float f, *v, *c;
                                        surface = texturesurfacelist[texturesurfaceindex];
-                                       if (layer->texture)
-                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
-                                       R_Mesh_ColorPointer(rsurface_array_color4f);
                                        for (i = 0, v = (rsurface_vertex3f + 3 * surface->num_firstvertex), c = (rsurface_array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                        {
                                                f = VERTEXFOGTABLE(VectorDistance(v, modelorg));
@@ -3029,25 +2983,27 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        default:
                                Con_Printf("R_DrawTextureSurfaceList: unknown layer type %i\n", layer->type);
                        }
+                       GL_LockArrays(0, 0);
                        // if trying to do overbright on first pass of an opaque surface
                        // when combine is not supported, brighten as a post process
                        if (layertexrgbscale > 1 && !gl_combine.integer && layer->depthmask)
                        {
                                int scale;
                                GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
+                               R_Mesh_ColorPointer(NULL);
                                GL_Color(1, 1, 1, 1);
-                               memset(&m, 0, sizeof(m));
-                               m.pointer_vertex = rsurface_vertex3f;
-                               R_Mesh_State(&m);
+                               R_Mesh_ResetTextureState();
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        for (scale = 1;scale < layertexrgbscale;scale <<= 1)
                                                RSurf_Draw(surface);
                                }
+                               GL_LockArrays(0, 0);
                        }
                }
        }
+       GL_LockArrays(0, 0);
        if ((texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (ent->flags & RENDER_NOCULLFACE))
                qglEnable(GL_CULL_FACE);
 }
@@ -3207,6 +3163,8 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                msurface_t *surface;
                q3mbrush_t *brush;
                R_Mesh_Matrix(&ent->matrix);
+               R_Mesh_ColorPointer(NULL);
+               R_Mesh_ResetTextureState();
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
                GL_DepthMask(false);
                GL_DepthTest(!r_showdisabledepthtest.integer);
@@ -3224,15 +3182,14 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
        {
                int k, l;
                const int *elements;
-               rmeshstate_t m;
                vec3_t v;
                GL_DepthTest(true);
                GL_DepthMask(true);
                if (r_showdisabledepthtest.integer)
                        qglDepthFunc(GL_ALWAYS);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               memset(&m, 0, sizeof(m));
-               R_Mesh_State(&m);
+               R_Mesh_ColorPointer(NULL);
+               R_Mesh_ResetTextureState();
                for (i = 0, j = model->firstmodelsurface, surface = model->data_surfaces + j;i < model->nummodelsurfaces;i++, j++, surface++)
                {
                        if (ent == r_refdef.worldentity && !r_worldsurfacevisible[j])
index 8b5d8e5..5db3bcf 100644 (file)
@@ -342,7 +342,6 @@ static void R_DrawPortal_Callback(const entity_render_t *ent, int surfacenumber,
        const mportal_t *portal = (mportal_t *)ent;
        int i, numpoints;
        float *v;
-       rmeshstate_t m;
        float vertex3f[POLYGONELEMENTS_MAXPOINTS*3];
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
@@ -352,9 +351,9 @@ static void R_DrawPortal_Callback(const entity_render_t *ent, int surfacenumber,
 
        numpoints = min(portal->numpoints, POLYGONELEMENTS_MAXPOINTS);
 
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = vertex3f;
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(vertex3f);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
 
        i = surfacenumber;
        GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
@@ -768,7 +767,7 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                                texture = t->currentframe;
                                f = (texture->currentmaterialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT | MATERIALFLAG_WALL)) == MATERIALFLAG_WALL;
                        }
-                       if (!f && surface->num_triangles)
+                       if (f && surface->num_triangles)
                                surfacelist[numsurfacelist++] = surface;
                }
                if (numsurfacelist)
index 2f249f9..4dd9f85 100644 (file)
@@ -196,11 +196,12 @@ static void R_DrawExplosion_TransparentCallback(const entity_render_t *ent, int
        numverts = EXPLOSIONVERTS;
        alpha = e->alpha;
 
+       R_Mesh_VertexPointer(e->vert[0]);
+       R_Mesh_ColorPointer(NULL);
        memset(&m, 0, sizeof(m));
        m.tex[0] = R_GetTexture(explosiontexture);
        m.pointer_texcoord[0] = explosiontexcoord2f[0];
-       m.pointer_vertex = e->vert[0];
-       R_Mesh_State(&m);
+       R_Mesh_TextureState(&m);
 
        GL_Color(alpha, alpha, alpha, 1);
 
index 6b38c35..fb21927 100644 (file)
@@ -280,14 +280,6 @@ void R_DrawLightningBeam_TransparentCallback(const entity_render_t *ent, int sur
        // (and realize that the whole polygon assembly orients itself to face
        //  the viewer)
 
-       memset(&m, 0, sizeof(m));
-       if (r_lightningbeam_qmbtexture.integer)
-               m.tex[0] = R_GetTexture(r_lightningbeamqmbtexture);
-       else
-               m.tex[0] = R_GetTexture(r_lightningbeamtexture);
-       m.pointer_texcoord[0] = texcoord2f;
-       m.pointer_vertex = vertex3f;
-
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
        GL_DepthMask(false);
        GL_DepthTest(true);
@@ -311,18 +303,26 @@ void R_DrawLightningBeam_TransparentCallback(const entity_render_t *ent, int sur
        R_CalcLightningBeamPolygonTexCoord2f(texcoord2f + 8, t1 + 0.33, t2 + 0.33);
        R_CalcLightningBeamPolygonTexCoord2f(texcoord2f + 16, t1 + 0.66, t2 + 0.66);
 
+       R_Mesh_VertexPointer(vertex3f);
        if (fogenabled)
        {
                // per vertex colors if fog is used
-               m.pointer_color = color4f;
+               R_Mesh_ColorPointer(color4f);
                R_FogLightningBeam_Vertex3f_Color4f(vertex3f, color4f, 12, r_lightningbeam_color_red.value, r_lightningbeam_color_green.value, r_lightningbeam_color_blue.value, 1);
        }
        else
        {
                // solid color if fog is not used
+               R_Mesh_ColorPointer(NULL);
                GL_Color(r_lightningbeam_color_red.value, r_lightningbeam_color_green.value, r_lightningbeam_color_blue.value, 1);
        }
-       R_Mesh_State(&m);
+       memset(&m, 0, sizeof(m));
+       if (r_lightningbeam_qmbtexture.integer)
+               m.tex[0] = R_GetTexture(r_lightningbeamqmbtexture);
+       else
+               m.tex[0] = R_GetTexture(r_lightningbeamtexture);
+       m.pointer_texcoord[0] = texcoord2f;
+       R_Mesh_TextureState(&m);
 
        // draw the 3 polygons as one batch of 6 triangles using the 12 vertices
        GL_LockArrays(0, 12);
index d43bf7b..9ddb71f 100644 (file)
@@ -702,7 +702,6 @@ void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *inv
 
 void R_Shadow_RenderVolume(int numvertices, int numtriangles, const float *vertex3f, const int *element3i)
 {
-       rmeshstate_t m;
        if (r_shadow_compilingrtlight)
        {
                // if we're compiling an rtlight, capture the mesh
@@ -710,9 +709,7 @@ void R_Shadow_RenderVolume(int numvertices, int numtriangles, const float *verte
                return;
        }
        renderstats.lights_shadowtriangles += numtriangles;
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = vertex3f;
-       R_Mesh_State(&m);
+       R_Mesh_VertexPointer(vertex3f);
        GL_LockArrays(0, numvertices);
        if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
        {
@@ -811,8 +808,6 @@ matrix4x4_t r_shadow_entitytoattenuationz;
 
 void R_Shadow_RenderMode_Begin(void)
 {
-       rmeshstate_t m;
-
        R_Shadow_ValidateCvars();
 
        if (!r_shadow_attenuation2dtexture
@@ -821,8 +816,8 @@ void R_Shadow_RenderMode_Begin(void)
         || r_shadow_lightattenuationscale.value != r_shadow_attenscale)
                R_Shadow_MakeTextures();
 
-       memset(&m, 0, sizeof(m));
-       R_Mesh_State(&m);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(false);
        GL_DepthTest(true);
@@ -853,7 +848,6 @@ void R_Shadow_RenderMode_ActiveLight(rtlight_t *rtlight)
 
 void R_Shadow_RenderMode_Reset(void)
 {
-       rmeshstate_t m;
        if (r_shadow_rendermode == R_SHADOW_RENDERMODE_LIGHT_GLSL)
        {
                qglUseProgramObjectARB(0);
@@ -864,8 +858,8 @@ void R_Shadow_RenderMode_Reset(void)
        }
        else if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCILTWOSIDE)
                qglDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
-       memset(&m, 0, sizeof(m));
-       R_Mesh_State(&m);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
 }
 
 void R_Shadow_RenderMode_StencilShadowVolumes(void)
@@ -940,6 +934,9 @@ void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent)
                R_Mesh_TexBind(4, R_GetTexture(r_texture_fogattenuation)); // fog
                R_Mesh_TexBind(5, R_GetTexture(r_texture_white)); // pants
                R_Mesh_TexBind(6, R_GetTexture(r_texture_white)); // shirt
+               R_Mesh_TexBind(7, R_GetTexture(r_texture_white)); // lightmap
+               R_Mesh_TexBind(8, R_GetTexture(r_texture_blanknormalmap)); // deluxemap
+               R_Mesh_TexBind(9, R_GetTexture(r_texture_black)); // glow
                //R_Mesh_TexMatrix(3, r_shadow_entitytolight); // light filter matrix
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
                GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
@@ -1237,10 +1234,9 @@ static void R_Shadow_RenderSurfacesLighting_VisibleLighting(const entity_render_
        // used to display how many times a surface is lit for level design purposes
        int surfacelistindex;
        model_t *model = ent->model;
-       rmeshstate_t m;
        GL_Color(0.1, 0.025, 0, 1);
-       memset(&m, 0, sizeof(m));
-       R_Mesh_State(&m);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
        RSurf_PrepareVerticesForBatch(ent, texture, r_shadow_entityeyeorigin, false, false, numsurfaces, surfacelist);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
@@ -1258,18 +1254,17 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en
        model_t *model = ent->model;
        RSurf_PrepareVerticesForBatch(ent, texture, r_shadow_entityeyeorigin, true, true, numsurfaces, surfacelist);
        R_SetupSurfaceShader(ent, texture, r_shadow_entityeyeorigin, lightcolorbase, false);
+       R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
+       R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
+       R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
+       R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
-               const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
-               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
-               R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
-               R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
-               R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
-               GL_LockArrays(0, 0);
+               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, model->surfmesh.data_element3i + surface->num_firsttriangle * 3);
        }
+       GL_LockArrays(0, 0);
 }
 
 static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t lightcolorbase, rtexture_t *basetexture, float colorscale)
@@ -1291,7 +1286,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
        {
                // 3 3D combine path (Geforce3, Radeon 8500)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
@@ -1307,7 +1301,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
        {
                // 2 3D combine path (Geforce3, original Radeon)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
@@ -1320,7 +1313,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
        {
                // 4 2D combine path (Geforce3, Radeon 8500)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
@@ -1342,7 +1334,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
        {
                // 3 2D combine path (Geforce3, original Radeon)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
@@ -1358,14 +1349,13 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
        {
                // 2/2/2 2D combine path (any dot3 card)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
                m.texmatrix[1] = r_shadow_entitytoattenuationz;
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1373,7 +1363,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1386,7 +1375,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
        // this final code is shared
-       R_Mesh_State(&m);
+       R_Mesh_TextureState(&m);
        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
        VectorScale(lightcolorbase, colorscale, color2);
        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1417,7 +1406,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
        {
                // 3/2 3D combine path (Geforce3, Radeon 8500)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
@@ -1429,7 +1417,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.tex3d[2] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[2] = rsurface_vertex3f;
                m.texmatrix[2] = r_shadow_entitytoattenuationxyz;
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1437,7 +1425,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1453,11 +1440,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
        {
                // 1/2/2 3D combine path (original Radeon)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1465,7 +1451,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
@@ -1474,14 +1459,13 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
                R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(rsurface_array_texcoord3f + 3 * surface->num_firstvertex, surface->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_svector3f + 3 * surface->num_firstvertex, rsurface_tvector3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, r_shadow_entitylightorigin);
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
                R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1497,7 +1481,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
        {
                // 2/2 3D combine path (original Radeon)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
@@ -1506,7 +1489,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
                R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(rsurface_array_texcoord3f + 3 * surface->num_firstvertex, surface->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_svector3f + 3 * surface->num_firstvertex, rsurface_tvector3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, r_shadow_entitylightorigin);
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1514,7 +1497,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1527,7 +1509,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
        {
                // 4/2 2D combine path (Geforce3, Radeon 8500)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
@@ -1542,7 +1523,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.tex[3] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[3] = rsurface_vertex3f;
                m.texmatrix[3] = r_shadow_entitytoattenuationz;
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1550,7 +1531,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1566,14 +1546,13 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
        {
                // 2/2/2 2D combine path (any dot3 card)
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
                m.texmatrix[1] = r_shadow_entitytoattenuationz;
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1581,7 +1560,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
@@ -1590,14 +1568,13 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
                R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(rsurface_array_texcoord3f + 3 * surface->num_firstvertex, surface->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_svector3f + 3 * surface->num_firstvertex, rsurface_tvector3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, r_shadow_entitylightorigin);
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
                R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1610,7 +1587,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
        // this final code is shared
-       R_Mesh_State(&m);
+       R_Mesh_TextureState(&m);
        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
        VectorScale(lightcolorbase, colorscale, color2);
        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1637,7 +1614,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
        {
                // 2/0/0/1/2 3D combine blendsquare path
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1645,7 +1621,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
                R_Shadow_GenTexCoords_Specular_NormalCubeMap(rsurface_array_texcoord3f + 3 * surface->num_firstvertex, surface->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_svector3f + 3 * surface->num_firstvertex, rsurface_tvector3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, r_shadow_entitylightorigin, r_shadow_entityeyeorigin);
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                // this squares the result
                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
@@ -1653,9 +1629,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
                GL_LockArrays(0, 0);
 
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
-               R_Mesh_State(&m);
+               R_Mesh_ResetTextureState();
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
                // square alpha in framebuffer a few times to make it shiny
                GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
@@ -1668,18 +1642,16 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
                R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1695,7 +1667,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
        {
                // 2/0/0/2 3D combine blendsquare path
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1703,7 +1674,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
                R_Shadow_GenTexCoords_Specular_NormalCubeMap(rsurface_array_texcoord3f + 3 * surface->num_firstvertex, surface->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_svector3f + 3 * surface->num_firstvertex, rsurface_tvector3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, r_shadow_entitylightorigin, r_shadow_entityeyeorigin);
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                // this squares the result
                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
@@ -1711,9 +1682,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
                GL_LockArrays(0, 0);
 
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
-               R_Mesh_State(&m);
+               R_Mesh_ResetTextureState();
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
                // square alpha in framebuffer a few times to make it shiny
                GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
@@ -1726,7 +1695,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1739,7 +1707,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
        {
                // 2/0/0/2/2 2D combine blendsquare path
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1747,7 +1714,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
                R_Shadow_GenTexCoords_Specular_NormalCubeMap(rsurface_array_texcoord3f + 3 * surface->num_firstvertex, surface->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_svector3f + 3 * surface->num_firstvertex, rsurface_tvector3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, r_shadow_entitylightorigin, r_shadow_entityeyeorigin);
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                // this squares the result
                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
@@ -1755,9 +1722,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
                GL_LockArrays(0, 0);
 
-               memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
-               R_Mesh_State(&m);
+               R_Mesh_ResetTextureState();
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
                // square alpha in framebuffer a few times to make it shiny
                GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
@@ -1770,21 +1735,19 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
                m.texmatrix[1] = r_shadow_entitytoattenuationz;
-               R_Mesh_State(&m);
+               R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
                R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, elements);
                GL_LockArrays(0, 0);
 
                memset(&m, 0, sizeof(m));
-               m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
                m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
@@ -1796,7 +1759,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
-       R_Mesh_State(&m);
+       R_Mesh_TextureState(&m);
        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
        VectorScale(lightcolorbase, colorscale, color2);
        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
@@ -1818,6 +1781,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en
        if (!doambient && !dodiffuse && !dospecular)
                return;
        RSurf_PrepareVerticesForBatch(ent, texture, r_shadow_entityeyeorigin, true, true, numsurfaces, surfacelist);
+       R_Mesh_ColorPointer(NULL);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
@@ -1929,39 +1893,31 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t *
        VectorScale(lightcolorshirt, r_shadow_rtlight->ambientscale * 2, ambientcolorshirt);
        VectorScale(lightcolorshirt, r_shadow_rtlight->diffusescale * 2, diffusecolorshirt);
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
+       R_Mesh_ColorPointer(rsurface_array_color4f);
        memset(&m, 0, sizeof(m));
        m.tex[0] = R_GetTexture(basetexture);
+       m.texmatrix[0] = texture->currenttexmatrix;
+       m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
        if (r_textureunits.integer >= 2)
        {
-               // voodoo2
+               // voodoo2 or TNT
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.texmatrix[1] = r_shadow_entitytoattenuationxyz;
+               m.pointer_texcoord3f[1] = rsurface_vertex3f;
                if (r_textureunits.integer >= 3)
                {
-                       // Geforce3/Radeon class but not using dot3
+                       // Voodoo4 or Kyro (or Geforce3/Radeon with gl_combine off)
                        m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture);
                        m.texmatrix[2] = r_shadow_entitytoattenuationz;
+                       m.pointer_texcoord3f[2] = rsurface_vertex3f;
                }
        }
-       m.pointer_color = rsurface_array_color4f;
-       R_Mesh_State(&m);
+       R_Mesh_TextureState(&m);
        RSurf_PrepareVerticesForBatch(ent, texture, r_shadow_entityeyeorigin, true, false, numsurfaces, surfacelist);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
                // OpenGL 1.1 path (anything)
-               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
-               R_Mesh_TexMatrix(0, &texture->currenttexmatrix);
-               if (r_textureunits.integer >= 2)
-               {
-                       // voodoo2 or TNT
-                       R_Mesh_TexCoordPointer(1, 3, rsurface_vertex3f);
-                       if (r_textureunits.integer >= 3)
-                       {
-                               // Voodoo4 or Kyro (or Geforce3/Radeon with gl_combine off)
-                               R_Mesh_TexCoordPointer(2, 3, rsurface_vertex3f);
-                       }
-               }
                R_Mesh_TexBind(0, R_GetTexture(basetexture));
                R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(model, surface, diffusecolorbase, ambientcolorbase);
                if (dopants)
diff --git a/r_sky.c b/r_sky.c
index 1eecc6c..a505372 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -268,19 +268,18 @@ int skyboxelements[6*2*3] =
 static void R_SkyBox(void)
 {
        int i;
-       rmeshstate_t m;
        GL_Color(1, 1, 1, 1);
-       memset(&m, 0, sizeof(m));
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(false);
        GL_DepthTest(false); // don't modify or read zbuffer
-       m.pointer_vertex = skyboxvertex3f;
-       m.pointer_texcoord[0] = skyboxtexcoord2f;
+       R_Mesh_VertexPointer(skyboxvertex3f);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
+       R_Mesh_TexCoordPointer(0, 2, skyboxtexcoord2f);
        GL_LockArrays(0, 6*4);
        for (i = 0;i < 6;i++)
        {
-               m.tex[0] = R_GetTexture(skyboxside[i]);
-               R_Mesh_State(&m);
+               R_Mesh_TexBind(0, R_GetTexture(skyboxside[i]));
                R_Mesh_Draw(0, 6*4, 2, skyboxelements + i * 6);
        }
        GL_LockArrays(0, 0);
@@ -348,7 +347,6 @@ static void R_SkySphere(void)
 {
        float speedscale;
        static qboolean skysphereinitialized = false;
-       rmeshstate_t m;
        matrix4x4_t scroll1matrix, scroll2matrix;
        if (!skysphereinitialized)
        {
@@ -371,19 +369,19 @@ static void R_SkySphere(void)
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(true);
        GL_DepthTest(false); // don't modify or read zbuffer
-       memset(&m, 0, sizeof(m));
-       m.pointer_vertex = skysphere_vertex3f;
-       m.tex[0] = R_GetTexture(r_refdef.worldmodel->brush.solidskytexture);
-       m.pointer_texcoord[0] = skysphere_texcoord2f;
-       m.texmatrix[0] = scroll1matrix;
+       R_Mesh_VertexPointer(skysphere_vertex3f);
+       R_Mesh_ColorPointer(NULL);
+       R_Mesh_ResetTextureState();
+       R_Mesh_TexBind(0, R_GetTexture(r_refdef.worldmodel->brush.solidskytexture));
+       R_Mesh_TexCoordPointer(0, 2, skysphere_texcoord2f);
+       R_Mesh_TexMatrix(0, &scroll1matrix);
        if (r_textureunits.integer >= 2)
        {
                // one pass using GL_DECAL or GL_INTERPOLATE_ARB for alpha layer
-               m.tex[1] = R_GetTexture(r_refdef.worldmodel->brush.alphaskytexture);
-               m.texcombinergb[1] = gl_combine.integer ? GL_INTERPOLATE_ARB : GL_DECAL;
-               m.pointer_texcoord[1] = skysphere_texcoord2f;
-               m.texmatrix[1] = scroll2matrix;
-               R_Mesh_State(&m);
+               R_Mesh_TexBind(1, R_GetTexture(r_refdef.worldmodel->brush.alphaskytexture));
+               R_Mesh_TexCombine(1, gl_combine.integer ? GL_INTERPOLATE_ARB : GL_DECAL, GL_MODULATE, 1, 1);
+               R_Mesh_TexCoordPointer(1, 2, skysphere_texcoord2f);
+               R_Mesh_TexMatrix(1, &scroll2matrix);
                GL_LockArrays(0, skysphere_numverts);
                R_Mesh_Draw(0, skysphere_numverts, skysphere_numtriangles, skysphere_element3i);
                GL_LockArrays(0, 0);
@@ -391,15 +389,12 @@ static void R_SkySphere(void)
        else
        {
                // two pass
-               R_Mesh_State(&m);
                GL_LockArrays(0, skysphere_numverts);
                R_Mesh_Draw(0, skysphere_numverts, skysphere_numtriangles, skysphere_element3i);
-               GL_LockArrays(0, 0);
 
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               m.tex[0] = R_GetTexture(r_refdef.worldmodel->brush.alphaskytexture);
-               m.texmatrix[0] = scroll2matrix;
-               R_Mesh_State(&m);
+               R_Mesh_TexBind(0, R_GetTexture(r_refdef.worldmodel->brush.alphaskytexture));
+               R_Mesh_TexMatrix(0, &scroll2matrix);
                GL_LockArrays(0, skysphere_numverts);
                R_Mesh_Draw(0, skysphere_numverts, skysphere_numtriangles, skysphere_element3i);
                GL_LockArrays(0, 0);