]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
reduced shadowmaps from 32bit to 24bit depth format
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Sep 2009 08:58:24 +0000 (08:58 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Sep 2009 08:58:24 +0000 (08:58 +0000)
some tweaks to shadowmap texture handling to reduce code

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9225 d7cf8633-e32d-0410-b094-e92efae38249

gl_textures.c
r_shadow.c

index 53f34c2d4b429b4de39d323bbc70add23fa5d5cc..a42595adbf76a408313b8c273b9f13de2867c985 100644 (file)
@@ -60,7 +60,7 @@ static textypeinfo_t textype_bgra                   = {TEXTYPE_BGRA   , 4, 4, 4.
 static textypeinfo_t textype_bgra_alpha             = {TEXTYPE_BGRA   , 4, 4, 4.0f, GL_BGRA   , 4, GL_UNSIGNED_BYTE};
 static textypeinfo_t textype_bgra_compress          = {TEXTYPE_BGRA   , 4, 4, 0.5f, GL_BGRA   , GL_COMPRESSED_RGB_ARB, GL_UNSIGNED_BYTE};
 static textypeinfo_t textype_bgra_alpha_compress    = {TEXTYPE_BGRA   , 4, 4, 1.0f, GL_BGRA   , GL_COMPRESSED_RGBA_ARB, GL_UNSIGNED_BYTE};
-static textypeinfo_t textype_shadowmap              = {TEXTYPE_SHADOWMAP,4,4, 4.0f, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT32_ARB, GL_UNSIGNED_INT};
+static textypeinfo_t textype_shadowmap              = {TEXTYPE_SHADOWMAP,4,4, 4.0f, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT24_ARB, GL_UNSIGNED_INT};
 
 typedef enum gltexturetype_e
 {
@@ -1133,7 +1133,7 @@ rtexture_t *R_LoadTextureShadowMapRectangle(rtexturepool_t *rtexturepool, const
 
 rtexture_t *R_LoadTextureShadowMapCube(rtexturepool_t *rtexturepool, const char *identifier, int width)
 {
-       return R_SetupTexture(rtexturepool, identifier, width, width, 1, 6, TEXF_ALWAYSPRECACHE | TEXF_FORCENEAREST | TEXF_CLAMP, TEXTYPE_SHADOWMAP, GLTEXTURETYPE_CUBEMAP, NULL, NULL);
+       return R_SetupTexture(rtexturepool, identifier, width, width, 1, 6, TEXF_ALWAYSPRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP, TEXTYPE_SHADOWMAP, GLTEXTURETYPE_CUBEMAP, NULL, NULL);
 }
 
 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height)
@@ -1143,7 +1143,7 @@ rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *i
 
 rtexture_t *R_LoadTextureCubeProjection(rtexturepool_t *rtexturepool, const char *identifier)
 {
-       return R_SetupTexture(rtexturepool, identifier, 2, 2, 1, 6, TEXF_ALWAYSPRECACHE | TEXF_FORCENEAREST | TEXF_CLAMP, TEXTYPE_SHADOWMAP, GLTEXTURETYPE_CUBEMAP, NULL, NULL);
+       return R_SetupTexture(rtexturepool, identifier, 2, 2, 1, 6, TEXF_ALWAYSPRECACHE | TEXF_FORCELINEAR | TEXF_CLAMP, TEXTYPE_BGRA, GLTEXTURETYPE_CUBEMAP, NULL, NULL);
 }
 
 int R_TextureHasAlpha(rtexture_t *rt)
index f7c7da673ed70ca0abb18b87ec0ea92339deae55..81e9a767a801a349caff711fdd5b4d5c41802709 100644 (file)
@@ -179,6 +179,7 @@ int r_shadow_readbuffer;
 GLuint r_shadow_fborectangle;
 GLuint r_shadow_fbocubeside[R_SHADOW_SHADOWMAP_NUMCUBEMAPS][6];
 GLuint r_shadow_fbo2d;
+int r_shadow_shadowmode;
 int r_shadow_shadowmapmaxsize;
 int r_shadow_lightscissor[4];
 
@@ -334,6 +335,51 @@ cachepic_t *r_editlights_sprcubemaplight;
 cachepic_t *r_editlights_sprcubemapnoshadowlight;
 cachepic_t *r_editlights_sprselection;
 
+void R_Shadow_FreeShadowMaps(void)
+{
+       int i;
+
+       r_shadow_shadowmapmaxsize = bound(1, r_shadow_shadowmapping_maxsize.integer, 2048);
+       r_shadow_shadowmode = r_shadow_shadowmapping.integer;
+       r_shadow_shadowmaplod = -1;
+
+       CHECKGLERROR
+       if (r_shadow_fborectangle)
+               qglDeleteFramebuffersEXT(1, &r_shadow_fborectangle);
+       r_shadow_fborectangle = 0;
+       CHECKGLERROR
+
+       if (r_shadow_fbo2d)
+               qglDeleteFramebuffersEXT(1, &r_shadow_fbo2d);
+       r_shadow_fbo2d = 0;
+       CHECKGLERROR
+
+       for (i = 0;i < R_SHADOW_SHADOWMAP_NUMCUBEMAPS;i++)
+               if (r_shadow_fbocubeside[i])
+                       qglDeleteFramebuffersEXT(6, r_shadow_fbocubeside[i]);
+       memset(r_shadow_fbocubeside, 0, sizeof(r_shadow_fbocubeside));
+       CHECKGLERROR
+
+       if (r_shadow_shadowmaprectangletexture)
+               R_FreeTexture(r_shadow_shadowmaprectangletexture);
+       r_shadow_shadowmaprectangletexture = NULL;
+
+       if (r_shadow_shadowmap2dtexture)
+               R_FreeTexture(r_shadow_shadowmap2dtexture);
+       r_shadow_shadowmap2dtexture = NULL;
+
+       if (r_shadow_shadowmapcubeprojectiontexture)
+               R_FreeTexture(r_shadow_shadowmapcubeprojectiontexture);
+       r_shadow_shadowmapcubeprojectiontexture = NULL;
+
+       for (i = 0;i < R_SHADOW_SHADOWMAP_NUMCUBEMAPS;i++)
+               if (r_shadow_shadowmapcubetexture[i])
+                       R_FreeTexture(r_shadow_shadowmapcubetexture[i]);
+       memset(r_shadow_shadowmapcubetexture, 0, sizeof(r_shadow_shadowmapcubetexture));
+
+       CHECKGLERROR
+}
+
 void r_shadow_start(void)
 {
        // allocate vertex processing arrays
@@ -351,6 +397,9 @@ void r_shadow_start(void)
        r_shadow_fborectangle = 0;
        memset(r_shadow_fbocubeside, 0, sizeof(r_shadow_fbocubeside));
        r_shadow_fbo2d = 0;
+
+       R_Shadow_FreeShadowMaps();
+
        r_shadow_texturepool = NULL;
        r_shadow_filters_texturepool = NULL;
        R_Shadow_ValidateCvars();
@@ -386,18 +435,14 @@ void r_shadow_shutdown(void)
        int i;
        CHECKGLERROR
        R_Shadow_UncompileWorldLights();
+
+       R_Shadow_FreeShadowMaps();
+
        CHECKGLERROR
        numcubemaps = 0;
        r_shadow_attenuationgradienttexture = NULL;
        r_shadow_attenuation2dtexture = NULL;
        r_shadow_attenuation3dtexture = NULL;
-       r_shadow_shadowmaprectangletexture = NULL;
-       memset(r_shadow_shadowmapcubetexture, 0, sizeof(r_shadow_shadowmapcubetexture));
-       r_shadow_shadowmapcubeprojectiontexture = NULL;
-       r_shadow_shadowmap2dtexture = NULL;
-       r_shadow_shadowmapmaxsize = 0;
-       r_shadow_shadowmapsize = 0;
-       r_shadow_shadowmaplod = 0;
        CHECKGLERROR
        if (r_shadow_fborectangle)
                qglDeleteFramebuffersEXT(1, &r_shadow_fborectangle);
@@ -1444,42 +1489,6 @@ void R_Shadow_RenderMode_ShadowMap(int side, qboolean clear, int size)
        r_viewport_t viewport;
        CHECKGLERROR
        maxsize = bound(1, r_shadow_shadowmapping_maxsize.integer, 2048);
-       if (r_shadow_shadowmapmaxsize != maxsize)
-       {
-               r_shadow_shadowmapmaxsize = maxsize;
-
-               if (r_shadow_fborectangle)
-                       qglDeleteFramebuffersEXT(1, &r_shadow_fborectangle);
-               r_shadow_fborectangle = 0;
-
-               if (r_shadow_fbo2d)
-                       qglDeleteFramebuffersEXT(1, &r_shadow_fbo2d);
-               r_shadow_fbo2d = 0;
-
-               for (i = 0;i < R_SHADOW_SHADOWMAP_NUMCUBEMAPS;i++)
-                       if (r_shadow_fbocubeside[i])
-                               qglDeleteFramebuffersEXT(6, r_shadow_fbocubeside[i]);
-               memset(r_shadow_fbocubeside, 0, sizeof(r_shadow_fbocubeside));
-
-               if (r_shadow_shadowmaprectangletexture)
-                       R_FreeTexture(r_shadow_shadowmaprectangletexture);
-               r_shadow_shadowmaprectangletexture = NULL;
-
-               if (r_shadow_shadowmap2dtexture)
-                       R_FreeTexture(r_shadow_shadowmap2dtexture);
-               r_shadow_shadowmap2dtexture = NULL;
-
-               if (r_shadow_shadowmapcubeprojectiontexture)
-                       R_FreeTexture(r_shadow_shadowmapcubeprojectiontexture);
-               r_shadow_shadowmapcubeprojectiontexture = NULL;
-
-               for (i = 0;i < R_SHADOW_SHADOWMAP_NUMCUBEMAPS;i++)
-                       if (r_shadow_shadowmapcubetexture[i])
-                               R_FreeTexture(r_shadow_shadowmapcubetexture[i]);
-               memset(r_shadow_shadowmapcubetexture, 0, sizeof(r_shadow_shadowmapcubetexture));
-
-               CHECKGLERROR
-       }
        nearclip = r_shadow_shadowmapping_nearclip.value / rsurface.rtlight->radius;
        farclip = 1.0f;
        r_shadow_shadowmap_bias = r_shadow_shadowmapping_bias.value * nearclip * (1024.0f / size);// * rsurface.rtlight->radius;
@@ -1487,11 +1496,11 @@ void R_Shadow_RenderMode_ShadowMap(int side, qboolean clear, int size)
        r_shadow_shadowmap_parameters[1] = 1.0f - r_shadow_shadowmapping_bordersize.value / size;
        r_shadow_shadowmap_parameters[2] = -(farclip + nearclip) / (farclip - nearclip);
        r_shadow_shadowmap_parameters[3] = -2.0f * nearclip * farclip / (farclip - nearclip);
-       if (!r_shadow_shadowmapcubeprojectiontexture)
-               r_shadow_shadowmapcubeprojectiontexture = R_LoadTextureCubeProjection(r_shadow_texturepool, "shadowmapcubeprojection");
        if (r_shadow_shadowmapping.integer == 1)
        {
                // complex unrolled cube approach (more flexible)
+               //if (!r_shadow_shadowmapcubeprojectiontexture)
+               //      r_shadow_shadowmapcubeprojectiontexture = R_LoadTextureCubeProjection(r_shadow_texturepool, "shadowmapcubeprojection");
                if (!r_shadow_shadowmap2dtexture)
                {
 #if 1
@@ -1530,6 +1539,8 @@ void R_Shadow_RenderMode_ShadowMap(int side, qboolean clear, int size)
        else if (r_shadow_shadowmapping.integer == 2)
        {
                // complex unrolled cube approach (more flexible)
+               //if (!r_shadow_shadowmapcubeprojectiontexture)
+               //      r_shadow_shadowmapcubeprojectiontexture = R_LoadTextureCubeProjection(r_shadow_texturepool, "shadowmapcubeprojection");
                if (!r_shadow_shadowmaprectangletexture)
                {
 #if 1
@@ -3820,6 +3831,9 @@ void R_ShadowVolumeLighting(qboolean visible)
        dlight_t *light;
        size_t range;
 
+       if (r_shadow_shadowmapmaxsize != bound(1, r_shadow_shadowmapping_maxsize.integer, 2048) || r_shadow_shadowmode != r_shadow_shadowmapping.integer)
+               R_Shadow_FreeShadowMaps();
+
        if (r_editlights.integer)
                R_Shadow_DrawLightSprites();