]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
minor cleanup
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Dec 2009 22:58:52 +0000 (22:58 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Dec 2009 22:58:52 +0000 (22:58 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9573 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
r_shadow.c
vid_shared.c

index 03b08130f2384f8b15e58c93b381eab0e0ba5926..17128079c105021cd20ec2a1a3f1d8f68cd88a43 100644 (file)
@@ -107,9 +107,6 @@ cvar_t gl_fogstart = {0, "gl_fogstart", "0", "nehahra fog start distance (for Ne
 cvar_t gl_fogend = {0, "gl_fogend","0", "nehahra fog end distance (for Nehahra compatibility only)"};
 cvar_t gl_skyclip = {0, "gl_skyclip", "4608", "nehahra farclip distance - the real fog end (for Nehahra compatibility only)"};
 
-cvar_t r_textureunits = {0, "r_textureunits", "32", "number of hardware texture units reported by driver (note: setting this to 1 turns off gl_combine)"};
-
-cvar_t r_glsl = {CVAR_SAVE, "r_glsl", "1", "enables use of OpenGL 2.0 pixel shaders for lighting"};
 cvar_t r_glsl_deluxemapping = {CVAR_SAVE, "r_glsl_deluxemapping", "1", "use per pixel lighting on deluxemap-compiled q3bsp maps (or a value of 2 forces deluxemap shading even without deluxemaps)"};
 cvar_t r_glsl_offsetmapping = {CVAR_SAVE, "r_glsl_offsetmapping", "0", "offset mapping effect (also known as parallax mapping or virtual displacement mapping)"};
 cvar_t r_glsl_offsetmapping_reliefmapping = {CVAR_SAVE, "r_glsl_offsetmapping_reliefmapping", "0", "relief mapping effect (higher quality)"};
@@ -3121,8 +3118,6 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable(&r_polygonoffset_decals_offset);
        Cvar_RegisterVariable(&r_fog_exp2);
        Cvar_RegisterVariable(&r_drawfog);
-       Cvar_RegisterVariable(&r_textureunits);
-       Cvar_RegisterVariable(&r_glsl);
        Cvar_RegisterVariable(&r_glsl_deluxemapping);
        Cvar_RegisterVariable(&r_glsl_offsetmapping);
        Cvar_RegisterVariable(&r_glsl_offsetmapping_reliefmapping);
index 8b077f2d751aef9d2400faca7aabb73c8a253856..a57fdd2aa14869b5ed43269addd48680d964d0e1 100644 (file)
@@ -365,11 +365,10 @@ skinframe_t *r_editlights_sprnoshadowlight;
 skinframe_t *r_editlights_sprcubemaplight;
 skinframe_t *r_editlights_sprcubemapnoshadowlight;
 skinframe_t *r_editlights_sprselection;
-extern cvar_t gl_max_size;
 
 void R_Shadow_SetShadowMode(void)
 {
-       r_shadow_shadowmapmaxsize = bound(1, r_shadow_shadowmapping_maxsize.integer, gl_max_size.integer / 4);
+       r_shadow_shadowmapmaxsize = bound(1, r_shadow_shadowmapping_maxsize.integer, (int)vid.maxtexturesize_2d / 4);
        r_shadow_shadowmapvsdct = r_shadow_shadowmapping_vsdct.integer != 0;
        r_shadow_shadowmapfilterquality = r_shadow_shadowmapping_filterquality.integer;
        r_shadow_shadowmaptexturetype = r_shadow_shadowmapping_texturetype.integer;
@@ -415,25 +414,25 @@ void R_Shadow_SetShadowMode(void)
                                break;
                        }
                }
-        switch (r_shadow_shadowmaptexturetype)
-        {
-        case 0:
-            r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
-            break;
-        case 1:
-            r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAPRECTANGLE;
-            break;
-        case 2:
-            r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAPCUBESIDE;
-            break;
-        default:
+               switch (r_shadow_shadowmaptexturetype)
+               {
+               case 0:
+                       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
+                       break;
+               case 1:
+                       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAPRECTANGLE;
+                       break;
+               case 2:
+                       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAPCUBESIDE;
+                       break;
+               default:
                        if((vid.support.amd_texture_texture4 || vid.support.arb_texture_gather) && r_shadow_shadowmappcf && !r_shadow_shadowmapsampler)
                                r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
                        else if(vid.support.arb_texture_rectangle) 
                                r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAPRECTANGLE;
                        else
                                r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
-            break;
+                       break;
                }
        }
 }
@@ -444,20 +443,22 @@ void R_Shadow_FreeShadowMaps(void)
 
        R_Shadow_SetShadowMode();
 
+       if (!vid.support.ext_framebuffer_object || !vid.support.arb_fragment_shader)
+               return;
+
+       CHECKGLERROR
+
        if (r_shadow_fborectangle)
-               qglDeleteFramebuffersEXT(1, &r_shadow_fborectangle);
+               qglDeleteFramebuffersEXT(1, &r_shadow_fborectangle);CHECKGLERROR
        r_shadow_fborectangle = 0;
-       CHECKGLERROR
 
        if (r_shadow_fbo2d)
-               qglDeleteFramebuffersEXT(1, &r_shadow_fbo2d);
+               qglDeleteFramebuffersEXT(1, &r_shadow_fbo2d);CHECKGLERROR
        r_shadow_fbo2d = 0;
-       CHECKGLERROR
        for (i = 0;i < R_SHADOW_SHADOWMAP_NUMCUBEMAPS;i++)
                if (r_shadow_fbocubeside[i])
-                       qglDeleteFramebuffersEXT(1, &r_shadow_fbocubeside[i]);
+                       qglDeleteFramebuffersEXT(1, &r_shadow_fbocubeside[i]);CHECKGLERROR
        memset(r_shadow_fbocubeside, 0, sizeof(r_shadow_fbocubeside));
-       CHECKGLERROR
 
        if (r_shadow_shadowmaprectangletexture)
                R_FreeTexture(r_shadow_shadowmaprectangletexture);
@@ -628,41 +629,6 @@ void r_shadow_newmap(void)
                R_Shadow_EditLights_Reload_f();
 }
 
-void R_Shadow_Help_f(void)
-{
-       Con_Printf(
-"Documentation on r_shadow system:\n"
-"Settings:\n"
-"r_shadow_bumpscale_basetexture : base texture as bumpmap with this scale\n"
-"r_shadow_bumpscale_bumpmap : depth scale for bumpmap conversion\n"
-"r_shadow_debuglight : render only this light number (-1 = all)\n"
-"r_shadow_gloss 0/1/2 : no gloss, gloss textures only, force gloss\n"
-"r_shadow_gloss2intensity : brightness of forced gloss\n"
-"r_shadow_glossintensity : brightness of textured gloss\n"
-"r_shadow_lightattenuationlinearscale : used to generate attenuation texture\n"
-"r_shadow_lightattenuationdividebias : used to generate attenuation texture\n"
-"r_shadow_lightintensityscale : scale rendering brightness of all lights\n"
-"r_shadow_lightradiusscale : scale rendering radius of all lights\n"
-"r_shadow_portallight : use portal visibility for static light precomputation\n"
-"r_shadow_projectdistance : shadow volume projection distance\n"
-"r_shadow_realtime_dlight : use high quality dynamic lights in normal mode\n"
-"r_shadow_realtime_dlight_shadows : cast shadows from dlights\n"
-"r_shadow_realtime_world : use high quality world lighting mode\n"
-"r_shadow_realtime_world_lightmaps : use lightmaps in addition to lights\n"
-"r_shadow_realtime_world_shadows : cast shadows from world lights\n"
-"r_shadow_realtime_world_compile : compile surface/visibility information\n"
-"r_shadow_realtime_world_compileshadow : compile shadow geometry\n"
-"r_shadow_scissor : use scissor optimization\n"
-"r_shadow_polygonfactor : nudge shadow volumes closer/further\n"
-"r_shadow_polygonoffset : nudge shadow volumes closer/further\n"
-"r_shadow_texture3d : use 3d attenuation texture (if hardware supports)\n"
-"r_showlighting : useful for performance testing; bright = slow!\n"
-"r_showshadowvolumes : useful for performance testing; bright = slow!\n"
-"Commands:\n"
-"r_shadow_help : this help\n"
-       );
-}
-
 void R_Shadow_Init(void)
 {
        Cvar_RegisterVariable(&r_shadow_bumpscale_basetexture);
@@ -725,7 +691,6 @@ void R_Shadow_Init(void)
                Cvar_SetValue("r_shadow_gloss", 2);
                Cvar_SetValue("r_shadow_bumpscale_basetexture", 4);
        }
-       Cmd_AddCommand("r_shadow_help", R_Shadow_Help_f, "prints documentation on console commands and variables used by realtime lighting and shadowing system");
        R_Shadow_EditLights_Init();
        Mem_ExpandableArray_NewArray(&r_shadow_worldlightsarray, r_main_mempool, sizeof(dlight_t), 128);
        maxshadowtriangles = 0;
@@ -1884,12 +1849,12 @@ void R_Shadow_RenderMode_Begin(void)
 
        r_shadow_rendermode = R_SHADOW_RENDERMODE_NONE;
 
-       if (gl_ext_separatestencil.integer)
+       if (gl_ext_separatestencil.integer && vid.support.ati_separate_stencil)
        {
                r_shadow_shadowingrendermode_zpass = R_SHADOW_RENDERMODE_ZPASS_SEPARATESTENCIL;
                r_shadow_shadowingrendermode_zfail = R_SHADOW_RENDERMODE_ZFAIL_SEPARATESTENCIL;
        }
-       else if (gl_ext_stenciltwoside.integer)
+       else if (gl_ext_stenciltwoside.integer && vid.support.ext_stencil_two_side)
        {
                r_shadow_shadowingrendermode_zpass = R_SHADOW_RENDERMODE_ZPASS_STENCILTWOSIDE;
                r_shadow_shadowingrendermode_zfail = R_SHADOW_RENDERMODE_ZFAIL_STENCILTWOSIDE;
@@ -2254,8 +2219,7 @@ void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent, qb
                        }
                }
        }
-       else if (r_shadow_rendermode == R_SHADOW_RENDERMODE_LIGHT_VERTEX)
-               R_Mesh_ColorPointer(rsurface.array_color4f, 0, 0);
+       R_Mesh_ColorPointer(rsurface.array_color4f, 0, 0);
        //GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
        CHECKGLERROR
 }
@@ -2443,7 +2407,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
        const float *normal3f = rsurface.normal3f + 3 * firstvertex;
        float *color4f = rsurface.array_color4f + 4 * firstvertex;
        float dist, dot, distintensity, shadeintensity, v[3], n[3];
-       if (r_textureunits.integer >= 3)
+       if (r_textureunits.integer >= 3 && vid.texunits >= 3)
        {
                if (VectorLength2(diffusecolor) > 0)
                {
@@ -2483,7 +2447,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
                        }
                }
        }
-       else if (r_textureunits.integer >= 2)
+       else if (r_textureunits.integer >= 2 && vid.texunits >= 2)
        {
                if (VectorLength2(diffusecolor) > 0)
                {
@@ -2673,7 +2637,7 @@ static void R_Shadow_RenderLighting_Light_GLSL(int firstvertex, int numvertices,
                R_Mesh_TexBind(GL20TU_SECONDARY_GLOSS, R_GetTexture(rsurface.texture->backgroundglosstexture));
                R_Mesh_TexBind(GL20TU_SECONDARY_GLOW, R_GetTexture(rsurface.texture->backgroundcurrentskinframe->glow));
        }
-       //R_Mesh_TexBindCubeMap(GL20TU_CUBE, R_GetTexture(rsurface.rtlight->currentcubemap));
+       //R_Mesh_TexBindAll(GL20TU_CUBE, 0, 0, R_GetTexture(rsurface.rtlight->currentcubemap), 0);
        R_Mesh_TexBind(GL20TU_FOGMASK, R_GetTexture(r_texture_fogattenuation));
        if(rsurface.texture->colormapping)
        {
@@ -3399,7 +3363,7 @@ static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertice
        m.pointer_texcoord[0] = rsurface.texcoordtexture2f;
        m.pointer_texcoord_bufferobject[0] = rsurface.texcoordtexture2f_bufferobject;
        m.pointer_texcoord_bufferoffset[0] = rsurface.texcoordtexture2f_bufferoffset;
-       if (r_textureunits.integer >= 2)
+       if (r_textureunits.integer >= 2 && vid.texunits >= 2)
        {
                // voodoo2 or TNT
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
@@ -3407,7 +3371,7 @@ static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertice
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-               if (r_textureunits.integer >= 3)
+               if (r_textureunits.integer >= 3 && vid.texunits >= 3)
                {
                        // Voodoo4 or Kyro (or Geforce3/Radeon with r_shadow_dot3 off)
                        m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture);
@@ -4011,8 +3975,14 @@ void R_Shadow_SetupEntityLight(const entity_render_t *ent)
        Matrix4x4_Concat(&rsurface.entitytoattenuationxyz, &matrix_attenuationxyz, &rsurface.entitytolight);
        Matrix4x4_Concat(&rsurface.entitytoattenuationz, &matrix_attenuationz, &rsurface.entitytolight);
        Matrix4x4_Transform(&ent->inversematrix, rsurface.rtlight->shadoworigin, rsurface.entitylightorigin);
-       if (r_shadow_lightingrendermode == R_SHADOW_RENDERMODE_LIGHT_GLSL)
+       switch(r_shadow_lightingrendermode)
+       {
+       case R_SHADOW_RENDERMODE_LIGHT_GLSL:
                R_Mesh_TexMatrix(3, &rsurface.entitytolight);
+               break;
+       default:
+               break;
+       }
 }
 
 void R_Shadow_DrawWorldLight(int numsurfaces, int *surfacelist, const unsigned char *trispvs)
@@ -4027,8 +3997,14 @@ void R_Shadow_DrawWorldLight(int numsurfaces, int *surfacelist, const unsigned c
        Matrix4x4_Concat(&rsurface.entitytoattenuationxyz, &matrix_attenuationxyz, &rsurface.entitytolight);
        Matrix4x4_Concat(&rsurface.entitytoattenuationz, &matrix_attenuationz, &rsurface.entitytolight);
        VectorCopy(rsurface.rtlight->shadoworigin, rsurface.entitylightorigin);
-       if (r_shadow_lightingrendermode == R_SHADOW_RENDERMODE_LIGHT_GLSL)
+       switch(r_shadow_lightingrendermode)
+       {
+       case R_SHADOW_RENDERMODE_LIGHT_GLSL:
                R_Mesh_TexMatrix(3, &rsurface.entitytolight);
+               break;
+       default:
+               break;
+       }
 
        r_refdef.scene.worldmodel->DrawLight(r_refdef.scene.worldentity, numsurfaces, surfacelist, trispvs);
 
@@ -4458,8 +4434,8 @@ void R_ShadowVolumeLighting(qboolean visible)
        size_t range;
        float f;
 
-       if (r_shadow_shadowmapmaxsize != bound(1, r_shadow_shadowmapping_maxsize.integer, gl_max_size.integer / 4) ||
-               (r_shadow_shadowmode != R_SHADOW_SHADOWMODE_STENCIL) != (r_shadow_shadowmapping.integer && r_glsl.integer && vid.support.arb_fragment_shader && vid.support.ext_framebuffer_object) || 
+       if (r_shadow_shadowmapmaxsize != bound(1, r_shadow_shadowmapping_maxsize.integer, (int)vid.maxtexturesize_2d / 4) ||
+               (r_shadow_shadowmode != R_SHADOW_SHADOWMODE_STENCIL) != r_shadow_shadowmapping.integer ||
                r_shadow_shadowmapvsdct != (r_shadow_shadowmapping_vsdct.integer != 0) || 
                r_shadow_shadowmaptexturetype != r_shadow_shadowmapping_texturetype.integer ||
                r_shadow_shadowmapfilterquality != r_shadow_shadowmapping_filterquality.integer || 
index d3884eaf86e6c6bd2e4e1fa6c7508096ead48bc1..41b71a6849a289017eaa77f9e5e043e10801b6ec 100644 (file)
@@ -54,7 +54,9 @@ cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1", "whether to use the mouse in wi
 cvar_t vid_grabkeyboard = {CVAR_SAVE, "vid_grabkeyboard", "0", "whether to grab the keyboard when mouse is active (prevents use of volume control keys, music player keys, etc on some keyboards)"};
 cvar_t vid_minwidth = {0, "vid_minwidth", "0", "minimum vid_width that is acceptable (to be set in default.cfg in mods)"};
 cvar_t vid_minheight = {0, "vid_minheight", "0", "minimum vid_height that is acceptable (to be set in default.cfg in mods)"};
-cvar_t gl_combine = {0, "gl_combine", "1", "enables faster rendering using GL_ARB_texture_env_combine extension (part of OpenGL 1.3 and above)"};
+cvar_t r_textureunits = {0, "r_textureunits", "32", "number of texture units to use in GL 1.1 and GL 1.3 rendering paths"};
+cvar_t gl_combine = {0, "gl_combine", "1", "enables the OpenGL 1.3 rendering path"};
+cvar_t r_glsl = {CVAR_SAVE, "r_glsl", "1", "enables the OpenGL 2.0 rendering path"};
 cvar_t vid_gl13 = {0, "vid_gl13", "1", "enables faster rendering using OpenGL 1.3 features (such as GL_ARB_texture_env_combine extension)"};
 cvar_t vid_gl20 = {0, "vid_gl20", "1", "enables faster rendering using OpenGL 2.0 features (such as GL_ARB_fragment_shader extension)"};
 cvar_t gl_finish = {0, "gl_finish", "0", "make the cpu wait for the graphics processor at the end of each rendered frame (can help with strange input or video lag problems on some machines)"};
@@ -1172,7 +1174,9 @@ void VID_Shared_Init(void)
        Cvar_RegisterVariable(&vid_resizable);
        Cvar_RegisterVariable(&vid_minwidth);
        Cvar_RegisterVariable(&vid_minheight);
+       Cvar_RegisterVariable(&r_textureunits);
        Cvar_RegisterVariable(&gl_combine);
+       Cvar_RegisterVariable(&r_glsl);
        Cvar_RegisterVariable(&vid_gl13);
        Cvar_RegisterVariable(&vid_gl20);
        Cvar_RegisterVariable(&gl_finish);