mirror of
https://github.com/leozide/leocad
synced 2025-01-13 08:01:38 +01:00
Reduce z-fighting when translucent walls are touching opaque walls. (#303)
* Move GL calls around drawing of translucent meshes to lcContext. * Reduce z-fighting when translucent walls are touching opaque walls. This fixes issue #301.
This commit is contained in:
parent
944ffbf5e5
commit
31703618c3
4 changed files with 24 additions and 34 deletions
|
@ -241,7 +241,7 @@ void lcContext::SetDefaultState()
|
|||
else
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0.5f, 0.1f);
|
||||
|
||||
if (gSupportsVertexBufferObject)
|
||||
|
@ -404,6 +404,20 @@ void lcContext::SetSmoothShading(bool Smooth)
|
|||
#endif
|
||||
}
|
||||
|
||||
void lcContext::BeginTranslucent()
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
|
||||
void lcContext::EndTranslucent()
|
||||
{
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
|
||||
void lcContext::BindTexture2D(GLuint Texture)
|
||||
{
|
||||
if (mTexture2D == Texture)
|
||||
|
|
|
@ -141,6 +141,8 @@ public:
|
|||
void SetViewport(int x, int y, int Width, int Height);
|
||||
void SetLineWidth(float LineWidth);
|
||||
void SetSmoothShading(bool Smooth);
|
||||
void BeginTranslucent();
|
||||
void EndTranslucent();
|
||||
void BindTexture2D(GLuint Texture);
|
||||
void BindTexture2DMS(GLuint Texture);
|
||||
void BindTextureCubeMap(GLuint Texture);
|
||||
|
|
|
@ -70,6 +70,9 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab
|
|||
{
|
||||
const lcArray<int>& Meshes = DrawTranslucent ? mTranslucentMeshes : mOpaqueMeshes;
|
||||
|
||||
if (DrawTranslucent)
|
||||
Context->BeginTranslucent();
|
||||
|
||||
for (int MeshIndex : Meshes)
|
||||
{
|
||||
const lcRenderMesh& RenderMesh = mRenderMeshes[MeshIndex];
|
||||
|
@ -227,6 +230,9 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (DrawTranslucent)
|
||||
Context->EndTranslucent();
|
||||
}
|
||||
|
||||
void lcScene::Draw(lcContext* Context) const
|
||||
|
@ -286,16 +292,8 @@ void lcScene::Draw(lcContext* Context) const
|
|||
DrawRenderMeshes(Context, UntexturedPrimitives, false, false, false);
|
||||
|
||||
if (!mTranslucentMeshes.IsEmpty())
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
DrawRenderMeshes(Context, LC_MESH_TRIANGLES, false, true, false);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
if (mHasTexture)
|
||||
{
|
||||
Context->SetMaterial(LC_MATERIAL_UNLIT_TEXTURE_DECAL);
|
||||
|
@ -306,16 +304,8 @@ void lcScene::Draw(lcContext* Context) const
|
|||
DrawRenderMeshes(Context, LC_MESH_TEXTURED_TRIANGLES, false, false, true);
|
||||
|
||||
if (!mTranslucentMeshes.IsEmpty())
|
||||
{
|
||||
glEnable(GL_BLEND); // todo: remove GL calls
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
DrawRenderMeshes(Context, LC_MESH_TEXTURED_TRIANGLES, false, true, true);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
Context->BindTexture2D(0);
|
||||
}
|
||||
}
|
||||
|
@ -339,16 +329,8 @@ void lcScene::Draw(lcContext* Context) const
|
|||
DrawRenderMeshes(Context, LC_MESH_TRIANGLES, true, false, false);
|
||||
|
||||
if (!mTranslucentMeshes.IsEmpty())
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
DrawRenderMeshes(Context, LC_MESH_TRIANGLES, true, true, false);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
if (mHasTexture)
|
||||
{
|
||||
if (DrawLines)
|
||||
|
@ -361,16 +343,8 @@ void lcScene::Draw(lcContext* Context) const
|
|||
DrawRenderMeshes(Context, LC_MESH_TEXTURED_TRIANGLES, true, false, true);
|
||||
|
||||
if (!mTranslucentMeshes.IsEmpty())
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
DrawRenderMeshes(Context, LC_MESH_TEXTURED_TRIANGLES, true, true, true);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
Context->BindTexture2D(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ QSize lcQGLWidget::sizeHint() const
|
|||
|
||||
void lcQGLWidget::initializeGL()
|
||||
{
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0.5f, 0.1f);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
|
Loading…
Reference in a new issue