#include "quakedef.h"
-#include "image.h"
-#include "jpeg.h"
#include "cl_collision.h"
-cvar_t gl_mesh_drawrangeelements = {0, "gl_mesh_drawrangeelements", "1"};
-cvar_t gl_mesh_testarrayelement = {0, "gl_mesh_testarrayelement", "0"};
-cvar_t gl_mesh_testmanualfeeding = {0, "gl_mesh_testmanualfeeding", "0"};
-cvar_t gl_delayfinish = {CVAR_SAVE, "gl_delayfinish", "0"};
-cvar_t gl_paranoid = {0, "gl_paranoid", "0"};
-cvar_t gl_printcheckerror = {0, "gl_printcheckerror", "0"};
+cvar_t gl_mesh_drawrangeelements = {0, "gl_mesh_drawrangeelements", "1", "use glDrawRangeElements function if available instead of glDrawElements (for performance comparisons or bug testing)"};
+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_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"};
-cvar_t r_render = {0, "r_render", "1"};
-cvar_t r_waterwarp = {CVAR_SAVE, "r_waterwarp", "1"};
-cvar_t gl_dither = {CVAR_SAVE, "gl_dither", "1"}; // whether or not to use dithering
-cvar_t gl_lockarrays = {0, "gl_lockarrays", "1"};
+cvar_t r_render = {0, "r_render", "1", "enables rendering calls (you want this on!)"};
+cvar_t r_waterwarp = {CVAR_SAVE, "r_waterwarp", "1", "warp view while underwater"};
+cvar_t gl_polyblend = {CVAR_SAVE, "gl_polyblend", "1", "tints view while underwater, hurt, etc"};
+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", "1", "enables use of glLockArraysEXT, may cause glitches with some broken drivers"};
int gl_maxdrawrangeelementsvertices;
int gl_maxdrawrangeelementsindices;
}
#endif
-#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active\n");
-
-int c_meshs, c_meshelements;
+#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active");
void SCR_ScreenShot_f (void);
static matrix4x4_t backend_glmodelviewmatrix;
static matrix4x4_t backend_projectmatrix;
-static int backendunits, backendactive;
-static mempool_t *gl_backend_mempool;
+static unsigned int backendunits, backendimageunits, backendarrayunits, backendactive;
/*
note: here's strip order for a terrain row:
}
*/
-int polygonelements[768];
+int polygonelements[(POLYGONELEMENTS_MAXPOINTS-2)*3];
+int quadelements[QUADELEMENTS_MAXQUADS*6];
-static void R_Mesh_CacheArray_Startup(void);
-static void R_Mesh_CacheArray_Shutdown(void);
void GL_Backend_AllocArrays(void)
{
- if (!gl_backend_mempool)
- gl_backend_mempool = Mem_AllocPool("GL_Backend");
- R_Mesh_CacheArray_Startup();
}
void GL_Backend_FreeArrays(void)
{
- R_Mesh_CacheArray_Shutdown();
- Mem_FreePool(&gl_backend_mempool);
}
static void gl_backend_start(void)
{
- Con_DPrint("OpenGL Backend started\n");
+ Con_Print("OpenGL Backend starting...\n");
+ CHECKGLERROR
+
if (qglDrawRangeElements != NULL)
{
CHECKGLERROR
CHECKGLERROR
qglGetIntegerv(GL_MAX_ELEMENTS_INDICES, &gl_maxdrawrangeelementsindices);
CHECKGLERROR
- Con_DPrintf("glDrawRangeElements detected (max vertices %i, max indices %i)\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
+ Con_Printf("glDrawRangeElements detected (max vertices %i, max indices %i)\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
}
backendunits = min(MAX_TEXTUREUNITS, gl_textureunits);
+ backendimageunits = backendunits;
+ backendarrayunits = backendunits;
+ if (gl_support_fragment_shader)
+ {
+ CHECKGLERROR
+ qglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, (int *)&backendimageunits);
+ CHECKGLERROR
+ qglGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, (int *)&backendarrayunits);
+ CHECKGLERROR
+ Con_Printf("GLSL shader support detected: texture units = %i texenv, %i image, %i array\n", backendunits, backendimageunits, backendarrayunits);
+ }
+ else if (backendunits > 1)
+ Con_Printf("multitexture detected: texture units = %i\n", backendunits);
+ else
+ Con_Printf("singletexture\n");
GL_Backend_AllocArrays();
+ Con_Printf("OpenGL backend started.\n");
+
+ CHECKGLERROR
+
backendactive = true;
}
static void gl_backend_shutdown(void)
{
backendunits = 0;
+ backendimageunits = 0;
+ backendarrayunits = 0;
backendactive = false;
- Con_DPrint("OpenGL Backend shutting down\n");
+ Con_Print("OpenGL Backend shutting down\n");
GL_Backend_FreeArrays();
}
{
}
-cvar_t scr_zoomwindow = {CVAR_SAVE, "scr_zoomwindow", "0"};
-cvar_t scr_zoomwindow_viewsizex = {CVAR_SAVE, "scr_zoomwindow_viewsizex", "20"};
-cvar_t scr_zoomwindow_viewsizey = {CVAR_SAVE, "scr_zoomwindow_viewsizey", "20"};
-cvar_t scr_zoomwindow_fov = {CVAR_SAVE, "scr_zoomwindow_fov", "20"};
-
void gl_backend_init(void)
{
int i;
polygonelements[i * 3 + 1] = i + 1;
polygonelements[i * 3 + 2] = i + 2;
}
+ // elements for rendering a series of quads as triangles
+ for (i = 0;i < QUADELEMENTS_MAXQUADS;i++)
+ {
+ quadelements[i * 6 + 0] = i * 4;
+ quadelements[i * 6 + 1] = i * 4 + 1;
+ quadelements[i * 6 + 2] = i * 4 + 2;
+ quadelements[i * 6 + 3] = i * 4;
+ quadelements[i * 6 + 4] = i * 4 + 2;
+ quadelements[i * 6 + 5] = i * 4 + 3;
+ }
Cvar_RegisterVariable(&r_render);
Cvar_RegisterVariable(&r_waterwarp);
+ Cvar_RegisterVariable(&gl_polyblend);
Cvar_RegisterVariable(&gl_dither);
Cvar_RegisterVariable(&gl_lockarrays);
- Cvar_RegisterVariable(&gl_delayfinish);
Cvar_RegisterVariable(&gl_paranoid);
Cvar_RegisterVariable(&gl_printcheckerror);
#ifdef NORENDER
Cvar_RegisterVariable(&gl_mesh_testarrayelement);
Cvar_RegisterVariable(&gl_mesh_testmanualfeeding);
- Cvar_RegisterVariable(&scr_zoomwindow);
- Cvar_RegisterVariable(&scr_zoomwindow_viewsizex);
- Cvar_RegisterVariable(&scr_zoomwindow_viewsizey);
- Cvar_RegisterVariable(&scr_zoomwindow_fov);
-
R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap);
}
void GL_SetupView_Orientation_Identity (void)
{
- Matrix4x4_CreateIdentity(&backend_viewmatrix);
+ backend_viewmatrix = identitymatrix;
memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
}
memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
}
-void GL_SetupView_Mode_Perspective (double fovx, double fovy, double zNear, double zFar)
+void GL_SetupView_Mode_Perspective (double frustumx, double frustumy, double zNear, double zFar)
{
- double xmax, ymax;
double m[16];
if (!r_render.integer)
// set up viewpoint
qglMatrixMode(GL_PROJECTION);CHECKGLERROR
qglLoadIdentity();CHECKGLERROR
- // pyramid slopes
- xmax = zNear * tan(fovx * M_PI / 360.0);
- ymax = zNear * tan(fovy * M_PI / 360.0);
// set view pyramid
- qglFrustum(-xmax, xmax, -ymax, ymax, zNear, zFar);CHECKGLERROR
+ qglFrustum(-frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar);CHECKGLERROR
qglGetDoublev(GL_PROJECTION_MATRIX, m);
backend_projectmatrix.m[0][0] = m[0];
backend_projectmatrix.m[1][0] = m[1];
GL_SetupView_Orientation_Identity();
}
-void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double fovx, double fovy, double zNear)
+void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double frustumx, double frustumy, double zNear)
{
double nudge, m[16];
qglLoadIdentity();CHECKGLERROR
// set view pyramid
nudge = 1.0 - 1.0 / (1<<23);
- m[ 0] = 1.0 / tan(fovx * M_PI / 360.0);
+ m[ 0] = 1.0 / frustumx;
m[ 1] = 0;
m[ 2] = 0;
m[ 3] = 0;
m[ 4] = 0;
- m[ 5] = 1.0 / tan(fovy * M_PI / 360.0);
+ m[ 5] = 1.0 / frustumy;
m[ 6] = 0;
m[ 7] = 0;
m[ 8] = 0;
{
int t1d, t2d, t3d, tcubemap;
int arrayenabled;
- int arrayis3d;
+ 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
}
gltextureunit_t;
-static struct
+static struct gl_state_s
{
int blendfunc1;
int blendfunc2;
GLboolean depthmask;
int colormask; // stored as bottom 4 bits: r g b a (3 2 1 0 order)
int depthtest;
+ int alphatest;
int scissortest;
- int unit;
- int clientunit;
+ unsigned int unit;
+ unsigned int clientunit;
gltextureunit_t units[MAX_TEXTUREUNITS];
float color4f[4];
int lockrange_first;
void GL_SetupTextureState(void)
{
- int i;
+ unsigned int i;
gltextureunit_t *unit;
CHECKGLERROR
- gl_state.unit = -1;
- gl_state.clientunit = -1;
- for (i = 0;i < backendunits;i++)
+ gl_state.unit = MAX_TEXTUREUNITS;
+ gl_state.clientunit = MAX_TEXTUREUNITS;
+ for (i = 0;i < MAX_TEXTUREUNITS;i++)
{
- GL_ActiveTexture(i);
- GL_ClientActiveTexture(i);
unit = gl_state.units + i;
unit->t1d = 0;
unit->t2d = 0;
unit->t3d = 0;
unit->tcubemap = 0;
unit->arrayenabled = false;
- unit->arrayis3d = false;
+ unit->arraycomponents = 0;
unit->pointer_texcoord = NULL;
unit->rgbscale = 1;
unit->alphascale = 1;
unit->combinergb = GL_MODULATE;
unit->combinealpha = GL_MODULATE;
unit->texmatrixenabled = false;
- unit->matrix = r_identitymatrix;
- qglMatrixMode(GL_TEXTURE);
- qglLoadIdentity();
- qglMatrixMode(GL_MODELVIEW);
+ unit->matrix = identitymatrix;
+ }
+
+ for (i = 0;i < backendimageunits;i++)
+ {
+ GL_ActiveTexture(i);
+ qglBindTexture(GL_TEXTURE_1D, 0);CHECKGLERROR
+ qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
+ if (gl_texture3d)
+ {
+ qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
+ }
+ if (gl_texturecubemap)
+ {
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);CHECKGLERROR
+ }
+ }
+ for (i = 0;i < backendarrayunits;i++)
+ {
+ GL_ClientActiveTexture(i);
qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), NULL);CHECKGLERROR
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
+ }
+ for (i = 0;i < backendunits;i++)
+ {
+ GL_ActiveTexture(i);
qglDisable(GL_TEXTURE_1D);CHECKGLERROR
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
if (gl_texture3d)
{
qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
}
+ qglMatrixMode(GL_TEXTURE);
+ qglLoadIdentity();
+ qglMatrixMode(GL_MODELVIEW);
if (gl_combine.integer)
{
qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);CHECKGLERROR
{
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
GL_SetupTextureState();
}
-void GL_ActiveTexture(int num)
+void GL_ActiveTexture(unsigned int num)
{
if (gl_state.unit != num)
{
}
}
-void GL_ClientActiveTexture(int num)
+void GL_ClientActiveTexture(unsigned int num)
{
if (gl_state.clientunit != num)
{
{
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)
- 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.colormask != state)
{
- if (r_showtrispass)
- return;
gl_state.colormask = state;
qglColorMask((GLboolean)r, (GLboolean)g, (GLboolean)b, (GLboolean)a);CHECKGLERROR
}
{
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 = false;
- GL_Color(cr * r_showtris.value, cg * r_showtris.value, cb * r_showtris.value, ca);
- r_showtrispass = true;
-}
-
-
void GL_LockArrays(int first, int count)
{
if (gl_state.lockrange_count != count || gl_state.lockrange_first != first)
void GL_Scissor (int x, int y, int width, int height)
{
CHECKGLERROR
- qglScissor(x, vid.realheight - (y + height),width,height);
+ qglScissor(x, vid.height - (y + height),width,height);
CHECKGLERROR
}
void GL_Clear(int mask)
{
- if (r_showtrispass)
- return;
qglClear(mask);CHECKGLERROR
}
iw = 1.0f / out[3];
out[0] = r_view_x + (out[0] * iw + 1.0f) * r_view_width * 0.5f;
out[1] = r_view_y + (out[1] * iw + 1.0f) * r_view_height * 0.5f;
- out[2] = out[2] * iw;
+ out[2] = r_view_z + (out[2] * iw + 1.0f) * r_view_depth * 0.5f;
}
// called at beginning of frame
GL_Backend_ResetState();
}
+unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **vertexstrings_list, int fragmentstrings_count, const char **fragmentstrings_list)
+{
+ GLint vertexshadercompiled, fragmentshadercompiled, programlinked;
+ GLuint vertexshaderobject, fragmentshaderobject, programobject = 0;
+ char compilelog[MAX_INPUTLINE];
+ CHECKGLERROR
+
+ programobject = qglCreateProgramObjectARB();
+ 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
+ vertexshaderobject = qglCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
+ if (!vertexshaderobject)
+ {
+ qglDeleteObjectARB(programobject);
+ CHECKGLERROR
+ return 0;
+ }
+ qglShaderSourceARB(vertexshaderobject, vertexstrings_count, vertexstrings_list, NULL);
+ qglCompileShaderARB(vertexshaderobject);
+ CHECKGLERROR
+ qglGetObjectParameterivARB(vertexshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &vertexshadercompiled);
+ qglGetInfoLogARB(vertexshaderobject, sizeof(compilelog), NULL, compilelog);
+ if (compilelog[0])
+ Con_DPrintf("vertex shader compile log:\n%s\n", compilelog);
+ if (!vertexshadercompiled)
+ {
+ qglDeleteObjectARB(programobject);
+ qglDeleteObjectARB(vertexshaderobject);
+ CHECKGLERROR
+ return 0;
+ }
+ qglAttachObjectARB(programobject, vertexshaderobject);
+ qglDeleteObjectARB(vertexshaderobject);
+ CHECKGLERROR
+ }
+
+ if (fragmentstrings_count)
+ {
+ CHECKGLERROR
+ fragmentshaderobject = qglCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
+ if (!fragmentshaderobject)
+ {
+ qglDeleteObjectARB(programobject);
+ CHECKGLERROR
+ return 0;
+ }
+ qglShaderSourceARB(fragmentshaderobject, fragmentstrings_count, fragmentstrings_list, NULL);
+ qglCompileShaderARB(fragmentshaderobject);
+ CHECKGLERROR
+ qglGetObjectParameterivARB(fragmentshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &fragmentshadercompiled);
+ qglGetInfoLogARB(fragmentshaderobject, sizeof(compilelog), NULL, compilelog);
+ if (compilelog[0])
+ Con_DPrintf("fragment shader compile log:\n%s\n", compilelog);
+ if (!fragmentshadercompiled)
+ {
+ qglDeleteObjectARB(programobject);
+ qglDeleteObjectARB(fragmentshaderobject);
+ CHECKGLERROR
+ return 0;
+ }
+ qglAttachObjectARB(programobject, fragmentshaderobject);
+ qglDeleteObjectARB(fragmentshaderobject);
+ CHECKGLERROR
+ }
+
+ qglLinkProgramARB(programobject);
+ CHECKGLERROR
+ qglGetObjectParameterivARB(programobject, GL_OBJECT_LINK_STATUS_ARB, &programlinked);
+ qglGetInfoLogARB(programobject, sizeof(compilelog), NULL, compilelog);
+ if (compilelog[0])
+ {
+ Con_DPrintf("program link log:\n%s\n", compilelog);
+ // software vertex shader is ok but software fragment shader is WAY
+ // too slow, fail program if so.
+ // NOTE: this string might be ATI specific, but that's ok because the
+ // ATI R300 chip (Radeon 9500-9800/X300) is the most likely to use a
+ // software fragment shader due to low instruction and dependent
+ // texture limits.
+ if (strstr(compilelog, "fragment shader will run in software"))
+ programlinked = false;
+ }
+ CHECKGLERROR
+ if (!programlinked)
+ {
+ qglDeleteObjectARB(programobject);
+ return 0;
+ }
+ CHECKGLERROR
+ return programobject;
+}
+
+void GL_Backend_FreeProgram(unsigned int prog)
+{
+ CHECKGLERROR
+ qglDeleteObjectARB(prog);
+ CHECKGLERROR
+}
+
int gl_backend_rebindtextures;
void GL_Backend_RenumberElements(int *out, int count, const int *in, int offset)
// renders triangles using vertices from the active arrays
int paranoidblah = 0;
-void R_Mesh_Draw(int numverts, int numtriangles, const int *elements)
+void R_Mesh_Draw(int firstvertex, int numvertices, int numtriangles, const int *elements)
{
- int numelements = numtriangles * 3;
- if (numverts == 0 || numtriangles == 0)
+ unsigned int numelements = numtriangles * 3;
+ if (numvertices < 3 || numtriangles < 1)
{
- Con_Printf("R_Mesh_Draw(%d, %d, %08p);\n", numverts, numtriangles, elements);
+ Con_Printf("R_Mesh_Draw(%d, %d, %d, %08p);\n", firstvertex, numvertices, numtriangles, elements);
return;
}
- CHECKGLERROR
- if (r_showtrispass)
- {
- R_Mesh_Draw_ShowTris(numverts, numtriangles, elements);
- return;
- }
- c_meshs++;
- c_meshelements += numelements;
+ //CHECKGLERROR
+ renderstats.meshes++;
+ renderstats.meshes_elements += numelements;
if (gl_paranoid.integer)
{
- int i, j, size;
+ unsigned int i, j, size;
const int *p;
if (!qglIsEnabled(GL_VERTEX_ARRAY))
Con_Print("R_Mesh_Draw: vertex array not enabled\n");
- for (j = 0, size = numverts * (int)sizeof(float[3]), p = gl_state.pointer_vertex;j < size;j += sizeof(int), p++)
+ for (j = 0, size = numvertices * 3, p = (int *)((float *)gl_state.pointer_vertex + firstvertex * 3);j < size;j++, p++)
paranoidblah += *p;
if (gl_state.pointer_color)
{
if (!qglIsEnabled(GL_COLOR_ARRAY))
Con_Print("R_Mesh_Draw: color array set but not enabled\n");
- for (j = 0, size = numverts * (int)sizeof(float[4]), p = gl_state.pointer_color;j < size;j += sizeof(int), p++)
+ for (j = 0, size = numvertices * 4, p = (int *)((float *)gl_state.pointer_color + firstvertex * 4);j < size;j++, p++)
paranoidblah += *p;
}
- for (i = 0;i < backendunits;i++)
+ for (i = 0;i < backendarrayunits;i++)
{
- if (gl_state.units[i].t1d || gl_state.units[i].t2d || gl_state.units[i].t3d || gl_state.units[i].tcubemap || gl_state.units[i].arrayenabled)
+ if (gl_state.units[i].arrayenabled)
{
- if (gl_state.units[i].arrayenabled && !(gl_state.units[i].t1d || gl_state.units[i].t2d || gl_state.units[i].t3d || gl_state.units[i].tcubemap))
- Con_Print("R_Mesh_Draw: array enabled but no texture bound\n");
GL_ClientActiveTexture(i);
if (!qglIsEnabled(GL_TEXTURE_COORD_ARRAY))
Con_Print("R_Mesh_Draw: texcoord array set but not enabled\n");
- for (j = 0, size = numverts * ((gl_state.units[i].t3d || gl_state.units[i].tcubemap) ? (int)sizeof(float[3]) : (int)sizeof(float[2])), p = gl_state.units[i].pointer_texcoord;j < size;j += sizeof(int), p++)
+ 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++)
paranoidblah += *p;
}
}
- for (i = 0;i < numtriangles * 3;i++)
+ for (i = 0;i < (unsigned int) numtriangles * 3;i++)
{
- if (elements[i] < 0 || elements[i] >= numverts)
+ if (elements[i] < firstvertex || elements[i] >= firstvertex + numvertices)
{
- Con_Printf("R_Mesh_Draw: invalid vertex index %i (outside range 0 - %i) in elements list\n", elements[i], numverts);
+ Con_Printf("R_Mesh_Draw: invalid vertex index %i (outside range %i - %i) in elements list\n", elements[i], firstvertex, firstvertex + numvertices);
return;
}
}
CHECKGLERROR
if (gl_mesh_testmanualfeeding.integer)
{
- int i, j;
+ unsigned int i, j;
const GLfloat *p;
qglBegin(GL_TRIANGLES);
- for (i = 0;i < numtriangles * 3;i++)
+ for (i = 0;i < (unsigned int) numtriangles * 3;i++)
{
- for (j = 0;j < backendunits;j++)
+ for (j = 0;j < backendarrayunits;j++)
{
if (gl_state.units[j].pointer_texcoord)
{
- if (backendunits > 1)
+ if (backendarrayunits > 1)
{
- if (gl_state.units[j].t3d || gl_state.units[j].tcubemap)
+ if (gl_state.units[j].arraycomponents == 4)
+ {
+ p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 4;
+ qglMultiTexCoord4f(GL_TEXTURE0_ARB + j, p[0], p[1], p[2], p[3]);
+ }
+ else if (gl_state.units[j].arraycomponents == 3)
{
p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 3;
qglMultiTexCoord3f(GL_TEXTURE0_ARB + j, p[0], p[1], p[2]);
}
- else
+ else if (gl_state.units[j].arraycomponents == 2)
{
p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 2;
qglMultiTexCoord2f(GL_TEXTURE0_ARB + j, p[0], p[1]);
}
+ else
+ {
+ p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 1;
+ qglMultiTexCoord1f(GL_TEXTURE0_ARB + j, p[0]);
+ }
}
else
{
- if (gl_state.units[j].t3d || gl_state.units[j].tcubemap)
+ if (gl_state.units[j].arraycomponents == 4)
+ {
+ p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 4;
+ qglTexCoord4f(p[0], p[1], p[2], p[3]);
+ }
+ else if (gl_state.units[j].arraycomponents == 3)
{
p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 3;
qglTexCoord3f(p[0], p[1], p[2]);
}
- else
+ else if (gl_state.units[j].arraycomponents == 2)
{
p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 2;
qglTexCoord2f(p[0], p[1]);
}
+ else
+ {
+ p = ((const GLfloat *)(gl_state.units[j].pointer_texcoord)) + elements[i] * 1;
+ qglTexCoord1f(p[0]);
+ }
}
}
}
}
else if (gl_mesh_drawrangeelements.integer && qglDrawRangeElements != NULL)
{
- qglDrawRangeElements(GL_TRIANGLES, 0, numverts, numelements, GL_UNSIGNED_INT, elements);CHECKGLERROR
+ qglDrawRangeElements(GL_TRIANGLES, firstvertex, firstvertex + numvertices, numelements, GL_UNSIGNED_INT, elements);
+ CHECKGLERROR
}
else
{
- qglDrawElements(GL_TRIANGLES, numelements, GL_UNSIGNED_INT, elements);CHECKGLERROR
+ qglDrawElements(GL_TRIANGLES, numelements, GL_UNSIGNED_INT, elements);
+ CHECKGLERROR
}
- CHECKGLERROR
}
}
// restores backend state, used when done with 3D rendering
void R_Mesh_Finish(void)
{
- int i;
+ unsigned int i;
BACKENDACTIVECHECK
CHECKGLERROR
GL_LockArrays(0, 0);
CHECKGLERROR
- for (i = backendunits - 1;i >= 0;i--)
+ for (i = 0;i < backendimageunits;i++)
{
- if (qglActiveTexture)
- qglActiveTexture(GL_TEXTURE0_ARB + i);CHECKGLERROR
- if (qglClientActiveTexture)
- qglClientActiveTexture(GL_TEXTURE0_ARB + i);CHECKGLERROR
+ GL_ActiveTexture(i);
+ qglBindTexture(GL_TEXTURE_1D, 0);CHECKGLERROR
+ qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
+ if (gl_texture3d)
+ {
+ qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
+ }
+ if (gl_texturecubemap)
+ {
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);CHECKGLERROR
+ }
+ }
+ for (i = 0;i < backendarrayunits;i++)
+ {
+ GL_ActiveTexture(backendarrayunits - 1 - i);
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
+ }
+ for (i = 0;i < backendunits;i++)
+ {
+ GL_ActiveTexture(backendunits - 1 - i);
qglDisable(GL_TEXTURE_1D);CHECKGLERROR
qglDisable(GL_TEXTURE_2D);CHECKGLERROR
if (gl_texture3d)
}
}
-void R_Mesh_State(const rmeshstate_t *m)
+void R_Mesh_VertexPointer(const float *vertex3f)
{
- int i, combinergb, combinealpha, scale;
- gltextureunit_t *unit;
- matrix4x4_t tempmatrix;
-
- BACKENDACTIVECHECK
-
- if (gl_state.pointer_vertex != m->pointer_vertex)
+ if (gl_state.pointer_vertex != vertex3f)
{
- gl_state.pointer_vertex = m->pointer_vertex;
+ gl_state.pointer_vertex = vertex3f;
CHECKGLERROR
qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), gl_state.pointer_vertex);
CHECKGLERROR
}
+}
- if (r_showtrispass)
- return;
-
- if (gl_state.pointer_color != m->pointer_color)
+void R_Mesh_ColorPointer(const float *color4f)
+{
+ if (gl_state.pointer_color != color4f)
{
CHECKGLERROR
if (!gl_state.pointer_color)
qglEnableClientState(GL_COLOR_ARRAY);
CHECKGLERROR
}
- else if (!m->pointer_color)
+ else if (!color4f)
{
qglDisableClientState(GL_COLOR_ARRAY);
CHECKGLERROR
qglColor4f(gl_state.color4f[0], gl_state.color4f[1], gl_state.color4f[2], gl_state.color4f[3]);
CHECKGLERROR
}
- gl_state.pointer_color = m->pointer_color;
+ gl_state.pointer_color = color4f;
qglColorPointer(4, GL_FLOAT, sizeof(float[4]), gl_state.pointer_color);
CHECKGLERROR
}
+}
- if (gl_backend_rebindtextures)
+void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, const float *texcoord)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ // update array settings
+ if (texcoord)
{
- gl_backend_rebindtextures = false;
- GL_SetupTextureState();
+ // texcoord array
+ if (unit->pointer_texcoord != texcoord || unit->arraycomponents != numcomponents)
+ {
+ unit->pointer_texcoord = texcoord;
+ unit->arraycomponents = numcomponents;
+ GL_ClientActiveTexture(unitnum);
+ qglTexCoordPointer(unit->arraycomponents, GL_FLOAT, sizeof(float) * unit->arraycomponents, unit->pointer_texcoord);
+ CHECKGLERROR
+ }
+ // texture array unit is enabled, enable the array
+ if (!unit->arrayenabled)
+ {
+ unit->arrayenabled = true;
+ GL_ClientActiveTexture(unitnum);
+ qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
+ }
+ }
+ else
+ {
+ // texture array unit is disabled, disable the array
+ if (unit->arrayenabled)
+ {
+ unit->arrayenabled = false;
+ GL_ClientActiveTexture(unitnum);
+ qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
+ }
}
+}
- for (i = 0, unit = gl_state.units;i < backendunits;i++, unit++)
+void R_Mesh_TexBindAll(unsigned int unitnum, int tex1d, int tex2d, int tex3d, int texcubemap)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= backendimageunits)
+ return;
+ // update 1d texture binding
+ if (unit->t1d != tex1d)
{
- // update 1d texture binding
- if (unit->t1d != m->tex1d[i])
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- if (m->tex1d[i])
+ if (tex1d)
{
if (unit->t1d == 0)
- {
- GL_ActiveTexture(i);
- qglEnable(GL_TEXTURE_1D);CHECKGLERROR
- }
- unit->t1d = m->tex1d[i];
- GL_ActiveTexture(i);
- qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
+ qglEnable(GL_TEXTURE_1D);
}
else
{
if (unit->t1d)
- {
- unit->t1d = 0;
- GL_ActiveTexture(i);
- qglDisable(GL_TEXTURE_1D);CHECKGLERROR
- }
+ qglDisable(GL_TEXTURE_1D);
}
}
- // update 2d texture binding
- if (unit->t2d != m->tex[i])
+ unit->t1d = tex1d;
+ qglBindTexture(GL_TEXTURE_1D, unit->t1d);
+ CHECKGLERROR
+ }
+ // update 2d texture binding
+ if (unit->t2d != tex2d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- if (m->tex[i])
+ if (tex2d)
{
if (unit->t2d == 0)
- {
- GL_ActiveTexture(i);
- qglEnable(GL_TEXTURE_2D);CHECKGLERROR
- }
- unit->t2d = m->tex[i];
- GL_ActiveTexture(i);
- qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR
+ qglEnable(GL_TEXTURE_2D);
}
else
{
if (unit->t2d)
- {
- unit->t2d = 0;
- GL_ActiveTexture(i);
- qglDisable(GL_TEXTURE_2D);CHECKGLERROR
- }
+ qglDisable(GL_TEXTURE_2D);
}
}
- // update 3d texture binding
- if (unit->t3d != m->tex3d[i])
+ unit->t2d = tex2d;
+ qglBindTexture(GL_TEXTURE_2D, unit->t2d);
+ CHECKGLERROR
+ }
+ // update 3d texture binding
+ if (unit->t3d != tex3d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- if (m->tex3d[i])
+ if (tex3d)
{
if (unit->t3d == 0)
- {
- GL_ActiveTexture(i);
- qglEnable(GL_TEXTURE_3D);CHECKGLERROR
- }
- unit->t3d = m->tex3d[i];
- GL_ActiveTexture(i);
- qglBindTexture(GL_TEXTURE_3D, unit->t3d);CHECKGLERROR
+ qglEnable(GL_TEXTURE_3D);
}
else
{
if (unit->t3d)
- {
- unit->t3d = 0;
- GL_ActiveTexture(i);
- qglDisable(GL_TEXTURE_3D);CHECKGLERROR
- }
+ qglDisable(GL_TEXTURE_3D);
}
}
- // update cubemap texture binding
- if (unit->tcubemap != m->texcubemap[i])
+ unit->t3d = tex3d;
+ qglBindTexture(GL_TEXTURE_3D, unit->t3d);
+ CHECKGLERROR
+ }
+ // update cubemap texture binding
+ if (unit->tcubemap != texcubemap)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- if (m->texcubemap[i])
+ if (texcubemap)
{
if (unit->tcubemap == 0)
- {
- GL_ActiveTexture(i);
- qglEnable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
- }
- unit->tcubemap = m->texcubemap[i];
- GL_ActiveTexture(i);
- qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
+ qglEnable(GL_TEXTURE_CUBE_MAP_ARB);
}
else
{
if (unit->tcubemap)
- {
- unit->tcubemap = 0;
- GL_ActiveTexture(i);
- qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
- }
+ qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
}
}
- // update texture unit settings if the unit is enabled
- if (unit->t1d || unit->t2d || unit->t3d || unit->tcubemap)
+ unit->tcubemap = texcubemap;
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
+ CHECKGLERROR
+ }
+}
+
+void R_Mesh_TexBind1D(unsigned int unitnum, int texnum)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= backendimageunits)
+ return;
+ // update 1d texture binding
+ if (unit->t1d != texnum)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- // texture unit is enabled, enable the array
- if (!unit->arrayenabled)
+ if (texnum)
{
- unit->arrayenabled = true;
- GL_ClientActiveTexture(i);
- qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
- }
- // update combine settings
- if (gl_combine.integer)
- {
- // GL_ARB_texture_env_combine
- combinergb = m->texcombinergb[i] ? m->texcombinergb[i] : GL_MODULATE;
- if (unit->combinergb != combinergb)
- {
- unit->combinergb = combinergb;
- GL_ActiveTexture(i);
- qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, unit->combinergb);CHECKGLERROR
- }
- combinealpha = m->texcombinealpha[i] ? m->texcombinealpha[i] : GL_MODULATE;
- if (unit->combinealpha != combinealpha)
- {
- unit->combinealpha = combinealpha;
- GL_ActiveTexture(i);
- qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, unit->combinealpha);CHECKGLERROR
- }
- scale = max(m->texrgbscale[i], 1);
- if (unit->rgbscale != scale)
- {
- GL_ActiveTexture(i);
- qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (unit->rgbscale = scale));CHECKGLERROR
- }
- scale = max(m->texalphascale[i], 1);
- if (unit->alphascale != scale)
- {
- GL_ActiveTexture(i);
- qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, (unit->alphascale = scale));CHECKGLERROR
- }
- }
- else
- {
- // normal GL texenv
- combinergb = m->texcombinergb[i] ? m->texcombinergb[i] : GL_MODULATE;
- if (unit->combinergb != combinergb)
- {
- unit->combinergb = combinergb;
- GL_ActiveTexture(i);
- qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->combinergb);CHECKGLERROR
- }
- }
- // update array settings
- if (m->pointer_texcoord3f[i])
- {
- // 3d texcoord array
- if (unit->pointer_texcoord != m->pointer_texcoord3f[i] || !unit->arrayis3d)
- {
- unit->pointer_texcoord = m->pointer_texcoord3f[i];
- unit->arrayis3d = true;
- GL_ClientActiveTexture(i);
- qglTexCoordPointer(3, GL_FLOAT, sizeof(float[3]), unit->pointer_texcoord);
- CHECKGLERROR
- }
+ if (unit->t1d == 0)
+ qglEnable(GL_TEXTURE_1D);
}
else
{
- // 2d texcoord array
- if (unit->pointer_texcoord != m->pointer_texcoord[i] || unit->arrayis3d)
- {
- unit->pointer_texcoord = m->pointer_texcoord[i];
- unit->arrayis3d = false;
- GL_ClientActiveTexture(i);
- qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), unit->pointer_texcoord);
- CHECKGLERROR
- }
+ if (unit->t1d)
+ qglDisable(GL_TEXTURE_1D);
}
- // update texmatrix
- if (m->texmatrix[i].m[3][3])
+ }
+ unit->t1d = texnum;
+ qglBindTexture(GL_TEXTURE_1D, unit->t1d);
+ CHECKGLERROR
+ }
+ // update 2d texture binding
+ if (unit->t2d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ if (unit->t2d)
+ 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)
+ {
+ if (unit->t3d)
+ 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)
+ {
+ if (unit->tcubemap)
+ qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
+ }
+ unit->tcubemap = 0;
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
+ CHECKGLERROR
+ }
+}
+
+void R_Mesh_TexBind(unsigned int unitnum, int texnum)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= backendimageunits)
+ return;
+ // update 1d texture binding
+ if (unit->t1d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ if (unit->t1d)
+ qglDisable(GL_TEXTURE_1D);
+ }
+ unit->t1d = 0;
+ qglBindTexture(GL_TEXTURE_1D, unit->t1d);
+ CHECKGLERROR
+ }
+ // update 2d texture binding
+ if (unit->t2d != texnum)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ if (texnum)
{
- // texmatrix specified, check if it is different
- if (!unit->texmatrixenabled || memcmp(&unit->matrix, &m->texmatrix[i], sizeof(matrix4x4_t)))
- {
- unit->texmatrixenabled = true;
- unit->matrix = m->texmatrix[i];
- Matrix4x4_Transpose(&tempmatrix, &unit->matrix);
- qglMatrixMode(GL_TEXTURE);
- GL_ActiveTexture(i);
- qglLoadMatrixf(&tempmatrix.m[0][0]);
- qglMatrixMode(GL_MODELVIEW);
- }
+ if (unit->t2d == 0)
+ qglEnable(GL_TEXTURE_2D);
}
else
{
- // no texmatrix specified, revert to identity
- if (unit->texmatrixenabled)
- {
- unit->texmatrixenabled = false;
- qglMatrixMode(GL_TEXTURE);
- GL_ActiveTexture(i);
- qglLoadIdentity();
- qglMatrixMode(GL_MODELVIEW);
- }
+ if (unit->t2d)
+ qglDisable(GL_TEXTURE_2D);
}
}
- else
+ unit->t2d = texnum;
+ qglBindTexture(GL_TEXTURE_2D, unit->t2d);
+ CHECKGLERROR
+ }
+ // update 3d texture binding
+ if (unit->t3d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- // texture unit is disabled, disable the array
- if (unit->arrayenabled)
- {
- unit->arrayenabled = false;
- GL_ClientActiveTexture(i);
- qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
- }
- // no need to update most settings on a disabled texture unit
+ if (unit->t3d)
+ qglDisable(GL_TEXTURE_3D);
}
+ unit->t3d = 0;
+ qglBindTexture(GL_TEXTURE_3D, unit->t3d);
+ CHECKGLERROR
}
-}
-
-void R_Mesh_Draw_ShowTris(int numverts, int numtriangles, const int *elements)
-{
- qglBegin(GL_LINES);
- for (;numtriangles;numtriangles--, elements += 3)
+ // update cubemap texture binding
+ if (unit->tcubemap != 0)
{
- qglArrayElement(elements[0]);qglArrayElement(elements[1]);
- qglArrayElement(elements[1]);qglArrayElement(elements[2]);
- qglArrayElement(elements[2]);qglArrayElement(elements[0]);
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ if (unit->tcubemap)
+ qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
+ }
+ unit->tcubemap = 0;
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
+ CHECKGLERROR
}
- qglEnd();
- CHECKGLERROR
-}
-
-/*
-==============================================================================
-
- SCREEN SHOTS
-
-==============================================================================
-*/
-
-qboolean SCR_ScreenShot(char *filename, int x, int y, int width, int height, qboolean jpeg)
-{
- qboolean ret;
- qbyte *buffer;
-
- if (!r_render.integer)
- return false;
-
- buffer = Mem_Alloc(tempmempool, width*height*3);
- qglReadPixels (x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
- CHECKGLERROR
-
- if (jpeg)
- ret = JPEG_SaveImage_preflipped (filename, width, height, buffer);
- else
- ret = Image_WriteTGARGB_preflipped (filename, width, height, buffer);
-
- Mem_Free(buffer);
- return ret;
}
-//=============================================================================
-
-void R_ClearScreen(void)
+void R_Mesh_TexBind3D(unsigned int unitnum, int texnum)
{
- if (r_render.integer)
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= backendimageunits)
+ return;
+ // update 1d texture binding
+ if (unit->t1d)
{
- // clear to black
- qglClearColor(0,0,0,0);CHECKGLERROR
- qglClearDepth(1);CHECKGLERROR
- if (gl_stencil)
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- // LordHavoc: we use a stencil centered around 128 instead of 0,
- // to avoid clamping interfering with strange shadow volume
- // drawing orders
- qglClearStencil(128);CHECKGLERROR
+ if (unit->t1d)
+ qglDisable(GL_TEXTURE_1D);
}
- // clear the screen
- GL_Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | (gl_stencil ? GL_STENCIL_BUFFER_BIT : 0));
- // set dithering mode
- if (gl_dither.integer)
+ unit->t1d = 0;
+ qglBindTexture(GL_TEXTURE_1D, unit->t1d);
+ CHECKGLERROR
+ }
+ // update 2d texture binding
+ if (unit->t2d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- qglEnable(GL_DITHER);CHECKGLERROR
+ if (unit->t2d)
+ qglDisable(GL_TEXTURE_2D);
}
- else
+ unit->t2d = 0;
+ qglBindTexture(GL_TEXTURE_2D, unit->t2d);
+ CHECKGLERROR
+ }
+ // update 3d texture binding
+ if (unit->t3d != texnum)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- qglDisable(GL_DITHER);CHECKGLERROR
+ if (texnum)
+ {
+ if (unit->t3d == 0)
+ qglEnable(GL_TEXTURE_3D);
+ }
+ else
+ {
+ if (unit->t3d)
+ qglDisable(GL_TEXTURE_3D);
+ }
}
+ unit->t3d = texnum;
+ qglBindTexture(GL_TEXTURE_3D, unit->t3d);
+ CHECKGLERROR
+ }
+ // update cubemap texture binding
+ if (unit->tcubemap != 0)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ if (unit->tcubemap)
+ qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
+ }
+ unit->tcubemap = 0;
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
+ CHECKGLERROR
}
}
-/*
-====================
-CalcFov
-====================
-*/
-float CalcFov (float fov_x, float width, float height)
-{
- // calculate vision size and alter by aspect, then convert back to angle
- return atan (height / (width / tan(fov_x/360*M_PI))) * 360 / M_PI;
-}
-
-/*
-==================
-SCR_UpdateScreen
-
-This is called every frame, and can also be called explicitly to flush
-text to the screen.
-==================
-*/
-void SCR_UpdateScreen (void)
+void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum)
{
- if (gl_delayfinish.integer)
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (unitnum >= backendimageunits)
+ return;
+ // update 1d texture binding
+ if (unit->t1d)
{
- R_Mesh_Finish();
- R_TimeReport("meshfinish");
- VID_Finish();
- R_TimeReport("finish");
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ if (unit->t1d)
+ qglDisable(GL_TEXTURE_1D);
+ }
+ unit->t1d = 0;
+ qglBindTexture(GL_TEXTURE_1D, unit->t1d);
+ CHECKGLERROR
}
-
- R_Mesh_Start();
-
- if (r_textureunits.integer > gl_textureunits)
- Cvar_SetValueQuick(&r_textureunits, gl_textureunits);
- if (r_textureunits.integer < 1)
- Cvar_SetValueQuick(&r_textureunits, 1);
-
- if (gl_combine.integer && (!gl_combine_extension || r_textureunits.integer < 2))
- Cvar_SetValueQuick(&gl_combine, 0);
-
-showtris:
- R_TimeReport("setup");
-
- R_ClearScreen();
-
- R_TimeReport("clear");
-
- if (scr_conlines < vid.conheight && cls.signon == SIGNONS)
+ // update 2d texture binding
+ if (unit->t2d)
{
- float size;
- int contents;
-
- // bound viewsize
- if (scr_viewsize.value < 30)
- Cvar_Set ("viewsize","30");
- if (scr_viewsize.value > 120)
- Cvar_Set ("viewsize","120");
-
- // bound field of view
- if (scr_fov.value < 1)
- Cvar_Set ("fov","1");
- if (scr_fov.value > 170)
- Cvar_Set ("fov","170");
-
- // intermission is always full screen
- if (cl.intermission)
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- size = 1;
- sb_lines = 0;
+ if (unit->t2d)
+ qglDisable(GL_TEXTURE_2D);
}
- else
+ unit->t2d = 0;
+ qglBindTexture(GL_TEXTURE_2D, unit->t2d);
+ CHECKGLERROR
+ }
+ // update 3d texture binding
+ if (unit->t3d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ if (unit->t3d)
+ qglDisable(GL_TEXTURE_3D);
+ }
+ unit->t3d = 0;
+ qglBindTexture(GL_TEXTURE_3D, unit->t3d);
+ CHECKGLERROR
+ }
+ // update cubemap texture binding
+ if (unit->tcubemap != texnum)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
{
- if (scr_viewsize.value >= 120)
- sb_lines = 0; // no status bar at all
- else if (scr_viewsize.value >= 110)
- sb_lines = 24; // no inventory
+ if (texnum)
+ {
+ if (unit->tcubemap == 0)
+ qglEnable(GL_TEXTURE_CUBE_MAP_ARB);
+ }
else
- sb_lines = 24+16+8;
- size = scr_viewsize.value * (1.0 / 100.0);
- size = min(size, 1);
- }
-
- r_refdef.width = vid.realwidth * size;
- r_refdef.height = vid.realheight * size;
- r_refdef.x = (vid.realwidth - r_refdef.width)/2;
- r_refdef.y = (vid.realheight - r_refdef.height)/2;
-
- // LordHavoc: viewzoom (zoom in for sniper rifles, etc)
- r_refdef.fov_x = scr_fov.value * cl.viewzoom;
- r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.width, r_refdef.height);
-
- if (r_waterwarp.value > 0)
- {
- if (cl.worldmodel)
{
- Mod_CheckLoaded(cl.worldmodel);
- contents = CL_PointSuperContents(r_vieworigin);
- if (contents & SUPERCONTENTS_LIQUIDSMASK)
- {
- r_refdef.fov_x *= 1 - (((sin(cl.time * 4.7) + 1) * 0.015) * r_waterwarp.value);
- r_refdef.fov_y *= 1 - (((sin(cl.time * 3.0) + 1) * 0.015) * r_waterwarp.value);
- }
+ if (unit->tcubemap)
+ qglDisable(GL_TEXTURE_CUBE_MAP_ARB);
}
}
+ unit->tcubemap = texnum;
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);
+ CHECKGLERROR
+ }
+}
- R_RenderView();
-
- if (scr_zoomwindow.integer)
+void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (matrix->m[3][3])
+ {
+ // texmatrix specified, check if it is different
+ if (!unit->texmatrixenabled || memcmp(&unit->matrix, matrix, sizeof(matrix4x4_t)))
{
- float sizex = bound(10, scr_zoomwindow_viewsizex.value, 100) / 100.0;
- float sizey = bound(10, scr_zoomwindow_viewsizey.value, 100) / 100.0;
- r_refdef.width = vid.realwidth * sizex;
- r_refdef.height = vid.realheight * sizey;
- r_refdef.x = (vid.realwidth - r_refdef.width)/2;
- r_refdef.y = 0;
- r_refdef.fov_x = scr_zoomwindow_fov.value;
- r_refdef.fov_y = CalcFov(r_refdef.fov_x, r_refdef.width, r_refdef.height);
-
- R_RenderView();
+ matrix4x4_t tempmatrix;
+ unit->texmatrixenabled = true;
+ unit->matrix = *matrix;
+ Matrix4x4_Transpose(&tempmatrix, &unit->matrix);
+ qglMatrixMode(GL_TEXTURE);
+ GL_ActiveTexture(unitnum);
+ qglLoadMatrixf(&tempmatrix.m[0][0]);
+ qglMatrixMode(GL_MODELVIEW);
}
}
-
- // draw 2D stuff
- R_DrawQueue();
-
- if (r_showtrispass)
- r_showtrispass = false;
- else if (r_showtris.value > 0)
+ else
{
- rmeshstate_t m;
- GL_BlendFunc(GL_ONE, GL_ONE);
- GL_DepthTest(GL_FALSE);
- GL_DepthMask(GL_FALSE);
- memset(&m, 0, sizeof(m));
- R_Mesh_State(&m);
- r_showtrispass = true;
- GL_ShowTrisColor(0.2,0.2,0.2,1);
- goto showtris;
+ // no texmatrix specified, revert to identity
+ if (unit->texmatrixenabled)
+ {
+ unit->texmatrixenabled = false;
+ qglMatrixMode(GL_TEXTURE);
+ GL_ActiveTexture(unitnum);
+ qglLoadIdentity();
+ qglMatrixMode(GL_MODELVIEW);
+ }
}
+}
- if (gl_delayfinish.integer)
+void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, int rgbscale, int alphascale)
+{
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ if (gl_combine.integer)
{
- // tell driver to commit it's partially full geometry queue to the rendering queue
- // (this doesn't wait for the commands themselves to complete)
- qglFlush();
+ // GL_ARB_texture_env_combine
+ if (!combinergb)
+ combinergb = GL_MODULATE;
+ if (!combinealpha)
+ combinealpha = GL_MODULATE;
+ if (!rgbscale)
+ rgbscale = 1;
+ if (!alphascale)
+ alphascale = 1;
+ if (unit->combinergb != combinergb)
+ {
+ unit->combinergb = combinergb;
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, unit->combinergb);CHECKGLERROR
+ }
+ if (unit->combinealpha != combinealpha)
+ {
+ unit->combinealpha = combinealpha;
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, unit->combinealpha);CHECKGLERROR
+ }
+ if (unit->rgbscale != rgbscale)
+ {
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (unit->rgbscale = rgbscale));CHECKGLERROR
+ }
+ if (unit->alphascale != alphascale)
+ {
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, (unit->alphascale = alphascale));CHECKGLERROR
+ }
}
else
{
- R_Mesh_Finish();
- R_TimeReport("meshfinish");
- VID_Finish();
- R_TimeReport("finish");
+ // normal GL texenv
+ if (!combinergb)
+ combinergb = GL_MODULATE;
+ if (unit->combinergb != combinergb)
+ {
+ unit->combinergb = combinergb;
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->combinergb);CHECKGLERROR
+ }
}
}
+void R_Mesh_TextureState(const rmeshstate_t *m)
+{
+ unsigned int i;
-//===========================================================================
-// dynamic vertex array buffer subsystem
-//===========================================================================
-
-float varray_vertex3f[65536*3];
-float varray_color4f[65536*4];
-float varray_texcoord2f[4][65536*2];
-float varray_texcoord3f[4][65536*3];
-float varray_normal3f[65536*3];
-int earray_element3i[65536];
+ BACKENDACTIVECHECK
-//===========================================================================
-// vertex array caching subsystem
-//===========================================================================
+ if (gl_backend_rebindtextures)
+ {
+ gl_backend_rebindtextures = false;
+ GL_SetupTextureState();
+ }
-typedef struct rcachearraylink_s
-{
- struct rcachearraylink_s *next, *prev;
- struct rcachearrayitem_s *data;
+ for (i = 0;i < backendimageunits;i++)
+ R_Mesh_TexBindAll(i, m->tex1d[i], m->tex[i], m->tex3d[i], m->texcubemap[i]);
+ for (i = 0;i < backendarrayunits;i++)
+ {
+ if (m->pointer_texcoord3f[i])
+ R_Mesh_TexCoordPointer(i, 3, m->pointer_texcoord3f[i]);
+ else
+ R_Mesh_TexCoordPointer(i, 2, m->pointer_texcoord[i]);
+ }
+ for (i = 0;i < backendunits;i++)
+ {
+ R_Mesh_TexMatrix(i, &m->texmatrix[i]);
+ R_Mesh_TexCombine(i, m->texcombinergb[i], m->texcombinealpha[i], m->texrgbscale[i], m->texalphascale[i]);
+ }
}
-rcachearraylink_t;
-typedef struct rcachearrayitem_s
+void R_Mesh_ResetTextureState(void)
{
- // the original request structure
- rcachearrayrequest_t request;
- // active
- int active;
- // offset into r_mesh_rcachedata
- int offset;
- // for linking this into the sequential list
- rcachearraylink_t sequentiallink;
- // for linking this into the lookup list
- rcachearraylink_t hashlink;
-}
-rcachearrayitem_t;
-
-#define RCACHEARRAY_HASHSIZE 65536
-#define RCACHEARRAY_ITEMS 4096
-#define RCACHEARRAY_DEFAULTSIZE (4 << 20)
-
-// all active items are linked into this chain in sorted order
-static rcachearraylink_t r_mesh_rcachesequentialchain;
-// all inactive items are linked into this chain in unknown order
-static rcachearraylink_t r_mesh_rcachefreechain;
-// all active items are also linked into these chains (using their hashlink)
-static rcachearraylink_t r_mesh_rcachechain[RCACHEARRAY_HASHSIZE];
-
-// all items are stored here, whether active or inactive
-static rcachearrayitem_t r_mesh_rcacheitems[RCACHEARRAY_ITEMS];
-
-// size of data buffer
-static int r_mesh_rcachedata_size = RCACHEARRAY_DEFAULTSIZE;
-// data buffer
-static qbyte r_mesh_rcachedata[RCACHEARRAY_DEFAULTSIZE];
-
-// current state
-static int r_mesh_rcachedata_offset;
-static rcachearraylink_t *r_mesh_rcachesequentialchain_current;
+ unsigned int unitnum;
-static void R_Mesh_CacheArray_Startup(void)
-{
- int i;
- rcachearraylink_t *l;
- // prepare all the linked lists
- l = &r_mesh_rcachesequentialchain;l->next = l->prev = l;l->data = NULL;
- l = &r_mesh_rcachefreechain;l->next = l->prev = l;l->data = NULL;
- memset(&r_mesh_rcachechain, 0, sizeof(r_mesh_rcachechain));
- for (i = 0;i < RCACHEARRAY_HASHSIZE;i++)
- {
- l = &r_mesh_rcachechain[i];
- l->next = l->prev = l;
- l->data = NULL;
- }
- memset(&r_mesh_rcacheitems, 0, sizeof(r_mesh_rcacheitems));
- for (i = 0;i < RCACHEARRAY_ITEMS;i++)
- {
- r_mesh_rcacheitems[i].hashlink.data = r_mesh_rcacheitems[i].sequentiallink.data = &r_mesh_rcacheitems[i];
- l = &r_mesh_rcacheitems[i].sequentiallink;
- l->next = &r_mesh_rcachefreechain;
- l->prev = l->next->prev;
- l->next->prev = l->prev->next = l;
- }
- // clear other state
- r_mesh_rcachedata_offset = 0;
- r_mesh_rcachesequentialchain_current = &r_mesh_rcachesequentialchain;
-}
+ BACKENDACTIVECHECK
-static void R_Mesh_CacheArray_Shutdown(void)
-{
-}
+ if (gl_backend_rebindtextures)
+ {
+ gl_backend_rebindtextures = false;
+ GL_SetupTextureState();
+ }
-/*
-static void R_Mesh_CacheArray_ValidateState(int num)
-{
- rcachearraylink_t *l, *lhead;
- lhead = &r_mesh_rcachesequentialchain;
- if (r_mesh_rcachesequentialchain_current == lhead)
- return;
- for (l = lhead->next;l != lhead;l = l->next)
- if (r_mesh_rcachesequentialchain_current == l)
- return;
- Sys_Error("%i", num);
+ 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
+ }
+ }
+ }
}
-*/
-int R_Mesh_CacheArray(rcachearrayrequest_t *r)
+void R_Mesh_Draw_ShowTris(int firstvertex, int numvertices, int numtriangles, const int *elements)
{
- rcachearraylink_t *l, *lhead, *lnext;
- rcachearrayitem_t *d;
- int hashindex, offset, offsetend;
-
- //R_Mesh_CacheArray_ValidateState(3);
- // calculate a hashindex to choose a cache chain
- r->data = NULL;
- hashindex = CRC_Block((void *)r, sizeof(*r)) % RCACHEARRAY_HASHSIZE;
-
- // is it already cached?
- for (lhead = &r_mesh_rcachechain[hashindex], l = lhead->next;l != lhead;l = l->next)
- {
- if (!memcmp(&l->data->request, r, sizeof(l->data->request)))
- {
- // we have it cached already
- r->data = r_mesh_rcachedata + l->data->offset;
- return false;
- }
- }
-
- // we need to add a new cache item, this means finding a place for the new
- // data and making sure we have a free item available, lots of work...
-
- // check if buffer needs to wrap
- if (r_mesh_rcachedata_offset + r->data_size > r_mesh_rcachedata_size)
- {
- /*
- if (r->data_size * 10 > r_mesh_rcachedata_size)
- {
- // realloc whole cache
- }
- */
- // reset back to start
- r_mesh_rcachedata_offset = 0;
- r_mesh_rcachesequentialchain_current = &r_mesh_rcachesequentialchain;
- }
- offset = r_mesh_rcachedata_offset;
- r_mesh_rcachedata_offset += r->data_size;
- offsetend = r_mesh_rcachedata_offset;
- //R_Mesh_CacheArray_ValidateState(4);
-
- /*
- {
- int n;
- for (lhead = &r_mesh_rcachesequentialchain, l = lhead->next, n = 0;l != lhead;l = l->next, n++);
- Con_Printf("R_Mesh_CacheArray: new data range %i:%i, %i items are already linked\n", offset, offsetend, n);
- }
- */
-
- // make room for the new data (remove old items)
- lhead = &r_mesh_rcachesequentialchain;
- l = r_mesh_rcachesequentialchain_current;
- if (l == lhead)
- l = l->next;
- while (l != lhead && l->data->offset < offsetend && l->data->offset + l->data->request.data_size > offset)
- {
- //r_mesh_rcachesequentialchain_current = l;
- //R_Mesh_CacheArray_ValidateState(8);
- lnext = l->next;
- // if at the end of the chain, wrap around
- if (lnext == lhead)
- lnext = lnext->next;
- //r_mesh_rcachesequentialchain_current = lnext;
- //R_Mesh_CacheArray_ValidateState(10);
-
- // unlink from sequential chain
- l->next->prev = l->prev;
- l->prev->next = l->next;
- //R_Mesh_CacheArray_ValidateState(11);
- // link into free chain
- l->next = &r_mesh_rcachefreechain;
- l->prev = l->next->prev;
- l->next->prev = l->prev->next = l;
- //R_Mesh_CacheArray_ValidateState(12);
-
- l = &l->data->hashlink;
- // unlink from hash chain
- l->next->prev = l->prev;
- l->prev->next = l->next;
-
- l = lnext;
- //r_mesh_rcachesequentialchain_current = l;
- //R_Mesh_CacheArray_ValidateState(9);
- }
- //r_mesh_rcachesequentialchain_current = l;
- //R_Mesh_CacheArray_ValidateState(5);
- // gobble an extra item if we have no free items available
- if (r_mesh_rcachefreechain.next == &r_mesh_rcachefreechain)
- {
- lnext = l->next;
-
- // unlink from sequential chain
- l->next->prev = l->prev;
- l->prev->next = l->next;
- // link into free chain
- l->next = &r_mesh_rcachefreechain;
- l->prev = l->next->prev;
- l->next->prev = l->prev->next = l;
-
- l = &l->data->hashlink;
- // unlink from hash chain
- l->next->prev = l->prev;
- l->prev->next = l->next;
-
- l = lnext;
- }
- r_mesh_rcachesequentialchain_current = l;
- //R_Mesh_CacheArray_ValidateState(6);
-
- // now take an item from the free chain
- l = r_mesh_rcachefreechain.next;
- // set it up
- d = l->data;
- d->request = *r;
- d->offset = offset;
- // unlink
- l->next->prev = l->prev;
- l->prev->next = l->next;
- // relink to sequential
- l->next = r_mesh_rcachesequentialchain_current->prev;
- l->prev = l->next->prev;
- while (l->next->data && l->data && l->next->data->offset <= d->offset)
- {
- //Con_Print(">\n");
- l->next = l->next->next;
- l->prev = l->prev->next;
- }
- while (l->prev->data && l->data && l->prev->data->offset >= d->offset)
- {
- //Con_Print("<\n");
- l->prev = l->prev->prev;
- l->next = l->next->prev;
- }
- l->next->prev = l->prev->next = l;
- // also link into hash chain
- l = &l->data->hashlink;
- l->next = &r_mesh_rcachechain[hashindex];
- l->prev = l->next->prev;
- l->prev->next = l;
- l->next->prev = l->prev->next = l;
-
-
- //r_mesh_rcachesequentialchain_current = d->sequentiallink.next;
-
- //R_Mesh_CacheArray_ValidateState(7);
- // and finally set the data pointer
- r->data = r_mesh_rcachedata + d->offset;
- // and tell the caller to fill the array
- return true;
+ qglBegin(GL_LINES);
+ for (;numtriangles;numtriangles--, elements += 3)
+ {
+ qglArrayElement(elements[0]);qglArrayElement(elements[1]);
+ qglArrayElement(elements[1]);qglArrayElement(elements[2]);
+ qglArrayElement(elements[2]);qglArrayElement(elements[0]);
+ }
+ qglEnd();
+ CHECKGLERROR
}
-