3 #include "cl_collision.h"
5 cvar_t gl_mesh_drawrangeelements = {0, "gl_mesh_drawrangeelements", "1", "use glDrawRangeElements function if available instead of glDrawElements (for performance comparisons or bug testing)"};
6 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)"};
7 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)"};
8 cvar_t gl_paranoid = {0, "gl_paranoid", "0", "enables OpenGL error checking and other tests"};
9 cvar_t gl_printcheckerror = {0, "gl_printcheckerror", "0", "prints all OpenGL error checks, useful to identify location of driver crashes"};
11 cvar_t r_render = {0, "r_render", "1", "enables rendering calls (you want this on!)"};
12 cvar_t r_waterwarp = {CVAR_SAVE, "r_waterwarp", "1", "warp view while underwater"};
13 cvar_t gl_polyblend = {CVAR_SAVE, "gl_polyblend", "1", "tints view while underwater, hurt, etc"};
14 cvar_t gl_dither = {CVAR_SAVE, "gl_dither", "1", "enables OpenGL dithering (16bit looks bad with this off)"};
15 cvar_t gl_lockarrays = {0, "gl_lockarrays", "1", "enables use of glLockArraysEXT, may cause glitches with some broken drivers"};
17 int gl_maxdrawrangeelementsvertices;
18 int gl_maxdrawrangeelementsindices;
23 void GL_PrintError(int errornumber, char *filename, int linenumber)
27 #ifdef GL_INVALID_ENUM
29 Con_Printf("GL_INVALID_ENUM at %s:%i\n", filename, linenumber);
32 #ifdef GL_INVALID_VALUE
33 case GL_INVALID_VALUE:
34 Con_Printf("GL_INVALID_VALUE at %s:%i\n", filename, linenumber);
37 #ifdef GL_INVALID_OPERATION
38 case GL_INVALID_OPERATION:
39 Con_Printf("GL_INVALID_OPERATION at %s:%i\n", filename, linenumber);
42 #ifdef GL_STACK_OVERFLOW
43 case GL_STACK_OVERFLOW:
44 Con_Printf("GL_STACK_OVERFLOW at %s:%i\n", filename, linenumber);
47 #ifdef GL_STACK_UNDERFLOW
48 case GL_STACK_UNDERFLOW:
49 Con_Printf("GL_STACK_UNDERFLOW at %s:%i\n", filename, linenumber);
52 #ifdef GL_OUT_OF_MEMORY
53 case GL_OUT_OF_MEMORY:
54 Con_Printf("GL_OUT_OF_MEMORY at %s:%i\n", filename, linenumber);
57 #ifdef GL_TABLE_TOO_LARGE
58 case GL_TABLE_TOO_LARGE:
59 Con_Printf("GL_TABLE_TOO_LARGE at %s:%i\n", filename, linenumber);
63 Con_Printf("GL UNKNOWN (%i) at %s:%i\n", errornumber, filename, linenumber);
69 #define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active");
71 void SCR_ScreenShot_f (void);
73 static matrix4x4_t backend_viewmatrix;
74 static matrix4x4_t backend_modelmatrix;
75 static matrix4x4_t backend_modelviewmatrix;
76 static matrix4x4_t backend_glmodelviewmatrix;
77 static matrix4x4_t backend_projectmatrix;
79 static unsigned int backendunits, backendimageunits, backendarrayunits, backendactive;
82 note: here's strip order for a terrain row:
89 A0B, 01B, B1C, 12C, C2D, 23D, D3E, 34E
91 *elements++ = i + row;
93 *elements++ = i + row + 1;
96 *elements++ = i + row + 1;
99 for (y = 0;y < rows - 1;y++)
101 for (x = 0;x < columns - 1;x++)
104 *elements++ = i + columns;
106 *elements++ = i + columns + 1;
109 *elements++ = i + columns + 1;
120 for (y = 0;y < rows - 1;y++)
122 for (x = 0;x < columns - 1;x++)
126 *elements++ = i + columns;
127 *elements++ = i + columns + 1;
128 *elements++ = i + columns;
129 *elements++ = i + columns + 1;
135 int polygonelements[(POLYGONELEMENTS_MAXPOINTS-2)*3];
136 int quadelements[QUADELEMENTS_MAXQUADS*6];
138 void GL_Backend_AllocArrays(void)
142 void GL_Backend_FreeArrays(void)
146 static void gl_backend_start(void)
148 Con_Print("OpenGL Backend starting...\n");
151 if (qglDrawRangeElements != NULL)
154 qglGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &gl_maxdrawrangeelementsvertices);
156 qglGetIntegerv(GL_MAX_ELEMENTS_INDICES, &gl_maxdrawrangeelementsindices);
158 Con_Printf("glDrawRangeElements detected (max vertices %i, max indices %i)\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
161 backendunits = min(MAX_TEXTUREUNITS, gl_textureunits);
162 backendimageunits = backendunits;
163 backendarrayunits = backendunits;
164 if (gl_support_fragment_shader)
167 qglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, (int *)&backendimageunits);
169 qglGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, (int *)&backendarrayunits);
171 Con_Printf("GLSL shader support detected: texture units = %i texenv, %i image, %i array\n", backendunits, backendimageunits, backendarrayunits);
173 else if (backendunits > 1)
174 Con_Printf("multitexture detected: texture units = %i\n", backendunits);
176 Con_Printf("singletexture\n");
178 GL_Backend_AllocArrays();
180 Con_Printf("OpenGL backend started.\n");
184 backendactive = true;
187 static void gl_backend_shutdown(void)
190 backendimageunits = 0;
191 backendarrayunits = 0;
192 backendactive = false;
194 Con_Print("OpenGL Backend shutting down\n");
196 GL_Backend_FreeArrays();
199 static void gl_backend_newmap(void)
203 void gl_backend_init(void)
207 for (i = 0;i < POLYGONELEMENTS_MAXPOINTS - 2;i++)
209 polygonelements[i * 3 + 0] = 0;
210 polygonelements[i * 3 + 1] = i + 1;
211 polygonelements[i * 3 + 2] = i + 2;
213 // elements for rendering a series of quads as triangles
214 for (i = 0;i < QUADELEMENTS_MAXQUADS;i++)
216 quadelements[i * 6 + 0] = i * 4;
217 quadelements[i * 6 + 1] = i * 4 + 1;
218 quadelements[i * 6 + 2] = i * 4 + 2;
219 quadelements[i * 6 + 3] = i * 4;
220 quadelements[i * 6 + 4] = i * 4 + 2;
221 quadelements[i * 6 + 5] = i * 4 + 3;
224 Cvar_RegisterVariable(&r_render);
225 Cvar_RegisterVariable(&r_waterwarp);
226 Cvar_RegisterVariable(&gl_polyblend);
227 Cvar_RegisterVariable(&gl_dither);
228 Cvar_RegisterVariable(&gl_lockarrays);
229 Cvar_RegisterVariable(&gl_paranoid);
230 Cvar_RegisterVariable(&gl_printcheckerror);
232 Cvar_SetValue("r_render", 0);
235 Cvar_RegisterVariable(&gl_mesh_drawrangeelements);
236 Cvar_RegisterVariable(&gl_mesh_testarrayelement);
237 Cvar_RegisterVariable(&gl_mesh_testmanualfeeding);
239 R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap);
242 void GL_SetupView_Orientation_Identity (void)
244 backend_viewmatrix = identitymatrix;
245 memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
248 void GL_SetupView_Orientation_FromEntity(matrix4x4_t *matrix)
250 matrix4x4_t tempmatrix, basematrix;
251 Matrix4x4_Invert_Simple(&tempmatrix, matrix);
252 Matrix4x4_CreateRotate(&basematrix, -90, 1, 0, 0);
253 Matrix4x4_ConcatRotate(&basematrix, 90, 0, 0, 1);
254 Matrix4x4_Concat(&backend_viewmatrix, &basematrix, &tempmatrix);
255 //Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[2], 1, 0, 0);
256 //Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[0], 0, 1, 0);
257 //Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[1], 0, 0, 1);
258 //Matrix4x4_ConcatTranslate(&backend_viewmatrix, -origin[0], -origin[1], -origin[2]);
259 memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
262 void GL_SetupView_Mode_Perspective (double frustumx, double frustumy, double zNear, double zFar)
266 if (!r_render.integer)
270 qglMatrixMode(GL_PROJECTION);CHECKGLERROR
271 qglLoadIdentity();CHECKGLERROR
273 qglFrustum(-frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar);CHECKGLERROR
274 qglGetDoublev(GL_PROJECTION_MATRIX, m);
275 backend_projectmatrix.m[0][0] = m[0];
276 backend_projectmatrix.m[1][0] = m[1];
277 backend_projectmatrix.m[2][0] = m[2];
278 backend_projectmatrix.m[3][0] = m[3];
279 backend_projectmatrix.m[0][1] = m[4];
280 backend_projectmatrix.m[1][1] = m[5];
281 backend_projectmatrix.m[2][1] = m[6];
282 backend_projectmatrix.m[3][1] = m[7];
283 backend_projectmatrix.m[0][2] = m[8];
284 backend_projectmatrix.m[1][2] = m[9];
285 backend_projectmatrix.m[2][2] = m[10];
286 backend_projectmatrix.m[3][2] = m[11];
287 backend_projectmatrix.m[0][3] = m[12];
288 backend_projectmatrix.m[1][3] = m[13];
289 backend_projectmatrix.m[2][3] = m[14];
290 backend_projectmatrix.m[3][3] = m[15];
291 qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
292 GL_SetupView_Orientation_Identity();
295 void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double frustumx, double frustumy, double zNear)
299 if (!r_render.integer)
303 qglMatrixMode(GL_PROJECTION);CHECKGLERROR
304 qglLoadIdentity();CHECKGLERROR
306 nudge = 1.0 - 1.0 / (1<<23);
307 m[ 0] = 1.0 / frustumx;
312 m[ 5] = 1.0 / frustumy;
321 m[14] = -2 * zNear * nudge;
324 qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
325 GL_SetupView_Orientation_Identity();
326 backend_projectmatrix.m[0][0] = m[0];
327 backend_projectmatrix.m[1][0] = m[1];
328 backend_projectmatrix.m[2][0] = m[2];
329 backend_projectmatrix.m[3][0] = m[3];
330 backend_projectmatrix.m[0][1] = m[4];
331 backend_projectmatrix.m[1][1] = m[5];
332 backend_projectmatrix.m[2][1] = m[6];
333 backend_projectmatrix.m[3][1] = m[7];
334 backend_projectmatrix.m[0][2] = m[8];
335 backend_projectmatrix.m[1][2] = m[9];
336 backend_projectmatrix.m[2][2] = m[10];
337 backend_projectmatrix.m[3][2] = m[11];
338 backend_projectmatrix.m[0][3] = m[12];
339 backend_projectmatrix.m[1][3] = m[13];
340 backend_projectmatrix.m[2][3] = m[14];
341 backend_projectmatrix.m[3][3] = m[15];
344 void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar)
348 if (!r_render.integer)
352 qglMatrixMode(GL_PROJECTION);CHECKGLERROR
353 qglLoadIdentity();CHECKGLERROR
354 qglOrtho(x1, x2, y2, y1, zNear, zFar);
355 qglGetDoublev(GL_PROJECTION_MATRIX, m);
356 backend_projectmatrix.m[0][0] = m[0];
357 backend_projectmatrix.m[1][0] = m[1];
358 backend_projectmatrix.m[2][0] = m[2];
359 backend_projectmatrix.m[3][0] = m[3];
360 backend_projectmatrix.m[0][1] = m[4];
361 backend_projectmatrix.m[1][1] = m[5];
362 backend_projectmatrix.m[2][1] = m[6];
363 backend_projectmatrix.m[3][1] = m[7];
364 backend_projectmatrix.m[0][2] = m[8];
365 backend_projectmatrix.m[1][2] = m[9];
366 backend_projectmatrix.m[2][2] = m[10];
367 backend_projectmatrix.m[3][2] = m[11];
368 backend_projectmatrix.m[0][3] = m[12];
369 backend_projectmatrix.m[1][3] = m[13];
370 backend_projectmatrix.m[2][3] = m[14];
371 backend_projectmatrix.m[3][3] = m[15];
372 qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
373 GL_SetupView_Orientation_Identity();
376 typedef struct gltextureunit_s
378 int t1d, t2d, t3d, tcubemap;
380 unsigned int arraycomponents;
381 const void *pointer_texcoord;
382 float rgbscale, alphascale;
383 int combinergb, combinealpha;
384 // FIXME: add more combine stuff
385 // texmatrixenabled exists only to avoid unnecessary texmatrix compares
386 int texmatrixenabled;
391 static struct gl_state_s
397 int colormask; // stored as bottom 4 bits: r g b a (3 2 1 0 order)
401 unsigned int clientunit;
402 gltextureunit_t units[MAX_TEXTUREUNITS];
406 const void *pointer_vertex;
407 const void *pointer_color;
411 void GL_SetupTextureState(void)
414 gltextureunit_t *unit;
416 gl_state.unit = MAX_TEXTUREUNITS;
417 gl_state.clientunit = MAX_TEXTUREUNITS;
418 for (i = 0;i < MAX_TEXTUREUNITS;i++)
420 unit = gl_state.units + i;
425 unit->arrayenabled = false;
426 unit->arraycomponents = 0;
427 unit->pointer_texcoord = NULL;
429 unit->alphascale = 1;
430 unit->combinergb = GL_MODULATE;
431 unit->combinealpha = GL_MODULATE;
432 unit->texmatrixenabled = false;
433 unit->matrix = identitymatrix;
436 for (i = 0;i < backendimageunits;i++)
439 qglBindTexture(GL_TEXTURE_1D, 0);CHECKGLERROR
440 qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
443 qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
445 if (gl_texturecubemap)
447 qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);CHECKGLERROR
451 for (i = 0;i < backendarrayunits;i++)
453 GL_ClientActiveTexture(i);
454 qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), NULL);CHECKGLERROR
455 qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
458 for (i = 0;i < backendunits;i++)
461 qglDisable(GL_TEXTURE_1D);CHECKGLERROR
462 qglDisable(GL_TEXTURE_2D);CHECKGLERROR
465 qglDisable(GL_TEXTURE_3D);CHECKGLERROR
467 if (gl_texturecubemap)
469 qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
471 qglMatrixMode(GL_TEXTURE);
473 qglMatrixMode(GL_MODELVIEW);
474 if (gl_combine.integer)
476 qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);CHECKGLERROR
477 qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);CHECKGLERROR
478 qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);CHECKGLERROR
479 qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);CHECKGLERROR
480 qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE);CHECKGLERROR // for GL_INTERPOLATE_ARB mode
481 qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);CHECKGLERROR
482 qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);CHECKGLERROR
483 qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);CHECKGLERROR
484 qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);CHECKGLERROR
485 qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);CHECKGLERROR
486 qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB);CHECKGLERROR
487 qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, GL_CONSTANT_ARB);CHECKGLERROR
488 qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);CHECKGLERROR
489 qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);CHECKGLERROR
490 qglTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, GL_SRC_ALPHA);CHECKGLERROR
491 qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1);CHECKGLERROR
492 qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);CHECKGLERROR
496 qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);CHECKGLERROR
502 void GL_Backend_ResetState(void)
504 memset(&gl_state, 0, sizeof(gl_state));
505 gl_state.depthtest = true;
506 gl_state.blendfunc1 = GL_ONE;
507 gl_state.blendfunc2 = GL_ZERO;
508 gl_state.blend = false;
509 gl_state.depthmask = GL_TRUE;
510 gl_state.colormask = 15;
511 gl_state.color4f[0] = gl_state.color4f[1] = gl_state.color4f[2] = gl_state.color4f[3] = 1;
512 gl_state.lockrange_first = 0;
513 gl_state.lockrange_count = 0;
514 gl_state.pointer_vertex = NULL;
515 gl_state.pointer_color = NULL;
519 qglColorMask(1, 1, 1, 1);
520 qglEnable(GL_CULL_FACE);CHECKGLERROR
521 qglCullFace(GL_FRONT);CHECKGLERROR
522 qglEnable(GL_DEPTH_TEST);CHECKGLERROR
523 qglBlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);CHECKGLERROR
524 qglDisable(GL_BLEND);CHECKGLERROR
525 qglDepthMask(gl_state.depthmask);CHECKGLERROR
527 qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), NULL);CHECKGLERROR
528 qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
530 qglColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL);CHECKGLERROR
531 qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR
533 GL_Color(0, 0, 0, 0);
534 GL_Color(1, 1, 1, 1);
536 GL_SetupTextureState();
539 void GL_ActiveTexture(unsigned int num)
541 if (gl_state.unit != num)
544 if (qglActiveTexture)
546 qglActiveTexture(GL_TEXTURE0_ARB + gl_state.unit);
552 void GL_ClientActiveTexture(unsigned int num)
554 if (gl_state.clientunit != num)
556 gl_state.clientunit = num;
557 if (qglActiveTexture)
559 qglClientActiveTexture(GL_TEXTURE0_ARB + gl_state.clientunit);
565 void GL_BlendFunc(int blendfunc1, int blendfunc2)
567 if (gl_state.blendfunc1 != blendfunc1 || gl_state.blendfunc2 != blendfunc2)
571 qglBlendFunc(gl_state.blendfunc1 = blendfunc1, gl_state.blendfunc2 = blendfunc2);CHECKGLERROR
572 if (gl_state.blendfunc2 == GL_ZERO)
574 if (gl_state.blendfunc1 == GL_ONE)
579 qglDisable(GL_BLEND);CHECKGLERROR
587 qglEnable(GL_BLEND);CHECKGLERROR
596 qglEnable(GL_BLEND);CHECKGLERROR
602 void GL_DepthMask(int state)
604 if (gl_state.depthmask != state)
608 qglDepthMask(gl_state.depthmask = state);CHECKGLERROR
612 void GL_DepthTest(int state)
614 if (gl_state.depthtest != state)
616 if (r_showtrispass && r_showdisabledepthtest.integer)
618 gl_state.depthtest = state;
619 if (gl_state.depthtest)
621 qglEnable(GL_DEPTH_TEST);CHECKGLERROR
625 qglDisable(GL_DEPTH_TEST);CHECKGLERROR
630 void GL_ColorMask(int r, int g, int b, int a)
632 int state = r*8 + g*4 + b*2 + a*1;
633 if (gl_state.colormask != state)
635 gl_state.colormask = state;
636 qglColorMask((GLboolean)r, (GLboolean)g, (GLboolean)b, (GLboolean)a);CHECKGLERROR
640 void GL_Color(float cr, float cg, float cb, float ca)
642 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)
646 gl_state.color4f[0] = cr;
647 gl_state.color4f[1] = cg;
648 gl_state.color4f[2] = cb;
649 gl_state.color4f[3] = ca;
651 qglColor4f(gl_state.color4f[0], gl_state.color4f[1], gl_state.color4f[2], gl_state.color4f[3]);
656 void GL_ShowTrisColor(float cr, float cg, float cb, float ca)
661 GL_Color(cr * r_showtris.value, cg * r_showtris.value, cb * r_showtris.value, ca);
666 void GL_LockArrays(int first, int count)
668 if (gl_state.lockrange_count != count || gl_state.lockrange_first != first)
670 if (gl_state.lockrange_count)
672 gl_state.lockrange_count = 0;
674 qglUnlockArraysEXT();
677 if (count && gl_supportslockarrays && gl_lockarrays.integer && r_render.integer)
679 gl_state.lockrange_first = first;
680 gl_state.lockrange_count = count;
682 qglLockArraysEXT(first, count);
688 void GL_Scissor (int x, int y, int width, int height)
691 qglScissor(x, vid.height - (y + height),width,height);
695 void GL_ScissorTest(int state)
697 if(gl_state.scissortest == state)
701 if((gl_state.scissortest = state))
702 qglEnable(GL_SCISSOR_TEST);
704 qglDisable(GL_SCISSOR_TEST);
708 void GL_Clear(int mask)
710 // in showtris rendering, don't clear the color buffer as that would hide
711 // the accumulated lines
713 mask &= ~GL_COLOR_BUFFER_BIT;
714 qglClear(mask);CHECKGLERROR
717 void GL_TransformToScreen(const vec4_t in, vec4_t out)
721 Matrix4x4_Transform4 (&backend_viewmatrix, in, temp);
722 Matrix4x4_Transform4 (&backend_projectmatrix, temp, out);
724 out[0] = r_view_x + (out[0] * iw + 1.0f) * r_view_width * 0.5f;
725 out[1] = r_view_y + (out[1] * iw + 1.0f) * r_view_height * 0.5f;
726 out[2] = r_view_z + (out[2] * iw + 1.0f) * r_view_depth * 0.5f;
729 // called at beginning of frame
730 void R_Mesh_Start(void)
734 GL_Backend_ResetState();
737 unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **vertexstrings_list, int fragmentstrings_count, const char **fragmentstrings_list)
739 GLint vertexshadercompiled, fragmentshadercompiled, programlinked;
740 GLuint vertexshaderobject, fragmentshaderobject, programobject = 0;
741 char compilelog[MAX_INPUTLINE];
744 programobject = qglCreateProgramObjectARB();
749 if (vertexstrings_count)
752 vertexshaderobject = qglCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
753 if (!vertexshaderobject)
755 qglDeleteObjectARB(programobject);
759 qglShaderSourceARB(vertexshaderobject, vertexstrings_count, vertexstrings_list, NULL);
760 qglCompileShaderARB(vertexshaderobject);
762 qglGetObjectParameterivARB(vertexshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &vertexshadercompiled);
763 qglGetInfoLogARB(vertexshaderobject, sizeof(compilelog), NULL, compilelog);
765 Con_DPrintf("vertex shader compile log:\n%s\n", compilelog);
766 if (!vertexshadercompiled)
768 qglDeleteObjectARB(programobject);
769 qglDeleteObjectARB(vertexshaderobject);
773 qglAttachObjectARB(programobject, vertexshaderobject);
774 qglDeleteObjectARB(vertexshaderobject);
778 if (fragmentstrings_count)
781 fragmentshaderobject = qglCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
782 if (!fragmentshaderobject)
784 qglDeleteObjectARB(programobject);
788 qglShaderSourceARB(fragmentshaderobject, fragmentstrings_count, fragmentstrings_list, NULL);
789 qglCompileShaderARB(fragmentshaderobject);
791 qglGetObjectParameterivARB(fragmentshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &fragmentshadercompiled);
792 qglGetInfoLogARB(fragmentshaderobject, sizeof(compilelog), NULL, compilelog);
794 Con_DPrintf("fragment shader compile log:\n%s\n", compilelog);
795 if (!fragmentshadercompiled)
797 qglDeleteObjectARB(programobject);
798 qglDeleteObjectARB(fragmentshaderobject);
802 qglAttachObjectARB(programobject, fragmentshaderobject);
803 qglDeleteObjectARB(fragmentshaderobject);
807 qglLinkProgramARB(programobject);
809 qglGetObjectParameterivARB(programobject, GL_OBJECT_LINK_STATUS_ARB, &programlinked);
810 qglGetInfoLogARB(programobject, sizeof(compilelog), NULL, compilelog);
813 Con_DPrintf("program link log:\n%s\n", compilelog);
814 // software vertex shader is ok but software fragment shader is WAY
815 // too slow, fail program if so.
816 // NOTE: this string might be ATI specific, but that's ok because the
817 // ATI R300 chip (Radeon 9500-9800/X300) is the most likely to use a
818 // software fragment shader due to low instruction and dependent
820 if (strstr(compilelog, "fragment shader will run in software"))
821 programlinked = false;
826 qglDeleteObjectARB(programobject);
830 return programobject;
833 void GL_Backend_FreeProgram(unsigned int prog)
836 qglDeleteObjectARB(prog);
840 int gl_backend_rebindtextures;
842 void GL_Backend_RenumberElements(int *out, int count, const int *in, int offset)
847 for (i = 0;i < count;i++)
848 *out++ = *in++ + offset;
851 memcpy(out, in, sizeof(*out) * count);
854 // renders triangles using vertices from the active arrays
855 int paranoidblah = 0;
856 void R_Mesh_Draw(int firstvertex, int numvertices, int numtriangles, const int *elements)
858 unsigned int numelements = numtriangles * 3;
859 if (numvertices < 3 || numtriangles < 1)
861 Con_Printf("R_Mesh_Draw(%d, %d, %d, %08p);\n", firstvertex, numvertices, numtriangles, elements);
867 R_Mesh_Draw_ShowTris(firstvertex, numvertices, numtriangles, elements);
870 renderstats.meshes++;
871 renderstats.meshes_elements += numelements;
872 if (gl_paranoid.integer)
874 unsigned int i, j, size;
876 if (!qglIsEnabled(GL_VERTEX_ARRAY))
877 Con_Print("R_Mesh_Draw: vertex array not enabled\n");
878 for (j = 0, size = numvertices * 3, p = (int *)((float *)gl_state.pointer_vertex + firstvertex * 3);j < size;j++, p++)
880 if (gl_state.pointer_color)
882 if (!qglIsEnabled(GL_COLOR_ARRAY))
883 Con_Print("R_Mesh_Draw: color array set but not enabled\n");
884 for (j = 0, size = numvertices * 4, p = (int *)((float *)gl_state.pointer_color + firstvertex * 4);j < size;j++, p++)
887 for (i = 0;i < backendarrayunits;i++)
889 if (gl_state.units[i].arrayenabled)
891 GL_ClientActiveTexture(i);
892 if (!qglIsEnabled(GL_TEXTURE_COORD_ARRAY))
893 Con_Print("R_Mesh_Draw: texcoord array set but not enabled\n");
894 for (j = 0, size = numvertices * gl_state.units[i].arraycomponents, p = (int *)((float *)gl_state.units[i].pointer_texcoord + firstvertex * gl_state.units[i].arraycomponents);j < size;j++, p++)
898 for (i = 0;i < (unsigned int) numtriangles * 3;i++)
900 if (elements[i] < firstvertex || elements[i] >= firstvertex + numvertices)
902 Con_Printf("R_Mesh_Draw: invalid vertex index %i (outside range %i - %i) in elements list\n", elements[i], firstvertex, firstvertex + numvertices);
908 if (r_render.integer)
911 if (gl_mesh_testmanualfeeding.integer)
915 qglBegin(GL_TRIANGLES);
916 for (i = 0;i < (unsigned int) numtriangles * 3;i++)
918 for (j = 0;j < backendarrayunits;j++)
920 if (gl_state.units[j].pointer_texcoord)
922 if (backendarrayunits > 1)
924 if (gl_state.units[j].arraycomponents == 4)
926 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 4;
927 qglMultiTexCoord4f(GL_TEXTURE0_ARB + j, p[0], p[1], p[2], p[3]);
929 else if (gl_state.units[j].arraycomponents == 3)
931 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 3;
932 qglMultiTexCoord3f(GL_TEXTURE0_ARB + j, p[0], p[1], p[2]);
934 else if (gl_state.units[j].arraycomponents == 2)
936 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 2;
937 qglMultiTexCoord2f(GL_TEXTURE0_ARB + j, p[0], p[1]);
941 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 1;
942 qglMultiTexCoord1f(GL_TEXTURE0_ARB + j, p[0]);
947 if (gl_state.units[j].arraycomponents == 4)
949 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 4;
950 qglTexCoord4f(p[0], p[1], p[2], p[3]);
952 else if (gl_state.units[j].arraycomponents == 3)
954 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 3;
955 qglTexCoord3f(p[0], p[1], p[2]);
957 else if (gl_state.units[j].arraycomponents == 2)
959 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 2;
960 qglTexCoord2f(p[0], p[1]);
964 p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 1;
970 if (gl_state.pointer_color)
972 p = ((const GLfloat *)(gl_state.pointer_color)) + elements[i] * 4;
973 qglColor4f(p[0], p[1], p[2], p[3]);
975 p = ((const GLfloat *)(gl_state.pointer_vertex)) + elements[i] * 3;
976 qglVertex3f(p[0], p[1], p[2]);
981 else if (gl_mesh_testarrayelement.integer)
984 qglBegin(GL_TRIANGLES);
985 for (i = 0;i < numtriangles * 3;i++)
987 qglArrayElement(elements[i]);
992 else if (gl_mesh_drawrangeelements.integer && qglDrawRangeElements != NULL)
994 qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices, numelements, GL_UNSIGNED_INT, elements);
999 qglDrawElements(GL_TRIANGLES, numelements, GL_UNSIGNED_INT, elements);
1005 // restores backend state, used when done with 3D rendering
1006 void R_Mesh_Finish(void)
1011 GL_LockArrays(0, 0);
1014 for (i = 0;i < backendimageunits;i++)
1016 GL_ActiveTexture(i);
1017 qglBindTexture(GL_TEXTURE_1D, 0);CHECKGLERROR
1018 qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
1021 qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
1023 if (gl_texturecubemap)
1025 qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);CHECKGLERROR
1028 for (i = 0;i < backendarrayunits;i++)
1030 GL_ActiveTexture(backendarrayunits - 1 - i);
1031 qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
1033 for (i = 0;i < backendunits;i++)
1035 GL_ActiveTexture(backendunits - 1 - i);
1036 qglDisable(GL_TEXTURE_1D);CHECKGLERROR
1037 qglDisable(GL_TEXTURE_2D);CHECKGLERROR
1040 qglDisable(GL_TEXTURE_3D);CHECKGLERROR
1042 if (gl_texturecubemap)
1044 qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
1046 qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);CHECKGLERROR
1047 if (gl_combine.integer)
1049 qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1);CHECKGLERROR
1050 qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);CHECKGLERROR
1053 qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR
1054 qglDisableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
1056 qglDisable(GL_BLEND);CHECKGLERROR
1057 qglEnable(GL_DEPTH_TEST);CHECKGLERROR
1058 qglDepthMask(GL_TRUE);CHECKGLERROR
1059 qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);CHECKGLERROR
1062 void R_Mesh_Matrix(const matrix4x4_t *matrix)
1064 if (memcmp(matrix, &backend_modelmatrix, sizeof(matrix4x4_t)))
1066 backend_modelmatrix = *matrix;
1067 Matrix4x4_Concat(&backend_modelviewmatrix, &backend_viewmatrix, matrix);
1068 Matrix4x4_Transpose(&backend_glmodelviewmatrix, &backend_modelviewmatrix);
1069 qglLoadMatrixf(&backend_glmodelviewmatrix.m[0][0]);
1073 void R_Mesh_VertexPointer(const float *vertex3f)
1075 if (gl_state.pointer_vertex != vertex3f)
1077 gl_state.pointer_vertex = vertex3f;
1079 qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), gl_state.pointer_vertex);
1084 void R_Mesh_ColorPointer(const float *color4f)
1088 if (gl_state.pointer_color != color4f)
1091 if (!gl_state.pointer_color)
1093 qglEnableClientState(GL_COLOR_ARRAY);
1098 qglDisableClientState(GL_COLOR_ARRAY);
1100 // when color array is on the glColor gets trashed, set it again
1101 qglColor4f(gl_state.color4f[0], gl_state.color4f[1], gl_state.color4f[2], gl_state.color4f[3]);
1104 gl_state.pointer_color = color4f;
1105 qglColorPointer(4, GL_FLOAT, sizeof(float[4]), gl_state.pointer_color);
1110 void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, const float *texcoord)
1112 gltextureunit_t *unit = gl_state.units + unitnum;
1115 // update array settings
1119 if (unit->pointer_texcoord != texcoord || unit->arraycomponents != numcomponents)
1121 unit->pointer_texcoord = texcoord;
1122 unit->arraycomponents = numcomponents;
1123 GL_ClientActiveTexture(unitnum);
1124 qglTexCoordPointer(unit->arraycomponents, GL_FLOAT, sizeof(float) * unit->arraycomponents, unit->pointer_texcoord);
1127 // texture array unit is enabled, enable the array
1128 if (!unit->arrayenabled)
1130 unit->arrayenabled = true;
1131 GL_ClientActiveTexture(unitnum);
1132 qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
1137 // texture array unit is disabled, disable the array
1138 if (unit->arrayenabled)
1140 unit->arrayenabled = false;
1141 GL_ClientActiveTexture(unitnum);
1142 qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
1147 void R_Mesh_TexBindAll(unsigned int unitnum, int tex1d, int tex2d, int tex3d, int texcubemap)
1149 gltextureunit_t *unit = gl_state.units + unitnum;
1150 if (unitnum >= backendimageunits)
1154 // update 1d texture binding
1155 if (unit->t1d != tex1d)
1157 GL_ActiveTexture(unitnum);
1158 if (unitnum < backendunits)
1163 qglEnable(GL_TEXTURE_1D);
1168 qglDisable(GL_TEXTURE_1D);
1172 qglBindTexture(GL_TEXTURE_1D, unit->t1d);
1175 // update 2d texture binding
1176 if (unit->t2d != tex2d)
1178 GL_ActiveTexture(unitnum);
1179 if (unitnum < backendunits)
1184 qglEnable(GL_TEXTURE_2D);
1189 qglDisable(GL_TEXTURE_2D);
1193 qglBindTexture(GL_TEXTURE_2D, unit->t2d);
1196 // update 3d texture binding
1197 if (unit->t3d != tex3d)
1199 GL_ActiveTexture(unitnum);
1200 if (unitnum < backendunits)
1205 qglEnable(GL_TEXTURE_3D);
1210 qglDisable(GL_TEXTURE_3D);
1214 qglBindTexture(GL_TEXTURE_3D, unit->t3d);
1217 // update cubemap texture binding
1218 if (unit->tcubemap != texcubemap)
1220 GL_ActiveTexture(unitnum);
1221 if (unitnum < backendunits)
1225 if (unit->tcubemap == 0)
1226 qglEnable(GL_TEXTURE_CUBE_MAP_ARB);
1231 qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
1234 unit->tcubemap = texcubemap;
1235 qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
1240 void R_Mesh_TexBind1D(unsigned int unitnum, int texnum)
1242 gltextureunit_t *unit = gl_state.units + unitnum;
1243 if (unitnum >= backendimageunits)
1247 // update 1d texture binding
1248 if (unit->t1d != texnum)
1250 GL_ActiveTexture(unitnum);
1251 if (unitnum < backendunits)
1256 qglEnable(GL_TEXTURE_1D);
1261 qglDisable(GL_TEXTURE_1D);
1265 qglBindTexture(GL_TEXTURE_1D, unit->t1d);
1268 // update 2d texture binding
1271 GL_ActiveTexture(unitnum);
1272 if (unitnum < backendunits)
1275 qglDisable(GL_TEXTURE_2D);
1278 qglBindTexture(GL_TEXTURE_2D, unit->t2d);
1281 // update 3d texture binding
1284 GL_ActiveTexture(unitnum);
1285 if (unitnum < backendunits)
1288 qglDisable(GL_TEXTURE_3D);
1291 qglBindTexture(GL_TEXTURE_3D, unit->t3d);
1294 // update cubemap texture binding
1297 GL_ActiveTexture(unitnum);
1298 if (unitnum < backendunits)
1301 qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
1304 qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
1309 void R_Mesh_TexBind(unsigned int unitnum, int texnum)
1311 gltextureunit_t *unit = gl_state.units + unitnum;
1312 if (unitnum >= backendimageunits)
1316 // update 1d texture binding
1319 GL_ActiveTexture(unitnum);
1320 if (unitnum < backendunits)
1323 qglDisable(GL_TEXTURE_1D);
1326 qglBindTexture(GL_TEXTURE_1D, unit->t1d);
1329 // update 2d texture binding
1330 if (unit->t2d != texnum)
1332 GL_ActiveTexture(unitnum);
1333 if (unitnum < backendunits)
1338 qglEnable(GL_TEXTURE_2D);
1343 qglDisable(GL_TEXTURE_2D);
1347 qglBindTexture(GL_TEXTURE_2D, unit->t2d);
1350 // update 3d texture binding
1353 GL_ActiveTexture(unitnum);
1354 if (unitnum < backendunits)
1357 qglDisable(GL_TEXTURE_3D);
1360 qglBindTexture(GL_TEXTURE_3D, unit->t3d);
1363 // update cubemap texture binding
1364 if (unit->tcubemap != 0)
1366 GL_ActiveTexture(unitnum);
1367 if (unitnum < backendunits)
1370 qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
1373 qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
1378 void R_Mesh_TexBind3D(unsigned int unitnum, int texnum)
1380 gltextureunit_t *unit = gl_state.units + unitnum;
1381 if (unitnum >= backendimageunits)
1385 // update 1d texture binding
1388 GL_ActiveTexture(unitnum);
1389 if (unitnum < backendunits)
1392 qglDisable(GL_TEXTURE_1D);
1395 qglBindTexture(GL_TEXTURE_1D, unit->t1d);
1398 // update 2d texture binding
1401 GL_ActiveTexture(unitnum);
1402 if (unitnum < backendunits)
1405 qglDisable(GL_TEXTURE_2D);
1408 qglBindTexture(GL_TEXTURE_2D, unit->t2d);
1411 // update 3d texture binding
1412 if (unit->t3d != texnum)
1414 GL_ActiveTexture(unitnum);
1415 if (unitnum < backendunits)
1420 qglEnable(GL_TEXTURE_3D);
1425 qglDisable(GL_TEXTURE_3D);
1429 qglBindTexture(GL_TEXTURE_3D, unit->t3d);
1432 // update cubemap texture binding
1433 if (unit->tcubemap != 0)
1435 GL_ActiveTexture(unitnum);
1436 if (unitnum < backendunits)
1439 qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
1442 qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
1447 void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum)
1449 gltextureunit_t *unit = gl_state.units + unitnum;
1450 if (unitnum >= backendimageunits)
1454 // update 1d texture binding
1457 GL_ActiveTexture(unitnum);
1458 if (unitnum < backendunits)
1461 qglDisable(GL_TEXTURE_1D);
1464 qglBindTexture(GL_TEXTURE_1D, unit->t1d);
1467 // update 2d texture binding
1470 GL_ActiveTexture(unitnum);
1471 if (unitnum < backendunits)
1474 qglDisable(GL_TEXTURE_2D);
1477 qglBindTexture(GL_TEXTURE_2D, unit->t2d);
1480 // update 3d texture binding
1483 GL_ActiveTexture(unitnum);
1484 if (unitnum < backendunits)
1487 qglDisable(GL_TEXTURE_3D);
1490 qglBindTexture(GL_TEXTURE_3D, unit->t3d);
1493 // update cubemap texture binding
1494 if (unit->tcubemap != texnum)
1496 GL_ActiveTexture(unitnum);
1497 if (unitnum < backendunits)
1501 if (unit->tcubemap == 0)
1502 qglEnable(GL_TEXTURE_CUBE_MAP_ARB);
1507 qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
1510 unit->tcubemap = texnum;
1511 qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
1516 void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix)
1518 gltextureunit_t *unit = gl_state.units + unitnum;
1521 if (matrix->m[3][3])
1523 // texmatrix specified, check if it is different
1524 if (!unit->texmatrixenabled || memcmp(&unit->matrix, matrix, sizeof(matrix4x4_t)))
1526 matrix4x4_t tempmatrix;
1527 unit->texmatrixenabled = true;
1528 unit->matrix = *matrix;
1529 Matrix4x4_Transpose(&tempmatrix, &unit->matrix);
1530 qglMatrixMode(GL_TEXTURE);
1531 GL_ActiveTexture(unitnum);
1532 qglLoadMatrixf(&tempmatrix.m[0][0]);
1533 qglMatrixMode(GL_MODELVIEW);
1538 // no texmatrix specified, revert to identity
1539 if (unit->texmatrixenabled)
1541 unit->texmatrixenabled = false;
1542 qglMatrixMode(GL_TEXTURE);
1543 GL_ActiveTexture(unitnum);
1545 qglMatrixMode(GL_MODELVIEW);
1550 void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, int rgbscale, int alphascale)
1552 gltextureunit_t *unit = gl_state.units + unitnum;
1555 if (gl_combine.integer)
1557 // GL_ARB_texture_env_combine
1559 combinergb = GL_MODULATE;
1561 combinealpha = GL_MODULATE;
1566 if (unit->combinergb != combinergb)
1568 unit->combinergb = combinergb;
1569 GL_ActiveTexture(unitnum);
1570 qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, unit->combinergb);CHECKGLERROR
1572 if (unit->combinealpha != combinealpha)
1574 unit->combinealpha = combinealpha;
1575 GL_ActiveTexture(unitnum);
1576 qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, unit->combinealpha);CHECKGLERROR
1578 if (unit->rgbscale != rgbscale)
1580 GL_ActiveTexture(unitnum);
1581 qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (unit->rgbscale = rgbscale));CHECKGLERROR
1583 if (unit->alphascale != alphascale)
1585 GL_ActiveTexture(unitnum);
1586 qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, (unit->alphascale = alphascale));CHECKGLERROR
1593 combinergb = GL_MODULATE;
1594 if (unit->combinergb != combinergb)
1596 unit->combinergb = combinergb;
1597 GL_ActiveTexture(unitnum);
1598 qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->combinergb);CHECKGLERROR
1603 void R_Mesh_State(const rmeshstate_t *m)
1609 R_Mesh_VertexPointer(m->pointer_vertex);
1610 R_Mesh_ColorPointer(m->pointer_color);
1612 if (gl_backend_rebindtextures)
1614 gl_backend_rebindtextures = false;
1615 GL_SetupTextureState();
1618 for (i = 0;i < backendimageunits;i++)
1619 R_Mesh_TexBindAll(i, m->tex1d[i], m->tex[i], m->tex3d[i], m->texcubemap[i]);
1620 for (i = 0;i < backendarrayunits;i++)
1622 if (m->pointer_texcoord3f[i])
1623 R_Mesh_TexCoordPointer(i, 3, m->pointer_texcoord3f[i]);
1625 R_Mesh_TexCoordPointer(i, 2, m->pointer_texcoord[i]);
1627 for (i = 0;i < backendunits;i++)
1629 R_Mesh_TexMatrix(i, &m->texmatrix[i]);
1630 R_Mesh_TexCombine(i, m->texcombinergb[i], m->texcombinealpha[i], m->texrgbscale[i], m->texalphascale[i]);
1634 void R_Mesh_Draw_ShowTris(int firstvertex, int numvertices, int numtriangles, const int *elements)
1637 for (;numtriangles;numtriangles--, elements += 3)
1639 qglArrayElement(elements[0]);qglArrayElement(elements[1]);
1640 qglArrayElement(elements[1]);qglArrayElement(elements[2]);
1641 qglArrayElement(elements[2]);qglArrayElement(elements[0]);