- moved the clipline uniform to the viewpoint buffer.

This was the final one of the per-scene values that could be taken out of the render state.
This commit is contained in:
Christoph Oelckers 2018-06-22 23:49:39 +02:00
parent 7f0e29db48
commit 82d7e5970f
12 changed files with 35 additions and 107 deletions

View file

@ -61,7 +61,7 @@ static void matrixToGL(const VSMatrix &mat, int loc)
void FRenderState::Reset() void FRenderState::Reset()
{ {
mTextureEnabled = true; mTextureEnabled = true;
mClipLineShouldBeActive = mClipLineEnabled = mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false;
mColorMask[0] = mColorMask[1] = mColorMask[2] = mColorMask[3] = true; mColorMask[0] = mColorMask[1] = mColorMask[2] = mColorMask[3] = true;
currentColorMask[0] = currentColorMask[1] = currentColorMask[2] = currentColorMask[3] = true; currentColorMask[0] = currentColorMask[1] = currentColorMask[2] = currentColorMask[3] = true;
mFogColor.d = -1; mFogColor.d = -1;
@ -99,7 +99,6 @@ void FRenderState::Reset()
mGlowBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); mGlowBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mSplitTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); mSplitTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mSplitBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); mSplitBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mClipLine.Set(0.0f, 0.0f, 0.0f, 0.0f);
mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f); mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f);
mEffectState = 0; mEffectState = 0;
activeShader = nullptr; activeShader = nullptr;
@ -201,17 +200,6 @@ bool FRenderState::ApplyShader()
activeShader->currentsplitstate = 0; activeShader->currentsplitstate = 0;
} }
if (mClipLineEnabled)
{
activeShader->muClipLine.Set(mClipLine.vec);
activeShader->currentcliplinestate = 1;
}
else if (activeShader->currentcliplinestate)
{
activeShader->muClipLine.Set(-10000000.0, 0, 0, 0);
activeShader->currentcliplinestate = 0;
}
if (mTextureMatrixEnabled) if (mTextureMatrixEnabled)
{ {
matrixToGL(mTextureMatrix, activeShader->texturematrix_index); matrixToGL(mTextureMatrix, activeShader->texturematrix_index);

View file

@ -79,8 +79,6 @@ class FRenderState
uint8_t mFogEnabled; uint8_t mFogEnabled;
bool mGlowEnabled; bool mGlowEnabled;
bool mSplitEnabled; bool mSplitEnabled;
bool mClipLineEnabled;
bool mClipLineShouldBeActive;
bool mBrightmapEnabled; bool mBrightmapEnabled;
bool mColorMask[4]; bool mColorMask[4];
bool currentColorMask[4]; bool currentColorMask[4];
@ -96,7 +94,6 @@ class FRenderState
bool mTextureMatrixEnabled; bool mTextureMatrixEnabled;
bool mLastDepthClamp; bool mLastDepthClamp;
float mInterpolationFactor; float mInterpolationFactor;
float mClipHeight, mClipHeightDirection;
float mGlossiness, mSpecularLevel; float mGlossiness, mSpecularLevel;
float mShaderTimer; float mShaderTimer;
@ -106,7 +103,6 @@ class FRenderState
FStateVec4 mGlowTop, mGlowBottom; FStateVec4 mGlowTop, mGlowBottom;
FStateVec4 mGlowTopPlane, mGlowBottomPlane; FStateVec4 mGlowTopPlane, mGlowBottomPlane;
FStateVec4 mSplitTopPlane, mSplitBottomPlane; FStateVec4 mSplitTopPlane, mSplitBottomPlane;
FStateVec4 mClipLine;
PalEntry mFogColor; PalEntry mFogColor;
PalEntry mObjectColor; PalEntry mObjectColor;
PalEntry mObjectColor2; PalEntry mObjectColor2;
@ -171,31 +167,6 @@ public:
mCurrentVertexBuffer = NULL; mCurrentVertexBuffer = NULL;
} }
float GetClipHeight()
{
return mClipHeight;
}
float GetClipHeightDirection()
{
return mClipHeightDirection;
}
FStateVec4 &GetClipLine()
{
return mClipLine;
}
bool GetClipLineState()
{
return mClipLineEnabled;
}
bool GetClipLineShouldBeActive()
{
return mClipLineShouldBeActive;
}
void SetNormal(FVector3 norm) void SetNormal(FVector3 norm)
{ {
mNormal.Set(norm.X, norm.Y, norm.Z, 0.f); mNormal.Set(norm.X, norm.Y, norm.Z, 0.f);
@ -300,32 +271,6 @@ public:
} }
} }
void SetClipLine(line_t *line)
{
mClipLine.Set(line->v1->fX(), line->v1->fY(), line->Delta().X, line->Delta().Y);
}
void EnableClipLine(bool on)
{
if (!(gl.flags & RFL_NO_CLIP_PLANES))
{
mClipLineEnabled = on;
if (on)
{
glEnable(GL_CLIP_DISTANCE0);
}
else
{
glDisable(GL_CLIP_DISTANCE0);
}
}
else
{
// this needs to be flagged because in this case per-sector plane rendering needs to be disabled if a clip plane is active.
mClipLineShouldBeActive = on;
}
}
void EnableBrightmap(bool on) void EnableBrightmap(bool on)
{ {
mBrightmapEnabled = on; mBrightmapEnabled = on;

View file

@ -207,7 +207,13 @@ FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUnifo
di->mVBO = GLRenderer->mVBO; di->mVBO = GLRenderer->mVBO;
di->mClipper = &staticClipper; di->mClipper = &staticClipper;
di->Viewpoint = parentvp; di->Viewpoint = parentvp;
if (uniforms) di->VPUniforms = *uniforms; if (uniforms)
{
di->VPUniforms = *uniforms;
// The clip planes will never be inherited from the parent drawinfo.
di->VPUniforms.mClipLine.X = -1000001.f;
di->VPUniforms.mClipHeight = 0;
}
else di->VPUniforms.SetDefaults(); else di->VPUniforms.SetDefaults();
di->mClipper->SetViewpoint(di->Viewpoint); di->mClipper->SetViewpoint(di->Viewpoint);
staticClipper.Clear(); staticClipper.Clear();

View file

@ -166,7 +166,7 @@ void FDrawInfo::ProcessLights(GLFlat *flat, bool istrans)
{ {
flat->dynlightindex = GLRenderer->mLights->GetIndexPtr(); flat->dynlightindex = GLRenderer->mLights->GetIndexPtr();
if (flat->sector->ibocount > 0 && !gl_RenderState.GetClipLineShouldBeActive()) if (flat->sector->ibocount > 0 && !ClipLineShouldBeActive())
{ {
SetupSectorLights(flat, GLPASS_LIGHTSONLY, nullptr); SetupSectorLights(flat, GLPASS_LIGHTSONLY, nullptr);
} }
@ -215,7 +215,7 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool
if (iboindex >= 0) if (iboindex >= 0)
{ {
if (vcount > 0 && !gl_RenderState.GetClipLineShouldBeActive()) if (vcount > 0 && !ClipLineShouldBeActive())
{ {
if (processlights) SetupSectorLights(flat, GLPASS_ALL, &dli); if (processlights) SetupSectorLights(flat, GLPASS_ALL, &dli);
drawcalls.Clock(); drawcalls.Clock();

View file

@ -758,29 +758,6 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GLLinePortal::PushState()
{
FStateVec4 &v = gl_RenderState.GetClipLine();
planestack.Push(v.vec[0]);
planestack.Push(v.vec[1]);
planestack.Push(v.vec[2]);
planestack.Push(v.vec[3]);
planestack.Push(gl_RenderState.GetClipLineState());
gl_RenderState.EnableClipLine(false);
}
void GLLinePortal::PopState()
{
FStateVec4 &v = gl_RenderState.GetClipLine();
float e = 0;
planestack.Pop(e);
planestack.Pop(v.vec[3]);
planestack.Pop(v.vec[2]);
planestack.Pop(v.vec[1]);
planestack.Pop(v.vec[0]);
gl_RenderState.EnableClipLine(e != 0);
}
int GLLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos) int GLLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos)
{ {
line_t *linedef = seg->linedef; line_t *linedef = seg->linedef;
@ -793,7 +770,7 @@ int GLLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos)
int GLLinePortal::ClipSubsector(subsector_t *sub) int GLLinePortal::ClipSubsector(subsector_t *sub)
{ {
// this seg is completely behind the mirror! // this seg is completely behind the mirror
for(unsigned int i=0;i<sub->numlines;i++) for(unsigned int i=0;i<sub->numlines;i++)
{ {
if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), line()) == 0) return PClip_Inside; if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), line()) == 0) return PClip_Inside;
@ -895,6 +872,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
vp.ViewActor = nullptr; vp.ViewActor = nullptr;
MirrorFlag++; MirrorFlag++;
di->SetClipLine(linedef);
di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
di->mClipper->Clear(); di->mClipper->Clear();
@ -904,10 +882,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2); di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2);
gl_RenderState.SetClipLine(linedef);
gl_RenderState.EnableClipLine(true);
di->DrawScene(DM_PORTAL); di->DrawScene(DM_PORTAL);
gl_RenderState.EnableClipLine(false);
MirrorFlag--; MirrorFlag--;
} }
@ -972,13 +947,11 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di)
} }
vp.ViewActor = nullptr; vp.ViewActor = nullptr;
di->SetClipLine(glport->lines[0]->mDestination);
di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
ClearClipper(di); ClearClipper(di);
gl_RenderState.SetClipLine(glport->lines[0]->mDestination);
gl_RenderState.EnableClipLine(true);
di->DrawScene(DM_PORTAL); di->DrawScene(DM_PORTAL);
gl_RenderState.EnableClipLine(false);
} }
void GLLineToLinePortal::RenderAttached(FDrawInfo *di) void GLLineToLinePortal::RenderAttached(FDrawInfo *di)

View file

@ -180,8 +180,6 @@ struct GLLinePortal : public GLPortal
virtual int ClipSubsector(subsector_t *sub); virtual int ClipSubsector(subsector_t *sub);
virtual int ClipPoint(const DVector2 &pos); virtual int ClipPoint(const DVector2 &pos);
virtual bool NeedCap() { return false; } virtual bool NeedCap() { return false; }
virtual void PushState();
virtual void PopState();
}; };

View file

@ -79,7 +79,7 @@ void FDrawInfo::ApplyVPUniforms()
if (!(gl.flags & RFL_NO_CLIP_PLANES)) if (!(gl.flags & RFL_NO_CLIP_PLANES))
{ {
if (VPUniforms.mClipHeightDirection != 0.f) if (VPUniforms.mClipHeightDirection != 0.f || VPUniforms.mClipLine.X > -10000000.0f)
{ {
glEnable(GL_CLIP_DISTANCE0); glEnable(GL_CLIP_DISTANCE0);
} }
@ -90,6 +90,7 @@ void FDrawInfo::ApplyVPUniforms()
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Setup the modelview matrix // Setup the modelview matrix

View file

@ -322,7 +322,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
muGlowTopPlane.Init(hShader, "uGlowTopPlane"); muGlowTopPlane.Init(hShader, "uGlowTopPlane");
muSplitBottomPlane.Init(hShader, "uSplitBottomPlane"); muSplitBottomPlane.Init(hShader, "uSplitBottomPlane");
muSplitTopPlane.Init(hShader, "uSplitTopPlane"); muSplitTopPlane.Init(hShader, "uSplitTopPlane");
muClipLine.Init(hShader, "uClipLine");
muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muInterpolationFactor.Init(hShader, "uInterpolationFactor");
muAlphaThreshold.Init(hShader, "uAlphaThreshold"); muAlphaThreshold.Init(hShader, "uAlphaThreshold");
muSpecularMaterial.Init(hShader, "uSpecularMaterial"); muSpecularMaterial.Init(hShader, "uSpecularMaterial");
@ -345,6 +344,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
globvis_index = glGetUniformLocation(hShader, "uGlobVis"); globvis_index = glGetUniformLocation(hShader, "uGlobVis");
clipheight_index = glGetUniformLocation(hShader, "uClipHeight"); clipheight_index = glGetUniformLocation(hShader, "uClipHeight");
clipheightdirection_index = glGetUniformLocation(hShader, "uClipHeightDirection"); clipheightdirection_index = glGetUniformLocation(hShader, "uClipHeightDirection");
clipline_index = glGetUniformLocation(hShader, "uClipLine");
if (!(gl.flags & RFL_SHADER_STORAGE_BUFFER)) if (!(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{ {

View file

@ -257,7 +257,6 @@ class FShader
FUniform4f muGlowTopPlane; FUniform4f muGlowTopPlane;
FUniform4f muSplitBottomPlane; FUniform4f muSplitBottomPlane;
FUniform4f muSplitTopPlane; FUniform4f muSplitTopPlane;
FUniform4f muClipLine;
FBufferedUniform1f muInterpolationFactor; FBufferedUniform1f muInterpolationFactor;
FBufferedUniform1f muAlphaThreshold; FBufferedUniform1f muAlphaThreshold;
FBufferedUniform2f muSpecularMaterial; FBufferedUniform2f muSpecularMaterial;
@ -277,6 +276,7 @@ class FShader
int globvis_index; int globvis_index;
int clipheight_index; int clipheight_index;
int clipheightdirection_index; int clipheightdirection_index;
int clipline_index;
public: public:
int vertexmatrix_index; int vertexmatrix_index;

View file

@ -226,7 +226,8 @@ void HWViewpointUniforms::SetDefaults()
mViewMatrix.loadIdentity(); mViewMatrix.loadIdentity();
mNormalViewMatrix.loadIdentity(); mNormalViewMatrix.loadIdentity();
mViewHeight = viewheight; mViewHeight = viewheight;
mGlobVis = R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f;
mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8); mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8);
mClipLine.X = -10000000.0f;
} }

View file

@ -5,6 +5,7 @@
#include "r_defs.h" #include "r_defs.h"
#include "r_utility.h" #include "r_utility.h"
#include "hw_viewpointuniforms.h" #include "hw_viewpointuniforms.h"
#include "v_video.h"
struct FSectorPortalGroup; struct FSectorPortalGroup;
@ -162,6 +163,18 @@ public:
{ {
VPUniforms.mClipHeight = h; VPUniforms.mClipHeight = h;
VPUniforms.mClipHeightDirection = d; VPUniforms.mClipHeightDirection = d;
VPUniforms.mClipLine.X = -1000001.f;
}
void SetClipLine(line_t *line)
{
VPUniforms.mClipLine = { (float)line->v1->fX(), (float)line->v1->fY(), (float)line->Delta().X, (float)line->Delta().Y };
VPUniforms.mClipHeight = 0;
}
bool ClipLineShouldBeActive()
{
return (screen->hwcaps & RFL_NO_CLIP_PLANES) && VPUniforms.mClipLine.X > -1000000.f;
} }
void RenderBSPNode(void *node); void RenderBSPNode(void *node);

View file

@ -25,3 +25,6 @@ struct HWViewpointUniforms
void SetDefaults(); void SetDefaults();
}; };