diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 823665cc37..4a5d65f511 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -309,7 +309,7 @@ void OpenGl_Text::releaseVbos (OpenGl_Context* theCtx) Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.ChangeValue (anIter); Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.ChangeValue (anIter); - if (theCtx) + if (theCtx != NULL) { theCtx->DelayedRelease (aVerts); theCtx->DelayedRelease (aTCrds); @@ -317,9 +317,16 @@ void OpenGl_Text::releaseVbos (OpenGl_Context* theCtx) aVerts.Nullify(); aTCrds.Nullify(); } + if (theCtx != NULL + && !myBndVertsVbo.IsNull()) + { + theCtx->DelayedRelease (myBndVertsVbo); + } + myTextures.Clear(); myVertsVbo.Clear(); myTCrdsVbo.Clear(); + myBndVertsVbo.Nullify(); } // ======================================================================= @@ -331,11 +338,12 @@ void OpenGl_Text::Release (OpenGl_Context* theCtx) releaseVbos (theCtx); if (!myFont.IsNull()) { - Handle(OpenGl_Context) aCtx = theCtx; const TCollection_AsciiString aKey = myFont->ResourceKey(); myFont.Nullify(); - if (! aCtx.IsNull()) - aCtx->ReleaseResource (aKey, Standard_True); + if (theCtx != NULL) + { + theCtx->ReleaseResource (aKey, Standard_True); + } } } @@ -697,6 +705,50 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx, return aFont; } +// ======================================================================= +// function : drawRect +// purpose : +// ======================================================================= +void OpenGl_Text::drawRect (const Handle(OpenGl_Context)& theCtx, + const OpenGl_AspectText& theTextAspect, + const OpenGl_Vec4& theColorSubs) const +{ + Handle(OpenGl_ShaderProgram) aPrevProgram = theCtx->ActiveProgram(); + if (myBndVertsVbo.IsNull()) + { + OpenGl_Vec2 aQuad[4] = + { + OpenGl_Vec2(myBndBox.Right, myBndBox.Bottom), + OpenGl_Vec2(myBndBox.Right, myBndBox.Top), + OpenGl_Vec2(myBndBox.Left, myBndBox.Bottom), + OpenGl_Vec2(myBndBox.Left, myBndBox.Top) + }; + myBndVertsVbo = new OpenGl_VertexBuffer(); + myBndVertsVbo->Init (theCtx, 2, 4, aQuad[0].GetData()); + } + + if (theCtx->core20fwd != NULL) + { + // bind flat program + theCtx->ShaderManager()->BindFaceProgram (Handle(OpenGl_Texture)(), Standard_False, Standard_False, Standard_False, Handle(OpenGl_ShaderProgram)()); + } +#if !defined(GL_ES_VERSION_2_0) + if (theCtx->core11 != NULL + && theCtx->ActiveProgram().IsNull()) + { + glBindTexture (GL_TEXTURE_2D, 0); + } +#endif + theCtx->SetColor4fv (theColorSubs); + setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f)); + myBndVertsVbo->BindAttribute (theCtx, Graphic3d_TOA_POS); + + theCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); + + myBndVertsVbo->UnbindAttribute (theCtx, Graphic3d_TOA_POS); + theCtx->BindProgram (aPrevProgram); +} + // ======================================================================= // function : render // purpose : @@ -749,6 +801,11 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, myTCrdsVbo); aFormatter.BndBox (myBndBox); + if (!myBndVertsVbo.IsNull()) + { + myBndVertsVbo->Release (theCtx.get()); + myBndVertsVbo.Nullify(); + } } if (myTextures.IsEmpty()) @@ -872,21 +929,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, } case Aspect_TODT_SUBTITLE: { - #if !defined(GL_ES_VERSION_2_0) - if (theCtx->core11 != NULL) - { - theCtx->SetColor4fv (theColorSubs); - setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f)); - - glBindTexture (GL_TEXTURE_2D, 0); - glBegin (GL_QUADS); - glVertex2f (myBndBox.Left, myBndBox.Top); - glVertex2f (myBndBox.Right, myBndBox.Top); - glVertex2f (myBndBox.Right, myBndBox.Bottom); - glVertex2f (myBndBox.Left, myBndBox.Bottom); - glEnd(); - } - #endif + drawRect (theCtx, theTextAspect, theColorSubs); break; } case Aspect_TODT_DEKALE: @@ -929,8 +972,6 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, if (theTextAspect.Aspect()->DisplayType() == Aspect_TODT_DIMENSION) { - setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f)); - glDisable (GL_BLEND); if (!myIs2d) { @@ -950,17 +991,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, glStencilFunc (GL_ALWAYS, 1, 0xFF); glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE); - #if !defined(GL_ES_VERSION_2_0) - if (theCtx->core11 != NULL) - { - glBegin (GL_QUADS); - glVertex2f (myBndBox.Left, myBndBox.Top); - glVertex2f (myBndBox.Right, myBndBox.Top); - glVertex2f (myBndBox.Right, myBndBox.Bottom); - glVertex2f (myBndBox.Left, myBndBox.Bottom); - glEnd(); - } - #endif + drawRect (theCtx, theTextAspect, OpenGl_Vec4 (1.0f, 1.0f, 1.0f, 1.0f)); glStencilFunc (GL_ALWAYS, 0, 0xFF); diff --git a/src/OpenGl/OpenGl_Text.hxx b/src/OpenGl/OpenGl_Text.hxx index 36b6c037d1..7907fccd6b 100755 --- a/src/OpenGl/OpenGl_Text.hxx +++ b/src/OpenGl/OpenGl_Text.hxx @@ -128,6 +128,11 @@ private: void drawText (const Handle(OpenGl_Context)& theCtx, const OpenGl_AspectText& theTextAspect) const; + //! Draw rectangle from bounding text box. + void drawRect (const Handle(OpenGl_Context)& theCtx, + const OpenGl_AspectText& theTextAspect, + const OpenGl_Vec4& theColorSubs) const; + //! Main rendering code void render (const Handle(OpenGl_Context)& theCtx, const OpenGl_AspectText& theTextAspect, @@ -141,6 +146,7 @@ protected: mutable NCollection_Vector myTextures; //!< textures' IDs mutable NCollection_Vector myVertsVbo; //!< VBOs of vertices mutable NCollection_Vector myTCrdsVbo; //!< VBOs of texture coordinates + mutable Handle(OpenGl_VertexBuffer) myBndVertsVbo;//!< VBOs of vertices for bounding box mutable Font_Rect myBndBox; protected: diff --git a/tests/bugs/vis/bug28099_text_core b/tests/bugs/vis/bug28099_text_core new file mode 100644 index 0000000000..57f2172c71 --- /dev/null +++ b/tests/bugs/vis/bug28099_text_core @@ -0,0 +1,33 @@ +puts "============" +puts "OCC28099: handle DIMENSION and SUBTITLE styles within Core Profile" +puts "Test case prints overlay labels with different subtitle styles" +puts "============" +puts "" + +pload MODELING VISUALIZATION + +vclear +vcaps -core 1 +vinit View1 +vaxo +vfont add [locate_data_file DejaVuSans.ttf] SansFont + +vdrawtext t1 "Overlay Test Blend" -2d -perspos -1 1 -pos 100 -50 0 -height 16 -font SansFont -color 1 1 0 -disptype blend -subcolor 0 0 1 +vdrawtext t2 "Overlay Test Decal" -2d -perspos -1 1 -pos 100 -100 0 -height 16 -font SansFont -color 1 1 0 -disptype decal -subcolor 0 0 1 +vdrawtext t3 "Overlay Test Subtitle" -2d -perspos -1 1 -pos 100 -150 0 -height 16 -font SansFont -color 1 1 0 -disptype subtitle -subcolor 0 0 1 +vdrawtext t4 "Overlay Test Normal" -2d -perspos -1 1 -pos 100 -200 0 -height 16 -font SansFont -color 0 1 1 -disptype normal -subcolor 0 0 1 + +vdrawtext t5 " Overlay Test Normal \n Second line" -2d -perspos -1 1 -pos 100 -250 0 -height 16 -font SansFont -color 0 1 1 -disptype normal -subcolor 0 0 1 +vdrawtext t6 " Overlay Test Subtitle\n Second line" -2d -perspos -1 1 -pos 100 -300 0 -height 16 -font SansFont -color 1 1 0 -disptype subtitle -subcolor 0 0 1 +vdrawtext t7 " Overlay Test Decal \n Second line" -2d -perspos -1 1 -pos 100 -350 0 -height 16 -font SansFont -color 1 1 0 -disptype decal -subcolor 0 0 1 +vdrawtext t8 " Overlay Test Blend \n Second line" -2d -perspos -1 1 -pos 100 -400 0 -height 16 -font SansFont -color 1 1 0 -disptype blend -subcolor 0 0 1 + +box b 50 50 50 +vdisplay -dispMode 1 b + +vpoint lengthP1 0 50 50 +vpoint lengthP2 50 50 50 +vdimension dim1 -length -plane xoy -shapes lengthP1 lengthP2 -font SansFont +vfit + +vdump $::imagedir/${::casename}.png