- fixed: The depth clamp setting needs to be tracked per portal so that it can be properly restored afterward.

Regular skies need it off but SkyViewpoints need it on - and all others need to use the parent's setting.
So without engine side tracking we can end up rendering the sky with this setting off, resulting in omission of the fog layer.
This commit is contained in:
Christoph Oelckers 2014-11-27 12:26:52 +01:00
parent eb753a0b7c
commit ec627d94dd
4 changed files with 16 additions and 3 deletions

View file

@ -90,6 +90,7 @@ void FRenderState::Reset()
stSrcBlend = stDstBlend = -1;
stBlendEquation = -1;
stAlphaThreshold = -1.f;
mLastDepthClamp = true;
}
//==========================================================================

View file

@ -63,6 +63,7 @@ class FRenderState
float mInterpolationFactor;
float mClipHeightTop, mClipHeightBottom;
float mShaderTimer;
bool mLastDepthClamp;
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
FStateVec4 mColor;
@ -309,6 +310,16 @@ public:
}
}
// This wraps the depth clamp setting because we frequently need to read it which OpenGL is not particularly performant at...
bool SetDepthClamp(bool on)
{
bool res = mLastDepthClamp;
if (!on) glDisable(GL_DEPTH_CLAMP);
else glEnable(GL_DEPTH_CLAMP);
mLastDepthClamp = on;
return res;
}
void Set2DMode(bool on)
{
m2D = on;

View file

@ -633,8 +633,7 @@ void GLSkyboxPortal::DrawContents()
PlaneMirrorMode=0;
glDisable(GL_DEPTH_CLAMP);
bool oldclamp = gl_RenderState.SetDepthClamp(false);
viewx = origin->PrevX + FixedMul(r_TicFrac, origin->x - origin->PrevX);
viewy = origin->PrevY + FixedMul(r_TicFrac, origin->y - origin->PrevY);
viewz = origin->PrevZ + FixedMul(r_TicFrac, origin->z - origin->PrevZ);
@ -663,7 +662,7 @@ void GLSkyboxPortal::DrawContents()
GLRenderer->DrawScene();
origin->flags&=~MF_JUSTHIT;
inskybox=false;
glEnable(GL_DEPTH_CLAMP);
gl_RenderState.SetDepthClamp(oldclamp);
skyboxrecursion--;
PlaneMirrorMode=old_pm;

View file

@ -475,6 +475,7 @@ void GLSkyPortal::DrawContents()
gl_RenderState.EnableFog(false);
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
bool oldClamp = gl_RenderState.SetDepthClamp(true);
gl_MatrixStack.Push(gl_RenderState.mViewMatrix);
GLRenderer->SetupView(0, 0, 0, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
@ -519,5 +520,6 @@ void GLSkyPortal::DrawContents()
gl_MatrixStack.Pop(gl_RenderState.mViewMatrix);
gl_RenderState.ApplyMatrices();
glset.lightmode = oldlightmode;
gl_RenderState.SetDepthClamp(oldClamp);
}