diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index 890d85b7d0..14fc5923d7 100644 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -998,21 +998,24 @@ void OpenGl_ShaderManager::PushState (const Handle(OpenGl_ShaderProgram)& thePro Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFont() { Handle(Graphic3d_ShaderProgram) aProgramSrc = new Graphic3d_ShaderProgram(); - TCollection_AsciiString aSrcVert = - EOL"void main()" - EOL"{" - EOL" gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;" - EOL"}"; + TCollection_AsciiString aSrcVert = TCollection_AsciiString() + + THE_VARY_TexCoord + + EOL"void main()" + EOL"{" + EOL" TexCoord = occTexCoord.st;" + EOL" gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;" + EOL"}"; - TCollection_AsciiString aSrcFrag = - EOL"float getAlpha(void) { return texture2D(occActiveSampler, gl_PointCoord).a; }" - EOL"void main()" - EOL"{" - EOL" vec4 aColor = occColor;" - EOL" aColor.a *= getAlpha();" - EOL" if (aColor.a <= 0.285) discard;" - EOL" gl_FragColor = aColor;" - EOL"}"; + TCollection_AsciiString aSrcFrag = TCollection_AsciiString() + + + THE_VARY_TexCoord + + EOL"float getAlpha(void) { return texture2D(occActiveSampler, TexCoord.st).a; }" + EOL"void main()" + EOL"{" + EOL" vec4 aColor = occColor;" + EOL" aColor.a *= getAlpha();" + EOL" if (aColor.a <= 0.285) discard;" + EOL" gl_FragColor = aColor;" + EOL"}"; aProgramSrc->AttachShader (Graphic3d_ShaderObject::CreateFromSource (Graphic3d_TOS_VERTEX, aSrcVert)); aProgramSrc->AttachShader (Graphic3d_ShaderObject::CreateFromSource (Graphic3d_TOS_FRAGMENT, aSrcFrag)); diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index da89880e4c..f530593e3c 100755 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -382,21 +382,11 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); + // Bind custom shader program or generate default version if (aCtx->IsGlGreaterEqual (2, 0)) { - const Handle(OpenGl_ShaderProgram)& aProgram = aTextAspect->ShaderProgramRes (aCtx); - aCtx->BindProgram (aProgram); - if (!aProgram.IsNull()) - { - aProgram->ApplyVariables (aCtx); - - const OpenGl_MaterialState* aMaterialState = aCtx->ShaderManager()->MaterialState (aProgram); - - if (aMaterialState == NULL || aMaterialState->Aspect() != aTextAspect) - aCtx->ShaderManager()->UpdateMaterialStateTo (aProgram, aTextAspect); - - aCtx->ShaderManager()->PushState (aProgram); - } + aCtx->ShaderManager()->BindProgram ( + aTextAspect, aTextAspect->ShaderProgramRes (aCtx)); } // use highlight color or colors from aspect @@ -444,9 +434,6 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, const OpenGl_AspectText& theTextAspect, const OpenGl_Vec3 theDVec) const { - // setup matrix -#if !defined(GL_ES_VERSION_2_0) - OpenGl_Mat4d aModViewMat; if (myIs2d) @@ -495,7 +482,12 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, theCtx->WorldViewState.SetCurrent (aModViewMat); theCtx->ApplyWorldViewMatrix(); -#endif + + if (!theCtx->ActiveProgram().IsNull()) + { + // Upload updated state to shader program + theCtx->ShaderManager()->PushState (theCtx->ActiveProgram()); + } } // ======================================================================= @@ -538,7 +530,7 @@ void OpenGl_Text::drawText (const Handle(OpenGl_PrinterContext)& , glDrawArrays (GL_TRIANGLES, 0, GLsizei(aVerts->GetElemsNb())); - aVerts->UnbindAttribute (theCtx, Graphic3d_TOA_UV); + aTCrds->UnbindAttribute (theCtx, Graphic3d_TOA_UV); aVerts->UnbindAttribute (theCtx, Graphic3d_TOA_POS); } glBindTexture (GL_TEXTURE_2D, 0); @@ -662,7 +654,6 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, theCtx->WorldViewState.Push(); -#if !defined(GL_ES_VERSION_2_0) myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current()); if (!myIs2d) @@ -712,6 +703,8 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, } myExportHeight = (float )myFont->FTFont()->PointSize() / myExportHeight; +#if !defined(GL_ES_VERSION_2_0) + // push enabled flags to the stack glPushAttrib (GL_ENABLE_BIT); glDisable (GL_LIGHTING); @@ -774,7 +767,7 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, } case Aspect_TODT_DEKALE: { - theCtx->core11->glColor3fv (theColorSubs.rgb); + theCtx->SetColor4fv (*(const OpenGl_Vec4* )theColorSubs.rgb); setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.00001f)); drawText (thePrintCtx, theCtx, theTextAspect); setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.00001f)); @@ -793,7 +786,7 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, } // main draw call - theCtx->core11->glColor3fv (theColorText.rgb); + theCtx->SetColor4fv (*(const OpenGl_Vec4* )theColorText.rgb); setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f)); drawText (thePrintCtx, theCtx, theTextAspect);