mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Enabled polygon offset (with a smaller offset) for opaque triangles so they don't z fight with lines.
This commit is contained in:
parent
31703618c3
commit
0abc4a258a
4 changed files with 42 additions and 8 deletions
|
@ -35,6 +35,7 @@ lcContext::lcContext()
|
|||
mTexture2D = 0;
|
||||
mTexture2DMS = 0;
|
||||
mTextureCubeMap = 0;
|
||||
mPolygonOffset = LC_POLYGON_OFFSET_NONE;
|
||||
mLineWidth = 1.0f;
|
||||
#ifndef LC_OPENGLES
|
||||
mMatrixMode = GL_MODELVIEW;
|
||||
|
@ -241,9 +242,6 @@ void lcContext::SetDefaultState()
|
|||
else
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0.5f, 0.1f);
|
||||
|
||||
if (gSupportsVertexBufferObject)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||
|
@ -294,6 +292,9 @@ void lcContext::SetDefaultState()
|
|||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
mTextureCubeMap = 0;
|
||||
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
mPolygonOffset = LC_POLYGON_OFFSET_NONE;
|
||||
|
||||
glLineWidth(1.0f);
|
||||
mLineWidth = 1.0f;
|
||||
|
||||
|
@ -387,6 +388,31 @@ void lcContext::SetViewport(int x, int y, int Width, int Height)
|
|||
glViewport(x, y, Width, Height);
|
||||
}
|
||||
|
||||
void lcContext::SetPolygonOffset(lcPolygonOffset PolygonOffset)
|
||||
{
|
||||
if (mPolygonOffset == PolygonOffset)
|
||||
return;
|
||||
|
||||
switch (PolygonOffset)
|
||||
{
|
||||
case LC_POLYGON_OFFSET_NONE:
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
break;
|
||||
|
||||
case LC_POLYGON_OFFSET_OPAQUE:
|
||||
glPolygonOffset(0.25f, 0.1f);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
break;
|
||||
|
||||
case LC_POLYGON_OFFSET_TRANSLUCENT:
|
||||
glPolygonOffset(0.5f, 0.1f);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
break;
|
||||
}
|
||||
|
||||
mPolygonOffset = PolygonOffset;
|
||||
}
|
||||
|
||||
void lcContext::SetLineWidth(float LineWidth)
|
||||
{
|
||||
if (LineWidth == mLineWidth)
|
||||
|
@ -408,14 +434,14 @@ void lcContext::BeginTranslucent()
|
|||
{
|
||||
glEnable(GL_BLEND);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
SetPolygonOffset(LC_POLYGON_OFFSET_TRANSLUCENT);
|
||||
}
|
||||
|
||||
void lcContext::EndTranslucent()
|
||||
{
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
SetPolygonOffset(LC_POLYGON_OFFSET_OPAQUE);
|
||||
}
|
||||
|
||||
void lcContext::BindTexture2D(GLuint Texture)
|
||||
|
|
|
@ -100,6 +100,13 @@ public:
|
|||
int mHeight = 0;
|
||||
};
|
||||
|
||||
enum lcPolygonOffset
|
||||
{
|
||||
LC_POLYGON_OFFSET_NONE,
|
||||
LC_POLYGON_OFFSET_OPAQUE,
|
||||
LC_POLYGON_OFFSET_TRANSLUCENT
|
||||
};
|
||||
|
||||
class lcContext
|
||||
{
|
||||
public:
|
||||
|
@ -139,6 +146,7 @@ public:
|
|||
|
||||
void SetMaterial(lcMaterialType MaterialType);
|
||||
void SetViewport(int x, int y, int Width, int Height);
|
||||
void SetPolygonOffset(lcPolygonOffset PolygonOffset);
|
||||
void SetLineWidth(float LineWidth);
|
||||
void SetSmoothShading(bool Smooth);
|
||||
void BeginTranslucent();
|
||||
|
@ -222,6 +230,7 @@ protected:
|
|||
GLuint mTexture2D;
|
||||
GLuint mTexture2DMS;
|
||||
GLuint mTextureCubeMap;
|
||||
lcPolygonOffset mPolygonOffset;
|
||||
float mLineWidth;
|
||||
int mMatrixMode;
|
||||
bool mTextureEnabled;
|
||||
|
|
|
@ -72,6 +72,8 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab
|
|||
|
||||
if (DrawTranslucent)
|
||||
Context->BeginTranslucent();
|
||||
else
|
||||
Context->SetPolygonOffset(LC_POLYGON_OFFSET_OPAQUE);
|
||||
|
||||
for (int MeshIndex : Meshes)
|
||||
{
|
||||
|
|
|
@ -159,9 +159,6 @@ QSize lcQGLWidget::sizeHint() const
|
|||
|
||||
void lcQGLWidget::initializeGL()
|
||||
{
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0.5f, 0.1f);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
|
Loading…
Reference in a new issue