Skip to content

Commit

Permalink
- moved the clipline uniform to the viewpoint buffer.
Browse files Browse the repository at this point in the history
This was the final one of the per-scene values that could be taken out of the render state.
  • Loading branch information
coelckers committed Jun 22, 2018
1 parent 7f0e29d commit 82d7e59
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 107 deletions.
14 changes: 1 addition & 13 deletions src/gl/renderer/gl_renderstate.cpp
Expand Up @@ -61,7 +61,7 @@ static void matrixToGL(const VSMatrix &mat, int loc)
void FRenderState::Reset()
{
mTextureEnabled = true;
mClipLineShouldBeActive = mClipLineEnabled = mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false;
mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false;
mColorMask[0] = mColorMask[1] = mColorMask[2] = mColorMask[3] = true;
currentColorMask[0] = currentColorMask[1] = currentColorMask[2] = currentColorMask[3] = true;
mFogColor.d = -1;
Expand Down Expand Up @@ -99,7 +99,6 @@ void FRenderState::Reset()
mGlowBottomPlane.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);
mClipLine.Set(0.0f, 0.0f, 0.0f, 0.0f);
mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f);
mEffectState = 0;
activeShader = nullptr;
Expand Down Expand Up @@ -201,17 +200,6 @@ bool FRenderState::ApplyShader()
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)
{
matrixToGL(mTextureMatrix, activeShader->texturematrix_index);
Expand Down
55 changes: 0 additions & 55 deletions src/gl/renderer/gl_renderstate.h
Expand Up @@ -79,8 +79,6 @@ class FRenderState
uint8_t mFogEnabled;
bool mGlowEnabled;
bool mSplitEnabled;
bool mClipLineEnabled;
bool mClipLineShouldBeActive;
bool mBrightmapEnabled;
bool mColorMask[4];
bool currentColorMask[4];
Expand All @@ -96,7 +94,6 @@ class FRenderState
bool mTextureMatrixEnabled;
bool mLastDepthClamp;
float mInterpolationFactor;
float mClipHeight, mClipHeightDirection;
float mGlossiness, mSpecularLevel;
float mShaderTimer;

Expand All @@ -106,7 +103,6 @@ class FRenderState
FStateVec4 mGlowTop, mGlowBottom;
FStateVec4 mGlowTopPlane, mGlowBottomPlane;
FStateVec4 mSplitTopPlane, mSplitBottomPlane;
FStateVec4 mClipLine;
PalEntry mFogColor;
PalEntry mObjectColor;
PalEntry mObjectColor2;
Expand Down Expand Up @@ -171,31 +167,6 @@ class FRenderState
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)
{
mNormal.Set(norm.X, norm.Y, norm.Z, 0.f);
Expand Down Expand Up @@ -300,32 +271,6 @@ class FRenderState
}
}

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)
{
mBrightmapEnabled = on;
Expand Down
8 changes: 7 additions & 1 deletion src/gl/scene/gl_drawinfo.cpp
Expand Up @@ -207,7 +207,13 @@ FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUnifo
di->mVBO = GLRenderer->mVBO;
di->mClipper = &staticClipper;
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();
di->mClipper->SetViewpoint(di->Viewpoint);
staticClipper.Clear();
Expand Down
4 changes: 2 additions & 2 deletions src/gl/scene/gl_flats.cpp
Expand Up @@ -166,7 +166,7 @@ void FDrawInfo::ProcessLights(GLFlat *flat, bool istrans)
{
flat->dynlightindex = GLRenderer->mLights->GetIndexPtr();

if (flat->sector->ibocount > 0 && !gl_RenderState.GetClipLineShouldBeActive())
if (flat->sector->ibocount > 0 && !ClipLineShouldBeActive())
{
SetupSectorLights(flat, GLPASS_LIGHTSONLY, nullptr);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool

if (iboindex >= 0)
{
if (vcount > 0 && !gl_RenderState.GetClipLineShouldBeActive())
if (vcount > 0 && !ClipLineShouldBeActive())
{
if (processlights) SetupSectorLights(flat, GLPASS_ALL, &dli);
drawcalls.Clock();
Expand Down
33 changes: 3 additions & 30 deletions src/gl/scene/gl_portal.cpp
Expand Up @@ -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)
{
line_t *linedef = seg->linedef;
Expand All @@ -793,7 +770,7 @@ int GLLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos)

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++)
{
if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), line()) == 0) return PClip_Inside;
Expand Down Expand Up @@ -895,6 +872,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
vp.ViewActor = nullptr;

MirrorFlag++;
di->SetClipLine(linedef);
di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));

di->mClipper->Clear();
Expand All @@ -904,10 +882,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)

di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2);

gl_RenderState.SetClipLine(linedef);
gl_RenderState.EnableClipLine(true);
di->DrawScene(DM_PORTAL);
gl_RenderState.EnableClipLine(false);

MirrorFlag--;
}
Expand Down Expand Up @@ -972,13 +947,11 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di)
}

vp.ViewActor = nullptr;
di->SetClipLine(glport->lines[0]->mDestination);
di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));

ClearClipper(di);
gl_RenderState.SetClipLine(glport->lines[0]->mDestination);
gl_RenderState.EnableClipLine(true);
di->DrawScene(DM_PORTAL);
gl_RenderState.EnableClipLine(false);
}

void GLLineToLinePortal::RenderAttached(FDrawInfo *di)
Expand Down
2 changes: 0 additions & 2 deletions src/gl/scene/gl_portal.h
Expand Up @@ -180,8 +180,6 @@ struct GLLinePortal : public GLPortal
virtual int ClipSubsector(subsector_t *sub);
virtual int ClipPoint(const DVector2 &pos);
virtual bool NeedCap() { return false; }
virtual void PushState();
virtual void PopState();
};


Expand Down
3 changes: 2 additions & 1 deletion src/gl/scene/gl_scene.cpp
Expand Up @@ -79,7 +79,7 @@ void FDrawInfo::ApplyVPUniforms()

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);
}
Expand All @@ -90,6 +90,7 @@ void FDrawInfo::ApplyVPUniforms()
}
}


//-----------------------------------------------------------------------------
//
// Setup the modelview matrix
Expand Down
2 changes: 1 addition & 1 deletion src/gl/shaders/gl_shader.cpp
Expand Up @@ -322,7 +322,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
muGlowTopPlane.Init(hShader, "uGlowTopPlane");
muSplitBottomPlane.Init(hShader, "uSplitBottomPlane");
muSplitTopPlane.Init(hShader, "uSplitTopPlane");
muClipLine.Init(hShader, "uClipLine");
muInterpolationFactor.Init(hShader, "uInterpolationFactor");
muAlphaThreshold.Init(hShader, "uAlphaThreshold");
muSpecularMaterial.Init(hShader, "uSpecularMaterial");
Expand All @@ -345,6 +344,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
globvis_index = glGetUniformLocation(hShader, "uGlobVis");
clipheight_index = glGetUniformLocation(hShader, "uClipHeight");
clipheightdirection_index = glGetUniformLocation(hShader, "uClipHeightDirection");
clipline_index = glGetUniformLocation(hShader, "uClipLine");

if (!(gl.flags & RFL_SHADER_STORAGE_BUFFER))
{
Expand Down
2 changes: 1 addition & 1 deletion src/gl/shaders/gl_shader.h
Expand Up @@ -257,7 +257,6 @@ class FShader
FUniform4f muGlowTopPlane;
FUniform4f muSplitBottomPlane;
FUniform4f muSplitTopPlane;
FUniform4f muClipLine;
FBufferedUniform1f muInterpolationFactor;
FBufferedUniform1f muAlphaThreshold;
FBufferedUniform2f muSpecularMaterial;
Expand All @@ -277,6 +276,7 @@ class FShader
int globvis_index;
int clipheight_index;
int clipheightdirection_index;
int clipline_index;

public:
int vertexmatrix_index;
Expand Down
3 changes: 2 additions & 1 deletion src/hwrenderer/scene/hw_drawinfo.cpp
Expand Up @@ -226,7 +226,8 @@ void HWViewpointUniforms::SetDefaults()
mViewMatrix.loadIdentity();
mNormalViewMatrix.loadIdentity();
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);
mClipLine.X = -10000000.0f;

}
13 changes: 13 additions & 0 deletions src/hwrenderer/scene/hw_drawinfo.h
Expand Up @@ -5,6 +5,7 @@
#include "r_defs.h"
#include "r_utility.h"
#include "hw_viewpointuniforms.h"
#include "v_video.h"


struct FSectorPortalGroup;
Expand Down Expand Up @@ -162,6 +163,18 @@ struct HWDrawInfo
{
VPUniforms.mClipHeight = h;
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);
Expand Down
3 changes: 3 additions & 0 deletions src/hwrenderer/scene/hw_viewpointuniforms.h
Expand Up @@ -25,3 +25,6 @@ struct HWViewpointUniforms
void SetDefaults();

};



0 comments on commit 82d7e59

Please sign in to comment.