diff --git a/common/lc_scene.cpp b/common/lc_scene.cpp index 14f056c3..182a1540 100644 --- a/common/lc_scene.cpp +++ b/common/lc_scene.cpp @@ -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); } } diff --git a/common/lc_scene.h b/common/lc_scene.h index 1945fae6..4eb551ca 100644 --- a/common/lc_scene.h +++ b/common/lc_scene.h @@ -69,6 +69,11 @@ public: mAllowLOD = AllowLOD; } + void SetPreTranslucentCallback(std::function 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 mPreTranslucentCallback; lcArray mRenderMeshes; lcArray mOpaqueMeshes; lcArray mTranslucentMeshes; diff --git a/common/view.cpp b/common/view.cpp index a624c035..897bc2fb 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -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); }