mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Moved blend to context.
This commit is contained in:
parent
89c0b58592
commit
94a5a5dc52
6 changed files with 60 additions and 22 deletions
|
@ -48,6 +48,8 @@ lcContext::lcContext()
|
||||||
mDepthWrite = true;
|
mDepthWrite = true;
|
||||||
mDepthFunction = lcDepthFunction::LessEqual;
|
mDepthFunction = lcDepthFunction::LessEqual;
|
||||||
mDepthTest = true;
|
mDepthTest = true;
|
||||||
|
mColorWrite = true;
|
||||||
|
mColorBlend = false;
|
||||||
mCullFace = false;
|
mCullFace = false;
|
||||||
mLineWidth = 1.0f;
|
mLineWidth = 1.0f;
|
||||||
#if LC_FIXED_FUNCTION
|
#if LC_FIXED_FUNCTION
|
||||||
|
@ -387,6 +389,12 @@ void lcContext::SetDefaultState()
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
mDepthFunction = lcDepthFunction::LessEqual;
|
mDepthFunction = lcDepthFunction::LessEqual;
|
||||||
|
|
||||||
|
mColorWrite = true;
|
||||||
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
|
|
||||||
|
mColorBlend = false;
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
if (gSupportsBlendFuncSeparate)
|
if (gSupportsBlendFuncSeparate)
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE);
|
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE);
|
||||||
else
|
else
|
||||||
|
@ -622,6 +630,32 @@ void lcContext::EnableDepthTest(bool Enable)
|
||||||
mDepthTest = Enable;
|
mDepthTest = Enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcContext::EnableColorWrite(bool Enable)
|
||||||
|
{
|
||||||
|
if (Enable == mColorWrite)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Enable)
|
||||||
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
|
else
|
||||||
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||||
|
|
||||||
|
mColorWrite = Enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcContext::EnableColorBlend(bool Enable)
|
||||||
|
{
|
||||||
|
if (Enable == mColorBlend)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Enable)
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
else
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
mColorBlend = Enable;
|
||||||
|
}
|
||||||
|
|
||||||
void lcContext::EnableCullFace(bool Enable)
|
void lcContext::EnableCullFace(bool Enable)
|
||||||
{
|
{
|
||||||
if (Enable == mCullFace)
|
if (Enable == mCullFace)
|
||||||
|
|
|
@ -166,6 +166,8 @@ public:
|
||||||
void SetDepthWrite(bool Enable);
|
void SetDepthWrite(bool Enable);
|
||||||
void SetDepthFunction(lcDepthFunction DepthFunction);
|
void SetDepthFunction(lcDepthFunction DepthFunction);
|
||||||
void EnableDepthTest(bool Enable);
|
void EnableDepthTest(bool Enable);
|
||||||
|
void EnableColorWrite(bool Enable);
|
||||||
|
void EnableColorBlend(bool Enable);
|
||||||
void EnableCullFace(bool Enable);
|
void EnableCullFace(bool Enable);
|
||||||
void SetLineWidth(float LineWidth);
|
void SetLineWidth(float LineWidth);
|
||||||
|
|
||||||
|
@ -252,6 +254,8 @@ protected:
|
||||||
bool mDepthWrite;
|
bool mDepthWrite;
|
||||||
lcDepthFunction mDepthFunction;
|
lcDepthFunction mDepthFunction;
|
||||||
bool mDepthTest;
|
bool mDepthTest;
|
||||||
|
bool mColorWrite;
|
||||||
|
bool mColorBlend;
|
||||||
bool mCullFace;
|
bool mCullFace;
|
||||||
float mLineWidth;
|
float mLineWidth;
|
||||||
int mMatrixMode;
|
int mMatrixMode;
|
||||||
|
|
|
@ -324,11 +324,11 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawF
|
||||||
|
|
||||||
if (!DrawFadePrepass)
|
if (!DrawFadePrepass)
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
Context->EnableColorBlend(true);
|
||||||
Context->SetDepthWrite(false);
|
Context->SetDepthWrite(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
Context->EnableColorWrite(false);
|
||||||
|
|
||||||
Context->SetPolygonOffset(lcPolygonOffset::Translucent);
|
Context->SetPolygonOffset(lcPolygonOffset::Translucent);
|
||||||
|
|
||||||
|
@ -409,10 +409,10 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawF
|
||||||
if (!DrawFadePrepass)
|
if (!DrawFadePrepass)
|
||||||
{
|
{
|
||||||
Context->SetDepthWrite(true);
|
Context->SetDepthWrite(true);
|
||||||
glDisable(GL_BLEND);
|
Context->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
Context->EnableColorWrite(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcScene::Draw(lcContext* Context) const
|
void lcScene::Draw(lcContext* Context) const
|
||||||
|
|
|
@ -926,11 +926,11 @@ void lcView::OnDraw()
|
||||||
mContext->BindTexture2D(gTexFont.GetTexture());
|
mContext->BindTexture2D(gTexFont.GetTexture());
|
||||||
|
|
||||||
mContext->EnableDepthTest(false);
|
mContext->EnableDepthTest(false);
|
||||||
glEnable(GL_BLEND);
|
mContext->EnableColorBlend(true);
|
||||||
|
|
||||||
gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, Line.toLatin1().constData());
|
gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, Line.toLatin1().constData());
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
mContext->EnableColorBlend(false);
|
||||||
mContext->EnableDepthTest(true);
|
mContext->EnableDepthTest(true);
|
||||||
|
|
||||||
Redraw();
|
Redraw();
|
||||||
|
@ -1024,11 +1024,11 @@ void lcView::DrawViewport() const
|
||||||
mContext->SetColor(lcVector4FromColor(lcGetPreferences().mTextColor));
|
mContext->SetColor(lcVector4FromColor(lcGetPreferences().mTextColor));
|
||||||
mContext->BindTexture2D(gTexFont.GetTexture());
|
mContext->BindTexture2D(gTexFont.GetTexture());
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
mContext->EnableColorBlend(true);
|
||||||
|
|
||||||
gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, CameraName.toLatin1().constData());
|
gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, CameraName.toLatin1().constData());
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
mContext->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mContext->SetDepthWrite(true);
|
mContext->SetDepthWrite(true);
|
||||||
|
@ -1127,7 +1127,7 @@ void lcView::DrawAxes() const
|
||||||
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
||||||
mContext->SetViewMatrix(TranslationMatrix);
|
mContext->SetViewMatrix(TranslationMatrix);
|
||||||
mContext->BindTexture2D(gTexFont.GetTexture());
|
mContext->BindTexture2D(gTexFont.GetTexture());
|
||||||
glEnable(GL_BLEND);
|
mContext->EnableColorBlend(true);
|
||||||
|
|
||||||
float TextBuffer[6 * 5 * 3];
|
float TextBuffer[6 * 5 * 3];
|
||||||
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
|
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
|
||||||
|
@ -1143,7 +1143,7 @@ void lcView::DrawAxes() const
|
||||||
mContext->SetColor(lcVector4FromColor(lcGetPreferences().mAxesColor));
|
mContext->SetColor(lcVector4FromColor(lcGetPreferences().mAxesColor));
|
||||||
mContext->DrawPrimitives(GL_TRIANGLES, 0, 6 * 3);
|
mContext->DrawPrimitives(GL_TRIANGLES, 0, 6 * 3);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
mContext->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcView::DrawSelectZoomRegionOverlay()
|
void lcView::DrawSelectZoomRegionOverlay()
|
||||||
|
@ -1221,10 +1221,10 @@ void lcView::DrawSelectZoomRegionOverlay()
|
||||||
|
|
||||||
if (LC_RGBA_ALPHA(Preferences.mMarqueeFillColor))
|
if (LC_RGBA_ALPHA(Preferences.mMarqueeFillColor))
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
mContext->EnableColorBlend(true);
|
||||||
mContext->SetColor(lcVector4FromColor(Preferences.mMarqueeFillColor));
|
mContext->SetColor(lcVector4FromColor(Preferences.mMarqueeFillColor));
|
||||||
mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 10, 4);
|
mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 10, 4);
|
||||||
glDisable(GL_BLEND);
|
mContext->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mContext->EnableDepthTest(true);
|
mContext->EnableDepthTest(true);
|
||||||
|
@ -1453,7 +1453,7 @@ void lcView::DrawGrid()
|
||||||
{
|
{
|
||||||
mContext->BindTexture2D(gGridTexture);
|
mContext->BindTexture2D(gGridTexture);
|
||||||
mContext->SetDepthWrite(false);
|
mContext->SetDepthWrite(false);
|
||||||
glEnable(GL_BLEND);
|
mContext->EnableColorBlend(true);
|
||||||
|
|
||||||
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
||||||
mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor));
|
mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor));
|
||||||
|
@ -1461,7 +1461,7 @@ void lcView::DrawGrid()
|
||||||
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
|
mContext->SetVertexFormat(0, 3, 0, 2, 0, false);
|
||||||
mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 0, 4);
|
mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
mContext->EnableColorBlend(false);
|
||||||
mContext->SetDepthWrite(true);
|
mContext->SetDepthWrite(true);
|
||||||
|
|
||||||
BufferOffset = 4 * 5 * sizeof(float);
|
BufferOffset = 4 * 5 * sizeof(float);
|
||||||
|
|
|
@ -285,7 +285,7 @@ void lcViewManipulator::DrawSelectMove(lcTrackButton TrackButton, lcTrackTool Tr
|
||||||
|
|
||||||
if ((TrackTool == lcTrackTool::MoveXY) || (TrackTool == lcTrackTool::MoveXZ) || (TrackTool == lcTrackTool::MoveYZ))
|
if ((TrackTool == lcTrackTool::MoveXY) || (TrackTool == lcTrackTool::MoveXZ) || (TrackTool == lcTrackTool::MoveYZ))
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
Context->EnableColorBlend(true);
|
||||||
|
|
||||||
Context->SetColor(0.8f, 0.8f, 0.0f, 0.3f);
|
Context->SetColor(0.8f, 0.8f, 0.0f, 0.3f);
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ void lcViewManipulator::DrawSelectMove(lcTrackButton TrackButton, lcTrackTool Tr
|
||||||
else if (TrackTool == lcTrackTool::MoveYZ)
|
else if (TrackTool == lcTrackTool::MoveYZ)
|
||||||
Context->DrawIndexedPrimitives(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (108 + 360) * 2);
|
Context->DrawIndexedPrimitives(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (108 + 360) * 2);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
Context->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Focus && Focus->IsPiece())
|
if (Focus && Focus->IsPiece())
|
||||||
|
@ -439,7 +439,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT
|
||||||
|
|
||||||
Context->SetWorldMatrix(RotatedWorldMatrix);
|
Context->SetWorldMatrix(RotatedWorldMatrix);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
Context->EnableColorBlend(true);
|
||||||
|
|
||||||
lcVector3 Verts[33];
|
lcVector3 Verts[33];
|
||||||
Verts[0] = lcVector3(0.0f, 0.0f, 0.0f);
|
Verts[0] = lcVector3(0.0f, 0.0f, 0.0f);
|
||||||
|
@ -481,7 +481,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT
|
||||||
if (NumVerts > 2)
|
if (NumVerts > 2)
|
||||||
Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, NumVerts);
|
Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, NumVerts);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
Context->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,7 +650,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT
|
||||||
Context->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
|
Context->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
|
||||||
Context->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mView->GetWidth(), 0.0f, mView->GetHeight(), -1.0f, 1.0f));
|
Context->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mView->GetWidth(), 0.0f, mView->GetHeight(), -1.0f, 1.0f));
|
||||||
Context->BindTexture2D(gTexFont.GetTexture());
|
Context->BindTexture2D(gTexFont.GetTexture());
|
||||||
glEnable(GL_BLEND);
|
Context->EnableColorBlend(true);
|
||||||
|
|
||||||
char buf[32];
|
char buf[32];
|
||||||
sprintf(buf, "[%.2f]", fabsf(Angle));
|
sprintf(buf, "[%.2f]", fabsf(Angle));
|
||||||
|
@ -661,7 +661,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT
|
||||||
Context->SetColor(0.8f, 0.8f, 0.0f, 1.0f);
|
Context->SetColor(0.8f, 0.8f, 0.0f, 1.0f);
|
||||||
gTexFont.PrintText(Context, ScreenPos[0] - (cx / 2), ScreenPos[1] + (cy / 2), 0.0f, buf);
|
gTexFont.PrintText(Context, ScreenPos[0] - (cx / 2), ScreenPos[1] + (cy / 2), 0.0f, buf);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
Context->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Context->EnableDepthTest(true);
|
Context->EnableDepthTest(true);
|
||||||
|
|
|
@ -614,7 +614,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
|
||||||
7, 3, 2, 6, 7, 2, 0, 3, 7, 0, 7, 4, 6, 2, 1, 5, 6, 1
|
7, 3, 2, 6, 7, 2, 0, 3, 7, 0, 7, 4, 6, 2, 1, 5, 6, 1
|
||||||
};
|
};
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
Context->EnableColorBlend(true);
|
||||||
Context->EnableCullFace(true);
|
Context->EnableCullFace(true);
|
||||||
|
|
||||||
for (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++)
|
for (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++)
|
||||||
|
@ -634,7 +634,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
|
||||||
}
|
}
|
||||||
|
|
||||||
Context->EnableCullFace(false);
|
Context->EnableCullFace(false);
|
||||||
glDisable(GL_BLEND);
|
Context->EnableColorBlend(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue