From: havoc Date: Mon, 30 Sep 2002 06:53:30 +0000 (+0000) Subject: gl backend now has functions for color array and flat color states (GL_UseColorArray... X-Git-Tag: RELEASE_0_2_0_RC1~167 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d88ce08f9848343ae8a8302286b8307c3ec5c4aa;p=xonotic%2Fdarkplaces.git gl backend now has functions for color array and flat color states (GL_UseColorArray and GL_Color), this gets a 9.76% speed gain in bigass1 for me git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2482 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_particles.c b/cl_particles.c index 30a799c0..9995ccd8 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -1500,10 +1500,6 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2) cg *= r_colorscale; cb *= r_colorscale; - varray_color[ 0] = varray_color[ 4] = varray_color[ 8] = varray_color[12] = cr; - varray_color[ 1] = varray_color[ 5] = varray_color[ 9] = varray_color[13] = cg; - varray_color[ 2] = varray_color[ 6] = varray_color[10] = varray_color[14] = cb; - varray_color[ 3] = varray_color[ 7] = varray_color[11] = varray_color[15] = ca; varray_texcoord[0][0] = tex->s2;varray_texcoord[0][1] = tex->t1; varray_texcoord[0][2] = tex->s1;varray_texcoord[0][3] = tex->t1; varray_texcoord[0][4] = tex->s1;varray_texcoord[0][5] = tex->t2; @@ -1569,6 +1565,7 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2) glTexCoord2f(tex->s2, tex->t2);glVertex3f(varray_vertex[12], varray_vertex[13], varray_vertex[14]); glEnd(); #else + GL_Color(cr, cg, cb, ca); R_Mesh_Draw(4, 2, polygonelements); #endif } diff --git a/gl_backend.c b/gl_backend.c index d9521d4b..16088141 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -264,6 +264,7 @@ static struct int clientunit; int texture[MAX_TEXTUREUNITS]; float texturergbscale[MAX_TEXTUREUNITS]; + int colorarray; } gl_state; @@ -344,7 +345,6 @@ void GL_SetupTextureState(void) } } -int usedarrays; void GL_Backend_ResetState(void) { int i; @@ -373,8 +373,6 @@ void GL_Backend_ResetState(void) gl_state.depthmask = GL_TRUE; qglDepthMask(gl_state.depthmask);CHECKGLERROR - usedarrays = false; - usedarrays = true; qglVertexPointer(3, GL_FLOAT, sizeof(float[4]), varray_vertex);CHECKGLERROR qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR if (gl_mesh_floatcolors.integer) @@ -385,11 +383,32 @@ void GL_Backend_ResetState(void) { qglColorPointer(4, GL_UNSIGNED_BYTE, sizeof(qbyte[4]), varray_bcolor);CHECKGLERROR } - qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR + // LordHavoc: default to color array off + gl_state.colorarray = false; + GL_Color(1, 1, 1, 1); GL_SetupTextureState(); } +void GL_UseColorArray(void) +{ + if (!gl_state.colorarray) + { + gl_state.colorarray = true; + qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR + } +} + +void GL_Color(float cr, float cg, float cb, float ca) +{ + if (gl_state.colorarray) + { + gl_state.colorarray = false; + qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR + } + qglColor4f(cr, cg, cb, ca); +} + // called at beginning of frame void R_Mesh_Start(void) { @@ -511,7 +530,7 @@ void R_Mesh_Draw(int numverts, int numtriangles, int *elements) CHECKGLERROR - if (!gl_mesh_floatcolors.integer) + if (gl_state.colorarray && !gl_mesh_floatcolors.integer) GL_ConvertColorsFloatToByte(numverts); //GL_TransformVertices(numverts); if (!r_render.integer) @@ -545,27 +564,18 @@ void R_Mesh_Finish(void) } qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR - if (usedarrays) - { - qglClientActiveTexture(GL_TEXTURE0_ARB + i);CHECKGLERROR - qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR - } + qglClientActiveTexture(GL_TEXTURE0_ARB + i);CHECKGLERROR + qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR } } else { qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);CHECKGLERROR qglEnable(GL_TEXTURE_2D);CHECKGLERROR - if (usedarrays) - { - qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR - } - } - if (usedarrays) - { - qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR - qglDisableClientState(GL_VERTEX_ARRAY);CHECKGLERROR + qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR } + qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR + qglDisableClientState(GL_VERTEX_ARRAY);CHECKGLERROR qglDisable(GL_BLEND);CHECKGLERROR qglEnable(GL_DEPTH_TEST);CHECKGLERROR diff --git a/gl_backend.h b/gl_backend.h index 624df46a..cd4b85cb 100644 --- a/gl_backend.h +++ b/gl_backend.h @@ -14,6 +14,8 @@ void GL_SetupView_Orientation_Identity (void); void GL_SetupView_Orientation_FromEntity (vec3_t origin, vec3_t angles); void GL_SetupView_Mode_Perspective (double aspect, double fovx, double fovy, double zNear, double zFar); void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar); +void GL_UseColorArray(void); +void GL_Color(float cr, float cg, float cb, float ca); void GL_DepthFunc(int value); void GL_ClearDepth(void); diff --git a/gl_draw.c b/gl_draw.c index 9b3dbec8..598d9026 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -459,10 +459,6 @@ void R_DrawQueue(void) if (h == 0) h = pic->height; } - varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = cr; - varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = cg; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = cb; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = ca; varray_texcoord[0][0] = 0;varray_texcoord[0][1] = 0; varray_texcoord[0][2] = 1;varray_texcoord[0][3] = 0; varray_texcoord[0][4] = 1;varray_texcoord[0][5] = 1; @@ -471,6 +467,7 @@ void R_DrawQueue(void) varray_vertex[ 4] = x+w;varray_vertex[ 5] = y ;varray_vertex[ 6] = 10; varray_vertex[ 8] = x+w;varray_vertex[ 9] = y+h;varray_vertex[10] = 10; varray_vertex[12] = x ;varray_vertex[13] = y+h;varray_vertex[14] = 10; + GL_Color(cr, cg, cb, ca); R_Mesh_Draw(4, 2, quadelements); break; case DRAWQUEUE_STRING: @@ -482,9 +479,9 @@ void R_DrawQueue(void) R_Mesh_TextureState(&m); } batchcount = 0; - ac = varray_color; at = varray_texcoord[0]; av = varray_vertex; + GL_Color(cr, cg, cb, ca); while ((num = *str++) && x < vid.conwidth) { if (num != ' ') @@ -493,10 +490,6 @@ void R_DrawQueue(void) t = (num >> 4)*0.0625f + (0.5f / 256.0f); u = 0.0625f - (1.0f / 256.0f); v = 0.0625f - (1.0f / 256.0f); - ac[0] = ac[4] = ac[ 8] = ac[12] = cr; - ac[1] = ac[5] = ac[ 9] = ac[13] = cg; - ac[2] = ac[6] = ac[10] = ac[14] = cb; - ac[3] = ac[7] = ac[11] = ac[15] = ca; at[0] = s ;at[1] = t ; at[2] = s+u;at[3] = t ; at[4] = s+u;at[5] = t+v; @@ -513,7 +506,6 @@ void R_DrawQueue(void) { R_Mesh_Draw(batchcount * 4, batchcount * 2, quadelements); batchcount = 0; - ac = varray_color; at = varray_texcoord[0]; av = varray_vertex; } @@ -531,6 +523,7 @@ void R_DrawQueue(void) memcpy(varray_vertex, mesh->vertices, sizeof(float[4]) * mesh->numvertices); memcpy(varray_texcoord[0], mesh->texcoords, sizeof(float[2]) * mesh->numvertices); memcpy(varray_color, mesh->colors, sizeof(float[4]) * mesh->numvertices); + GL_UseColorArray(); R_Mesh_Draw(mesh->numvertices, mesh->numtriangles, mesh->indices); currentpic = "\0"; break; @@ -546,8 +539,6 @@ void R_DrawQueue(void) varray_vertex[0] = -5000;varray_vertex[1] = -5000;varray_vertex[2] = 10; varray_vertex[4] = 10000;varray_vertex[5] = -5000;varray_vertex[6] = 10; varray_vertex[8] = -5000;varray_vertex[9] = 10000;varray_vertex[10] = 10; - // alpha is 1 for all these - varray_color[3] = varray_color[7] = varray_color[11] = 1; // all the blends ignore depth memset(&m, 0, sizeof(m)); m.depthdisable = true; @@ -562,9 +553,7 @@ void R_DrawQueue(void) cr = t - 1.0f; if (cr > 1.0f) cr = 1.0f; - varray_color[0] = varray_color[4] = varray_color[ 8] = cr; - varray_color[1] = varray_color[5] = varray_color[ 9] = cr; - varray_color[2] = varray_color[6] = varray_color[10] = cr; + GL_Color(cr, cr, cr, 1); R_Mesh_Draw(3, 1, polygonelements); t *= 0.5; } @@ -574,9 +563,7 @@ void R_DrawQueue(void) m.blendfunc1 = GL_ZERO; m.blendfunc2 = GL_SRC_COLOR; R_Mesh_State(&m); - varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = t; - varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = t; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = t; + GL_Color(t, t, t, 1); R_Mesh_Draw(3, 1, polygonelements); } if (v_brightness.value >= 0.01f) @@ -584,9 +571,7 @@ void R_DrawQueue(void) m.blendfunc1 = GL_ONE; m.blendfunc2 = GL_ONE; R_Mesh_State(&m); - varray_color[0] = varray_color[4] = varray_color[ 8] = varray_color[12] = v_brightness.value; - varray_color[1] = varray_color[5] = varray_color[ 9] = varray_color[13] = v_brightness.value; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = v_brightness.value; + GL_Color(v_brightness.value, v_brightness.value, v_brightness.value, 1); R_Mesh_Draw(3, 1, polygonelements); } } diff --git a/gl_models.c b/gl_models.c index 17310919..c56ee35a 100644 --- a/gl_models.c +++ b/gl_models.c @@ -292,7 +292,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) colorscale = r_colorscale; if (gl_combine.integer) colorscale *= 0.25f; - + if (!skinframe->base && !skinframe->pants && !skinframe->shirt && !skinframe->glow) { // untextured @@ -313,6 +313,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false); aliasvert = aliasvertbuf; aliasvertcolor = aliasvertcolorbuf; + GL_UseColorArray(); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); return; } @@ -338,6 +339,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false); aliasvert = aliasvertbuf; aliasvertcolor = aliasvertcolorbuf; + GL_UseColorArray(); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); return; } @@ -380,6 +382,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) R_ModulateColors(aliasvertcolor, varray_color, model->numverts, colorscale, colorscale, colorscale); memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2])); + GL_UseColorArray(); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); } @@ -402,9 +405,12 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) blendfunc2 = GL_ONE; c_alias_polys += model->numtris; if (pantsfullbright) - R_FillColors(varray_color, model->numverts, pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale, ent->alpha); + GL_Color(pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale, ent->alpha); else + { + GL_UseColorArray(); R_ModulateColors(aliasvertcolor, varray_color, model->numverts, pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale); + } memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2])); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); @@ -427,9 +433,12 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) blendfunc2 = GL_ONE; c_alias_polys += model->numtris; if (shirtfullbright) - R_FillColors(varray_color, model->numverts, shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale, ent->alpha); + GL_Color(shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale, ent->alpha); else + { + GL_UseColorArray(); R_ModulateColors(aliasvertcolor, varray_color, model->numverts, shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale); + } memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2])); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); @@ -450,9 +459,9 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) blendfunc1 = GL_SRC_ALPHA; blendfunc2 = GL_ONE; c_alias_polys += model->numtris; - R_FillColors(varray_color, model->numverts, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, ent->alpha); memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2])); + GL_Color((1 - fog) * r_colorscale, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, ent->alpha); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); } } @@ -465,9 +474,9 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2) R_Mesh_State(&m); c_alias_polys += model->numtris; - R_FillColors(varray_color, model->numverts, fogcolor[0] * fog * r_colorscale, fogcolor[1] * fog * r_colorscale, fogcolor[2] * fog * r_colorscale, ent->alpha); memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2])); + GL_Color(fogcolor[0] * fog * r_colorscale, fogcolor[1] * fog * r_colorscale, fogcolor[2] * fog * r_colorscale, ent->alpha); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); } } @@ -500,12 +509,13 @@ void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent) R_Mesh_State(&m); R_Mesh_Matrix(&ent->matrix); R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm); - R_FillColors(varray_color, model->numverts * 2, 0.1 * r_colorscale, 0.025 * r_colorscale, 0.0125 * r_colorscale, 1); + GL_Color(0.1 * r_colorscale, 0.025 * r_colorscale, 0.0125 * r_colorscale, 1); Matrix4x4_Transform(&ent->inversematrix, r_dlight[i].origin, temp); - R_ShadowVolume(model->numverts, model->numtris, model->mdlmd2data_indices, model->mdlmd2data_triangleneighbors, temp, r_dlight[i].cullradius + model->radius - sqrt(f)); + R_ShadowVolume(model->numverts, model->numtris, model->mdlmd2data_indices, model->mdlmd2data_triangleneighbors, temp, r_dlight[i].cullradius + model->radius - sqrt(f), true); } } } + return; } lightdirection[0] = 0.5; @@ -529,7 +539,6 @@ void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent) c_alias_polys += model->numtris; R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm); - R_FillColors(varray_color, model->numverts, 0, 0, 0, 0.5); // put a light direction in the entity's coordinate space Matrix4x4_Transform3x3(&ent->inversematrix, lightdirection, projection); @@ -552,6 +561,7 @@ void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent) //if (i & 1) VectorMA(v, dist, projection, v); } + GL_Color(0, 0, 0, 0.5); R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices); } @@ -908,6 +918,7 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2) memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4])); R_ModulateColors(aliasvertcolor, varray_color, numverts, colorscale, colorscale, colorscale); memcpy(varray_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2])); + GL_UseColorArray(); R_Mesh_Draw(numverts, numtriangles, elements); if (fog) @@ -921,8 +932,8 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2) c_alias_polys += numtriangles; memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4])); - R_FillColors(varray_color, numverts, fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, ent->alpha * fog); //memcpy(mesh_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2])); + GL_Color(fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, ent->alpha * fog); R_Mesh_Draw(numverts, numtriangles, elements); } } diff --git a/gl_rmain.c b/gl_rmain.c index 1b10e6cd..dc4bd184 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -626,10 +626,6 @@ static void R_BlendView(void) R_Mesh_Matrix(&r_identitymatrix); R_Mesh_State(&m); - varray_color[0] = varray_color[4] = varray_color[8] = r_refdef.viewblend[0]; - varray_color[1] = varray_color[5] = varray_color[9] = r_refdef.viewblend[1]; - varray_color[2] = varray_color[6] = varray_color[10] = r_refdef.viewblend[2]; - varray_color[3] = varray_color[7] = varray_color[11] = r_refdef.viewblend[3]; r = 64000; varray_vertex[0] = r_origin[0] + vpn[0] * 1.5 - vright[0] * r - vup[0] * r; varray_vertex[1] = r_origin[1] + vpn[1] * 1.5 - vright[1] * r - vup[1] * r; @@ -641,6 +637,7 @@ static void R_BlendView(void) varray_vertex[8] = varray_vertex[0] + vright[0] * r; varray_vertex[9] = varray_vertex[1] + vright[1] * r; varray_vertex[10] = varray_vertex[2] + vright[2] * r; + GL_Color(r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]); R_Mesh_Draw(3, 1, polygonelements); } @@ -747,10 +744,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa varray_vertex[20] = maxs[0];varray_vertex[21] = mins[1];varray_vertex[22] = maxs[2]; varray_vertex[24] = mins[0];varray_vertex[25] = maxs[1];varray_vertex[26] = maxs[2]; varray_vertex[28] = maxs[0];varray_vertex[29] = maxs[1];varray_vertex[30] = maxs[2]; - varray_color[ 0] = varray_color[ 4] = varray_color[ 8] = varray_color[12] = varray_color[16] = varray_color[20] = varray_color[24] = varray_color[28] = cr * r_colorscale; - varray_color[ 1] = varray_color[ 5] = varray_color[ 9] = varray_color[13] = varray_color[17] = varray_color[21] = varray_color[25] = varray_color[29] = cg * r_colorscale; - varray_color[ 2] = varray_color[ 6] = varray_color[10] = varray_color[14] = varray_color[18] = varray_color[22] = varray_color[26] = varray_color[30] = cb * r_colorscale; - varray_color[ 3] = varray_color[ 7] = varray_color[11] = varray_color[15] = varray_color[19] = varray_color[23] = varray_color[27] = varray_color[31] = ca; + R_FillColors(varray_color, 8, cr * r_colorscale, cg * r_colorscale, cb * r_colorscale, ca); if (fogenabled) { for (i = 0, v = varray_vertex, c = varray_color;i < 8;i++, v += 4, c += 4) @@ -764,6 +758,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa c[2] = c[2] * f1 + fogcolor[2] * f2; } } + GL_UseColorArray(); R_Mesh_Draw(8, 12); } */ @@ -807,12 +802,12 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2) varray_vertex[12] = 0;varray_vertex[13] = 16;varray_vertex[14] = 0; varray_vertex[16] = 0;varray_vertex[17] = 0;varray_vertex[18] = -16; varray_vertex[20] = 0;varray_vertex[21] = 0;varray_vertex[22] = 16; - varray_color[ 0] = 0.00f;varray_color[ 1] = 0.00f;varray_color[ 2] = 0.50f;varray_color[ 3] = ent->alpha; - varray_color[ 4] = 0.00f;varray_color[ 5] = 0.00f;varray_color[ 6] = 0.50f;varray_color[ 7] = ent->alpha; - varray_color[ 8] = 0.00f;varray_color[ 9] = 0.50f;varray_color[10] = 0.00f;varray_color[11] = ent->alpha; - varray_color[12] = 0.00f;varray_color[13] = 0.50f;varray_color[14] = 0.00f;varray_color[15] = ent->alpha; - varray_color[16] = 0.50f;varray_color[17] = 0.00f;varray_color[18] = 0.00f;varray_color[19] = ent->alpha; - varray_color[20] = 0.50f;varray_color[21] = 0.00f;varray_color[22] = 0.00f;varray_color[23] = ent->alpha; + varray_color[ 0] = 0.00f * r_colorscale;varray_color[ 1] = 0.00f * r_colorscale;varray_color[ 2] = 0.50f * r_colorscale;varray_color[ 3] = ent->alpha; + varray_color[ 4] = 0.00f * r_colorscale;varray_color[ 5] = 0.00f * r_colorscale;varray_color[ 6] = 0.50f * r_colorscale;varray_color[ 7] = ent->alpha; + varray_color[ 8] = 0.00f * r_colorscale;varray_color[ 9] = 0.50f * r_colorscale;varray_color[10] = 0.00f * r_colorscale;varray_color[11] = ent->alpha; + varray_color[12] = 0.00f * r_colorscale;varray_color[13] = 0.50f * r_colorscale;varray_color[14] = 0.00f * r_colorscale;varray_color[15] = ent->alpha; + varray_color[16] = 0.50f * r_colorscale;varray_color[17] = 0.00f * r_colorscale;varray_color[18] = 0.00f * r_colorscale;varray_color[19] = ent->alpha; + varray_color[20] = 0.50f * r_colorscale;varray_color[21] = 0.00f * r_colorscale;varray_color[22] = 0.00f * r_colorscale;varray_color[23] = ent->alpha; if (fogenabled) { VectorSubtract(ent->origin, r_origin, diff); @@ -834,6 +829,7 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2) c[2] *= r_colorscale; } } + GL_UseColorArray(); R_Mesh_Draw(6, 8, element); } diff --git a/gl_rsurf.c b/gl_rsurf.c index b827c2ed..314429c0 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -791,10 +791,7 @@ static void RSurfShader_Sky(const entity_render_t *ent, const texture_t *texture { R_Mesh_ResizeCheck(mesh->numverts); memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); - if (skyrendermasked) - memset(varray_color, 0, mesh->numverts * sizeof(float[4])); - else - R_FillColors(varray_color, mesh->numverts, fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, 1); + GL_Color(fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, 1); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index); } } @@ -837,6 +834,7 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2) colorscale *= 0.25f; } R_Mesh_State(&m); + GL_UseColorArray(); for (mesh = surf->mesh;mesh;mesh = mesh->chain) { R_Mesh_ResizeCheck(mesh->numverts); @@ -923,6 +921,7 @@ static void RSurfShader_Wall_Pass_BaseVertex(const entity_render_t *ent, const m } base = ent->effects & EF_FULLBRIGHT ? 2.0f : r_ambient.value * (1.0f / 64.0f); R_Mesh_State(&m); + GL_UseColorArray(); for (mesh = surf->mesh;mesh;mesh = mesh->chain) { R_Mesh_ResizeCheck(mesh->numverts); @@ -965,6 +964,7 @@ static void RSurfShader_Wall_Pass_BaseFullbright(const entity_render_t *ent, con } m.tex[0] = R_GetTexture(surf->currenttexture->texture); R_Mesh_State(&m); + GL_UseColorArray(); for (mesh = surf->mesh;mesh;mesh = mesh->chain) { R_Mesh_ResizeCheck(mesh->numverts); @@ -986,6 +986,7 @@ static void RSurfShader_Wall_Pass_Glow(const entity_render_t *ent, const msurfac m.blendfunc2 = GL_ONE; m.tex[0] = R_GetTexture(surf->currenttexture->glowtexture); R_Mesh_State(&m); + GL_UseColorArray(); for (mesh = surf->mesh;mesh;mesh = mesh->chain) { R_Mesh_ResizeCheck(mesh->numverts); @@ -1007,6 +1008,7 @@ static void RSurfShader_Wall_Pass_Fog(const entity_render_t *ent, const msurface m.blendfunc2 = GL_ONE; m.tex[0] = R_GetTexture(surf->currenttexture->fogtexture); R_Mesh_State(&m); + GL_UseColorArray(); for (mesh = surf->mesh;mesh;mesh = mesh->chain) { R_Mesh_ResizeCheck(mesh->numverts); @@ -1035,6 +1037,8 @@ static void RSurfShader_OpaqueWall_Pass_BaseTripleTexCombine(const entity_render m.texrgbscale[1] = 4; m.texrgbscale[2] = 2; R_Mesh_State(&m); + cl = (float) (1 << r_lightmapscalebit) * r_colorscale; + GL_Color(cl, cl, cl, 1); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { lightmaptexturenum = R_GetTexture(surf->lightmaptexture); @@ -1050,8 +1054,6 @@ static void RSurfShader_OpaqueWall_Pass_BaseTripleTexCombine(const entity_render memcpy(varray_texcoord[0], mesh->st, mesh->numverts * sizeof(float[2])); memcpy(varray_texcoord[1], mesh->uv, mesh->numverts * sizeof(float[2])); memcpy(varray_texcoord[2], mesh->ab, mesh->numverts * sizeof(float[2])); - cl = (float) (1 << r_lightmapscalebit) * r_colorscale; - R_FillColors(varray_color, mesh->numverts, cl, cl, cl, 1); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index); } } @@ -1071,6 +1073,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseDoubleTex(const entity_render_t *ent if (gl_combine.integer) m.texrgbscale[1] = 4; R_Mesh_State(&m); + GL_Color(r_colorscale, r_colorscale, r_colorscale, 1); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { lightmaptexturenum = R_GetTexture(surf->lightmaptexture); @@ -1085,7 +1088,6 @@ static void RSurfShader_OpaqueWall_Pass_BaseDoubleTex(const entity_render_t *ent memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], mesh->st, mesh->numverts * sizeof(float[2])); memcpy(varray_texcoord[1], mesh->uv, mesh->numverts * sizeof(float[2])); - R_FillColors(varray_color, mesh->numverts, r_colorscale, r_colorscale, r_colorscale, 1); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index); } } @@ -1101,6 +1103,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseTexture(const entity_render_t *ent, m.blendfunc2 = GL_ZERO; m.tex[0] = R_GetTexture(texture->texture); R_Mesh_State(&m); + GL_Color(1, 1, 1, 1); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { for (mesh = surf->mesh;mesh;mesh = mesh->chain) @@ -1108,7 +1111,6 @@ static void RSurfShader_OpaqueWall_Pass_BaseTexture(const entity_render_t *ent, R_Mesh_ResizeCheck(mesh->numverts); memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], mesh->st, mesh->numverts * sizeof(float[2])); - R_FillColors(varray_color, mesh->numverts, 1, 1, 1, 1); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index); } } @@ -1127,6 +1129,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseLightmap(const entity_render_t *ent, if (gl_combine.integer) m.texrgbscale[0] = 4; R_Mesh_State(&m); + GL_Color(r_colorscale, r_colorscale, r_colorscale, 1); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { lightmaptexturenum = R_GetTexture(surf->lightmaptexture); @@ -1140,7 +1143,6 @@ static void RSurfShader_OpaqueWall_Pass_BaseLightmap(const entity_render_t *ent, R_Mesh_ResizeCheck(mesh->numverts); memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], mesh->uv, mesh->numverts * sizeof(float[2])); - R_FillColors(varray_color, mesh->numverts, r_colorscale, r_colorscale, r_colorscale, 1); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index); } } @@ -1164,6 +1166,7 @@ static void RSurfShader_OpaqueWall_Pass_Light(const entity_render_t *ent, const colorscale *= 0.25f; } R_Mesh_State(&m); + GL_UseColorArray(); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { if (surf->dlightframe == r_framecount) @@ -1196,6 +1199,7 @@ static void RSurfShader_OpaqueWall_Pass_Fog(const entity_render_t *ent, const te m.blendfunc1 = GL_SRC_ALPHA; m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA; R_Mesh_State(&m); + GL_UseColorArray(); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { for (mesh = surf->mesh;mesh;mesh = mesh->chain) @@ -1220,6 +1224,7 @@ static void RSurfShader_OpaqueWall_Pass_BaseDetail(const entity_render_t *ent, c m.blendfunc2 = GL_SRC_COLOR; m.tex[0] = R_GetTexture(texture->detailtexture); R_Mesh_State(&m); + GL_Color(1, 1, 1, 1); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { for (mesh = surf->mesh;mesh;mesh = mesh->chain) @@ -1227,7 +1232,6 @@ static void RSurfShader_OpaqueWall_Pass_BaseDetail(const entity_render_t *ent, c R_Mesh_ResizeCheck(mesh->numverts); memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], mesh->ab, mesh->numverts * sizeof(float[2])); - R_FillColors(varray_color, mesh->numverts, 1, 1, 1, 1); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index); } } @@ -1243,6 +1247,7 @@ static void RSurfShader_OpaqueWall_Pass_Glow(const entity_render_t *ent, const t m.blendfunc2 = GL_ONE; m.tex[0] = R_GetTexture(texture->glowtexture); R_Mesh_State(&m); + GL_Color(r_colorscale, r_colorscale, r_colorscale, 1); for (surf = texture->surfacechain;surf;surf = surf->texturechain) { for (mesh = surf->mesh;mesh;mesh = mesh->chain) @@ -1250,7 +1255,6 @@ static void RSurfShader_OpaqueWall_Pass_Glow(const entity_render_t *ent, const t R_Mesh_ResizeCheck(mesh->numverts); memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); memcpy(varray_texcoord[0], mesh->st, mesh->numverts * sizeof(float[2])); - R_FillColors(varray_color, mesh->numverts, r_colorscale, r_colorscale, r_colorscale, 1); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index); } } @@ -1484,11 +1488,10 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2) R_Mesh_State(&m); R_Mesh_ResizeCheck(portal->numpoints); i = portal - ent->model->portals; - R_FillColors(varray_color, portal->numpoints, - ((i & 0x0007) >> 0) * (1.0f / 7.0f) * r_colorscale, - ((i & 0x0038) >> 3) * (1.0f / 7.0f) * r_colorscale, - ((i & 0x01C0) >> 6) * (1.0f / 7.0f) * r_colorscale, - 0.125f); + GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f) * r_colorscale, + ((i & 0x0038) >> 3) * (1.0f / 7.0f) * r_colorscale, + ((i & 0x01C0) >> 6) * (1.0f / 7.0f) * r_colorscale, + 0.125f); if (PlaneDiff(r_origin, (&portal->plane)) > 0) { for (i = portal->numpoints - 1, v = varray_vertex;i >= 0;i--, v += 4) diff --git a/glquake.h b/glquake.h index 120da2c9..18e75d9e 100644 --- a/glquake.h +++ b/glquake.h @@ -321,7 +321,7 @@ extern void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei strid extern void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); extern void (GLAPIENTRY *qglArrayElement)(GLint i); -extern void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +extern void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); extern void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t); extern void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y); extern void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z); diff --git a/r_crosshairs.c b/r_crosshairs.c index ccd49fee..2de8d9b9 100644 --- a/r_crosshairs.c +++ b/r_crosshairs.c @@ -41,10 +41,7 @@ void R_DrawCrosshairSprite(rtexture_t *texture, vec3_t origin, vec_t scale, floa R_Mesh_Matrix(&r_identitymatrix); R_Mesh_State(&m); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = cr * r_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = cg * r_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = cb * r_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = ca; + GL_Color(cr * r_colorscale, cg * r_colorscale, cb * r_colorscale, ca); varray_texcoord[0][0] = 0; varray_texcoord[0][1] = 0; varray_texcoord[0][2] = 0; diff --git a/r_explosion.c b/r_explosion.c index 50c3d66f..6dac84ca 100644 --- a/r_explosion.c +++ b/r_explosion.c @@ -241,6 +241,7 @@ void R_DrawExplosionCallback(const void *calldata1, int calldata2) c[3] = 1; } } + GL_UseColorArray(); R_Mesh_Draw(numverts, numtriangles, explosiontris[0]); } diff --git a/r_light.c b/r_light.c index f0660972..b06f3cb9 100644 --- a/r_light.c +++ b/r_light.c @@ -167,10 +167,7 @@ void R_DrawCoronas(void) VectorSubtract(rd->origin, r_origin, diff); scale *= 1 - exp(fogdensity/DotProduct(diff,diff)); } - varray_color[ 0] = varray_color[ 4] = varray_color[ 8] = varray_color[12] = rd->light[0] * scale; - varray_color[ 1] = varray_color[ 5] = varray_color[ 9] = varray_color[13] = rd->light[1] * scale; - varray_color[ 2] = varray_color[ 6] = varray_color[10] = varray_color[14] = rd->light[2] * scale; - varray_color[ 3] = varray_color[ 7] = varray_color[11] = varray_color[15] = 1; + GL_Color(rd->light[0] * scale, rd->light[1] * scale, rd->light[2] * scale, 1); varray_texcoord[0][0] = 0; varray_texcoord[0][1] = 0; varray_texcoord[0][2] = 0; diff --git a/r_shadow.c b/r_shadow.c index f18b1558..153867fd 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -36,7 +36,7 @@ void R_Shadow_Init(void) R_RegisterModule("R_Shadow", r_shadow_start, r_shadow_shutdown, r_shadow_newmap); } -void R_ShadowVolume(int numverts, int numtris, int *elements, int *neighbors, vec3_t relativelightorigin, float projectdistance) +void R_ShadowVolume(int numverts, int numtris, int *elements, int *neighbors, vec3_t relativelightorigin, float projectdistance, int visiblevolume) { int i, *e, *n, *out, tris; float *v0, *v1, *v2, dir0[3], dir1[3], temp[3], f; @@ -164,5 +164,24 @@ void R_ShadowVolume(int numverts, int numtris, int *elements, int *neighbors, ve } } // draw the volume - R_Mesh_Draw(numverts * 2, tris, shadowelements); + if (visiblevolume) + { + qglDisable(GL_CULL_FACE); + R_Mesh_Draw(numverts * 2, tris, shadowelements); + qglEnable(GL_CULL_FACE); + } + else + { + qglCullFace(GL_FRONT); + //qglStencilFunc( + } +} + +void R_Shadow_BeginScene(void) +{ + rmeshstate_t m; + memset(&m, 0, sizeof(m)); + m.blendfunc1 = GL_ONE; + m.blendfunc2 = GL_ZERO; + R_Mesh_State(&m); } diff --git a/r_shadow.h b/r_shadow.h index 96586cb5..42e80ba1 100644 --- a/r_shadow.h +++ b/r_shadow.h @@ -3,6 +3,6 @@ #define R_SHADOW_H void R_Shadow_Init(void); -void R_ShadowVolume(int numverts, int numtris, int *elements, int *neighbors, vec3_t relativelightorigin, float projectdistance); +void R_ShadowVolume(int numverts, int numtris, int *elements, int *neighbors, vec3_t relativelightorigin, float projectdistance, int visiblevolume); #endif diff --git a/r_sky.c b/r_sky.c index 25fa9fd5..9b237f90 100644 --- a/r_sky.c +++ b/r_sky.c @@ -132,10 +132,7 @@ static void R_SkyBox(void) m.tex[0] = R_GetTexture(skyboxside[3]); // front R_Mesh_State(&m); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = r_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = r_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = r_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = 1; + GL_Color(r_colorscale, r_colorscale, r_colorscale, 1); R_SkyBoxPolyVec(0, 1, 0, 1, -1, 1); R_SkyBoxPolyVec(1, 1, 1, 1, -1, -1); @@ -229,15 +226,11 @@ static void skyspherecalc(float *sphere, float dx, float dy, float dz) } } -static void skyspherearrays(float *v, float *t, float *c, float *source, float s, float colorscale) +static void skyspherearrays(float *v, float *t, float *source, float s) { int i; - for (i = 0;i < (skygridx1*skygridy1);i++, c += 4, t += 2, v += 4, source += 5) + for (i = 0;i < (skygridx1*skygridy1);i++, t += 2, v += 4, source += 5) { - c[0] = colorscale; - c[1] = colorscale; - c[2] = colorscale; - c[3] = 1; t[0] = source[0] + s; t[1] = source[1] + s; v[0] = source[2]; @@ -275,7 +268,9 @@ static void R_SkySphere(void) m.tex[0] = R_GetTexture(solidskytexture); R_Mesh_State(&m); - skyspherearrays(varray_vertex, varray_texcoord[0], varray_color, skysphere, speedscale, r_colorscale); + GL_Color(r_colorscale, r_colorscale, r_colorscale, 1); + + skyspherearrays(varray_vertex, varray_texcoord[0], skysphere, speedscale); R_Mesh_Draw(numverts, numtriangles, skysphereindices); m.blendfunc1 = GL_SRC_ALPHA; @@ -283,7 +278,7 @@ static void R_SkySphere(void) m.tex[0] = R_GetTexture(alphaskytexture); R_Mesh_State(&m); - skyspherearrays(varray_vertex, varray_texcoord[0], varray_color, skysphere, speedscale2, r_colorscale); + skyspherearrays(varray_vertex, varray_texcoord[0], skysphere, speedscale2); R_Mesh_Draw(numverts, numtriangles, skysphereindices); } diff --git a/r_sprites.c b/r_sprites.c index a5654007..b9798058 100644 --- a/r_sprites.c +++ b/r_sprites.c @@ -89,10 +89,6 @@ static void R_DrawSpriteImage (int additive, mspriteframe_t *frame, int texture, m.tex[0] = texture; R_Mesh_State(&m); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = red * r_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = green * r_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = blue * r_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = alpha; varray_texcoord[0][0] = 0; varray_texcoord[0][1] = 1; varray_texcoord[0][2] = 0; @@ -114,6 +110,7 @@ static void R_DrawSpriteImage (int additive, mspriteframe_t *frame, int texture, varray_vertex[12] = origin[0] + frame->down * up[0] - frame->right * left[0]; varray_vertex[13] = origin[1] + frame->down * up[1] - frame->right * left[1]; varray_vertex[14] = origin[2] + frame->down * up[2] - frame->right * left[2]; + GL_Color(red * r_colorscale, green * r_colorscale, blue * r_colorscale, alpha); R_Mesh_Draw(4, 2, polygonelements); } diff --git a/vid_shared.c b/vid_shared.c index 0806ce06..4ae9663a 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -107,7 +107,7 @@ void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, cons void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); void (GLAPIENTRY *qglArrayElement)(GLint i); -void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t); void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y); void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z); @@ -229,7 +229,7 @@ static gl_extensionfunctionlist_t opengl110funcs[] = {"glColorPointer", (void **) &qglColorPointer}, {"glTexCoordPointer", (void **) &qglTexCoordPointer}, {"glArrayElement", (void **) &qglArrayElement}, - {"glColor4ub", (void **) &qglColor4ub}, + {"glColor4f", (void **) &qglColor4f}, {"glTexCoord2f", (void **) &qglTexCoord2f}, {"glVertex2f", (void **) &qglVertex2f}, {"glVertex3f", (void **) &qglVertex3f},