diff --git a/common/lc_context.cpp b/common/lc_context.cpp index d6903178..5187d453 100644 --- a/common/lc_context.cpp +++ b/common/lc_context.cpp @@ -48,6 +48,8 @@ lcContext::lcContext() mDepthWrite = true; mDepthFunction = lcDepthFunction::LessEqual; mDepthTest = true; + mColorWrite = true; + mColorBlend = false; mCullFace = false; mLineWidth = 1.0f; #if LC_FIXED_FUNCTION @@ -387,6 +389,12 @@ void lcContext::SetDefaultState() glDepthFunc(GL_LEQUAL); mDepthFunction = lcDepthFunction::LessEqual; + mColorWrite = true; + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + mColorBlend = false; + glDisable(GL_BLEND); + if (gSupportsBlendFuncSeparate) glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE); else @@ -622,6 +630,32 @@ void lcContext::EnableDepthTest(bool 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) { if (Enable == mCullFace) diff --git a/common/lc_context.h b/common/lc_context.h index ba642e7a..bbbee278 100644 --- a/common/lc_context.h +++ b/common/lc_context.h @@ -166,6 +166,8 @@ public: void SetDepthWrite(bool Enable); void SetDepthFunction(lcDepthFunction DepthFunction); void EnableDepthTest(bool Enable); + void EnableColorWrite(bool Enable); + void EnableColorBlend(bool Enable); void EnableCullFace(bool Enable); void SetLineWidth(float LineWidth); @@ -252,6 +254,8 @@ protected: bool mDepthWrite; lcDepthFunction mDepthFunction; bool mDepthTest; + bool mColorWrite; + bool mColorBlend; bool mCullFace; float mLineWidth; int mMatrixMode; diff --git a/common/lc_scene.cpp b/common/lc_scene.cpp index 50cb1b6d..a8b5ff0a 100644 --- a/common/lc_scene.cpp +++ b/common/lc_scene.cpp @@ -324,11 +324,11 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawF if (!DrawFadePrepass) { - glEnable(GL_BLEND); + Context->EnableColorBlend(true); Context->SetDepthWrite(false); } else - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + Context->EnableColorWrite(false); Context->SetPolygonOffset(lcPolygonOffset::Translucent); @@ -409,10 +409,10 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawF if (!DrawFadePrepass) { Context->SetDepthWrite(true); - glDisable(GL_BLEND); + Context->EnableColorBlend(false); } else - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + Context->EnableColorWrite(true); } void lcScene::Draw(lcContext* Context) const diff --git a/common/lc_view.cpp b/common/lc_view.cpp index f9944b51..d60bc24a 100644 --- a/common/lc_view.cpp +++ b/common/lc_view.cpp @@ -926,11 +926,11 @@ void lcView::OnDraw() mContext->BindTexture2D(gTexFont.GetTexture()); 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()); - glDisable(GL_BLEND); + mContext->EnableColorBlend(false); mContext->EnableDepthTest(true); Redraw(); @@ -1024,11 +1024,11 @@ void lcView::DrawViewport() const mContext->SetColor(lcVector4FromColor(lcGetPreferences().mTextColor)); 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()); - glDisable(GL_BLEND); + mContext->EnableColorBlend(false); } mContext->SetDepthWrite(true); @@ -1127,7 +1127,7 @@ void lcView::DrawAxes() const mContext->SetMaterial(lcMaterialType::UnlitTextureModulate); mContext->SetViewMatrix(TranslationMatrix); mContext->BindTexture2D(gTexFont.GetTexture()); - glEnable(GL_BLEND); + mContext->EnableColorBlend(true); float TextBuffer[6 * 5 * 3]; 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->DrawPrimitives(GL_TRIANGLES, 0, 6 * 3); - glDisable(GL_BLEND); + mContext->EnableColorBlend(false); } void lcView::DrawSelectZoomRegionOverlay() @@ -1221,10 +1221,10 @@ void lcView::DrawSelectZoomRegionOverlay() if (LC_RGBA_ALPHA(Preferences.mMarqueeFillColor)) { - glEnable(GL_BLEND); + mContext->EnableColorBlend(true); mContext->SetColor(lcVector4FromColor(Preferences.mMarqueeFillColor)); mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 10, 4); - glDisable(GL_BLEND); + mContext->EnableColorBlend(false); } mContext->EnableDepthTest(true); @@ -1453,7 +1453,7 @@ void lcView::DrawGrid() { mContext->BindTexture2D(gGridTexture); mContext->SetDepthWrite(false); - glEnable(GL_BLEND); + mContext->EnableColorBlend(true); mContext->SetMaterial(lcMaterialType::UnlitTextureModulate); mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor)); @@ -1461,7 +1461,7 @@ void lcView::DrawGrid() mContext->SetVertexFormat(0, 3, 0, 2, 0, false); mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 0, 4); - glDisable(GL_BLEND); + mContext->EnableColorBlend(false); mContext->SetDepthWrite(true); BufferOffset = 4 * 5 * sizeof(float); diff --git a/common/lc_viewmanipulator.cpp b/common/lc_viewmanipulator.cpp index 8c346d7c..1dcfc90c 100644 --- a/common/lc_viewmanipulator.cpp +++ b/common/lc_viewmanipulator.cpp @@ -285,7 +285,7 @@ void lcViewManipulator::DrawSelectMove(lcTrackButton TrackButton, lcTrackTool Tr 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); @@ -296,7 +296,7 @@ void lcViewManipulator::DrawSelectMove(lcTrackButton TrackButton, lcTrackTool Tr else if (TrackTool == lcTrackTool::MoveYZ) Context->DrawIndexedPrimitives(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (108 + 360) * 2); - glDisable(GL_BLEND); + Context->EnableColorBlend(false); } if (Focus && Focus->IsPiece()) @@ -439,7 +439,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT Context->SetWorldMatrix(RotatedWorldMatrix); - glEnable(GL_BLEND); + Context->EnableColorBlend(true); lcVector3 Verts[33]; Verts[0] = lcVector3(0.0f, 0.0f, 0.0f); @@ -481,7 +481,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT if (NumVerts > 2) 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->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mView->GetWidth(), 0.0f, mView->GetHeight(), -1.0f, 1.0f)); Context->BindTexture2D(gTexFont.GetTexture()); - glEnable(GL_BLEND); + Context->EnableColorBlend(true); char buf[32]; 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); gTexFont.PrintText(Context, ScreenPos[0] - (cx / 2), ScreenPos[1] + (cy / 2), 0.0f, buf); - glDisable(GL_BLEND); + Context->EnableColorBlend(false); } Context->EnableDepthTest(true); diff --git a/common/piece.cpp b/common/piece.cpp index 6294b27d..74064ffb 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -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 }; - glEnable(GL_BLEND); + Context->EnableColorBlend(true); Context->EnableCullFace(true); for (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++) @@ -634,7 +634,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const } Context->EnableCullFace(false); - glDisable(GL_BLEND); + Context->EnableColorBlend(false); } }