X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=gl_backend.c;h=439ec64b777964b30d43e77b97e3cae6fcfc2a0a;hb=d3e2f7e92ec8883147b70a7bc0971a7b4561d3d5;hp=38c4707319c657179b4db7e73624aa33e38a0993;hpb=9fa8ce6f31c95105ed4ac684b37f79f133b9c960;p=xonotic%2Fdarkplaces.git diff --git a/gl_backend.c b/gl_backend.c index 38c47073..439ec64b 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -4,22 +4,22 @@ #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_stereo_separation = {0, "r_stereo_separation", "4", "separation of eyes in the world (try negative values too)"}; +cvar_t r_stereo_sidebyside = {0, "r_stereo_sidebyside", "0", "side by side views (for those who can't afford glasses but can afford eye strain)"}; +cvar_t r_stereo_redblue = {0, "r_stereo_redblue", "0", "red/blue anaglyph stereo glasses (note: most of these glasses are actually red/cyan, try that one too)"}; +cvar_t r_stereo_redcyan = {0, "r_stereo_redcyan", "0", "red/cyan anaglyph stereo glasses, the kind given away at drive-in movies like Creature From The Black Lagoon In 3D"}; +cvar_t r_stereo_redgreen = {0, "r_stereo_redgreen", "0", "red/green anaglyph stereo glasses (for those who don't mind yellow)"}; + +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 +73,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); @@ -210,10 +210,10 @@ 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"}; +cvar_t scr_zoomwindow = {CVAR_SAVE, "scr_zoomwindow", "0", "displays a zoomed in overlay window"}; +cvar_t scr_zoomwindow_viewsizex = {CVAR_SAVE, "scr_zoomwindow_viewsizex", "20", "horizontal viewsize of zoom window"}; +cvar_t scr_zoomwindow_viewsizey = {CVAR_SAVE, "scr_zoomwindow_viewsizey", "20", "vertical viewsize of zoom window"}; +cvar_t scr_zoomwindow_fov = {CVAR_SAVE, "scr_zoomwindow_fov", "20", "fov of zoom window"}; void gl_backend_init(void) { @@ -274,9 +274,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) @@ -285,11 +284,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]; @@ -311,7 +307,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]; @@ -323,12 +319,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; @@ -407,7 +403,7 @@ typedef struct gltextureunit_s } gltextureunit_t; -static struct +static struct gl_state_s { int blendfunc1; int blendfunc2; @@ -432,8 +428,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; @@ -632,7 +628,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) @@ -651,8 +647,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 } @@ -678,9 +672,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; } @@ -728,8 +722,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 } @@ -757,7 +753,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(); @@ -781,7 +777,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); @@ -810,7 +806,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); @@ -829,7 +825,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 @@ -886,8 +882,8 @@ 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; @@ -1166,7 +1162,7 @@ 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; @@ -1259,7 +1255,7 @@ 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; @@ -1267,15 +1263,18 @@ void R_Mesh_TexBind1D(unsigned int unitnum, int texnum) 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); @@ -1285,8 +1284,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 @@ -1295,8 +1297,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 @@ -1305,8 +1310,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 @@ -1316,7 +1324,7 @@ 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; @@ -1324,8 +1332,11 @@ void R_Mesh_TexBind(unsigned int unitnum, int texnum) 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 @@ -1334,15 +1345,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); @@ -1352,8 +1366,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 @@ -1362,8 +1379,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 @@ -1373,7 +1393,7 @@ 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; @@ -1381,8 +1401,11 @@ void R_Mesh_TexBind3D(unsigned int unitnum, int texnum) 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 @@ -1391,8 +1414,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 @@ -1401,15 +1427,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); @@ -1419,8 +1448,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 @@ -1430,7 +1462,7 @@ 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; @@ -1438,8 +1470,11 @@ void R_Mesh_TexBindCubeMap(unsigned int unitnum, int texnum) 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 @@ -1448,8 +1483,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 @@ -1458,8 +1496,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 @@ -1468,15 +1509,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); @@ -1623,7 +1667,7 @@ void R_Mesh_Draw_ShowTris(int firstvertex, int numvertices, int numtriangles, co ============================================================================== */ -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) +qboolean SCR_ScreenShot(char *filename, unsigned char *buffer1, unsigned char *buffer2, unsigned char *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; @@ -1689,103 +1733,94 @@ void R_ClearScreen(void) } } -/* -==================== -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; -} +qboolean CL_VM_UpdateView (void); +void SCR_DrawConsole (void); int r_stereo_side; void SCR_DrawScreen (void) { - for (r_showtrispass = 0;r_showtrispass <= (r_showtris.value > 0);r_showtrispass++) - { - R_Mesh_Start(); + R_Mesh_Start(); + if (r_timereport_active) R_TimeReport("setup"); - if (r_showtrispass) + if (cls.signon == SIGNONS) + { + float size; + + size = scr_viewsize.value * (1.0 / 100.0); + size = min(size, 1); + + if (r_stereo_sidebyside.integer) { - 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); - //qglEnable(GL_LINE_SMOOTH); - GL_ShowTrisColor(0.2,0.2,0.2,1); - r_showtrispass = 1; + 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; } - - if (cls.signon == SIGNONS) + else { - float size; - - size = scr_viewsize.value * (1.0 / 100.0); - size = min(size, 1); + 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; + } - if (r_stereo_sidebyside.integer) - { - 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.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) + // LordHavoc: this is designed to produce widescreen fov values + // when the screen is wider than 4/3 width/height aspect, to do + // this it simply assumes the requested fov is the vertical fov + // for a 4x3 display, if the ratio is not 4x3 this makes the fov + // higher/lower according to the ratio + r_refdef.frustum_y = tan(scr_fov.value * cl.viewzoom * M_PI / 360.0) * (3.0/4.0); + r_refdef.frustum_x = r_refdef.frustum_y * (float)r_refdef.width / (float)r_refdef.height / vid_pixelheight.value; - // 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_refdef.frustum_x *= r_refdef.frustumscale_x; + r_refdef.frustum_y *= r_refdef.frustumscale_y; + if(!CL_VM_UpdateView()) R_RenderView(); + else + SCR_DrawConsole(); - 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.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; + 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.width * sizex; + r_refdef.height = vid.height * sizey; + r_refdef.x = (vid.width - r_refdef.width)/2; + r_refdef.y = 0; + + r_refdef.frustum_y = tan(scr_zoomwindow_fov.value * cl.viewzoom * M_PI / 360.0) * (3.0/4.0); + r_refdef.frustum_x = r_refdef.frustum_y * vid_pixelheight.value * (float)r_refdef.width / (float)r_refdef.height; + r_refdef.frustum_x *= r_refdef.frustumscale_x; + r_refdef.frustum_y *= r_refdef.frustumscale_y; + + if(!CL_VM_UpdateView()) R_RenderView(); - } } + } - if (!r_stereo_sidebyside.integer) - { - r_refdef.width = vid.width; - r_refdef.height = vid.height; - r_refdef.x = 0; - r_refdef.y = 0; - } + if (!r_stereo_sidebyside.integer) + { + r_refdef.width = vid.width; + r_refdef.height = vid.height; + r_refdef.x = 0; + r_refdef.y = 0; + } - // draw 2D stuff - R_DrawQueue(); + // draw 2D stuff + R_DrawQueue(); - R_Mesh_Finish(); + R_Mesh_Finish(); + if (r_timereport_active) R_TimeReport("meshfinish"); - } - r_showtrispass = 0; - //qglDisable(GL_LINE_SMOOTH); } void SCR_UpdateLoadingScreen (void) @@ -1860,6 +1895,8 @@ void SCR_UpdateScreen (void) if (gl_combine.integer && !gl_combine_extension) Cvar_SetValueQuick(&gl_combine, 0); + r_showtrispass = 0; + CHECKGLERROR qglViewport(0, 0, vid.width, vid.height); qglDisable(GL_SCISSOR_TEST); @@ -1869,7 +1906,8 @@ void SCR_UpdateScreen (void) qglClear(GL_COLOR_BUFFER_BIT); CHECKGLERROR - R_TimeReport("clear"); + if (r_timereport_active) + R_TimeReport("clear"); if (r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer || r_stereo_sidebyside.integer) { @@ -1909,27 +1947,11 @@ void SCR_UpdateScreen (void) 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"); + if (r_timereport_active) + R_TimeReport("finish"); } @@ -1991,7 +2013,7 @@ 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]; +static unsigned char r_mesh_rcachedata[RCACHEARRAY_DEFAULTSIZE]; // current state static int r_mesh_rcachedata_offset; @@ -2052,7 +2074,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((unsigned char *)r, sizeof(*r)) % RCACHEARRAY_HASHSIZE; // is it already cached? for (lhead = &r_mesh_rcachechain[hashindex], l = lhead->next;l != lhead;l = l->next)