diff --git a/engine/client/image.c b/engine/client/image.c index 1adc3ddd8..f03542ab0 100644 --- a/engine/client/image.c +++ b/engine/client/image.c @@ -3124,7 +3124,7 @@ static void Image_RoundDimensions(int *scaled_width, int *scaled_height, unsigne if (*scaled_height > sh_config.texture_maxsize) *scaled_height = sh_config.texture_maxsize; } - if (!(flags & IF_UIPIC)) + if (!(flags & (IF_UIPIC|IF_RENDERTARGET))) { if (gl_max_size.value) { diff --git a/engine/gl/gl_backend.c b/engine/gl/gl_backend.c index 37af41423..f1a540707 100644 --- a/engine/gl/gl_backend.c +++ b/engine/gl/gl_backend.c @@ -209,11 +209,70 @@ static void BE_PolyOffset(qboolean pushdepth) po.factor += r_polygonoffset_submodel_factor.value; po.unit += r_polygonoffset_submodel_offset.value; } - if (shaderstate.mode == BEM_DEPTHONLY) + +#ifndef FORCESTATE + if (shaderstate.curpolyoffset.factor != po.factor || shaderstate.curpolyoffset.unit != po.unit) +#endif { - extern cvar_t r_polygonoffset_shadowmap_offset, r_polygonoffset_shadowmap_factor; - po.factor += r_polygonoffset_shadowmap_factor.value; - po.unit += r_polygonoffset_shadowmap_offset.value; + shaderstate.curpolyoffset = po; + if (shaderstate.curpolyoffset.factor || shaderstate.curpolyoffset.unit) + { + qglEnable(GL_POLYGON_OFFSET_FILL); + qglPolygonOffset(shaderstate.curpolyoffset.factor, shaderstate.curpolyoffset.unit); + } + else + qglDisable(GL_POLYGON_OFFSET_FILL); + } +} + +void GLBE_PolyOffsetStencilShadow(qboolean pushdepth) +{ + extern cvar_t r_polygonoffset_stencil_offset, r_polygonoffset_stencil_factor; + polyoffset_t po; + if (pushdepth) + { + /*some quake doors etc are flush with the walls that they're meant to be hidden behind, or plats the same height as the floor, etc + we move them back very slightly using polygonoffset to avoid really ugly z-fighting*/ + extern cvar_t r_polygonoffset_submodel_offset, r_polygonoffset_submodel_factor; + po.factor = r_polygonoffset_submodel_factor.value + r_polygonoffset_stencil_factor.value; + po.unit = r_polygonoffset_submodel_offset.value + r_polygonoffset_stencil_offset.value; + } + else + { + po.factor = r_polygonoffset_stencil_factor.value; + po.unit = r_polygonoffset_stencil_offset.value; + } + +#ifndef FORCESTATE + if (shaderstate.curpolyoffset.factor != po.factor || shaderstate.curpolyoffset.unit != po.unit) +#endif + { + shaderstate.curpolyoffset = po; + if (shaderstate.curpolyoffset.factor || shaderstate.curpolyoffset.unit) + { + qglEnable(GL_POLYGON_OFFSET_FILL); + qglPolygonOffset(shaderstate.curpolyoffset.factor, shaderstate.curpolyoffset.unit); + } + else + qglDisable(GL_POLYGON_OFFSET_FILL); + } +} +static void GLBE_PolyOffsetShadowMap(qboolean pushdepth) +{ + extern cvar_t r_polygonoffset_shadowmap_offset, r_polygonoffset_shadowmap_factor; + polyoffset_t po; + if (pushdepth) + { + /*some quake doors etc are flush with the walls that they're meant to be hidden behind, or plats the same height as the floor, etc + we move them back very slightly using polygonoffset to avoid really ugly z-fighting*/ + extern cvar_t r_polygonoffset_submodel_offset, r_polygonoffset_submodel_factor; + po.factor = r_polygonoffset_submodel_factor.value + r_polygonoffset_shadowmap_factor.value; + po.unit = r_polygonoffset_submodel_offset.value + r_polygonoffset_shadowmap_offset.value; + } + else + { + po.factor = r_polygonoffset_shadowmap_factor.value; + po.unit = r_polygonoffset_shadowmap_offset.value; } #ifndef FORCESTATE @@ -800,6 +859,8 @@ void GLBE_RenderShadowBuffer(unsigned int numverts, int vbo, vecV_t *verts, unsi shaderstate.sourcevbo = &shaderstate.dummyvbo; shaderstate.dummyvbo.indicies.gl.vbo = ibo; + GLBE_PolyOffsetShadowMap(false); + if (shaderstate.allblackshader) { GL_SelectProgram(shaderstate.allblackshader); @@ -3362,7 +3423,7 @@ void GLBE_SelectMode(backendmode_t mode) //we don't write or blend anything (maybe alpha test... but mneh) BE_SendPassBlendDepthMask(SBITS_MISC_DEPTHWRITE | SBITS_MASK_BITS); - BE_PolyOffset(false); +// BE_PolyOffset(false); GL_CullFace(SHADER_CULL_FRONT); break; @@ -3370,7 +3431,7 @@ void GLBE_SelectMode(backendmode_t mode) #ifdef RTLIGHTS case BEM_STENCIL: /*BEM_STENCIL doesn't support mesh writing*/ - GLBE_PushOffsetShadow(false); + GLBE_PolyOffsetStencilShadow(false); if (gl_config_nofixedfunc && !shaderstate.allblackshader) { @@ -3604,39 +3665,6 @@ void GLBE_Scissor(srect_t *rect) } } -void GLBE_PushOffsetShadow(qboolean pushdepth) -{ - extern cvar_t r_polygonoffset_stencil_offset, r_polygonoffset_stencil_factor; - polyoffset_t po; - if (pushdepth) - { - /*some quake doors etc are flush with the walls that they're meant to be hidden behind, or plats the same height as the floor, etc - we move them back very slightly using polygonoffset to avoid really ugly z-fighting*/ - extern cvar_t r_polygonoffset_submodel_offset, r_polygonoffset_submodel_factor; - po.factor = r_polygonoffset_submodel_factor.value + r_polygonoffset_stencil_factor.value; - po.unit = r_polygonoffset_submodel_offset.value + r_polygonoffset_stencil_offset.value; - } - else - { - po.factor = r_polygonoffset_stencil_factor.value; - po.unit = r_polygonoffset_stencil_offset.value; - } - -#ifndef FORCESTATE - if (shaderstate.curpolyoffset.factor != po.factor || shaderstate.curpolyoffset.unit != po.unit) -#endif - { - shaderstate.curpolyoffset = po; - if (shaderstate.curpolyoffset.factor || shaderstate.curpolyoffset.unit) - { - qglEnable(GL_POLYGON_OFFSET_FILL); - qglPolygonOffset(shaderstate.curpolyoffset.factor, shaderstate.curpolyoffset.unit); - } - else - qglDisable(GL_POLYGON_OFFSET_FILL); - } -} - #if defined(RTLIGHTS) && !defined(GLSLONLY) texid_t GenerateNormalisationCubeMap(void); static void BE_LegacyLighting(void) diff --git a/engine/gl/gl_shadow.c b/engine/gl/gl_shadow.c index c6a33180c..24488b130 100644 --- a/engine/gl/gl_shadow.c +++ b/engine/gl/gl_shadow.c @@ -2665,7 +2665,7 @@ static void Sh_DrawBrushModelShadow(dlight_t *dl, entity_t *e) GL_SelectEBO(0); qglEnableClientState(GL_VERTEX_ARRAY); - GLBE_PushOffsetShadow(true); + GLBE_PolyOffsetStencilShadow(true); model = e->model; surf = model->surfaces+model->firstmodelsurface; @@ -2742,7 +2742,7 @@ static void Sh_DrawBrushModelShadow(dlight_t *dl, entity_t *e) qglEnd(); } - GLBE_PushOffsetShadow(false); + GLBE_PolyOffsetStencilShadow(false); #endif } diff --git a/engine/gl/shader.h b/engine/gl/shader.h index 044d66d1f..9f77a2b6e 100644 --- a/engine/gl/shader.h +++ b/engine/gl/shader.h @@ -750,7 +750,7 @@ void BE_GenerateProgram(shader_t *shader); void Sh_RegisterCvars(void); #ifdef RTLIGHTS // -void GLBE_PushOffsetShadow(qboolean foobar); +void GLBE_PolyOffsetStencilShadow(qboolean foobar); //sets up gl for depth-only FIXME int GLBE_SetupForShadowMap(texid_t shadowmaptex, int texwidth, int texheight, float shadowscale); //Called from shadowmapping code into backend