Always draw grid between opaque and translucent meshes. Fixes #399.

This commit is contained in:
Leonardo Zide 2019-11-30 11:38:11 -08:00
parent 41b89de83f
commit 2bd9b837dc
3 changed files with 25 additions and 11 deletions

View file

@ -13,6 +13,7 @@ lcScene::lcScene()
mActiveSubmodelInstance = nullptr;
mAllowWireframe = true;
mAllowLOD = true;
mPreTranslucentCallback = nullptr;
}
void lcScene::Begin(const lcMatrix44& ViewMatrix)
@ -20,6 +21,7 @@ void lcScene::Begin(const lcMatrix44& ViewMatrix)
mViewMatrix = ViewMatrix;
mActiveSubmodelInstance = nullptr;
mDrawInterface = false;
mPreTranslucentCallback = nullptr;
mRenderMeshes.RemoveAll();
mOpaqueMeshes.RemoveAll();
mTranslucentMeshes.RemoveAll();
@ -395,6 +397,9 @@ void lcScene::Draw(lcContext* Context) const
PrimitiveTypes |= LC_MESH_CONDITIONAL_LINES;
DrawOpaqueMeshes(Context, false, PrimitiveTypes);
if (mPreTranslucentCallback)
mPreTranslucentCallback();
}
else if (ShadingMode == LC_SHADING_FLAT)
{
@ -411,6 +416,10 @@ void lcScene::Draw(lcContext* Context) const
}
DrawOpaqueMeshes(Context, false, PrimitiveTypes);
if (mPreTranslucentCallback)
mPreTranslucentCallback();
DrawTranslucentMeshes(Context, false);
}
else
@ -428,6 +437,10 @@ void lcScene::Draw(lcContext* Context) const
}
DrawOpaqueMeshes(Context, true, LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES);
if (mPreTranslucentCallback)
mPreTranslucentCallback();
DrawTranslucentMeshes(Context, true);
}
}

View file

@ -69,6 +69,11 @@ public:
mAllowLOD = AllowLOD;
}
void SetPreTranslucentCallback(std::function<void()> Callback)
{
mPreTranslucentCallback = Callback;
}
lcMatrix44 ApplyActiveSubmodelTransform(const lcMatrix44& WorldMatrix) const
{
return !mActiveSubmodelInstance ? WorldMatrix : lcMul(WorldMatrix, mActiveSubmodelTransform);
@ -98,6 +103,7 @@ protected:
bool mAllowWireframe;
bool mAllowLOD;
std::function<void()> mPreTranslucentCallback;
lcArray<lcRenderMesh> mRenderMeshes;
lcArray<int> mOpaqueMeshes;
lcArray<lcTranslucentMeshInstance> mTranslucentMeshes;

View file

@ -826,6 +826,9 @@ void View::OnDraw()
}
}
if (DrawInterface)
mScene.SetPreTranslucentCallback([this]() { DrawGrid(); });
int TotalTileRows = 1;
int TotalTileColumns = 1;
@ -875,12 +878,6 @@ void View::OnDraw()
mContext->SetProjectionMatrix(GetProjectionMatrix());
}
if (DrawInterface)
{
mContext->SetViewMatrix(mScene.GetViewMatrix());
DrawGrid();
}
mContext->SetLineWidth(Preferences.mLineWidth);
mScene.Draw(mContext);
@ -1580,8 +1577,6 @@ void View::DrawGrid()
if (!Preferences.mDrawGridStuds && !Preferences.mDrawGridLines)
return;
mContext->SetWorldMatrix(lcMatrix44Identity());
const int Spacing = lcMax(Preferences.mGridLineSpacing, 1);
int MinX, MaxX, MinY, MaxY;
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
@ -1722,13 +1717,13 @@ void View::DrawGrid()
int BufferOffset = 0;
mContext->SetVertexBuffer(mGridBuffer);
mContext->SetWorldMatrix(lcMatrix44Identity());
if (Preferences.mDrawGridStuds)
{
mContext->BindTexture2D(gGridTexture->mTexture);
mContext->SetDepthWrite(false);
glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.25f);
mContext->SetMaterial(LC_MATERIAL_UNLIT_TEXTURE_MODULATE);
mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor));
@ -1736,8 +1731,8 @@ void View::DrawGrid()
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
mContext->SetDepthWrite(true);
BufferOffset = 4 * 5 * sizeof(float);
}