- first adjustments to decal code.

- moved texture mode constants to a global header and consolidated with the variants of the 2D drawer.
This commit is contained in:
Christoph Oelckers 2018-10-21 08:14:48 +02:00
parent 3b7a5da83e
commit 1768508c80
16 changed files with 73 additions and 73 deletions

View File

@ -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)
{

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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
{

View File

@ -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;

View File

@ -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()

View File

@ -34,6 +34,7 @@
#ifndef __V_VIDEO_H__
#define __V_VIDEO_H__
#include <functional>
#include "doomtype.h"
#include "vectors.h"
@ -43,7 +44,6 @@
#include "c_cvars.h"
#include "v_colortables.h"
#include "v_2ddrawer.h"
#include <functional>
struct sector_t;
class IShaderProgram;
@ -64,6 +64,7 @@ enum EHWCaps
RFL_DEBUG = 128,
};
struct IntRect
{
int left, top;

View File

@ -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);