X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=gl_backend.c;h=ddfe5bbc39fff9998c848b85ae28d47afdaabf31;hb=69a9f6bb4ea7d2a62b22238da58fe99d0ebd41d8;hp=c686bd5361c498733452f831eb481708b87120f7;hpb=9dc5208ff6b6b5969b5b86113363cbbc3b42850f;p=xonotic%2Fdarkplaces.git diff --git a/gl_backend.c b/gl_backend.c index c686bd53..ddfe5bbc 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -1,25 +1,18 @@ #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_paranoid = {0, "gl_paranoid", "0"}; -cvar_t gl_printcheckerror = {0, "gl_printcheckerror", "0"}; -cvar_t r_stereo_separation = {0, "r_stereo_separation", "4"}; -cvar_t r_stereo_sidebyside = {0, "r_stereo_sidebyside", "0"}; -cvar_t r_stereo_redblue = {0, "r_stereo_redblue", "0"}; -cvar_t r_stereo_redcyan = {0, "r_stereo_redcyan", "0"}; -cvar_t r_stereo_redgreen = {0, "r_stereo_redgreen", "0"}; - -cvar_t r_render = {0, "r_render", "1"}; -cvar_t r_waterwarp = {CVAR_SAVE, "r_waterwarp", "1"}; -cvar_t gl_polyblend = {CVAR_SAVE, "gl_polyblend", "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 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", "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; @@ -73,7 +66,7 @@ void GL_PrintError(int errornumber, char *filename, int linenumber) } #endif -#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active\n"); +#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active"); void SCR_ScreenShot_f (void); @@ -84,7 +77,6 @@ static matrix4x4_t backend_glmodelviewmatrix; static matrix4x4_t backend_projectmatrix; static unsigned int backendunits, backendimageunits, backendarrayunits, backendactive; -static mempool_t *gl_backend_mempool; /* note: here's strip order for a terrain row: @@ -140,21 +132,15 @@ for (y = 0;y < rows - 1;y++) } */ -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", 0, NULL); - R_Mesh_CacheArray_Startup(); } void GL_Backend_FreeArrays(void) { - R_Mesh_CacheArray_Shutdown(); - Mem_FreePool(&gl_backend_mempool); } static void gl_backend_start(void) @@ -178,9 +164,9 @@ static void gl_backend_start(void) if (gl_support_fragment_shader) { CHECKGLERROR - qglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &backendimageunits); + qglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, (int *)&backendimageunits); CHECKGLERROR - qglGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &backendarrayunits); + 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); } @@ -214,11 +200,6 @@ static void gl_backend_newmap(void) { } -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; @@ -229,14 +210,19 @@ void gl_backend_init(void) 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(&r_stereo_separation); - Cvar_RegisterVariable(&r_stereo_sidebyside); - Cvar_RegisterVariable(&r_stereo_redblue); - Cvar_RegisterVariable(&r_stereo_redcyan); - Cvar_RegisterVariable(&r_stereo_redgreen); Cvar_RegisterVariable(&gl_polyblend); Cvar_RegisterVariable(&gl_dither); Cvar_RegisterVariable(&gl_lockarrays); @@ -250,17 +236,12 @@ void gl_backend_init(void) 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)); } @@ -278,9 +259,8 @@ void GL_SetupView_Orientation_FromEntity(matrix4x4_t *matrix) 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) @@ -289,11 +269,8 @@ void GL_SetupView_Mode_Perspective (double fovx, double fovy, double zNear, doub // 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]; @@ -315,7 +292,7 @@ void GL_SetupView_Mode_Perspective (double fovx, double fovy, double zNear, doub 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]; @@ -327,12 +304,12 @@ void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double fovx, double fovy, dou 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; @@ -401,7 +378,7 @@ typedef struct gltextureunit_s int t1d, t2d, t3d, tcubemap; int arrayenabled; unsigned int arraycomponents; - const float *pointer_texcoord; + const void *pointer_texcoord; float rgbscale, alphascale; int combinergb, combinealpha; // FIXME: add more combine stuff @@ -411,7 +388,7 @@ typedef struct gltextureunit_s } gltextureunit_t; -static struct +static struct gl_state_s { int blendfunc1; int blendfunc2; @@ -426,8 +403,8 @@ static struct float color4f[4]; int lockrange_first; int lockrange_count; - const float *pointer_vertex; - const float *pointer_color; + const void *pointer_vertex; + const void *pointer_color; } gl_state; @@ -436,8 +413,8 @@ void GL_SetupTextureState(void) unsigned int i; gltextureunit_t *unit; CHECKGLERROR - gl_state.unit = -1; - gl_state.clientunit = -1; + gl_state.unit = MAX_TEXTUREUNITS; + gl_state.clientunit = MAX_TEXTUREUNITS; for (i = 0;i < MAX_TEXTUREUNITS;i++) { unit = gl_state.units + i; @@ -453,7 +430,7 @@ void GL_SetupTextureState(void) unit->combinergb = GL_MODULATE; unit->combinealpha = GL_MODULATE; unit->texmatrixenabled = false; - unit->matrix = r_identitymatrix; + unit->matrix = identitymatrix; } for (i = 0;i < backendimageunits;i++) @@ -636,7 +613,7 @@ void GL_DepthTest(int state) { if (gl_state.depthtest != state) { - if (r_showtrispass) + if (r_showtrispass && r_showdisabledepthtest.integer) return; gl_state.depthtest = state; if (gl_state.depthtest) @@ -655,8 +632,6 @@ 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 } @@ -682,9 +657,9 @@ void GL_ShowTrisColor(float cr, float cg, float cb, float ca) { if (!r_showtrispass) return; - r_showtrispass = false; + r_showtrispass = 0; GL_Color(cr * r_showtris.value, cg * r_showtris.value, cb * r_showtris.value, ca); - r_showtrispass = true; + r_showtrispass = 1; } @@ -713,7 +688,7 @@ void GL_LockArrays(int first, int count) 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 } @@ -732,8 +707,10 @@ void GL_ScissorTest(int state) void GL_Clear(int mask) { + // in showtris rendering, don't clear the color buffer as that would hide + // the accumulated lines if (r_showtrispass) - return; + mask &= ~GL_COLOR_BUFFER_BIT; qglClear(mask);CHECKGLERROR } @@ -761,7 +738,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver { GLint vertexshadercompiled, fragmentshadercompiled, programlinked; GLuint vertexshaderobject, fragmentshaderobject, programobject = 0; - char compilelog[4096]; + char compilelog[MAX_INPUTLINE]; CHECKGLERROR programobject = qglCreateProgramObjectARB(); @@ -785,7 +762,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver qglGetObjectParameterivARB(vertexshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &vertexshadercompiled); qglGetInfoLogARB(vertexshaderobject, sizeof(compilelog), NULL, compilelog); if (compilelog[0]) - Con_Printf("vertex shader compile log:\n%s\n", compilelog); + Con_DPrintf("vertex shader compile log:\n%s\n", compilelog); if (!vertexshadercompiled) { qglDeleteObjectARB(programobject); @@ -814,7 +791,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver qglGetObjectParameterivARB(fragmentshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &fragmentshadercompiled); qglGetInfoLogARB(fragmentshaderobject, sizeof(compilelog), NULL, compilelog); if (compilelog[0]) - Con_Printf("fragment shader compile log:\n%s\n", compilelog); + Con_DPrintf("fragment shader compile log:\n%s\n", compilelog); if (!fragmentshadercompiled) { qglDeleteObjectARB(programobject); @@ -833,7 +810,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver qglGetInfoLogARB(programobject, sizeof(compilelog), NULL, compilelog); if (compilelog[0]) { - Con_Printf("program link log:\n%s\n", compilelog); + 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 @@ -890,21 +867,21 @@ void R_Mesh_Draw(int firstvertex, int numvertices, int numtriangles, const int * R_Mesh_Draw_ShowTris(firstvertex, numvertices, numtriangles, elements); return; } - c_meshs++; - c_meshelements += numelements; + renderstats.meshes++; + renderstats.meshes_elements += numelements; if (gl_paranoid.integer) { 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 = numvertices * 3, p = gl_state.pointer_vertex + firstvertex * 3;j < size;j++, 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 = numvertices * 4, p = gl_state.pointer_color + firstvertex * 4;j < size;j++, 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 < backendarrayunits;i++) @@ -914,7 +891,7 @@ void R_Mesh_Draw(int firstvertex, int numvertices, int numtriangles, const int * 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 = numvertices * gl_state.units[i].arraycomponents, p = gl_state.units[i].pointer_texcoord + firstvertex * gl_state.units[i].arraycomponents;j < size;j++, 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; } } @@ -1106,6 +1083,8 @@ void R_Mesh_VertexPointer(const float *vertex3f) void R_Mesh_ColorPointer(const float *color4f) { + if (r_showtrispass) + return; if (gl_state.pointer_color != color4f) { CHECKGLERROR @@ -1131,6 +1110,8 @@ void R_Mesh_ColorPointer(const float *color4f) void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, const float *texcoord) { gltextureunit_t *unit = gl_state.units + unitnum; + if (r_showtrispass) + return; // update array settings if (texcoord) { @@ -1166,7 +1147,9 @@ void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, co void R_Mesh_TexBindAll(unsigned int unitnum, int tex1d, int tex2d, int tex3d, int texcubemap) { gltextureunit_t *unit = gl_state.units + unitnum; - if (unitnum >= backendunits) + if (unitnum >= backendimageunits) + return; + if (r_showtrispass) return; // update 1d texture binding if (unit->t1d != tex1d) @@ -1257,21 +1240,26 @@ void R_Mesh_TexBindAll(unsigned int unitnum, int tex1d, int tex2d, int tex3d, in void R_Mesh_TexBind1D(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; - if (unitnum >= backendunits) + if (unitnum >= backendimageunits) + return; + if (r_showtrispass) return; // update 1d texture binding if (unit->t1d != texnum) { GL_ActiveTexture(unitnum); - if (texnum) - { - if (unit->t1d == 0) - qglEnable(GL_TEXTURE_1D); - } - else + if (unitnum < backendunits) { - if (unit->t1d) - qglDisable(GL_TEXTURE_1D); + if (texnum) + { + if (unit->t1d == 0) + qglEnable(GL_TEXTURE_1D); + } + else + { + if (unit->t1d) + qglDisable(GL_TEXTURE_1D); + } } unit->t1d = texnum; qglBindTexture(GL_TEXTURE_1D, unit->t1d); @@ -1281,8 +1269,11 @@ void R_Mesh_TexBind1D(unsigned int unitnum, int texnum) if (unit->t2d) { GL_ActiveTexture(unitnum); - if (unit->t2d) - qglDisable(GL_TEXTURE_2D); + if (unitnum < backendunits) + { + if (unit->t2d) + qglDisable(GL_TEXTURE_2D); + } unit->t2d = 0; qglBindTexture(GL_TEXTURE_2D, unit->t2d); CHECKGLERROR @@ -1291,8 +1282,11 @@ void R_Mesh_TexBind1D(unsigned int unitnum, int texnum) if (unit->t3d) { GL_ActiveTexture(unitnum); - if (unit->t3d) - qglDisable(GL_TEXTURE_3D); + if (unitnum < backendunits) + { + if (unit->t3d) + qglDisable(GL_TEXTURE_3D); + } unit->t3d = 0; qglBindTexture(GL_TEXTURE_3D, unit->t3d); CHECKGLERROR @@ -1301,8 +1295,11 @@ void R_Mesh_TexBind1D(unsigned int unitnum, int texnum) if (unit->tcubemap) { GL_ActiveTexture(unitnum); - if (unit->tcubemap) - qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + if (unitnum < backendunits) + { + if (unit->tcubemap) + qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + } unit->tcubemap = 0; qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap); CHECKGLERROR @@ -1312,14 +1309,19 @@ void R_Mesh_TexBind1D(unsigned int unitnum, int texnum) void R_Mesh_TexBind(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; - if (unitnum >= backendunits) + if (unitnum >= backendimageunits) + return; + if (r_showtrispass) return; // update 1d texture binding if (unit->t1d) { GL_ActiveTexture(unitnum); - if (unit->t1d) - qglDisable(GL_TEXTURE_1D); + if (unitnum < backendunits) + { + if (unit->t1d) + qglDisable(GL_TEXTURE_1D); + } unit->t1d = 0; qglBindTexture(GL_TEXTURE_1D, unit->t1d); CHECKGLERROR @@ -1328,15 +1330,18 @@ void R_Mesh_TexBind(unsigned int unitnum, int texnum) if (unit->t2d != texnum) { GL_ActiveTexture(unitnum); - if (texnum) - { - if (unit->t2d == 0) - qglEnable(GL_TEXTURE_2D); - } - else + if (unitnum < backendunits) { - if (unit->t2d) - qglDisable(GL_TEXTURE_2D); + if (texnum) + { + if (unit->t2d == 0) + qglEnable(GL_TEXTURE_2D); + } + else + { + if (unit->t2d) + qglDisable(GL_TEXTURE_2D); + } } unit->t2d = texnum; qglBindTexture(GL_TEXTURE_2D, unit->t2d); @@ -1346,8 +1351,11 @@ void R_Mesh_TexBind(unsigned int unitnum, int texnum) if (unit->t3d) { GL_ActiveTexture(unitnum); - if (unit->t3d) - qglDisable(GL_TEXTURE_3D); + if (unitnum < backendunits) + { + if (unit->t3d) + qglDisable(GL_TEXTURE_3D); + } unit->t3d = 0; qglBindTexture(GL_TEXTURE_3D, unit->t3d); CHECKGLERROR @@ -1356,8 +1364,11 @@ void R_Mesh_TexBind(unsigned int unitnum, int texnum) if (unit->tcubemap != 0) { GL_ActiveTexture(unitnum); - if (unit->tcubemap) - qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + if (unitnum < backendunits) + { + if (unit->tcubemap) + qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + } unit->tcubemap = 0; qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap); CHECKGLERROR @@ -1367,14 +1378,19 @@ void R_Mesh_TexBind(unsigned int unitnum, int texnum) void R_Mesh_TexBind3D(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; - if (unitnum >= backendunits) + if (unitnum >= backendimageunits) + return; + if (r_showtrispass) return; // update 1d texture binding if (unit->t1d) { GL_ActiveTexture(unitnum); - if (unit->t1d) - qglDisable(GL_TEXTURE_1D); + if (unitnum < backendunits) + { + if (unit->t1d) + qglDisable(GL_TEXTURE_1D); + } unit->t1d = 0; qglBindTexture(GL_TEXTURE_1D, unit->t1d); CHECKGLERROR @@ -1383,8 +1399,11 @@ void R_Mesh_TexBind3D(unsigned int unitnum, int texnum) if (unit->t2d) { GL_ActiveTexture(unitnum); - if (unit->t2d) - qglDisable(GL_TEXTURE_2D); + if (unitnum < backendunits) + { + if (unit->t2d) + qglDisable(GL_TEXTURE_2D); + } unit->t2d = 0; qglBindTexture(GL_TEXTURE_2D, unit->t2d); CHECKGLERROR @@ -1393,15 +1412,18 @@ void R_Mesh_TexBind3D(unsigned int unitnum, int texnum) if (unit->t3d != texnum) { GL_ActiveTexture(unitnum); - if (texnum) - { - if (unit->t3d == 0) - qglEnable(GL_TEXTURE_3D); - } - else + if (unitnum < backendunits) { - if (unit->t3d) - qglDisable(GL_TEXTURE_3D); + 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); @@ -1411,8 +1433,11 @@ void R_Mesh_TexBind3D(unsigned int unitnum, int texnum) if (unit->tcubemap != 0) { GL_ActiveTexture(unitnum); - if (unit->tcubemap) - qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + if (unitnum < backendunits) + { + if (unit->tcubemap) + qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + } unit->tcubemap = 0; qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap); CHECKGLERROR @@ -1422,14 +1447,19 @@ void R_Mesh_TexBind3D(unsigned int unitnum, int texnum) void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; - if (unitnum >= backendunits) + if (unitnum >= backendimageunits) + return; + if (r_showtrispass) return; // update 1d texture binding if (unit->t1d) { GL_ActiveTexture(unitnum); - if (unit->t1d) - qglDisable(GL_TEXTURE_1D); + if (unitnum < backendunits) + { + if (unit->t1d) + qglDisable(GL_TEXTURE_1D); + } unit->t1d = 0; qglBindTexture(GL_TEXTURE_1D, unit->t1d); CHECKGLERROR @@ -1438,8 +1468,11 @@ void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum) if (unit->t2d) { GL_ActiveTexture(unitnum); - if (unit->t2d) - qglDisable(GL_TEXTURE_2D); + if (unitnum < backendunits) + { + if (unit->t2d) + qglDisable(GL_TEXTURE_2D); + } unit->t2d = 0; qglBindTexture(GL_TEXTURE_2D, unit->t2d); CHECKGLERROR @@ -1448,8 +1481,11 @@ void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum) if (unit->t3d) { GL_ActiveTexture(unitnum); - if (unit->t3d) - qglDisable(GL_TEXTURE_3D); + if (unitnum < backendunits) + { + if (unit->t3d) + qglDisable(GL_TEXTURE_3D); + } unit->t3d = 0; qglBindTexture(GL_TEXTURE_3D, unit->t3d); CHECKGLERROR @@ -1458,15 +1494,18 @@ void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum) if (unit->tcubemap != texnum) { GL_ActiveTexture(unitnum); - if (texnum) - { - if (unit->tcubemap == 0) - qglEnable(GL_TEXTURE_CUBE_MAP_ARB); - } - else + if (unitnum < backendunits) { - if (unit->tcubemap) - qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + if (texnum) + { + if (unit->tcubemap == 0) + qglEnable(GL_TEXTURE_CUBE_MAP_ARB); + } + else + { + if (unit->tcubemap) + qglDisable(GL_TEXTURE_CUBE_MAP_ARB); + } } unit->tcubemap = texnum; qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap); @@ -1477,6 +1516,8 @@ void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum) void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix) { gltextureunit_t *unit = gl_state.units + unitnum; + if (r_showtrispass) + return; if (matrix->m[3][3]) { // texmatrix specified, check if it is different @@ -1509,6 +1550,8 @@ void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix) void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, int rgbscale, int alphascale) { gltextureunit_t *unit = gl_state.units + unitnum; + if (r_showtrispass) + return; if (gl_combine.integer) { // GL_ARB_texture_env_combine @@ -1564,10 +1607,6 @@ void R_Mesh_State(const rmeshstate_t *m) BACKENDACTIVECHECK R_Mesh_VertexPointer(m->pointer_vertex); - - if (r_showtrispass) - return; - R_Mesh_ColorPointer(m->pointer_color); if (gl_backend_rebindtextures) @@ -1604,580 +1643,3 @@ void R_Mesh_Draw_ShowTris(int firstvertex, int numvertices, int numtriangles, co qglEnd(); CHECKGLERROR } - -/* -============================================================================== - - SCREEN SHOTS - -============================================================================== -*/ - -qboolean SCR_ScreenShot(char *filename, qbyte *buffer1, qbyte *buffer2, qbyte *buffer3, int x, int y, int width, int height, qboolean flipx, qboolean flipy, qboolean flipdiagonal, qboolean jpeg) -{ - int indices[3] = {0,1,2}; - qboolean ret; - - if (!r_render.integer) - return false; - - qglReadPixels (x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer1); - CHECKGLERROR - - if (scr_screenshot_gamma.value != 1) - { - int i; - double igamma = 1.0 / scr_screenshot_gamma.value; - unsigned char ramp[256]; - for (i = 0;i < 256;i++) - ramp[i] = (unsigned char) (pow(i * (1.0 / 255.0), igamma) * 255.0); - for (i = 0;i < width*height*3;i++) - buffer1[i] = ramp[buffer1[i]]; - } - - Image_CopyMux (buffer2, buffer1, width, height, flipx, flipy, flipdiagonal, 3, 3, indices); - - if (jpeg) - ret = JPEG_SaveImage_preflipped (filename, width, height, buffer2); - else - ret = Image_WriteTGARGB_preflipped (filename, width, height, buffer2, buffer3); - - return ret; -} - -//============================================================================= - -void R_ClearScreen(void) -{ - if (r_render.integer) - { - // clear to black - qglClearColor(0,0,0,0);CHECKGLERROR - qglClearDepth(1);CHECKGLERROR - if (gl_stencil) - { - // LordHavoc: we use a stencil centered around 128 instead of 0, - // to avoid clamping interfering with strange shadow volume - // drawing orders - qglClearStencil(128);CHECKGLERROR - } - // 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) - { - qglEnable(GL_DITHER);CHECKGLERROR - } - else - { - qglDisable(GL_DITHER);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)/vid_pixelaspect.value)*tan(fov_x/360.0*M_PI))*360.0/M_PI; -} - -int r_stereo_side; - -void SCR_DrawScreen (void) -{ - for (r_showtrispass = 0;r_showtrispass <= (r_showtris.value > 0);r_showtrispass++) - { - R_Mesh_Start(); - - R_TimeReport("setup"); - - if (r_showtrispass) - { - rmeshstate_t m; - r_showtrispass = 0; - GL_BlendFunc(GL_ONE, GL_ONE); - GL_DepthTest(GL_FALSE); - GL_DepthMask(GL_FALSE); - memset(&m, 0, sizeof(m)); - R_Mesh_State(&m); - GL_ShowTrisColor(0.2,0.2,0.2,1); - r_showtrispass = 1; - } - - if (cls.signon == SIGNONS) - { - float size; - - size = scr_viewsize.value * (1.0 / 100.0); - size = min(size, 1); - - if (r_stereo_sidebyside.integer) - { - r_refdef.width = vid.realwidth * size / 2.5; - r_refdef.height = vid.realheight * size / 2.5 * (1 - bound(0, r_letterbox.value, 100) / 100); - r_refdef.x = (vid.realwidth - r_refdef.width * 2.5) * 0.5; - r_refdef.y = (vid.realheight - r_refdef.height)/2; - if (r_stereo_side) - r_refdef.x += r_refdef.width * 1.5; - } - else - { - r_refdef.width = vid.realwidth * size; - r_refdef.height = vid.realheight * size * (1 - bound(0, r_letterbox.value, 100) / 100); - 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 * r_refdef.fovscale_x; - r_refdef.fov_y = CalcFov (scr_fov.value, r_refdef.width, r_refdef.height) * r_refdef.fovscale_y; - - R_RenderView(); - - if (scr_zoomwindow.integer) - { - 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.fovscale_x; - r_refdef.fov_y = CalcFov(scr_zoomwindow_fov.value, r_refdef.width, r_refdef.height) * r_refdef.fovscale_y; - - R_RenderView(); - } - } - - if (!r_stereo_sidebyside.integer) - { - r_refdef.width = vid.realwidth; - r_refdef.height = vid.realheight; - r_refdef.x = 0; - r_refdef.y = 0; - } - - // draw 2D stuff - R_DrawQueue(); - - R_Mesh_Finish(); - - R_TimeReport("meshfinish"); - } - r_showtrispass = 0; -} - -void SCR_UpdateLoadingScreen (void) -{ - float x, y; - cachepic_t *pic; - rmeshstate_t m; - // don't do anything if not initialized yet - if (vid_hidden) - return; - r_showtrispass = 0; - VID_GetWindowSize(&vid.realx, &vid.realy, &vid.realwidth, &vid.realheight); - VID_UpdateGamma(false); - qglViewport(0, 0, vid.realwidth, vid.realheight); - //qglDisable(GL_SCISSOR_TEST); - //qglDepthMask(1); - qglColorMask(1,1,1,1); - //qglClearColor(0,0,0,0); - //qglClear(GL_COLOR_BUFFER_BIT); - //qglCullFace(GL_FRONT); - //qglDisable(GL_CULL_FACE); - //R_ClearScreen(); - R_Textures_Frame(); - GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100); - R_Mesh_Start(); - R_Mesh_Matrix(&r_identitymatrix); - // draw the loading plaque - pic = Draw_CachePic("gfx/loading.lmp"); - x = (vid_conwidth.integer - pic->width)/2; - y = (vid_conheight.integer - pic->height)/2; - GL_Color(1,1,1,1); - GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - GL_DepthTest(false); - memset(&m, 0, sizeof(m)); - m.pointer_vertex = varray_vertex3f; - m.pointer_texcoord[0] = varray_texcoord2f[0]; - m.tex[0] = R_GetTexture(pic->tex); - R_Mesh_State(&m); - varray_vertex3f[0] = varray_vertex3f[9] = x; - varray_vertex3f[1] = varray_vertex3f[4] = y; - varray_vertex3f[3] = varray_vertex3f[6] = x + pic->width; - varray_vertex3f[7] = varray_vertex3f[10] = y + pic->height; - varray_texcoord2f[0][0] = 0;varray_texcoord2f[0][1] = 0; - varray_texcoord2f[0][2] = 1;varray_texcoord2f[0][3] = 0; - varray_texcoord2f[0][4] = 1;varray_texcoord2f[0][5] = 1; - varray_texcoord2f[0][6] = 0;varray_texcoord2f[0][7] = 1; - GL_LockArrays(0, 4); - R_Mesh_Draw(0, 4, 2, polygonelements); - GL_LockArrays(0, 0); - R_Mesh_Finish(); - // refresh - VID_Finish(); -} - -/* -================== -SCR_UpdateScreen - -This is called every frame, and can also be called explicitly to flush -text to the screen. -================== -*/ -void SCR_UpdateScreen (void) -{ - if (vid_hidden) - return; - - 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); - - CHECKGLERROR - qglViewport(0, 0, vid.realwidth, vid.realheight); - qglDisable(GL_SCISSOR_TEST); - qglDepthMask(1); - qglColorMask(1,1,1,1); - qglClearColor(0,0,0,0); - qglClear(GL_COLOR_BUFFER_BIT); - CHECKGLERROR - - R_TimeReport("clear"); - - if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer || r_stereo_sidebyside.integer) - { - matrix4x4_t originalmatrix = r_refdef.viewentitymatrix; - r_refdef.viewentitymatrix.m[0][3] = originalmatrix.m[0][3] + r_stereo_separation.value * -0.5f * r_refdef.viewentitymatrix.m[0][1]; - r_refdef.viewentitymatrix.m[1][3] = originalmatrix.m[1][3] + r_stereo_separation.value * -0.5f * r_refdef.viewentitymatrix.m[1][1]; - r_refdef.viewentitymatrix.m[2][3] = originalmatrix.m[2][3] + r_stereo_separation.value * -0.5f * r_refdef.viewentitymatrix.m[2][1]; - - if (r_stereo_sidebyside.integer) - r_stereo_side = 0; - - if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer) - { - r_refdef.colormask[0] = 1; - r_refdef.colormask[1] = 0; - r_refdef.colormask[2] = 0; - } - - SCR_DrawScreen(); - - r_refdef.viewentitymatrix.m[0][3] = originalmatrix.m[0][3] + r_stereo_separation.value * 0.5f * r_refdef.viewentitymatrix.m[0][1]; - r_refdef.viewentitymatrix.m[1][3] = originalmatrix.m[1][3] + r_stereo_separation.value * 0.5f * r_refdef.viewentitymatrix.m[1][1]; - r_refdef.viewentitymatrix.m[2][3] = originalmatrix.m[2][3] + r_stereo_separation.value * 0.5f * r_refdef.viewentitymatrix.m[2][1]; - - if (r_stereo_sidebyside.integer) - r_stereo_side = 1; - - if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer) - { - r_refdef.colormask[0] = 0; - r_refdef.colormask[1] = r_stereo_redcyan.integer || r_stereo_redgreen.integer; - r_refdef.colormask[2] = r_stereo_redcyan.integer || r_stereo_redblue.integer; - } - - SCR_DrawScreen(); - - r_refdef.viewentitymatrix = originalmatrix; - } - else - { - r_showtrispass = false; - SCR_DrawScreen(); - - if (r_showtris.value > 0) - { - 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); - SCR_DrawScreen(); - r_showtrispass = false; - } - } - - VID_Finish(); - R_TimeReport("finish"); -} - - -//=========================================================================== -// dynamic vertex array buffer subsystem -//=========================================================================== - -// FIXME: someday this should be dynamically allocated and resized? -float varray_vertex3f[65536*3]; -float varray_svector3f[65536*3]; -float varray_tvector3f[65536*3]; -float varray_normal3f[65536*3]; -float varray_color4f[65536*4]; -float varray_texcoord2f[4][65536*2]; -float varray_texcoord3f[4][65536*3]; -int earray_element3i[65536]; -float varray_vertex3f2[65536*3]; - -//=========================================================================== -// vertex array caching subsystem -//=========================================================================== - -typedef struct rcachearraylink_s -{ - struct rcachearraylink_s *next, *prev; - struct rcachearrayitem_s *data; -} -rcachearraylink_t; - -typedef struct rcachearrayitem_s -{ - // 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; - -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; -} - -static void R_Mesh_CacheArray_Shutdown(void) -{ -} - -/* -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); -} -*/ - -int R_Mesh_CacheArray(rcachearrayrequest_t *r) -{ - 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; -} -