diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 56321e6bc2..95e5e3e7c4 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -62,7 +62,6 @@ void FGLRenderState::Reset() mGlossiness = 0.0f; mSpecularLevel = 0.0f; mShaderTimer = 0.0f; - ClearClipSplit(); stRenderStyle = DefaultRenderStyle(); stSrcBlend = stDstBlend = -1; diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index f535dbe955..7e153efb86 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -57,7 +57,6 @@ class FGLRenderState : public FRenderState float mInterpolationFactor; FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer; - float mClipSplit[2]; int mEffectState; int mTempTM = TM_NORMAL; @@ -119,28 +118,6 @@ public: mSpecularLevel = specularLevel; } - void SetClipSplit(float bottom, float top) - { - mClipSplit[0] = bottom; - mClipSplit[1] = top; - } - - void SetClipSplit(float *vals) - { - memcpy(mClipSplit, vals, 2 * sizeof(float)); - } - - void GetClipSplit(float *out) - { - memcpy(out, mClipSplit, 2 * sizeof(float)); - } - - void ClearClipSplit() - { - mClipSplit[0] = -1000000.f; - mClipSplit[1] = 1000000.f; - } - // This wraps the depth clamp setting because we frequently need to read it which OpenGL is not particularly performant at... bool SetDepthClamp(bool on) { diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index fc3bc8e493..84e8793910 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -58,66 +58,6 @@ public: static FDrawInfo * gl_drawinfo; FDrawInfoList di_list; -//========================================================================== -// -// -// -//========================================================================== -void FDrawInfo::DoDrawSorted(HWDrawList *dl, SortNode * head) -{ - float clipsplit[2]; - int relation = 0; - float z = 0.f; - - gl_RenderState.GetClipSplit(clipsplit); - - if (dl->drawitems[head->itemindex].rendertype == GLDIT_FLAT) - { - z = dl->flats[dl->drawitems[head->itemindex].index]->z; - relation = z > Viewpoint.Pos.Z ? 1 : -1; - } - - - // left is further away, i.e. for stuff above viewz its z coordinate higher, for stuff below viewz its z coordinate is lower - if (head->left) - { - if (relation == -1) - { - gl_RenderState.SetClipSplit(clipsplit[0], z); // render below: set flat as top clip plane - } - else if (relation == 1) - { - gl_RenderState.SetClipSplit(z, clipsplit[1]); // render above: set flat as bottom clip plane - } - DoDrawSorted(dl, head->left); - gl_RenderState.SetClipSplit(clipsplit); - } - dl->DoDraw(this, gl_RenderState, true, head->itemindex); - if (head->equal) - { - SortNode * ehead=head->equal; - while (ehead) - { - dl->DoDraw(this, gl_RenderState, true, ehead->itemindex); - ehead=ehead->equal; - } - } - // right is closer, i.e. for stuff above viewz its z coordinate is lower, for stuff below viewz its z coordinate is higher - if (head->right) - { - if (relation == 1) - { - gl_RenderState.SetClipSplit(clipsplit[0], z); // render below: set flat as top clip plane - } - else if (relation == -1) - { - gl_RenderState.SetClipSplit(z, clipsplit[1]); // render above: set flat as bottom clip plane - } - DoDrawSorted(dl, head->right); - gl_RenderState.SetClipSplit(clipsplit); - } -} - //========================================================================== // // @@ -140,7 +80,7 @@ void FDrawInfo::DrawSorted(int listindex) glEnable(GL_CLIP_DISTANCE1); glEnable(GL_CLIP_DISTANCE2); } - DoDrawSorted(dl, dl->sorted); + dl->DrawSorted(this, gl_RenderState, dl->sorted); if (!(gl.flags & RFL_NO_CLIP_PLANES)) { glDisable(GL_CLIP_DISTANCE1); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 6393ac660e..d70f83dc24 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -56,7 +56,6 @@ struct FDrawInfo : public HWDrawInfo void StartScene(); - void DoDrawSorted(HWDrawList *dl, SortNode * head); void DrawSorted(int listindex); // These two may be moved to the API independent part of the renderer later. diff --git a/src/hwrenderer/scene/hw_drawinfo.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index 2b5a1a7a84..40219a00ae 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -33,6 +33,7 @@ #include "hw_fakeflat.h" #include "hw_drawinfo.h" #include "hw_portal.h" +#include "hw_renderstate.h" #include "hw_drawlist.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_cvars.h" diff --git a/src/hwrenderer/scene/hw_drawlist.cpp b/src/hwrenderer/scene/hw_drawlist.cpp index 59a95c259a..c35eed81f9 100644 --- a/src/hwrenderer/scene/hw_drawlist.cpp +++ b/src/hwrenderer/scene/hw_drawlist.cpp @@ -33,6 +33,7 @@ #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawlist.h" #include "hwrenderer/utility/hw_clock.h" +#include "hw_renderstate.h" FMemArena RenderDataAllocator(1024*1024); // Use large blocks to reduce allocation time. @@ -847,3 +848,63 @@ void HWDrawList::DrawFlats(HWDrawInfo *di, FRenderState &state, bool translucent RenderFlat.Unclock(); } +//========================================================================== +// +// +// +//========================================================================== +void HWDrawList::DrawSorted(HWDrawInfo *di, FRenderState &state, SortNode * head) +{ + float clipsplit[2]; + int relation = 0; + float z = 0.f; + + state.GetClipSplit(clipsplit); + + if (drawitems[head->itemindex].rendertype == GLDIT_FLAT) + { + z = flats[drawitems[head->itemindex].index]->z; + relation = z > di->Viewpoint.Pos.Z ? 1 : -1; + } + + + // left is further away, i.e. for stuff above viewz its z coordinate higher, for stuff below viewz its z coordinate is lower + if (head->left) + { + if (relation == -1) + { + state.SetClipSplit(clipsplit[0], z); // render below: set flat as top clip plane + } + else if (relation == 1) + { + state.SetClipSplit(z, clipsplit[1]); // render above: set flat as bottom clip plane + } + DrawSorted(di, state, head->left); + state.SetClipSplit(clipsplit); + } + DoDraw(di, state, true, head->itemindex); + if (head->equal) + { + SortNode * ehead = head->equal; + while (ehead) + { + DoDraw(di, state, true, ehead->itemindex); + ehead = ehead->equal; + } + } + // right is closer, i.e. for stuff above viewz its z coordinate is lower, for stuff below viewz its z coordinate is higher + if (head->right) + { + if (relation == 1) + { + state.SetClipSplit(clipsplit[0], z); // render below: set flat as top clip plane + } + else if (relation == -1) + { + state.SetClipSplit(z, clipsplit[1]); // render above: set flat as bottom clip plane + } + DrawSorted(di, state, head->right); + state.SetClipSplit(clipsplit); + } +} + diff --git a/src/hwrenderer/scene/hw_drawlist.h b/src/hwrenderer/scene/hw_drawlist.h index 3756533b60..a51bf6f104 100644 --- a/src/hwrenderer/scene/hw_drawlist.h +++ b/src/hwrenderer/scene/hw_drawlist.h @@ -107,7 +107,9 @@ public: void Draw(HWDrawInfo *di, FRenderState &state, bool translucent); void DrawWalls(HWDrawInfo *di, FRenderState &state, bool translucent); void DrawFlats(HWDrawInfo *di, FRenderState &state, bool translucent); - + + void DrawSorted(HWDrawInfo *di, FRenderState &state, SortNode * head); + HWDrawList * next; } ; diff --git a/src/hwrenderer/scene/hw_renderstate.h b/src/hwrenderer/scene/hw_renderstate.h index 2dc2b14500..4fa6a12404 100644 --- a/src/hwrenderer/scene/hw_renderstate.h +++ b/src/hwrenderer/scene/hw_renderstate.h @@ -90,6 +90,7 @@ protected: float mLightParms[4]; float mAlphaThreshold; + float mClipSplit[2]; FStateVec4 mNormal; FStateVec4 mColor; @@ -146,6 +147,7 @@ public: mModelMatrix.loadIdentity(); mTextureMatrix.loadIdentity(); + ClearClipSplit(); } void SetNormal(FVector3 norm) @@ -361,6 +363,29 @@ public: mMaterial.mChanged = true; } + void SetClipSplit(float bottom, float top) + { + mClipSplit[0] = bottom; + mClipSplit[1] = top; + } + + void SetClipSplit(float *vals) + { + memcpy(mClipSplit, vals, 2 * sizeof(float)); + } + + void GetClipSplit(float *out) + { + memcpy(out, mClipSplit, 2 * sizeof(float)); + } + + void ClearClipSplit() + { + mClipSplit[0] = -1000000.f; + mClipSplit[1] = 1000000.f; + } + + void SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false); void SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive);