]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
added r_drawfog cvar at esteel's request
[xonotic/darkplaces.git] / gl_rmain.c
index 1f59f2cb4fb7548d6bd055c237bc9390f95d4593..f0cedbc698ea79eef6d538a9ca8884804881b4e9 100644 (file)
@@ -34,6 +34,7 @@ rtexturepool_t *r_main_texturepool;
 r_refdef_t r_refdef;
 
 cvar_t r_depthfirst = {CVAR_SAVE, "r_depthfirst", "1", "renders a depth-only version of the scene before normal rendering begins to eliminate overdraw, values: 0 = off, 1 = world depth, 2 = world and model depth"};
+cvar_t r_useinfinitefarclip = {CVAR_SAVE, "r_useinfinitefarclip", "1", "enables use of a special kind of projection matrix that has an extremely large farclip"};
 cvar_t r_nearclip = {0, "r_nearclip", "1", "distance from camera of nearclip plane" };
 cvar_t r_showbboxes = {0, "r_showbboxes", "0", "shows bounding boxes of server entities, value controls opacity scaling (1 = 10%,  10 = 100%)"};
 cvar_t r_showsurfaces = {0, "r_showsurfaces", "0", "1 shows surfaces as different colors, or a value of 2 shows triangle draw order (for analyzing whether meshes are optimized for vertex cache)"};
@@ -63,6 +64,7 @@ cvar_t r_q1bsp_skymasking = {0, "r_q1bsp_skymasking", "1", "allows sky polygons
 cvar_t r_polygonoffset_submodel_factor = {0, "r_polygonoffset_submodel_factor", "0", "biases depth values of world submodels such as doors, to prevent z-fighting artifacts in Quake maps"};
 cvar_t r_polygonoffset_submodel_offset = {0, "r_polygonoffset_submodel_offset", "2", "biases depth values of world submodels such as doors, to prevent z-fighting artifacts in Quake maps"};
 cvar_t r_fog_exp2 = {0, "r_fog_exp2", "0", "uses GL_EXP2 fog (as in Nehahra) rather than realistic GL_EXP fog"};
+cvar_t r_drawfog = {CVAR_SAVE, "r_drawfog", "1", "allows one to disable fog rendering"};
 
 cvar_t gl_fogenable = {0, "gl_fogenable", "0", "nehahra fog enable (for Nehahra compatibility only)"};
 cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25", "nehahra fog density (recommend values below 0.1) (for Nehahra compatibility only)"};
@@ -546,7 +548,7 @@ static const char *builtinshaderstring =
 "      gl_FragColor += tex2;\n"
 "#  endif\n"
 "#  ifdef USEVERTEXTEXTUREBLEND\n"
-"      gl_FragColor = mix(tex2, gl_FragColor, tex2.a);\n"
+"      gl_FragColor = mix(gl_FragColor, tex2, tex2.a);\n"
 "#  endif\n"
 "}\n"
 "# endif\n"
@@ -2230,6 +2232,7 @@ void GL_Main_Init(void)
                Cvar_RegisterVariable (&gl_skyclip);
        }
        Cvar_RegisterVariable(&r_depthfirst);
+       Cvar_RegisterVariable(&r_useinfinitefarclip);
        Cvar_RegisterVariable(&r_nearclip);
        Cvar_RegisterVariable(&r_showbboxes);
        Cvar_RegisterVariable(&r_showsurfaces);
@@ -2259,6 +2262,7 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable(&r_polygonoffset_submodel_factor);
        Cvar_RegisterVariable(&r_polygonoffset_submodel_offset);
        Cvar_RegisterVariable(&r_fog_exp2);
+       Cvar_RegisterVariable(&r_drawfog);
        Cvar_RegisterVariable(&r_textureunits);
        Cvar_RegisterVariable(&r_glsl);
        Cvar_RegisterVariable(&r_glsl_contrastboost);
@@ -2763,7 +2767,7 @@ void R_SetupView(qboolean allowwaterclippingplane)
 {
        if (!r_refdef.view.useperspective)
                GL_SetupView_Mode_Ortho(-r_refdef.view.ortho_x, -r_refdef.view.ortho_y, r_refdef.view.ortho_x, r_refdef.view.ortho_y, -r_refdef.farclip, r_refdef.farclip);
-       else if (r_refdef.scene.rtworldshadows || r_refdef.scene.rtdlightshadows)
+       else if (gl_stencil && r_useinfinitefarclip.integer)
                GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_refdef.view.frustum_x, r_refdef.view.frustum_y, r_refdef.nearclip);
        else
                GL_SetupView_Mode_Perspective(r_refdef.view.frustum_x, r_refdef.view.frustum_y, r_refdef.nearclip, r_refdef.farclip);
@@ -3532,7 +3536,7 @@ void R_UpdateVariables(void)
 
        r_refdef.farclip = 4096;
        if (r_refdef.scene.worldmodel)
-               r_refdef.farclip += VectorDistance(r_refdef.scene.worldmodel->normalmins, r_refdef.scene.worldmodel->normalmaxs);
+               r_refdef.farclip += r_refdef.scene.worldmodel->radius * 2;
        r_refdef.nearclip = bound (0.001f, r_nearclip.value, r_refdef.farclip - 1.0f);
 
        if (r_shadow_frontsidecasting.integer < 0 || r_shadow_frontsidecasting.integer > 1)
@@ -3588,7 +3592,7 @@ void R_UpdateVariables(void)
 
        // R_UpdateFogColor(); // why? R_RenderScene does it anyway
 
-       if (r_refdef.fog_density)
+       if (r_refdef.fog_density && r_drawfog.integer)
        {
                r_refdef.fogenabled = true;
                // this is the point where the fog reaches 0.9986 alpha, which we
@@ -3684,7 +3688,7 @@ R_RenderView
 */
 void R_RenderView(void)
 {
-       if (!r_refdef.scene.entities/* || !r_refdef.scene.worldmodel*/)
+       if (!r_refdef.scene.entities || r_refdef.view.width * r_refdef.view.height == 0/* || !r_refdef.scene.worldmodel*/)
                return; //Host_Error ("R_RenderView: NULL worldmodel");
 
        r_refdef.view.colorscale = r_hdr_scenebrightness.value;
@@ -3997,6 +4001,7 @@ static void R_DrawEntityBBoxes_Callback(const entity_render_t *ent, const rtligh
        // this function draws bounding boxes of server entities
        if (!sv.active)
                return;
+       GL_CullFace(GL_NONE);
        R_SetupGenericShader(false);
        SV_VM_Begin();
        for (i = 0;i < numsurfaces;i++)