int arrayenabled;
unsigned int arraycomponents;
const void *pointer_texcoord;
- float rgbscale, alphascale;
+ int rgbscale, alphascale;
int combinergb, combinealpha;
// FIXME: add more combine stuff
// texmatrixenabled exists only to avoid unnecessary texmatrix compares
GLboolean depthmask;
int colormask; // stored as bottom 4 bits: r g b a (3 2 1 0 order)
int depthtest;
+ int alphatest;
int scissortest;
unsigned int unit;
unsigned int clientunit;
{
memset(&gl_state, 0, sizeof(gl_state));
gl_state.depthtest = true;
+ gl_state.alphatest = false;
gl_state.blendfunc1 = GL_ONE;
gl_state.blendfunc2 = GL_ZERO;
gl_state.blend = false;
CHECKGLERROR
qglColorMask(1, 1, 1, 1);
- qglEnable(GL_CULL_FACE);CHECKGLERROR
- qglCullFace(GL_FRONT);CHECKGLERROR
- qglEnable(GL_DEPTH_TEST);CHECKGLERROR
+ qglAlphaFunc(GL_GEQUAL, 0.5);CHECKGLERROR
+ qglDisable(GL_ALPHA_TEST);CHECKGLERROR
qglBlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);CHECKGLERROR
qglDisable(GL_BLEND);CHECKGLERROR
+ qglCullFace(GL_FRONT);CHECKGLERROR
+ qglEnable(GL_CULL_FACE);CHECKGLERROR
+ qglDepthFunc(GL_LEQUAL);CHECKGLERROR
+ qglEnable(GL_DEPTH_TEST);CHECKGLERROR
qglDepthMask(gl_state.depthmask);CHECKGLERROR
qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), NULL);CHECKGLERROR
{
if (gl_state.blendfunc1 != blendfunc1 || gl_state.blendfunc2 != blendfunc2)
{
- if (r_showtrispass)
- return;
qglBlendFunc(gl_state.blendfunc1 = blendfunc1, gl_state.blendfunc2 = blendfunc2);CHECKGLERROR
if (gl_state.blendfunc2 == GL_ZERO)
{
{
if (gl_state.depthmask != state)
{
- if (r_showtrispass)
- return;
qglDepthMask(gl_state.depthmask = state);CHECKGLERROR
}
}
{
if (gl_state.depthtest != state)
{
- if (r_showtrispass && r_showdisabledepthtest.integer)
- return;
gl_state.depthtest = state;
if (gl_state.depthtest)
{
}
}
+void GL_AlphaTest(int state)
+{
+ if (gl_state.alphatest != state)
+ {
+ gl_state.alphatest = state;
+ if (gl_state.alphatest)
+ {
+ qglEnable(GL_ALPHA_TEST);CHECKGLERROR
+ }
+ else
+ {
+ qglDisable(GL_ALPHA_TEST);CHECKGLERROR
+ }
+ }
+}
+
void GL_ColorMask(int r, int g, int b, int a)
{
int state = r*8 + g*4 + b*2 + a*1;
{
if (gl_state.pointer_color || gl_state.color4f[0] != cr || gl_state.color4f[1] != cg || gl_state.color4f[2] != cb || gl_state.color4f[3] != ca)
{
- if (r_showtrispass)
- return;
gl_state.color4f[0] = cr;
gl_state.color4f[1] = cg;
gl_state.color4f[2] = cb;
}
}
-void GL_ShowTrisColor(float cr, float cg, float cb, float ca)
-{
- if (!r_showtrispass)
- return;
- r_showtrispass = 0;
- GL_Color(cr * r_showtris.value, cg * r_showtris.value, cb * r_showtris.value, ca);
- r_showtrispass = 1;
-}
-
-
void GL_LockArrays(int first, int count)
{
if (gl_state.lockrange_count != count || gl_state.lockrange_first != first)
void GL_Clear(int mask)
{
- // in showtris rendering, don't clear the color buffer as that would hide
- // the accumulated lines
- if (r_showtrispass)
- mask &= ~GL_COLOR_BUFFER_BIT;
qglClear(mask);CHECKGLERROR
}
if (!programobject)
return 0;
+ if (developer.integer >= 100)
+ {
+ int i;
+ Con_Printf("Compiling shader:\n");
+ if (vertexstrings_count)
+ {
+ Con_Printf("------ VERTEX SHADER ------\n");
+ for (i = 0;i < vertexstrings_count;i++)
+ Con_Print(vertexstrings_list[i]);
+ Con_Print("\n");
+ }
+ if (fragmentstrings_count)
+ {
+ Con_Printf("------ FRAGMENT SHADER ------\n");
+ for (i = 0;i < fragmentstrings_count;i++)
+ Con_Print(fragmentstrings_list[i]);
+ Con_Print("\n");
+ }
+ }
+
if (vertexstrings_count)
{
CHECKGLERROR
return;
}
//CHECKGLERROR
- if (r_showtrispass)
- {
- R_Mesh_Draw_ShowTris(firstvertex, numvertices, numtriangles, elements);
- return;
- }
renderstats.meshes++;
renderstats.meshes_elements += numelements;
if (gl_paranoid.integer)
void R_Mesh_ColorPointer(const float *color4f)
{
- if (r_showtrispass)
- return;
if (gl_state.pointer_color != color4f)
{
CHECKGLERROR
void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, const float *texcoord)
{
gltextureunit_t *unit = gl_state.units + unitnum;
- if (r_showtrispass)
- return;
// update array settings
if (texcoord)
{
gltextureunit_t *unit = gl_state.units + unitnum;
if (unitnum >= backendimageunits)
return;
- if (r_showtrispass)
- return;
// update 1d texture binding
if (unit->t1d != tex1d)
{
gltextureunit_t *unit = gl_state.units + unitnum;
if (unitnum >= backendimageunits)
return;
- if (r_showtrispass)
- return;
// update 1d texture binding
if (unit->t1d != texnum)
{
gltextureunit_t *unit = gl_state.units + unitnum;
if (unitnum >= backendimageunits)
return;
- if (r_showtrispass)
- return;
// update 1d texture binding
if (unit->t1d)
{
gltextureunit_t *unit = gl_state.units + unitnum;
if (unitnum >= backendimageunits)
return;
- if (r_showtrispass)
- return;
// update 1d texture binding
if (unit->t1d)
{
gltextureunit_t *unit = gl_state.units + unitnum;
if (unitnum >= backendimageunits)
return;
- if (r_showtrispass)
- return;
// update 1d texture binding
if (unit->t1d)
{
void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix)
{
gltextureunit_t *unit = gl_state.units + unitnum;
- if (r_showtrispass)
- return;
if (matrix->m[3][3])
{
// texmatrix specified, check if it is different
void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, int rgbscale, int alphascale)
{
gltextureunit_t *unit = gl_state.units + unitnum;
- if (r_showtrispass)
- return;
if (gl_combine.integer)
{
// GL_ARB_texture_env_combine
}
}
-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;
}
}
+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);
qglEnd();
CHECKGLERROR
}
-
-// FIXME: someday this should be dynamically allocated and resized?
-float varray_vertex3f[65536*3];
-float varray_svector3f[65536*3];
-float varray_tvector3f[65536*3];
-float varray_normal3f[65536*3];
-float varray_color4f[65536*4];
-float varray_texcoord2f[4][65536*2];
-float varray_texcoord3f[4][65536*3];
-int earray_element3i[65536];
-float varray_vertex3f2[65536*3];