mirror of
https://github.com/leozide/leocad
synced 2025-01-29 20:34:50 +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;
|
mTexture2D = 0;
|
||||||
mTexture2DMS = 0;
|
mTexture2DMS = 0;
|
||||||
mTextureCubeMap = 0;
|
mTextureCubeMap = 0;
|
||||||
|
mPolygonOffset = LC_POLYGON_OFFSET_NONE;
|
||||||
mLineWidth = 1.0f;
|
mLineWidth = 1.0f;
|
||||||
#ifndef LC_OPENGLES
|
#ifndef LC_OPENGLES
|
||||||
mMatrixMode = GL_MODELVIEW;
|
mMatrixMode = GL_MODELVIEW;
|
||||||
|
@ -241,9 +242,6 @@ void lcContext::SetDefaultState()
|
||||||
else
|
else
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
|
||||||
glPolygonOffset(0.5f, 0.1f);
|
|
||||||
|
|
||||||
if (gSupportsVertexBufferObject)
|
if (gSupportsVertexBufferObject)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||||
|
@ -294,6 +292,9 @@ void lcContext::SetDefaultState()
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
mTextureCubeMap = 0;
|
mTextureCubeMap = 0;
|
||||||
|
|
||||||
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
mPolygonOffset = LC_POLYGON_OFFSET_NONE;
|
||||||
|
|
||||||
glLineWidth(1.0f);
|
glLineWidth(1.0f);
|
||||||
mLineWidth = 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);
|
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)
|
void lcContext::SetLineWidth(float LineWidth)
|
||||||
{
|
{
|
||||||
if (LineWidth == mLineWidth)
|
if (LineWidth == mLineWidth)
|
||||||
|
@ -408,14 +434,14 @@ void lcContext::BeginTranslucent()
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
SetPolygonOffset(LC_POLYGON_OFFSET_TRANSLUCENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcContext::EndTranslucent()
|
void lcContext::EndTranslucent()
|
||||||
{
|
{
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
SetPolygonOffset(LC_POLYGON_OFFSET_OPAQUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcContext::BindTexture2D(GLuint Texture)
|
void lcContext::BindTexture2D(GLuint Texture)
|
||||||
|
|
|
@ -100,6 +100,13 @@ public:
|
||||||
int mHeight = 0;
|
int mHeight = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum lcPolygonOffset
|
||||||
|
{
|
||||||
|
LC_POLYGON_OFFSET_NONE,
|
||||||
|
LC_POLYGON_OFFSET_OPAQUE,
|
||||||
|
LC_POLYGON_OFFSET_TRANSLUCENT
|
||||||
|
};
|
||||||
|
|
||||||
class lcContext
|
class lcContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -139,6 +146,7 @@ public:
|
||||||
|
|
||||||
void SetMaterial(lcMaterialType MaterialType);
|
void SetMaterial(lcMaterialType MaterialType);
|
||||||
void SetViewport(int x, int y, int Width, int Height);
|
void SetViewport(int x, int y, int Width, int Height);
|
||||||
|
void SetPolygonOffset(lcPolygonOffset PolygonOffset);
|
||||||
void SetLineWidth(float LineWidth);
|
void SetLineWidth(float LineWidth);
|
||||||
void SetSmoothShading(bool Smooth);
|
void SetSmoothShading(bool Smooth);
|
||||||
void BeginTranslucent();
|
void BeginTranslucent();
|
||||||
|
@ -222,6 +230,7 @@ protected:
|
||||||
GLuint mTexture2D;
|
GLuint mTexture2D;
|
||||||
GLuint mTexture2DMS;
|
GLuint mTexture2DMS;
|
||||||
GLuint mTextureCubeMap;
|
GLuint mTextureCubeMap;
|
||||||
|
lcPolygonOffset mPolygonOffset;
|
||||||
float mLineWidth;
|
float mLineWidth;
|
||||||
int mMatrixMode;
|
int mMatrixMode;
|
||||||
bool mTextureEnabled;
|
bool mTextureEnabled;
|
||||||
|
|
|
@ -72,6 +72,8 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab
|
||||||
|
|
||||||
if (DrawTranslucent)
|
if (DrawTranslucent)
|
||||||
Context->BeginTranslucent();
|
Context->BeginTranslucent();
|
||||||
|
else
|
||||||
|
Context->SetPolygonOffset(LC_POLYGON_OFFSET_OPAQUE);
|
||||||
|
|
||||||
for (int MeshIndex : Meshes)
|
for (int MeshIndex : Meshes)
|
||||||
{
|
{
|
||||||
|
|
|
@ -159,9 +159,6 @@ QSize lcQGLWidget::sizeHint() const
|
||||||
|
|
||||||
void lcQGLWidget::initializeGL()
|
void lcQGLWidget::initializeGL()
|
||||||
{
|
{
|
||||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
|
||||||
glPolygonOffset(0.5f, 0.1f);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
Loading…
Add table
Reference in a new issue