1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_AspectText.hxx>
17 #include <OpenGl_GlCore11.hxx>
18 #include <OpenGl_GraphicDriver.hxx>
19 #include <OpenGl_ShaderManager.hxx>
20 #include <OpenGl_ShaderProgram.hxx>
21 #include <OpenGl_ShaderStates.hxx>
22 #include <OpenGl_Text.hxx>
23 #include <OpenGl_Workspace.hxx>
24 #include <OpenGl_View.hxx>
25 #include <OpenGl_VertexBufferCompat.hxx>
27 #include <Font_FontMgr.hxx>
28 #include <Font_FTFont.hxx>
29 #include <Graphic3d_TransformUtils.hxx>
30 #include <TCollection_HAsciiString.hxx>
34 static const GLdouble THE_IDENTITY_MATRIX[16] =
42 //! Auxiliary tool for setting polygon offset temporarily.
43 struct BackPolygonOffsetSentry
45 BackPolygonOffsetSentry (const Handle(OpenGl_Context)& theCtx)
47 myOffsetBack (!theCtx.IsNull() ? theCtx->PolygonOffset() : Graphic3d_PolygonOffset())
51 Graphic3d_PolygonOffset aPolyOffset = myOffsetBack;
52 aPolyOffset.Mode = Aspect_POM_Fill;
53 aPolyOffset.Units += 1.0f;
54 theCtx->SetPolygonOffset (aPolyOffset);
58 ~BackPolygonOffsetSentry()
62 myCtx->SetPolygonOffset (myOffsetBack);
67 BackPolygonOffsetSentry (const BackPolygonOffsetSentry& );
68 BackPolygonOffsetSentry& operator= (const BackPolygonOffsetSentry& );
70 const Handle(OpenGl_Context)& myCtx;
71 const Graphic3d_PolygonOffset myOffsetBack;
74 } // anonymous namespace
76 // =======================================================================
77 // function : OpenGl_Text
79 // =======================================================================
80 OpenGl_Text::OpenGl_Text()
85 myPoint (0.0f, 0.0f, 0.0f),
88 myHasAnchorPoint (true)
91 myParams.HAlign = Graphic3d_HTA_LEFT;
92 myParams.VAlign = Graphic3d_VTA_BOTTOM;
95 // =======================================================================
96 // function : OpenGl_Text
98 // =======================================================================
99 OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText,
100 const OpenGl_Vec3& thePoint,
101 const OpenGl_TextParam& theParams)
105 myScaleHeight (1.0f),
106 myExportHeight (1.0f),
107 myParams (theParams),
112 myHasAnchorPoint (true)
117 // =======================================================================
118 // function : OpenGl_Text
120 // =======================================================================
121 OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText,
122 const gp_Ax2& theOrientation,
123 const OpenGl_TextParam& theParams,
124 const bool theHasOwnAnchor)
129 myExportHeight (1.0),
130 myParams (theParams),
133 myOrientation (theOrientation),
135 myHasAnchorPoint (theHasOwnAnchor)
137 const gp_Pnt& aPoint = theOrientation.Location();
138 myPoint = OpenGl_Vec3 (static_cast<Standard_ShortReal> (aPoint.X()),
139 static_cast<Standard_ShortReal> (aPoint.Y()),
140 static_cast<Standard_ShortReal> (aPoint.Z()));
143 // =======================================================================
144 // function : SetPosition
146 // =======================================================================
147 void OpenGl_Text::SetPosition (const OpenGl_Vec3& thePoint)
152 // =======================================================================
153 // function : SetFontSize
155 // =======================================================================
156 void OpenGl_Text::SetFontSize (const Handle(OpenGl_Context)& theCtx,
157 const Standard_Integer theFontSize)
159 if (myParams.Height != theFontSize)
161 Release (theCtx.operator->());
163 myParams.Height = theFontSize;
166 // =======================================================================
169 // =======================================================================
170 void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx,
171 const Standard_Utf8Char* theText,
172 const OpenGl_Vec3& thePoint)
174 releaseVbos (theCtx.operator->());
177 myString.FromUnicode (theText);
180 // =======================================================================
183 // =======================================================================
184 void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx,
185 const Standard_Utf8Char* theText,
186 const OpenGl_Vec3& thePoint,
187 const OpenGl_TextParam& theParams)
189 if (myParams.Height != theParams.Height)
191 Release (theCtx.operator->());
195 releaseVbos (theCtx.operator->());
198 myParams = theParams;
200 myString.FromUnicode (theText);
203 // =======================================================================
206 // =======================================================================
207 void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx,
208 const TCollection_ExtendedString& theText,
209 const OpenGl_Vec2& thePoint,
210 const OpenGl_TextParam& theParams)
212 if (myParams.Height != theParams.Height)
214 Release (theCtx.operator->());
218 releaseVbos (theCtx.operator->());
221 myParams = theParams;
222 myPoint.SetValues (thePoint, 0.0f);
223 myString.FromUnicode (theText.ToExtString());
226 // =======================================================================
227 // function : ~OpenGl_Text
229 // =======================================================================
230 OpenGl_Text::~OpenGl_Text()
235 // =======================================================================
236 // function : releaseVbos
238 // =======================================================================
239 void OpenGl_Text::releaseVbos (OpenGl_Context* theCtx)
241 for (Standard_Integer anIter = 0; anIter < myVertsVbo.Length(); ++anIter)
243 Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.ChangeValue (anIter);
244 Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.ChangeValue (anIter);
248 theCtx->DelayedRelease (aVerts);
249 theCtx->DelayedRelease (aTCrds);
255 && !myBndVertsVbo.IsNull())
257 theCtx->DelayedRelease (myBndVertsVbo);
263 myBndVertsVbo.Nullify();
266 // =======================================================================
267 // function : Release
269 // =======================================================================
270 void OpenGl_Text::Release (OpenGl_Context* theCtx)
272 releaseVbos (theCtx);
273 if (!myFont.IsNull())
275 const TCollection_AsciiString aKey = myFont->ResourceKey();
279 theCtx->ReleaseResource (aKey, Standard_True);
284 // =======================================================================
285 // function : StringSize
287 // =======================================================================
288 void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx,
289 const NCollection_String& theText,
290 const OpenGl_AspectText& theTextAspect,
291 const OpenGl_TextParam& theParams,
292 const unsigned int theResolution,
293 Standard_ShortReal& theWidth,
294 Standard_ShortReal& theAscent,
295 Standard_ShortReal& theDescent)
300 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, theParams.Height, theResolution);
301 Handle(OpenGl_Font) aFont = FindFont (theCtx, theTextAspect, theParams.Height, theResolution, aFontKey);
302 if (aFont.IsNull() || !aFont->IsValid())
307 theAscent = aFont->Ascender();
308 theDescent = aFont->Descender();
310 GLfloat aWidth = 0.0f;
311 for (NCollection_Utf8Iter anIter = theText.Iterator(); *anIter != 0;)
313 const Standard_Utf32Char aCharThis = *anIter;
314 const Standard_Utf32Char aCharNext = *++anIter;
316 if (aCharThis == '\x0D' // CR (carriage return)
317 || aCharThis == '\a' // BEL (alarm)
318 || aCharThis == '\f' // FF (form feed) NP (new page)
319 || aCharThis == '\b' // BS (backspace)
320 || aCharThis == '\v') // VT (vertical tab)
322 continue; // skip unsupported carriage control codes
324 else if (aCharThis == '\x0A') // LF (line feed, new line)
326 theWidth = Max (theWidth, aWidth);
330 else if (aCharThis == ' ')
332 aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
335 else if (aCharThis == '\t')
337 aWidth += aFont->FTFont()->AdvanceX (' ', aCharNext) * 8.0f;
341 aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
343 theWidth = Max (theWidth, aWidth);
345 Handle(OpenGl_Context) aCtx = theCtx;
347 aCtx->ReleaseResource (aFontKey, Standard_True);
350 // =======================================================================
353 // =======================================================================
354 void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
356 theWorkspace->SetAspectFace (&theWorkspace->FontFaceAspect());
357 theWorkspace->ApplyAspectFace();
358 const OpenGl_AspectText* aTextAspect = theWorkspace->ApplyAspectText();
359 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
360 const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
362 // Bind custom shader program or generate default version
363 aCtx->ShaderManager()->BindFontProgram (aTextAspect->ShaderProgramRes (aCtx));
365 myOrientationMatrix = theWorkspace->View()->Camera()->OrientationMatrix();
366 myProjMatrix.Convert (aCtx->ProjectionState.Current());
368 // use highlight color or colors from aspect
371 theWorkspace->TextColor(),
372 theWorkspace->TextSubtitleColor(),
376 if (!aPrevTexture.IsNull())
378 aCtx->BindTextures (aPrevTexture);
381 // restore Z buffer settings
382 if (theWorkspace->UseZBuffer())
384 glEnable (GL_DEPTH_TEST);
388 // =======================================================================
391 // =======================================================================
392 void OpenGl_Text::Render (const Handle(OpenGl_Context)& theCtx,
393 const OpenGl_AspectText& theTextAspect,
394 const unsigned int theResolution) const
396 render (theCtx, theTextAspect,
397 theTextAspect.Aspect()->ColorRGBA(),
398 theTextAspect.Aspect()->ColorSubTitleRGBA(),
402 // =======================================================================
403 // function : setupMatrix
405 // =======================================================================
406 void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
407 const OpenGl_AspectText& theTextAspect,
408 const OpenGl_Vec3 theDVec) const
410 OpenGl_Mat4d aModViewMat;
411 OpenGl_Mat4d aProjectMat;
412 if (myHasPlane && myHasAnchorPoint)
414 aProjectMat = myProjMatrix * myOrientationMatrix;
418 aProjectMat = myProjMatrix;
423 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.f);
424 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, 1.f, -1.f, 1.f);
425 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->GetTextAngle(), 0.f, 0.f, 1.f);
429 // align coordinates to the nearest integer
430 // to avoid extra interpolation issues
431 GLdouble anObjX, anObjY, anObjZ;
432 Graphic3d_TransformUtils::UnProject<Standard_Real> (std::floor (myWinX + theDVec.x()),
433 std::floor (myWinY + theDVec.y()),
434 myWinZ + theDVec.z(),
435 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
436 OpenGl_Mat4d::Map (aProjectMat),
444 const gp_Dir& aVectorDir = myOrientation.XDirection();
445 const gp_Dir& aVectorUp = myOrientation.Direction();
446 const gp_Dir& aVectorRight = myOrientation.YDirection();
448 aModViewMat.SetColumn (2, OpenGl_Vec3d (aVectorUp.X(), aVectorUp.Y(), aVectorUp.Z()));
449 aModViewMat.SetColumn (1, OpenGl_Vec3d (aVectorRight.X(), aVectorRight.Y(), aVectorRight.Z()));
450 aModViewMat.SetColumn (0, OpenGl_Vec3d (aVectorDir.X(), aVectorDir.Y(), aVectorDir.Z()));
452 if (!myHasAnchorPoint)
454 OpenGl_Mat4d aPosMat;
455 aPosMat.SetColumn (3, OpenGl_Vec3d (myPoint.x(), myPoint.y(), myPoint.z()));
456 aPosMat *= aModViewMat;
457 aModViewMat.SetColumn (3, aPosMat.GetColumn (3));
461 aModViewMat.SetColumn (3, OpenGl_Vec3d (anObjX, anObjY, anObjZ));
466 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
467 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->GetTextAngle(), 0.0, 0.0, 1.0);
470 if (!theTextAspect.Aspect()->GetTextZoomable())
472 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
474 else if (theCtx->HasRenderScale())
476 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, theCtx->RenderScaleInv(), theCtx->RenderScaleInv(), theCtx->RenderScaleInv());
480 if (myHasPlane && !myHasAnchorPoint)
482 OpenGl_Mat4d aCurrentWorldViewMat;
483 aCurrentWorldViewMat.Convert (theCtx->WorldViewState.Current());
484 theCtx->WorldViewState.SetCurrent<Standard_Real> (aCurrentWorldViewMat * aModViewMat);
488 theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
490 theCtx->ApplyWorldViewMatrix();
494 theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjectMat);
495 theCtx->ApplyProjectionMatrix();
498 // Upload updated state to shader program
499 theCtx->ShaderManager()->PushState (theCtx->ActiveProgram());
502 // =======================================================================
503 // function : drawText
505 // =======================================================================
506 void OpenGl_Text::drawText (const Handle(OpenGl_Context)& theCtx,
507 const OpenGl_AspectText& theTextAspect) const
509 (void )theTextAspect;
510 if (myVertsVbo.Length() != myTextures.Length()
511 || myTextures.IsEmpty())
516 for (Standard_Integer anIter = 0; anIter < myTextures.Length(); ++anIter)
518 const GLuint aTexId = myTextures.Value (anIter);
519 glBindTexture (GL_TEXTURE_2D, aTexId);
521 const Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.Value (anIter);
522 const Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.Value (anIter);
523 aVerts->BindAttribute (theCtx, Graphic3d_TOA_POS);
524 aTCrds->BindAttribute (theCtx, Graphic3d_TOA_UV);
526 glDrawArrays (GL_TRIANGLES, 0, GLsizei(aVerts->GetElemsNb()));
528 aTCrds->UnbindAttribute (theCtx, Graphic3d_TOA_UV);
529 aVerts->UnbindAttribute (theCtx, Graphic3d_TOA_POS);
531 glBindTexture (GL_TEXTURE_2D, 0);
534 // =======================================================================
535 // function : FontKey
537 // =======================================================================
538 TCollection_AsciiString OpenGl_Text::FontKey (const OpenGl_AspectText& theAspect,
539 const Standard_Integer theHeight,
540 const unsigned int theResolution)
542 const Font_FontAspect anAspect = theAspect.Aspect()->GetTextFontAspect() != Font_FA_Undefined
543 ? theAspect.Aspect()->GetTextFontAspect()
545 return theAspect.Aspect()->Font()
546 + TCollection_AsciiString(":") + Standard_Integer(anAspect)
547 + TCollection_AsciiString(":") + Standard_Integer(theResolution)
548 + TCollection_AsciiString(":") + theHeight;
551 // =======================================================================
552 // function : FindFont
554 // =======================================================================
555 Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
556 const OpenGl_AspectText& theAspect,
557 const Standard_Integer theHeight,
558 const unsigned int theResolution,
559 const TCollection_AsciiString theKey)
561 Handle(OpenGl_Font) aFont;
564 return aFont; // invalid parameters
567 if (!theCtx->GetResource (theKey, aFont))
569 Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
570 const TCollection_AsciiString& aFontName = theAspect.Aspect()->Font();
571 Font_FontAspect anAspect = theAspect.Aspect()->GetTextFontAspect() != Font_FA_Undefined
572 ? theAspect.Aspect()->GetTextFontAspect()
574 Handle(Font_FTFont) aFontFt;
575 if (Handle(Font_SystemFont) aRequestedFont = aFontMgr->FindFont (aFontName, anAspect))
577 aFontFt = new Font_FTFont (Handle(Font_FTLibrary)());
579 if (aFontFt->Init (aRequestedFont->FontPathAny (anAspect).ToCString(), theHeight, theResolution))
581 aFont = new OpenGl_Font (aFontFt, theKey);
582 if (!aFont->Init (theCtx))
584 TCollection_ExtendedString aMsg;
586 aMsg += theAspect.Aspect()->Font();
587 aMsg += "' - initialization of GL resources has failed!";
588 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
590 aFont->Release (theCtx.operator->());
591 aFont = new OpenGl_Font (aFontFt, theKey);
596 TCollection_ExtendedString aMsg;
598 aMsg += theAspect.Aspect()->Font();
599 aMsg += "' is broken or has incompatible format! File path: ";
600 aMsg += aRequestedFont->FontPathAny (anAspect);
601 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
603 aFont = new OpenGl_Font (aFontFt, theKey);
608 TCollection_ExtendedString aMsg;
610 aMsg += theAspect.Aspect()->Font();
611 aMsg += "' is not found in the system!";
612 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
613 aFont = new OpenGl_Font (aFontFt, theKey);
616 theCtx->ShareResource (theKey, aFont);
621 // =======================================================================
622 // function : drawRect
624 // =======================================================================
625 void OpenGl_Text::drawRect (const Handle(OpenGl_Context)& theCtx,
626 const OpenGl_AspectText& theTextAspect,
627 const OpenGl_Vec4& theColorSubs) const
629 Handle(OpenGl_ShaderProgram) aPrevProgram = theCtx->ActiveProgram();
630 if (myBndVertsVbo.IsNull())
632 OpenGl_Vec2 aQuad[4] =
634 OpenGl_Vec2(myBndBox.Right, myBndBox.Bottom),
635 OpenGl_Vec2(myBndBox.Right, myBndBox.Top),
636 OpenGl_Vec2(myBndBox.Left, myBndBox.Bottom),
637 OpenGl_Vec2(myBndBox.Left, myBndBox.Top)
639 if (theCtx->ToUseVbo())
641 myBndVertsVbo = new OpenGl_VertexBuffer();
645 myBndVertsVbo = new OpenGl_VertexBufferCompat();
647 myBndVertsVbo->Init (theCtx, 2, 4, aQuad[0].GetData());
650 // bind unlit program
651 theCtx->ShaderManager()->BindFaceProgram (Handle(OpenGl_TextureSet)(), Graphic3d_TOSM_UNLIT,
652 Graphic3d_AlphaMode_Opaque, Standard_False, Standard_False,
653 Handle(OpenGl_ShaderProgram)());
655 #if !defined(GL_ES_VERSION_2_0)
656 if (theCtx->core11 != NULL
657 && theCtx->ActiveProgram().IsNull())
659 glBindTexture (GL_TEXTURE_2D, 0);
662 theCtx->SetColor4fv (theColorSubs);
663 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
664 myBndVertsVbo->BindAttribute (theCtx, Graphic3d_TOA_POS);
666 theCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
668 myBndVertsVbo->UnbindAttribute (theCtx, Graphic3d_TOA_POS);
669 theCtx->BindProgram (aPrevProgram);
672 // =======================================================================
675 // =======================================================================
676 void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
677 const OpenGl_AspectText& theTextAspect,
678 const OpenGl_Vec4& theColorText,
679 const OpenGl_Vec4& theColorSubs,
680 const unsigned int theResolution) const
682 if (myString.IsEmpty())
687 // Note that using difference resolution in different Views in same Viewer
688 // will lead to performance regression (for example, text will be recreated every time).
689 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, myParams.Height, theResolution);
691 && !myFont->ResourceKey().IsEqual (aFontKey))
694 const_cast<OpenGl_Text* > (this)->Release (theCtx.operator->());
699 myFont = FindFont (theCtx, theTextAspect, myParams.Height, theResolution, aFontKey);
701 if (!myFont->WasInitialized())
706 if (myTextures.IsEmpty())
708 Font_TextFormatter aFormatter;
709 aFormatter.SetupAlignment (myParams.HAlign, myParams.VAlign);
712 aFormatter.Append (myString, *myFont->FTFont().operator->());
715 OpenGl_TextBuilder aBuilder;
716 aBuilder.Perform (aFormatter,
718 *myFont.operator->(),
723 aFormatter.BndBox (myBndBox);
724 if (!myBndVertsVbo.IsNull())
726 myBndVertsVbo->Release (theCtx.get());
727 myBndVertsVbo.Nullify();
731 if (myTextures.IsEmpty())
736 myExportHeight = 1.0f;
737 myScaleHeight = 1.0f;
739 theCtx->WorldViewState.Push();
740 myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current());
742 const GLdouble aPointSize = (GLdouble )myFont->FTFont()->PointSize();
745 Graphic3d_TransformUtils::Project<Standard_Real> (myPoint.x(), myPoint.y(), myPoint.z(),
746 myModelMatrix, myProjMatrix, theCtx->Viewport(),
747 myWinX, myWinY, myWinZ);
749 // compute scale factor for constant text height
750 if (theTextAspect.Aspect()->GetTextZoomable())
752 myExportHeight = aPointSize;
756 Graphic3d_Vec3d aPnt1, aPnt2;
757 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, myWinY, myWinZ,
758 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), myProjMatrix, theCtx->Viewport(),
759 aPnt1.x(), aPnt1.y(), aPnt1.z());
760 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, myWinY + aPointSize, myWinZ,
761 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), myProjMatrix, theCtx->Viewport(),
762 aPnt2.x(), aPnt2.y(), aPnt2.z());
763 myScaleHeight = (aPnt2.y() - aPnt1.y()) / aPointSize;
766 myExportHeight = aPointSize / myExportHeight;
768 #if !defined(GL_ES_VERSION_2_0)
769 if (theCtx->core11 != NULL
770 && theCtx->caps->ffpEnable)
772 glDisable (GL_LIGHTING);
775 const Standard_Integer aPrevPolygonMode = theCtx->SetPolygonMode (GL_FILL);
776 const bool aPrevHatchingMode = theCtx->SetPolygonHatchEnabled (false);
780 const bool hasDepthTest = !myIs2d
781 && theTextAspect.Aspect()->Style() != Aspect_TOST_ANNOTATION;
784 glDisable (GL_DEPTH_TEST);
787 if (theCtx->core15fwd != NULL)
789 theCtx->core15fwd->glActiveTexture (GL_TEXTURE0);
791 #if !defined(GL_ES_VERSION_2_0)
792 // activate texture unit
793 GLint aTexEnvParam = GL_REPLACE;
794 if (theCtx->core11 != NULL)
796 glDisable (GL_TEXTURE_1D);
797 glEnable (GL_TEXTURE_2D);
798 glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam);
799 if (aTexEnvParam != GL_REPLACE)
801 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
808 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
809 const bool anAlphaToCoverageOld = theCtx->SetSampleAlphaToCoverage (false);
812 switch (theTextAspect.Aspect()->DisplayType())
814 case Aspect_TODT_BLEND:
816 #if !defined(GL_ES_VERSION_2_0)
817 glEnable (GL_COLOR_LOGIC_OP);
822 case Aspect_TODT_SUBTITLE:
824 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
825 drawRect (theCtx, theTextAspect, theColorSubs);
828 case Aspect_TODT_DEKALE:
830 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
831 theCtx->SetColor4fv (theColorSubs);
832 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.0f));
833 drawText (theCtx, theTextAspect);
834 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.0f));
835 drawText (theCtx, theTextAspect);
836 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.0f));
837 drawText (theCtx, theTextAspect);
838 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
839 drawText (theCtx, theTextAspect);
842 case Aspect_TODT_SHADOW:
844 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
845 theCtx->SetColor4fv (theColorSubs);
846 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
847 drawText (theCtx, theTextAspect);
850 case Aspect_TODT_DIMENSION:
851 case Aspect_TODT_NORMAL:
858 theCtx->SetColor4fv (theColorText);
859 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
860 drawText (theCtx, theTextAspect);
864 theCtx->ProjectionState.SetCurrent<Standard_Real> (myProjMatrix);
865 theCtx->ApplyProjectionMatrix();
868 #if !defined(GL_ES_VERSION_2_0)
869 if (theCtx->core11 != NULL)
871 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam);
875 if (theTextAspect.Aspect()->DisplayType() == Aspect_TODT_DIMENSION)
877 glDisable (GL_BLEND);
880 glDisable (GL_DEPTH_TEST);
882 #if !defined(GL_ES_VERSION_2_0)
883 if (theCtx->core11 != NULL)
885 glDisable (GL_TEXTURE_2D);
888 const bool aColorMaskBack = theCtx->SetColorMask (false);
890 glClear (GL_STENCIL_BUFFER_BIT);
891 glEnable (GL_STENCIL_TEST);
892 glStencilFunc (GL_ALWAYS, 1, 0xFF);
893 glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE);
895 drawRect (theCtx, theTextAspect, OpenGl_Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
897 glStencilFunc (GL_ALWAYS, 0, 0xFF);
899 theCtx->SetColorMask (aColorMaskBack);
902 // reset OpenGL state
903 glDisable (GL_BLEND);
904 glDisable (GL_STENCIL_TEST);
905 #if !defined(GL_ES_VERSION_2_0)
906 glDisable (GL_COLOR_LOGIC_OP);
908 theCtx->SetPolygonMode (aPrevPolygonMode);
909 theCtx->SetPolygonHatchEnabled (aPrevHatchingMode);
911 theCtx->SetSampleAlphaToCoverage (anAlphaToCoverageOld);
913 // model view matrix was modified
914 theCtx->WorldViewState.Pop();
915 theCtx->ApplyModelViewMatrix();