Removed direct GL function calls.

This commit is contained in:
Leonardo Zide
2021-01-12 14:29:56 -08:00
parent 4e4fc504da
commit b8a8cb6730
4 changed files with 54 additions and 6 deletions
+38
View File
@@ -45,6 +45,8 @@ lcContext::lcContext()
mTextureCubeMap = 0;
mPolygonOffset = lcPolygonOffset::None;
mDepthWrite = true;
mDepthFunction = lcDepthFunction::LessEqual;
mCullFace = false;
mLineWidth = 1.0f;
#ifndef LC_OPENGLES
mMatrixMode = GL_MODELVIEW;
@@ -339,6 +341,7 @@ void lcContext::SetDefaultState()
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
mDepthFunction = lcDepthFunction::LessEqual;
if (gSupportsBlendFuncSeparate)
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE);
@@ -394,6 +397,9 @@ void lcContext::SetDefaultState()
mDepthWrite = true;
glDepthMask(GL_TRUE);
glDisable(GL_CULL_FACE);
mCullFace = false;
glLineWidth(1.0f);
mLineWidth = 1.0f;
@@ -531,6 +537,38 @@ void lcContext::SetDepthWrite(bool Enable)
mDepthWrite = Enable;
}
void lcContext::SetDepthFunction(lcDepthFunction DepthFunction)
{
if (DepthFunction == mDepthFunction)
return;
switch (DepthFunction)
{
case lcDepthFunction::Always:
glDepthFunc(GL_ALWAYS);
break;
case lcDepthFunction::LessEqual:
glDepthFunc(GL_LEQUAL);
break;
}
mDepthFunction = DepthFunction;
}
void lcContext::EnableCullFace(bool Enable)
{
if (Enable == mCullFace)
return;
if (Enable)
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
mCullFace = Enable;
}
void lcContext::SetLineWidth(float LineWidth)
{
if (LineWidth == mLineWidth)
+10
View File
@@ -83,6 +83,12 @@ enum class lcPolygonOffset
Translucent
};
enum class lcDepthFunction
{
LessEqual,
Always
};
class lcContext : protected QOpenGLFunctions
{
public:
@@ -138,6 +144,8 @@ public:
void SetViewport(int x, int y, int Width, int Height);
void SetPolygonOffset(lcPolygonOffset PolygonOffset);
void SetDepthWrite(bool Enable);
void SetDepthFunction(lcDepthFunction DepthFunction);
void EnableCullFace(bool Enable);
void SetLineWidth(float LineWidth);
void SetSmoothShading(bool Smooth);
void BindTexture2D(GLuint Texture);
@@ -211,6 +219,8 @@ protected:
GLuint mTextureCubeMap;
lcPolygonOffset mPolygonOffset;
bool mDepthWrite;
lcDepthFunction mDepthFunction;
bool mCullFace;
float mLineWidth;
int mMatrixMode;
bool mTextureEnabled;
+4 -4
View File
@@ -190,8 +190,8 @@ void lcViewSphere::Draw()
const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize;
Context->SetViewport(Left, Bottom, ViewportSize, ViewportSize);
glDepthFunc(GL_ALWAYS);
glEnable(GL_CULL_FACE);
Context->SetDepthFunction(lcDepthFunction::Always);
Context->EnableCullFace(true);
Context->SetVertexBuffer(mVertexBuffer);
Context->SetVertexFormatPosition(3);
@@ -237,8 +237,8 @@ void lcViewSphere::Draw()
Context->SetHighlightParams(HighlightPosition, TextColor, BackgroundColor, HighlightColor);
Context->DrawIndexedPrimitives(GL_TRIANGLES, mSubdivisions * mSubdivisions * 6 * 6, GL_UNSIGNED_SHORT, 0);
glDisable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL);
Context->EnableCullFace(false);
Context->SetDepthFunction(lcDepthFunction::LessEqual);
Context->SetViewport(0, 0, Width, Height);
}
+2 -2
View File
@@ -613,7 +613,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
};
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
Context->EnableCullFace(true);
for (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++)
{
@@ -631,7 +631,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
Context->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
}
glDisable(GL_CULL_FACE);
Context->EnableCullFace(false);
glDisable(GL_BLEND);
}
}