- moved DrawSorted back to HWDrawList.

This commit is contained in:
Christoph Oelckers 2018-10-25 22:45:55 +02:00
parent 21b658d34f
commit 4f4bcd2d7d
8 changed files with 91 additions and 87 deletions

View file

@ -62,7 +62,6 @@ void FGLRenderState::Reset()
mGlossiness = 0.0f;
mSpecularLevel = 0.0f;
mShaderTimer = 0.0f;
ClearClipSplit();
stRenderStyle = DefaultRenderStyle();
stSrcBlend = stDstBlend = -1;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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