X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=gl_backend.c;h=57372862ce74073896f3affd21929106b458be53;hb=f9d8bc7ea04ff91fcbd90fe50a299b37724b349b;hp=d40e618e72ec32518fedc138169b9055061dedbd;hpb=56907dd5e21a9a0ffaa655213e11a087edc32f41;p=xonotic%2Fdarkplaces.git diff --git a/gl_backend.c b/gl_backend.c index d40e618e..57372862 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -83,8 +83,7 @@ static matrix4x4_t backend_modelviewmatrix; static matrix4x4_t backend_glmodelviewmatrix; static matrix4x4_t backend_projectmatrix; -static int backendunits, backendimageunits, backendarrayunits, backendactive; -static mempool_t *gl_backend_mempool; +static unsigned int backendunits, backendimageunits, backendarrayunits, backendactive; /* note: here's strip order for a terrain row: @@ -146,15 +145,12 @@ 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 +174,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); } @@ -411,7 +407,7 @@ typedef struct gltextureunit_s } gltextureunit_t; -static struct +static struct gl_state_s { int blendfunc1; int blendfunc2; @@ -433,11 +429,11 @@ gl_state; void GL_SetupTextureState(void) { - int i; + 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; @@ -559,7 +555,7 @@ void GL_Backend_ResetState(void) GL_SetupTextureState(); } -void GL_ActiveTexture(int num) +void GL_ActiveTexture(unsigned int num) { if (gl_state.unit != num) { @@ -572,7 +568,7 @@ void GL_ActiveTexture(int num) } } -void GL_ClientActiveTexture(int num) +void GL_ClientActiveTexture(unsigned int num) { if (gl_state.clientunit != num) { @@ -713,7 +709,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 } @@ -876,35 +872,35 @@ 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 + //CHECKGLERROR if (r_showtrispass) { - R_Mesh_Draw_ShowTris(numverts, numtriangles, elements); + R_Mesh_Draw_ShowTris(firstvertex, numvertices, numtriangles, elements); return; } c_meshs++; c_meshelements += 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 < backendarrayunits;i++) @@ -914,15 +910,15 @@ void R_Mesh_Draw(int numverts, int numtriangles, const int *elements) 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; } } @@ -933,10 +929,10 @@ void R_Mesh_Draw(int numverts, int numtriangles, const int *elements) 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 < backendarrayunits;j++) { @@ -1014,20 +1010,21 @@ void R_Mesh_Draw(int numverts, int numtriangles, const int *elements) } 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); @@ -1047,14 +1044,14 @@ void R_Mesh_Finish(void) qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);CHECKGLERROR } } - for (i = backendarrayunits - 1;i >= 0;i--) + for (i = 0;i < backendarrayunits;i++) { - GL_ActiveTexture(i); + GL_ActiveTexture(backendarrayunits - 1 - i); qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR } - for (i = backendunits - 1;i >= 0;i--) + for (i = 0;i < backendunits;i++) { - GL_ActiveTexture(i); + GL_ActiveTexture(backendunits - 1 - i); qglDisable(GL_TEXTURE_1D);CHECKGLERROR qglDisable(GL_TEXTURE_2D);CHECKGLERROR if (gl_texture3d) @@ -1105,6 +1102,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 @@ -1130,6 +1129,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) { @@ -1162,11 +1163,13 @@ void R_Mesh_TexCoordPointer(unsigned int unitnum, unsigned int numcomponents, co } } -void R_Mesh_TexBindAll(unsigned int unitnum, unsigned int tex1d, unsigned int tex2d, unsigned int tex3d, unsigned int texcubemap) +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) return; + if (r_showtrispass) + return; // update 1d texture binding if (unit->t1d != tex1d) { @@ -1253,11 +1256,13 @@ void R_Mesh_TexBindAll(unsigned int unitnum, unsigned int tex1d, unsigned int te } } -void R_Mesh_TexBind1D(unsigned int unitnum, unsigned int texnum) +void R_Mesh_TexBind1D(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; if (unitnum >= backendunits) return; + if (r_showtrispass) + return; // update 1d texture binding if (unit->t1d != texnum) { @@ -1308,11 +1313,13 @@ void R_Mesh_TexBind1D(unsigned int unitnum, unsigned int texnum) } } -void R_Mesh_TexBind(unsigned int unitnum, unsigned int texnum) +void R_Mesh_TexBind(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; if (unitnum >= backendunits) return; + if (r_showtrispass) + return; // update 1d texture binding if (unit->t1d) { @@ -1363,11 +1370,13 @@ void R_Mesh_TexBind(unsigned int unitnum, unsigned int texnum) } } -void R_Mesh_TexBind3D(unsigned int unitnum, unsigned int texnum) +void R_Mesh_TexBind3D(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; if (unitnum >= backendunits) return; + if (r_showtrispass) + return; // update 1d texture binding if (unit->t1d) { @@ -1418,11 +1427,13 @@ void R_Mesh_TexBind3D(unsigned int unitnum, unsigned int texnum) } } -void R_Mesh_TexBindCubeMap(unsigned int unitnum, unsigned int texnum) +void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum) { gltextureunit_t *unit = gl_state.units + unitnum; if (unitnum >= backendunits) return; + if (r_showtrispass) + return; // update 1d texture binding if (unit->t1d) { @@ -1476,6 +1487,8 @@ void R_Mesh_TexBindCubeMap(unsigned int unitnum, unsigned 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 @@ -1508,6 +1521,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 @@ -1558,15 +1573,11 @@ void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, i void R_Mesh_State(const rmeshstate_t *m) { - int i; + unsigned int i; BACKENDACTIVECHECK R_Mesh_VertexPointer(m->pointer_vertex); - - if (r_showtrispass) - return; - R_Mesh_ColorPointer(m->pointer_color); if (gl_backend_rebindtextures) @@ -1591,7 +1602,7 @@ void R_Mesh_State(const rmeshstate_t *m) } } -void R_Mesh_Draw_ShowTris(int numverts, int numtriangles, const int *elements) +void R_Mesh_Draw_ShowTris(int firstvertex, int numvertices, int numtriangles, const int *elements) { qglBegin(GL_LINES); for (;numtriangles;numtriangles--, elements += 3) @@ -1612,7 +1623,7 @@ void R_Mesh_Draw_ShowTris(int numverts, int numtriangles, const int *elements) ============================================================================== */ -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) +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, qboolean gammacorrect) { int indices[3] = {0,1,2}; qboolean ret; @@ -1623,7 +1634,7 @@ qboolean SCR_ScreenShot(char *filename, qbyte *buffer1, qbyte *buffer2, qbyte *b qglReadPixels (x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer1); CHECKGLERROR - if (scr_screenshot_gamma.value != 1) + if (scr_screenshot_gamma.value != 1 && gammacorrect) { int i; double igamma = 1.0 / scr_screenshot_gamma.value; @@ -1651,7 +1662,11 @@ void R_ClearScreen(void) if (r_render.integer) { // clear to black - qglClearColor(0,0,0,0);CHECKGLERROR + if (fogenabled) + qglClearColor(fogcolor[0],fogcolor[1],fogcolor[2],0); + else + qglClearColor(0,0,0,0); + CHECKGLERROR qglClearDepth(1);CHECKGLERROR if (gl_stencil) { @@ -1704,6 +1719,7 @@ void SCR_DrawScreen (void) GL_DepthMask(GL_FALSE); memset(&m, 0, sizeof(m)); R_Mesh_State(&m); + //qglEnable(GL_LINE_SMOOTH); GL_ShowTrisColor(0.2,0.2,0.2,1); r_showtrispass = 1; } @@ -1717,19 +1733,19 @@ void SCR_DrawScreen (void) 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; + r_refdef.width = vid.width * size / 2.5; + r_refdef.height = vid.height * size / 2.5 * (1 - bound(0, r_letterbox.value, 100) / 100); + r_refdef.x = (vid.width - r_refdef.width * 2.5) * 0.5; + r_refdef.y = (vid.height - 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; + r_refdef.width = vid.width * size; + r_refdef.height = vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100); + r_refdef.x = (vid.width - r_refdef.width)/2; + r_refdef.y = (vid.height - r_refdef.height)/2; } // LordHavoc: viewzoom (zoom in for sniper rifles, etc) @@ -1742,9 +1758,9 @@ void SCR_DrawScreen (void) { 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.width = vid.width * sizex; + r_refdef.height = vid.height * sizey; + r_refdef.x = (vid.width - 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; @@ -1755,8 +1771,8 @@ void SCR_DrawScreen (void) if (!r_stereo_sidebyside.integer) { - r_refdef.width = vid.realwidth; - r_refdef.height = vid.realheight; + r_refdef.width = vid.width; + r_refdef.height = vid.height; r_refdef.x = 0; r_refdef.y = 0; } @@ -1769,6 +1785,7 @@ void SCR_DrawScreen (void) R_TimeReport("meshfinish"); } r_showtrispass = 0; + //qglDisable(GL_LINE_SMOOTH); } void SCR_UpdateLoadingScreen (void) @@ -1780,9 +1797,8 @@ void SCR_UpdateLoadingScreen (void) 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); + qglViewport(0, 0, vid.width, vid.height); //qglDisable(GL_SCISSOR_TEST); //qglDepthMask(1); qglColorMask(1,1,1,1); @@ -1796,7 +1812,7 @@ void SCR_UpdateLoadingScreen (void) R_Mesh_Start(); R_Mesh_Matrix(&r_identitymatrix); // draw the loading plaque - pic = Draw_CachePic("gfx/loading.lmp"); + pic = Draw_CachePic("gfx/loading", false); x = (vid_conwidth.integer - pic->width)/2; y = (vid_conheight.integer - pic->height)/2; GL_Color(1,1,1,1); @@ -1816,7 +1832,7 @@ void SCR_UpdateLoadingScreen (void) 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(4, 2, polygonelements); + R_Mesh_Draw(0, 4, 2, polygonelements); GL_LockArrays(0, 0); R_Mesh_Finish(); // refresh @@ -1841,11 +1857,11 @@ void SCR_UpdateScreen (void) if (r_textureunits.integer < 1) Cvar_SetValueQuick(&r_textureunits, 1); - if (gl_combine.integer && (!gl_combine_extension || r_textureunits.integer < 2)) + if (gl_combine.integer && !gl_combine_extension) Cvar_SetValueQuick(&gl_combine, 0); CHECKGLERROR - qglViewport(0, 0, vid.realwidth, vid.realheight); + qglViewport(0, 0, vid.width, vid.height); qglDisable(GL_SCISSOR_TEST); qglDepthMask(1); qglColorMask(1,1,1,1); @@ -2036,7 +2052,7 @@ int R_Mesh_CacheArray(rcachearrayrequest_t *r) //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; + hashindex = CRC_Block((qbyte *)r, sizeof(*r)) % RCACHEARRAY_HASHSIZE; // is it already cached? for (lhead = &r_mesh_rcachechain[hashindex], l = lhead->next;l != lhead;l = l->next)