X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=gl_backend.c;h=8e00108cbb92b5549e6f7be20fcc837c0b60de18;hb=323b17db9329c0c4e1f3832f9cacf9102659b7c5;hp=de7c0c254dce9514e0176d0c8703b59a63eb3a68;hpb=ba6a3d3c2759a59480bd2db8a16b2754fa038785;p=xonotic%2Fdarkplaces.git diff --git a/gl_backend.c b/gl_backend.c index de7c0c25..8e00108c 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -6,7 +6,6 @@ cvar_t gl_mesh_drawrangeelements = {0, "gl_mesh_drawrangeelements", "1", "use gl cvar_t gl_mesh_testarrayelement = {0, "gl_mesh_testarrayelement", "0", "use glBegin(GL_TRIANGLES);glArrayElement();glEnd(); primitives instead of glDrawElements (useful to test for driver bugs with glDrawElements)"}; cvar_t gl_mesh_testmanualfeeding = {0, "gl_mesh_testmanualfeeding", "0", "use glBegin(GL_TRIANGLES);glTexCoord2f();glVertex3f();glEnd(); primitives instead of glDrawElements (useful to test for driver bugs with glDrawElements)"}; cvar_t gl_mesh_prefer_short_elements = {0, "gl_mesh_prefer_short_elements", "1", "use GL_UNSIGNED_SHORT element arrays instead of GL_UNSIGNED_INT"}; -cvar_t gl_workaround_mac_texmatrix = {0, "gl_workaround_mac_texmatrix", "0", "if set to 1 this uses glLoadMatrixd followed by glLoadIdentity to clear a texture matrix (normally glLoadIdentity is sufficient by itself), if set to 2 it uses glLoadMatrixd without glLoadIdentity"}; cvar_t gl_paranoid = {0, "gl_paranoid", "0", "enables OpenGL error checking and other tests"}; cvar_t gl_printcheckerror = {0, "gl_printcheckerror", "0", "prints all OpenGL error checks, useful to identify location of driver crashes"}; @@ -16,7 +15,7 @@ cvar_t gl_polyblend = {CVAR_SAVE, "gl_polyblend", "1", "tints view while underwa cvar_t gl_dither = {CVAR_SAVE, "gl_dither", "1", "enables OpenGL dithering (16bit looks bad with this off)"}; cvar_t gl_lockarrays = {0, "gl_lockarrays", "0", "enables use of glLockArraysEXT, may cause glitches with some broken drivers, and may be slower than normal"}; cvar_t gl_lockarrays_minimumvertices = {0, "gl_lockarrays_minimumvertices", "1", "minimum number of vertices required for use of glLockArraysEXT, setting this too low may reduce performance"}; -cvar_t gl_vbo = {CVAR_SAVE, "gl_vbo", "1", "make use of GL_ARB_vertex_buffer_object extension to store static geometry in video memory for faster rendering"}; +cvar_t gl_vbo = {CVAR_SAVE, "gl_vbo", "3", "make use of GL_ARB_vertex_buffer_object extension to store static geometry in video memory for faster rendering, 0 disables VBO allocation or use, 1 enables VBOs for vertex and triangle data, 2 only for vertex data, 3 for vertex data and triangle data of simple meshes (ones with only one surface)"}; cvar_t v_flipped = {0, "v_flipped", "0", "mirror the screen (poor man's left handed mode)"}; qboolean v_flipped_state = false; @@ -256,7 +255,6 @@ void gl_backend_init(void) Cvar_RegisterVariable(&gl_vbo); Cvar_RegisterVariable(&gl_paranoid); Cvar_RegisterVariable(&gl_printcheckerror); - Cvar_RegisterVariable(&gl_workaround_mac_texmatrix); #ifdef NORENDER Cvar_SetValue("r_render", 0); #endif @@ -526,6 +524,7 @@ static struct gl_state_s int alphatest; int scissortest; unsigned int unit; + unsigned int clientunit; gltextureunit_t units[MAX_TEXTUREUNITS]; float color4f[4]; int lockrange_first; @@ -570,6 +569,7 @@ void GL_SetupTextureState(void) gltextureunit_t *unit; CHECKGLERROR gl_state.unit = MAX_TEXTUREUNITS; + gl_state.clientunit = MAX_TEXTUREUNITS; for (i = 0;i < MAX_TEXTUREUNITS;i++) { unit = gl_state.units + i; @@ -607,7 +607,7 @@ void GL_SetupTextureState(void) for (i = 0;i < backendarrayunits;i++) { - GL_ActiveTexture(i); + GL_ClientActiveTexture(i); GL_BindVBO(0); qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), NULL);CHECKGLERROR qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR @@ -717,7 +717,20 @@ void GL_ActiveTexture(unsigned int num) { CHECKGLERROR qglActiveTexture(GL_TEXTURE0_ARB + gl_state.unit); - qglClientActiveTexture(GL_TEXTURE0_ARB + gl_state.unit); + CHECKGLERROR + } + } +} + +void GL_ClientActiveTexture(unsigned int num) +{ + if (gl_state.clientunit != num) + { + gl_state.clientunit = num; + if (qglActiveTexture) + { + CHECKGLERROR + qglClientActiveTexture(GL_TEXTURE0_ARB + gl_state.clientunit); CHECKGLERROR } } @@ -1077,7 +1090,8 @@ void R_Mesh_Draw(int firstvertex, int numvertices, int firsttriangle, int numtri unsigned int numelements = numtriangles * 3; if (numvertices < 3 || numtriangles < 1) { - Con_Printf("R_Mesh_Draw(%d, %d, %d, %d, %8p, %8p, %i, %i);\n", firstvertex, numvertices, firsttriangle, numtriangles, element3i, element3s, bufferobject3i, bufferobject3s); + if (numvertices < 0 || numtriangles < 0 || developer.integer >= 100) + Con_Printf("R_Mesh_Draw(%d, %d, %d, %d, %8p, %8p, %i, %i);\n", firstvertex, numvertices, firsttriangle, numtriangles, element3i, element3s, bufferobject3i, bufferobject3s); return; } if (!gl_mesh_prefer_short_elements.integer) @@ -1136,7 +1150,7 @@ void R_Mesh_Draw(int firstvertex, int numvertices, int firsttriangle, int numtri { if (gl_state.units[i].arrayenabled) { - GL_ActiveTexture(i); + GL_ClientActiveTexture(i); if (!qglIsEnabled(GL_TEXTURE_COORD_ARRAY)) Con_Print("R_Mesh_Draw: texcoord array set but not enabled\n"); CHECKGLERROR @@ -1393,7 +1407,7 @@ int R_Mesh_CreateStaticBufferObject(unsigned int target, void *data, size_t size } qglBufferDataARB(target, size, data, GL_STATIC_DRAW_ARB); - info = Mem_ExpandableArray_AllocRecord(&gl_bufferobjectinfoarray); + info = (gl_bufferobjectinfo_t *) Mem_ExpandableArray_AllocRecord(&gl_bufferobjectinfoarray); memset(info, 0, sizeof(*info)); info->target = target; info->object = bufferobject; @@ -1413,7 +1427,7 @@ void R_Mesh_DestroyBufferObject(int bufferobject) endindex = Mem_ExpandableArray_IndexRange(&gl_bufferobjectinfoarray); for (i = 0;i < endindex;i++) { - info = Mem_ExpandableArray_RecordAtIndex(&gl_bufferobjectinfoarray, i); + info = (gl_bufferobjectinfo_t *) Mem_ExpandableArray_RecordAtIndex(&gl_bufferobjectinfoarray, i); if (!info) continue; if (info->object == bufferobject) @@ -1433,7 +1447,7 @@ void GL_Mesh_ListVBOs(qboolean printeach) endindex = Mem_ExpandableArray_IndexRange(&gl_bufferobjectinfoarray); for (i = 0;i < endindex;i++) { - info = Mem_ExpandableArray_RecordAtIndex(&gl_bufferobjectinfoarray, i); + info = (gl_bufferobjectinfo_t *) Mem_ExpandableArray_RecordAtIndex(&gl_bufferobjectinfoarray, i); if (!info) continue; switch(info->target) @@ -1529,7 +1543,7 @@ void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, co if (!unit->arrayenabled) { unit->arrayenabled = true; - GL_ActiveTexture(unitnum); + GL_ClientActiveTexture(unitnum); qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR } // texcoord array @@ -1539,7 +1553,7 @@ void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, co unit->pointer_texcoord_buffer = bufferobject; unit->pointer_texcoord_offset = bufferoffset; unit->arraycomponents = numcomponents; - GL_ActiveTexture(unitnum); + GL_ClientActiveTexture(unitnum); GL_BindVBO(bufferobject); qglTexCoordPointer(unit->arraycomponents, GL_FLOAT, sizeof(float) * unit->arraycomponents, bufferobject ? (void *)bufferoffset : texcoord);CHECKGLERROR } @@ -1550,7 +1564,7 @@ void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, co if (unit->arrayenabled) { unit->arrayenabled = false; - GL_ActiveTexture(unitnum); + GL_ClientActiveTexture(unitnum); qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR } } @@ -1968,11 +1982,6 @@ void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix) Matrix4x4_ToArrayDoubleGL(&unit->matrix, glmatrix); GL_ActiveTexture(unitnum); qglMatrixMode(GL_TEXTURE);CHECKGLERROR - if (gl_workaround_mac_texmatrix.integer & 4) - { - qglActiveTexture(GL_TEXTURE0_ARB + gl_state.unit); - qglClientActiveTexture(GL_TEXTURE0_ARB + gl_state.unit); - } qglLoadMatrixd(glmatrix);CHECKGLERROR qglMatrixMode(GL_MODELVIEW);CHECKGLERROR } @@ -1988,14 +1997,6 @@ void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix) GL_ActiveTexture(unitnum); qglMatrixMode(GL_TEXTURE);CHECKGLERROR qglLoadIdentity();CHECKGLERROR - if (gl_workaround_mac_texmatrix.integer) - { - qglActiveTexture(GL_TEXTURE0_ARB + gl_state.unit); - qglClientActiveTexture(GL_TEXTURE0_ARB + gl_state.unit); - qglLoadMatrixd(gl_identitymatrix);CHECKGLERROR - if (gl_workaround_mac_texmatrix.integer & 1) - qglLoadIdentity();CHECKGLERROR - } qglMatrixMode(GL_MODELVIEW);CHECKGLERROR } } @@ -2153,7 +2154,7 @@ void R_Mesh_ResetTextureState(void) if (unit->arrayenabled) { unit->arrayenabled = false; - GL_ActiveTexture(unitnum); + GL_ClientActiveTexture(unitnum); qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR } } @@ -2166,8 +2167,8 @@ void R_Mesh_ResetTextureState(void) unit->texmatrixenabled = false; unit->matrix = identitymatrix; CHECKGLERROR - qglMatrixMode(GL_TEXTURE);CHECKGLERROR GL_ActiveTexture(unitnum); + qglMatrixMode(GL_TEXTURE);CHECKGLERROR qglLoadIdentity();CHECKGLERROR qglMatrixMode(GL_MODELVIEW);CHECKGLERROR }