]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
added support for GL_EXT_packed_depth_stencil, this means that r_viewfbo
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 31 Oct 2011 00:42:04 +0000 (00:42 +0000)
committerRudolf Polzer <divverent@xonotic.org>
Mon, 31 Oct 2011 08:01:20 +0000 (09:01 +0100)
no longer breaks stencil shadows

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11492 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=c369a6525246f38a19a0d04ce47d352196dd37f0

gl_backend.c
gl_rmain.c
gl_textures.c
glquake.h
r_shadow.c
r_textures.h
vid.h
vid_sdl.c
vid_shared.c

index 9a5b6028211aeda6be1285444cbfc98cccfa4ec0..4b2bd905d6f04326c03cbb40176aa666ee01657d 100644 (file)
@@ -1264,6 +1264,7 @@ int R_Mesh_CreateFramebufferObject(rtexture_t *depthtexture, rtexture_t *colorte
                qglGenFramebuffersEXT(1, (GLuint*)&temp);CHECKGLERROR
                R_Mesh_SetRenderTargets(temp, NULL, NULL, NULL, NULL, NULL);
                if (depthtexture) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthtexture->gltexturetypeenum, R_GetTexture(depthtexture), 0);CHECKGLERROR
+               if (depthtexture) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, depthtexture->gltexturetypeenum, R_GetTexture(depthtexture), 0);CHECKGLERROR
                if (colortexture) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colortexture->gltexturetypeenum, R_GetTexture(colortexture), 0);CHECKGLERROR
                if (colortexture2) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, colortexture2->gltexturetypeenum, R_GetTexture(colortexture2), 0);CHECKGLERROR
                if (colortexture3) qglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, colortexture3->gltexturetypeenum, R_GetTexture(colortexture3), 0);CHECKGLERROR
index 20aff5a24551d832f97d6047d46740904cbeb10e..7fc61ce3f6c0fc4a7c8fc1403b1f8520cec03fb6 100644 (file)
@@ -5784,7 +5784,7 @@ static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t
                        if (usewaterfbo)
                        {
                                if (r_fb.water.depthtexture == NULL)
-                                       r_fb.water.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "waterviewdepth", r_fb.water.texturewidth, r_fb.water.textureheight, 24, false);
+                                       r_fb.water.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "waterviewdepth", r_fb.water.texturewidth, r_fb.water.textureheight, 24, false, vid.support.ext_packed_depth_stencil);
                                if (p->fbo_refraction == 0)
                                        p->fbo_refraction = R_Mesh_CreateFramebufferObject(r_fb.water.depthtexture, p->texture_refraction, NULL, NULL, NULL);
                        }
@@ -5798,7 +5798,7 @@ static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t
                        if (usewaterfbo)
                        {
                                if (r_fb.water.depthtexture == NULL)
-                                       r_fb.water.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "waterviewdepth", r_fb.water.texturewidth, r_fb.water.textureheight, 24, false);
+                                       r_fb.water.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "waterviewdepth", r_fb.water.texturewidth, r_fb.water.textureheight, 24, false, vid.support.ext_packed_depth_stencil);
                                if (p->fbo_camera == 0)
                                        p->fbo_camera = R_Mesh_CreateFramebufferObject(r_fb.water.depthtexture, p->texture_camera, NULL, NULL, NULL);
                        }
@@ -5813,7 +5813,7 @@ static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t
                        if (usewaterfbo)
                        {
                                if (r_fb.water.depthtexture == NULL)
-                                       r_fb.water.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "waterviewdepth", r_fb.water.texturewidth, r_fb.water.textureheight, 24, false);
+                                       r_fb.water.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "waterviewdepth", r_fb.water.texturewidth, r_fb.water.textureheight, 24, false, vid.support.ext_packed_depth_stencil);
                                if (p->fbo_reflection == 0)
                                        p->fbo_reflection = R_Mesh_CreateFramebufferObject(r_fb.water.depthtexture, p->texture_reflection, NULL, NULL, NULL);
                        }
@@ -6159,7 +6159,7 @@ void R_Bloom_StartFrame(void)
                        if (useviewfbo)
                        {
                                // FIXME: choose depth bits based on a cvar
-                               r_fb.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "framebufferdepth", r_fb.screentexturewidth, r_fb.screentextureheight, 24, false);
+                               r_fb.depthtexture = R_LoadTextureShadowMap2D(r_main_texturepool, "framebufferdepth", r_fb.screentexturewidth, r_fb.screentextureheight, 24, false, vid.support.ext_packed_depth_stencil);
                                r_fb.fbo = R_Mesh_CreateFramebufferObject(r_fb.depthtexture, r_fb.colortexture, NULL, NULL, NULL);
                                R_Mesh_SetRenderTargets(r_fb.fbo, r_fb.depthtexture, r_fb.colortexture, NULL, NULL, NULL);
 #ifndef USE_GLES2
index 2fbc559974ea2245026c178c1fd2b013cfea57af..c9714ef2b3bd5236283846efc5bd410044008134 100644 (file)
@@ -85,6 +85,7 @@ textypeinfo_t;
 // GLES2 devices rarely support depth textures, so we actually use a renderbuffer there
 static textypeinfo_t textype_shadowmap16                 = {"shadowmap16",              TEXTYPE_SHADOWMAP     ,  2,  2,  2.0f, GL_DEPTH_COMPONENT16                  , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT};
 static textypeinfo_t textype_shadowmap24                 = {"shadowmap24",              TEXTYPE_SHADOWMAP     ,  2,  2,  2.0f, GL_DEPTH_COMPONENT16                  , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT};
+static textypeinfo_t textype_shadowmap24s8               = {"shadowmap24",              TEXTYPE_SHADOWMAP_STENCIL,  2,  2,  2.0f, GL_DEPTH_COMPONENT16                  , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT};
 static textypeinfo_t textype_colorbuffer                 = {"colorbuffer",              TEXTYPE_COLORBUFFER   ,  4,  4,  4.0f, GL_RGBA                               , GL_BGRA           , GL_UNSIGNED_BYTE };
 static textypeinfo_t textype_colorbuffer16f              = {"colorbuffer16f",           TEXTYPE_COLORBUFFER16F,  8,  8,  8.0f, GL_RGBA                               , GL_RGBA           , GL_FLOAT         };
 static textypeinfo_t textype_colorbuffer32f              = {"colorbuffer32f",           TEXTYPE_COLORBUFFER32F, 16, 16, 16.0f, GL_RGBA                               , GL_RGBA           , GL_FLOAT         };
@@ -100,7 +101,8 @@ static textypeinfo_t textype_bgra_alpha                  = {"bgra_alpha",
 #else
 // framebuffer texture formats
 static textypeinfo_t textype_shadowmap16                 = {"shadowmap16",              TEXTYPE_SHADOWMAP     ,  2,  2,  2.0f, GL_DEPTH_COMPONENT16_ARB              , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT};
-static textypeinfo_t textype_shadowmap24                 = {"shadowmap24",              TEXTYPE_SHADOWMAP     ,  4,  4,  4.0f, GL_DEPTH_COMPONENT24_ARB              , GL_DEPTH_COMPONENT, GL_UNSIGNED_INT  };
+static textypeinfo_t textype_shadowmap24                 = {"shadowmap24",              TEXTYPE_SHADOWMAP     ,  4,  4,  4.0f, GL_DEPTH_COMPONENT                    , GL_DEPTH_COMPONENT, GL_UNSIGNED_INT  };
+static textypeinfo_t textype_shadowmap24s8               = {"shadowmap24",              TEXTYPE_SHADOWMAP_STENCIL,  4,  4,  4.0f, GL_DEPTH24_STENCIL8_EXT               , GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT};
 static textypeinfo_t textype_colorbuffer                 = {"colorbuffer",              TEXTYPE_COLORBUFFER   ,  4,  4,  4.0f, GL_RGBA                               , GL_BGRA           , GL_UNSIGNED_BYTE };
 static textypeinfo_t textype_colorbuffer16f              = {"colorbuffer16f",           TEXTYPE_COLORBUFFER16F,  8,  8,  8.0f, GL_RGBA16F_ARB                        , GL_RGBA           , GL_FLOAT         };
 static textypeinfo_t textype_colorbuffer32f              = {"colorbuffer32f",           TEXTYPE_COLORBUFFER32F, 16, 16, 16.0f, GL_RGBA32F_ARB                        , GL_RGBA           , GL_FLOAT         };
@@ -260,6 +262,7 @@ static textypeinfo_t *R_GetTexTypeInfo(textype_t textype, int flags)
        case TEXTYPE_BGRA: return ((flags & TEXF_ALPHA) ? &textype_bgra_alpha : &textype_bgra);
        case TEXTYPE_ALPHA: return &textype_alpha;
        case TEXTYPE_SHADOWMAP: return (flags & TEXF_LOWPRECISION) ? &textype_shadowmap16 : &textype_shadowmap24;
+       case TEXTYPE_SHADOWMAP_STENCIL: return &textype_shadowmap24s8;
        case TEXTYPE_COLORBUFFER: return &textype_colorbuffer;
        case TEXTYPE_COLORBUFFER16F: return &textype_colorbuffer16f;
        case TEXTYPE_COLORBUFFER32F: return &textype_colorbuffer32f;
@@ -279,6 +282,7 @@ static textypeinfo_t *R_GetTexTypeInfo(textype_t textype, int flags)
        case TEXTYPE_BGRA: return ((flags & TEXF_COMPRESS) && vid.support.ext_texture_compression_s3tc) ? ((flags & TEXF_ALPHA) ? &textype_bgra_alpha_compress : &textype_bgra_compress) : ((flags & TEXF_ALPHA) ? &textype_bgra_alpha : &textype_bgra);
        case TEXTYPE_ALPHA: return &textype_alpha;
        case TEXTYPE_SHADOWMAP: return (flags & TEXF_LOWPRECISION) ? &textype_shadowmap16 : &textype_shadowmap24;
+       case TEXTYPE_SHADOWMAP_STENCIL: return &textype_shadowmap24s8;
        case TEXTYPE_COLORBUFFER: return &textype_colorbuffer;
        case TEXTYPE_COLORBUFFER16F: return &textype_colorbuffer16f;
        case TEXTYPE_COLORBUFFER32F: return &textype_colorbuffer32f;
@@ -1097,7 +1101,7 @@ static void GL_SetupTextureParameters(int flags, textype_t textype, int texturet
        }
 
 #ifndef USE_GLES2
-       if (textype == TEXTYPE_SHADOWMAP)
+       if (textype == TEXTYPE_SHADOWMAP || TEXTYPE_SHADOWMAP_STENCIL)
        {
                if (vid.support.arb_shadow)
                {
@@ -1687,6 +1691,7 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
                }
                break;
        case TEXTYPE_SHADOWMAP:
+       case TEXTYPE_SHADOWMAP_STENCIL:
                break;
        case TEXTYPE_DXT1:
        case TEXTYPE_SRGB_DXT1:
@@ -1780,14 +1785,15 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
                        case TEXTYPE_COLORBUFFER: d3dformat = D3DFMT_A8R8G8B8;break;
                        case TEXTYPE_COLORBUFFER16F: d3dformat = D3DFMT_A16B16G16R16F;break;
                        case TEXTYPE_COLORBUFFER32F: d3dformat = D3DFMT_A32B32G32R32F;break;
-                       case TEXTYPE_SHADOWMAP: d3dformat = D3DFMT_D16;d3dusage = D3DUSAGE_DEPTHSTENCIL;break; // note: can not use D3DUSAGE_RENDERTARGET here
+                       case TEXTYPE_SHADOWMAP: d3dformat = D3DFMT_D24X8;d3dusage = D3DUSAGE_DEPTHSTENCIL;break; // note: can not use D3DUSAGE_RENDERTARGET here
+                       case TEXTYPE_SHADOWMAP_STENCIL: d3dformat = D3DFMT_D24S8;d3dusage = D3DUSAGE_DEPTHSTENCIL;break; // note: can not use D3DUSAGE_RENDERTARGET here
                        case TEXTYPE_ALPHA: d3dformat = D3DFMT_A8;break;
                        default: d3dformat = D3DFMT_A8R8G8B8;Sys_Error("R_LoadTexture: unsupported texture type %i when picking D3DFMT", (int)textype);break;
                        }
                        glt->d3dformat = d3dformat;
                        glt->d3dusage = d3dusage;
                        glt->d3dpool = d3dpool;
-                       glt->d3disdepthsurface = textype == TEXTYPE_SHADOWMAP;
+                       glt->d3disdepthsurface = (textype == TEXTYPE_SHADOWMAP || textype == TEXTYPE_SHADOWMAP_STENCIL);
                        if (glt->d3disdepthsurface)
                        {
                                if (FAILED(d3dresult = IDirect3DDevice9_CreateDepthStencilSurface(vid_d3d9dev, glt->tilewidth, glt->tileheight, (D3DFORMAT)glt->d3dformat, D3DMULTISAMPLE_NONE, 0, false, (IDirect3DSurface9 **)&glt->d3dtexture, NULL)))
@@ -1829,6 +1835,7 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
                        case TEXTYPE_COLORBUFFER16F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA16F;break;
                        case TEXTYPE_COLORBUFFER32F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA32F;break;
                        case TEXTYPE_SHADOWMAP: tflags = DPSOFTRAST_TEXTURE_FORMAT_DEPTH;break;
+                       case TEXTYPE_SHADOWMAP_STENCIL: tflags = DPSOFTRAST_TEXTURE_FORMAT_DEPTH;break;
                        case TEXTYPE_ALPHA: tflags = DPSOFTRAST_TEXTURE_FORMAT_ALPHA8;break;
                        default: Sys_Error("R_LoadTexture: unsupported texture type %i when picking DPSOFTRAST_TEXTURE_FLAGS", (int)textype);
                        }
@@ -1883,9 +1890,9 @@ static int R_ShadowMapTextureFlags(int precision, qboolean filter)
        return flags;
 }
 
-rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter)
+rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter, qboolean stencil)
 {
-       return R_SetupTexture(rtexturepool, identifier, width, height, 1, 1, R_ShadowMapTextureFlags(precision, filter), -1, TEXTYPE_SHADOWMAP, GLTEXTURETYPE_2D, NULL, NULL);
+       return R_SetupTexture(rtexturepool, identifier, width, height, 1, 1, R_ShadowMapTextureFlags(precision, filter), -1, stencil ? TEXTYPE_SHADOWMAP_STENCIL : TEXTYPE_SHADOWMAP, GLTEXTURETYPE_2D, NULL, NULL);
 }
 
 int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qboolean skipuncompressed, qboolean hasalpha)
index d09554a2626d77ea570e51cb3510178bd0645f6f..ba27242ed117026117cce1f889de3d69135c7560 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -1018,6 +1018,12 @@ extern void (GLAPIENTRY *qglGetQueryObjectuivARB)(GLuint qid, GLenum pname, GLui
 extern void (GLAPIENTRY *qglSampleCoverageARB)(GLclampf value, GLboolean invert);
 
 extern void (GLAPIENTRY *qglPointSize)(GLfloat size);
+
+//GL_EXT_packed_depth_stencil
+#define GL_DEPTH_STENCIL_EXT            0x84F9
+#define GL_UNSIGNED_INT_24_8_EXT        0x84FA
+#define GL_DEPTH24_STENCIL8_EXT         0x88F0
+
 #endif
 
 #define DEBUGGL
index 521f6984d4088b256227cbb59ce6d172c6390ad1..6d2d2b10e18105285221dabe3398d64f38c547df 100644 (file)
@@ -2100,7 +2100,7 @@ static void R_Shadow_MakeShadowMap(int side, int size)
        {
        case R_SHADOW_SHADOWMODE_SHADOWMAP2D:
                if (r_shadow_shadowmap2dtexture) return;
-               r_shadow_shadowmap2dtexture = R_LoadTextureShadowMap2D(r_shadow_texturepool, "shadowmap", size*2, size*(vid.support.arb_texture_non_power_of_two ? 3 : 4), r_shadow_shadowmapdepthbits, r_shadow_shadowmapsampler);
+               r_shadow_shadowmap2dtexture = R_LoadTextureShadowMap2D(r_shadow_texturepool, "shadowmap", size*2, size*(vid.support.arb_texture_non_power_of_two ? 3 : 4), r_shadow_shadowmapdepthbits, r_shadow_shadowmapsampler, false);
                r_shadow_shadowmap2dcolortexture = NULL;
                switch(vid.renderpath)
                {
@@ -4544,7 +4544,7 @@ void R_Shadow_PrepareLights(int fbo, rtexture_t *depthtexture, rtexture_t *color
                        r_shadow_usingdeferredprepass = true;
                        r_shadow_prepass_width = vid.width;
                        r_shadow_prepass_height = vid.height;
-                       r_shadow_prepassgeometrydepthtexture = R_LoadTextureShadowMap2D(r_shadow_texturepool, "prepassgeometrydepthmap", vid.width, vid.height, 24, false);
+                       r_shadow_prepassgeometrydepthtexture = R_LoadTextureShadowMap2D(r_shadow_texturepool, "prepassgeometrydepthmap", vid.width, vid.height, 24, false, false);
                        switch (vid.renderpath)
                        {
                        case RENDERPATH_D3D9:
index bc654a345791595dcbe54ca77dd445be30da550f..f93440e1bafeccbe5be9fbade652e72b04e209b6 100644 (file)
@@ -77,6 +77,8 @@ typedef enum textype_e
        TEXTYPE_COLORBUFFER16F,
        // this represents an RGBA float texture (4 32bit floats)
        TEXTYPE_COLORBUFFER32F,
+       // 32bit D24S8 (24bit depth, 8bit stencil)
+       TEXTYPE_SHADOWMAP_STENCIL,
        // 16bit D16 (16bit depth) or 32bit S8D24 (24bit depth, 8bit stencil unused)
        TEXTYPE_SHADOWMAP
 }
@@ -154,7 +156,7 @@ extern cvar_t r_texture_dds_save;
 rtexture_t *R_LoadTexture2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette);
 rtexture_t *R_LoadTexture3D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int depth, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette);
 rtexture_t *R_LoadTextureCubeMap(rtexturepool_t *rtexturepool, const char *identifier, int width, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette);
-rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
+rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter, qboolean stencil);
 rtexture_t *R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filename, qboolean srgb, int flags, qboolean *hasalphaflag, float *avgcolor, int miplevel);
 
 // saves a texture to a DDS file
diff --git a/vid.h b/vid.h
index 4840ae4a53451c476e45edaaa08e934e48df812d..61c10f56ec5baab34f77fc1883e35867509467f2 100644 (file)
--- a/vid.h
+++ b/vid.h
@@ -63,6 +63,7 @@ typedef struct viddef_support_s
        qboolean ext_blend_subtract;
        qboolean ext_draw_range_elements;
        qboolean ext_framebuffer_object;
+       qboolean ext_packed_depth_stencil;
        qboolean ext_stencil_two_side;
        qboolean ext_texture_3d;
        qboolean ext_texture_compression_s3tc;
index f72abea1021527172cc6898a02cff498bddd2f1b..9e21b4c7b4a09f36cbf0e0b36d2ab0286dc762e0 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -1572,6 +1572,7 @@ void GLES_Init(void)
        vid.support.ext_blend_subtract = true;
        vid.support.ext_draw_range_elements = true;
        vid.support.ext_framebuffer_object = false;//true;
+       vid.support.ext_packed_depth_stencil = false;
        vid.support.ext_stencil_two_side = false;
        vid.support.ext_texture_3d = SDL_GL_ExtensionSupported("GL_OES_texture_3D");
        vid.support.ext_texture_compression_s3tc = SDL_GL_ExtensionSupported("GL_EXT_texture_compression_s3tc");
index 1ace5fefb9003e86570d97f8aa6c584b51f5d25c..5325e6882d2338198025df9d9e4ce8c428ad8b3e 100644 (file)
@@ -1012,6 +1012,7 @@ void VID_CheckExtensions(void)
        vid.support.ext_blend_subtract = GL_CheckExtension("GL_EXT_blend_subtract", blendequationfuncs, "-noblendsubtract", false);
        vid.support.ext_draw_range_elements = GL_CheckExtension("drawrangeelements", drawrangeelementsfuncs, "-nodrawrangeelements", true) || GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
        vid.support.ext_framebuffer_object = GL_CheckExtension("GL_EXT_framebuffer_object", fbofuncs, "-nofbo", false);
+       vid.support.ext_packed_depth_stencil = GL_CheckExtension("GL_EXT_packed_depth_stencil", NULL, "-nopackeddepthstencil", false);
        vid.support.ext_stencil_two_side = GL_CheckExtension("GL_EXT_stencil_two_side", stenciltwosidefuncs, "-nostenciltwoside", false);
        vid.support.ext_texture_3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
        vid.support.ext_texture_compression_s3tc = GL_CheckExtension("GL_EXT_texture_compression_s3tc", NULL, "-nos3tc", false);