From 1768508c8066a9c28580f5a7ca2e746435a96ab9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 21 Oct 2018 08:14:48 +0200 Subject: [PATCH] - first adjustments to decal code. - moved texture mode constants to a global header and consolidated with the variants of the 2D drawer. --- src/gl/renderer/gl_lightdata.cpp | 6 ++--- src/gl/renderer/gl_renderer.cpp | 8 +------ src/gl/renderer/gl_renderstate.cpp | 4 ++-- src/gl/renderer/gl_renderstate.h | 2 +- src/gl/scene/gl_drawinfo.h | 6 ++--- src/gl/scene/gl_scene.cpp | 6 ++--- src/gl/scene/gl_skydome.cpp | 2 +- src/gl/scene/gl_sprite.cpp | 4 ++-- src/gl/scene/gl_walls_draw.cpp | 33 +++++++++++++-------------- src/gl_load/gl_interface.h | 13 ----------- src/hwrenderer/scene/hw_renderstate.h | 16 +++++++++++++ src/r_data/renderstyle.h | 13 +++++++++++ src/v_2ddrawer.cpp | 14 ++++++------ src/v_2ddrawer.h | 12 +--------- src/v_video.h | 3 ++- wadsrc/static/shaders/glsl/main.fp | 4 ++-- 16 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 597e6d3e52..1a2963756d 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -55,15 +55,15 @@ void gl_GetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblend int srcblend = blendstyles[style.SrcAlpha%STYLEALPHA_MAX]; int dstblend = blendstyles[style.DestAlpha%STYLEALPHA_MAX]; int blendequation = renderops[style.BlendOp&15]; - int texturemode = drawopaque? TM_OPAQUE : TM_MODULATE; + int texturemode = drawopaque? TM_OPAQUE : TM_NORMAL; if (style.Flags & STYLEF_RedIsAlpha) { - texturemode = TM_REDTOALPHA; + texturemode = TM_ALPHATEXTURE; } else if (style.Flags & STYLEF_ColorIsFixed) { - texturemode = TM_MASK; + texturemode = TM_STENCIL; } else if (style.Flags & STYLEF_InvertSource) { diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index bf439c675b..bd3f5f17d0 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -468,12 +468,6 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) gl_RenderState.EnableFog(2); // Special 2D mode 'fog'. // Rather than adding remapping code, let's enforce that the constants here are equal. - static_assert(int(F2DDrawer::DTM_Normal) == int(TM_MODULATE), "DTM_Normal != TM_MODULATE"); - static_assert(int(F2DDrawer::DTM_Opaque) == int(TM_OPAQUE), "DTM_Opaque != TM_OPAQUE"); - static_assert(int(F2DDrawer::DTM_Invert) == int(TM_INVERSE), "DTM_Invert != TM_INVERSE"); - static_assert(int(F2DDrawer::DTM_InvertOpaque) == int(TM_INVERTOPAQUE), "DTM_InvertOpaque != TM_INVERTOPAQUE"); - static_assert(int(F2DDrawer::DTM_Stencil) == int(TM_MASK), "DTM_Stencil != TM_MASK"); - static_assert(int(F2DDrawer::DTM_AlphaTexture) == int(TM_REDTOALPHA), "DTM_AlphaTexture != TM_REDTOALPHA"); gl_RenderState.SetTextureMode(cmd.mDrawMode); if (cmd.mFlags & F2DDrawer::DTF_Scissor) { @@ -555,7 +549,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) gl_RenderState.SetVertexBuffer(mVBO); gl_RenderState.EnableTexture(true); gl_RenderState.EnableBrightmap(true); - gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetTextureMode(TM_NORMAL); gl_RenderState.EnableFog(false); gl_RenderState.ResetColor(); gl_RenderState.Apply(); diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index add2fdb12d..feafbc5861 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -128,7 +128,7 @@ bool FGLRenderState::ApplyShader() activeShader->muDesaturation.Set(mDesaturation / 255.f); activeShader->muFogEnabled.Set(fogset); - activeShader->muTextureMode.Set(mTextureMode == TM_MODULATE && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode); + activeShader->muTextureMode.Set(mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode); activeShader->muLightParms.Set(mLightParms); activeShader->muFogColor.Set(mFogColor); activeShader->muObjectColor.Set(mObjectColor); @@ -288,7 +288,7 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio } else { - mTempTM = TM_MODULATE; + mTempTM = TM_NORMAL; } mEffectState = overrideshader >= 0 ? overrideshader : mat->GetShaderIndex(); mShaderTimer = mat->tex->shaderspeed; diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index a79f2cd2d3..51bf8224c8 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -63,7 +63,7 @@ class FGLRenderState : public FRenderState float mClipSplit[2]; int mEffectState; - int mTempTM = TM_MODULATE; + int mTempTM = TM_NORMAL; FRenderStyle stRenderStyle; int stSrcBlend, stDstBlend; diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 54ed46d599..ba2fb67c5d 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -57,9 +57,9 @@ struct FDrawInfo : public HWDrawInfo void Draw(EDrawType dt, FRenderState &state, int index, int count, bool apply = true); void DrawIndexed(EDrawType dt, FRenderState &state, int index, int count, bool apply = true); - void DrawDecal(GLDecal *gldecal); - void DrawDecals(); - void DrawDecalsForMirror(GLWall *wall); + void DrawDecal(GLDecal *gldecal, FRenderState &state); + void DrawDecals(FRenderState &state); + void DrawDecalsForMirror(GLWall *wall, FRenderState &state); void StartScene(); void SetupFloodStencil(int vindex); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 60ba54e00b..83f3ebb2fc 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -181,7 +181,7 @@ void FDrawInfo::RenderScene(int recursion) if (!gl_texture) { gl_RenderState.EnableTexture(true); - gl_RenderState.SetTextureMode(TM_MASK); + gl_RenderState.SetTextureMode(TM_STENCIL); } gl_RenderState.AlphaFunc(Alpha_GEqual, gl_mask_threshold); drawlists[GLDL_MASKEDWALLS].DrawWalls(this, pass); @@ -206,9 +206,9 @@ void FDrawInfo::RenderScene(int recursion) glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(-1.0f, -128.0f); glDepthMask(false); - DrawDecals(); + DrawDecals(gl_RenderState); - gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetTextureMode(TM_NORMAL); glPolygonOffset(0.0f, 0.0f); glDisable(GL_POLYGON_OFFSET_FILL); glDepthMask(true); diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index 8c05292553..0f19635547 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -245,7 +245,7 @@ void GLSkyPortal::DrawContents(HWDrawInfo *di) { gl_RenderState.SetTextureMode(TM_OPAQUE); RenderDome(origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored, FSkyVertexBuffer::SKYMODE_MAINLAYER); - gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetTextureMode(TM_NORMAL); } gl_RenderState.AlphaFunc(Alpha_Greater, 0.f); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 4dfc1cf7f2..1762c54f42 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -269,7 +269,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.Apply(); glDrawArrays(GL_TRIANGLE_STRIP, sprite->vertexindex, 4); - gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetTextureMode(TM_NORMAL); } } else @@ -289,7 +289,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) gl_RenderState.EnableBrightmap(true); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.BlendEquation(GL_FUNC_ADD); - gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetTextureMode(TM_NORMAL); if (sprite->actor != nullptr && (sprite->actor->renderflags & RF_SPRITETYPEMASK) == RF_FLATSPRITE) { glPolygonOffset(0.0f, 0.0f); diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 50cc72400e..209bef6104 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -125,11 +125,11 @@ void FDrawInfo::RenderMirrorSurface(GLWall *wall) glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(-1.0f, -128.0f); glDepthMask(false); - DrawDecalsForMirror(wall); + DrawDecalsForMirror(wall, gl_RenderState); glDepthMask(true); glPolygonOffset(0.0f, 0.0f); glDisable(GL_POLYGON_OFFSET_FILL); - gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetTextureMode(TM_NORMAL); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } @@ -157,7 +157,7 @@ void FDrawInfo::RenderTexturedWall(GLWall *wall, int rflags) { if (wall->flags & GLWall::GLWF_CLAMPY) { - if (tmode == TM_MODULATE) gl_RenderState.SetTextureMode(TM_CLAMPY); + if (tmode == TM_NORMAL) gl_RenderState.SetTextureMode(TM_CLAMPY); } SetFog(255, 0, nullptr, false); } @@ -445,7 +445,7 @@ void FDrawInfo::AddPortal(GLWall *wall, int ptype) // // //========================================================================== -void FDrawInfo::DrawDecal(GLDecal *gldecal) +void FDrawInfo::DrawDecal(GLDecal *gldecal, FRenderState &state) { auto decal = gldecal->decal; auto tex = gldecal->gltexture; @@ -462,13 +462,14 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) } // alpha color only has an effect when using an alpha texture. - if (decal->RenderStyle.Flags & STYLEF_RedIsAlpha) + if (decal->RenderStyle.Flags & (STYLEF_RedIsAlpha | STYLEF_ColorIsFixed)) { gl_RenderState.SetObjectColor(decal->AlphaColor | 0xff000000); } - gl_SetRenderStyle(decal->RenderStyle, false, false); - gl_RenderState.ApplyMaterial(tex, CLAMP_XY, decal->Translation, -1); + gl_RenderState.SetTextureMode(decal->RenderStyle); + gl_RenderState.SetRenderStyle(decal->RenderStyle); + gl_RenderState.SetMaterial(tex, CLAMP_XY, decal->Translation, -1); // If srcalpha is one it looks better with a higher alpha threshold @@ -488,8 +489,7 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) if (gldecal->lightlist == nullptr) { - gl_RenderState.Apply(); - GLRenderer->mVBO->RenderArray(GL_TRIANGLE_FAN, gldecal->vertindex, 4); + Draw(DT_TriangleFan, gl_RenderState, gldecal->vertindex, 4); } else { @@ -505,7 +505,7 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) if (low1 < dv[1].z || low2 < dv[2].z) { - int thisll = lightlist[k].caster != NULL ? hw_ClampLight(*lightlist[k].p_lightlevel) : gldecal->lightlevel; + int thisll = lightlist[k].caster != nullptr ? hw_ClampLight(*lightlist[k].p_lightlevel) : gldecal->lightlevel; FColormap thiscm; thiscm.FadeColor = gldecal->Colormap.FadeColor; thiscm.CopyFrom3DLight(&lightlist[k]); @@ -514,15 +514,14 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) SetFog(thisll, gldecal->rellight, &thiscm, false); gl_RenderState.SetSplitPlanes(lightlist[k].plane, lowplane); - gl_RenderState.Apply(); - GLRenderer->mVBO->RenderArray(GL_TRIANGLE_FAN, gldecal->vertindex, 4); + Draw(DT_TriangleFan, gl_RenderState, gldecal->vertindex, 4); } if (low1 <= dv[0].z && low2 <= dv[3].z) break; } } rendered_decals++; - gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetTextureMode(TM_NORMAL); gl_RenderState.SetObjectColor(0xffffffff); gl_RenderState.SetFog(fc, -1); gl_RenderState.SetDynLight(0, 0, 0); @@ -533,7 +532,7 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) // // //========================================================================== -void FDrawInfo::DrawDecals() +void FDrawInfo::DrawDecals(FRenderState &state) { side_t *wall = nullptr; bool splitting = false; @@ -554,7 +553,7 @@ void FDrawInfo::DrawDecals() SetFog(gldecal->lightlevel, gldecal->rellight, &gldecal->Colormap, false); } } - DrawDecal(gldecal); + DrawDecal(gldecal, state); } if (splitting) gl_RenderState.EnableSplit(false); } @@ -564,14 +563,14 @@ void FDrawInfo::DrawDecals() // This list will never get long, so this code should be ok. // //========================================================================== -void FDrawInfo::DrawDecalsForMirror(GLWall *wall) +void FDrawInfo::DrawDecalsForMirror(GLWall *wall, FRenderState &state) { SetFog(wall->lightlevel, wall->rellight + getExtraLight(), &wall->Colormap, false); for (auto gldecal : decals[1]) { if (gldecal->decal->Side == wall->seg->sidedef) { - DrawDecal(gldecal); + DrawDecal(gldecal, state); } } } diff --git a/src/gl_load/gl_interface.h b/src/gl_load/gl_interface.h index 682be7e770..f1f5801275 100644 --- a/src/gl_load/gl_interface.h +++ b/src/gl_load/gl_interface.h @@ -3,19 +3,6 @@ #include "basictypes.h" -enum TexMode -{ - TM_MODULATE = 0, // (r, g, b, a) - TM_MASK, // (1, 1, 1, a) - TM_OPAQUE, // (r, g, b, 1) - TM_INVERSE, // (1-r, 1-g, 1-b, a) - TM_REDTOALPHA, // (1, 1, 1, r) - TM_CLAMPY, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0) - TM_INVERTOPAQUE, // (1-r, 1-g, 1-b, 1) - TM_FOGLAYER, // (renders a fog layer in the shape of the active texture) - TM_FIXEDCOLORMAP = TM_FOGLAYER, // repurposes the objectcolor uniforms to render a fixed colormap range. (Same constant because they cannot be used in the same context. -}; - struct RenderContext { unsigned int flags; diff --git a/src/hwrenderer/scene/hw_renderstate.h b/src/hwrenderer/scene/hw_renderstate.h index e3ad61fc76..3cc8f22a08 100644 --- a/src/hwrenderer/scene/hw_renderstate.h +++ b/src/hwrenderer/scene/hw_renderstate.h @@ -218,6 +218,22 @@ public: mTextureMode = mode; } + void SetTextureMode(FRenderStyle style) + { + if (style.Flags & STYLEF_RedIsAlpha) + { + mTextureMode = TM_ALPHATEXTURE; + } + else if (style.Flags & STYLEF_ColorIsFixed) + { + mTextureMode = TM_STENCIL; + } + else if (style.Flags & STYLEF_InvertSource) + { + mTextureMode = TM_INVERSE; + } + } + int GetTextureMode() { return mTextureMode; diff --git a/src/r_data/renderstyle.h b/src/r_data/renderstyle.h index 4e84728edc..8bedb4cc55 100644 --- a/src/r_data/renderstyle.h +++ b/src/r_data/renderstyle.h @@ -44,6 +44,19 @@ enum OPAQUE = 65536, }; +enum ETexMode +{ + TM_NORMAL = 0, // (r, g, b, a) + TM_STENCIL, // (1, 1, 1, a) + TM_OPAQUE, // (r, g, b, 1) + TM_INVERSE, // (1-r, 1-g, 1-b, a) + TM_ALPHATEXTURE, // (1, 1, 1, r) + TM_CLAMPY, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0) + TM_INVERTOPAQUE, // (1-r, 1-g, 1-b, 1) + TM_FOGLAYER, // (renders a fog layer in the shape of the active texture) + TM_FIXEDCOLORMAP = TM_FOGLAYER, // repurposes the objectcolor uniforms to render a fixed colormap range. (Same constant because they cannot be used in the same context. +}; + // Legacy render styles enum ERenderStyle { diff --git a/src/v_2ddrawer.cpp b/src/v_2ddrawer.cpp index a2388b65b0..b45b671f95 100644 --- a/src/v_2ddrawer.cpp +++ b/src/v_2ddrawer.cpp @@ -203,22 +203,22 @@ bool F2DDrawer::SetStyle(FTexture *tex, DrawParms &parms, PalEntry &vertexcolor, if (style.Flags & STYLEF_RedIsAlpha) { - quad.mDrawMode = DTM_AlphaTexture; + quad.mDrawMode = TM_ALPHATEXTURE; } else { - quad.mDrawMode = DTM_Stencil; + quad.mDrawMode = TM_STENCIL; } } else { if (style.Flags & STYLEF_RedIsAlpha) { - quad.mDrawMode = DTM_AlphaTexture; + quad.mDrawMode = TM_ALPHATEXTURE; } else if (style.Flags & STYLEF_InvertSource) { - quad.mDrawMode = DTM_Invert; + quad.mDrawMode = TM_INVERSE; } if (parms.specialcolormap != nullptr) @@ -237,9 +237,9 @@ bool F2DDrawer::SetStyle(FTexture *tex, DrawParms &parms, PalEntry &vertexcolor, if (!parms.masked) { - // For DTM_AlphaTexture and DTM_Stencil the mask cannot be turned off because it would not yield a usable result. - if (quad.mDrawMode == DTM_Normal) quad.mDrawMode = DTM_Opaque; - else if (quad.mDrawMode == DTM_Invert) quad.mDrawMode = DTM_InvertOpaque; + // For TM_ALPHATEXTURE and TM_STENCIL the mask cannot be turned off because it would not yield a usable result. + if (quad.mDrawMode == TM_NORMAL) quad.mDrawMode = TM_OPAQUE; + else if (quad.mDrawMode == TM_INVERSE) quad.mDrawMode = TM_INVERTOPAQUE; } quad.mRenderStyle = parms.style; // this contains the blend mode and blend equation settings. if (parms.burn) quad.mFlags |= DTF_Burn; diff --git a/src/v_2ddrawer.h b/src/v_2ddrawer.h index 5cef4f7197..e9079de3df 100644 --- a/src/v_2ddrawer.h +++ b/src/v_2ddrawer.h @@ -39,16 +39,6 @@ public: DrawTypePoints, }; - enum ETextureDrawMode : uint8_t - { - DTM_Normal = 0, - DTM_Stencil = 1, - DTM_Opaque = 2, - DTM_Invert = 3, - DTM_AlphaTexture = 4, - DTM_InvertOpaque = 6, - }; - enum ETextureFlags : uint8_t { DTF_Wrap = 1, @@ -101,7 +91,7 @@ public: int mDesaturate; FRenderStyle mRenderStyle; PalEntry mColor1; // Overlay color - ETextureDrawMode mDrawMode; + ETexMode mDrawMode; uint8_t mFlags; RenderCommand() diff --git a/src/v_video.h b/src/v_video.h index 1e29ff473d..e96b67bc92 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -34,6 +34,7 @@ #ifndef __V_VIDEO_H__ #define __V_VIDEO_H__ +#include #include "doomtype.h" #include "vectors.h" @@ -43,7 +44,6 @@ #include "c_cvars.h" #include "v_colortables.h" #include "v_2ddrawer.h" -#include struct sector_t; class IShaderProgram; @@ -64,6 +64,7 @@ enum EHWCaps RFL_DEBUG = 128, }; + struct IntRect { int left, top; diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index f096d0dd7d..dd082e6146 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -76,7 +76,7 @@ vec4 getTexel(vec2 st) // switch (uTextureMode) { - case 1: // TM_MASK + case 1: // TM_STENCIL texel.rgb = vec3(1.0,1.0,1.0); break; @@ -88,7 +88,7 @@ vec4 getTexel(vec2 st) texel = vec4(1.0-texel.r, 1.0-texel.b, 1.0-texel.g, texel.a); break; - case 4: // TM_REDTOALPHA + case 4: // TM_ALPHATEXTURE { float gray = grayscale(texel); texel = vec4(1.0, 1.0, 1.0, gray*texel.a);