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.xy() = thePoint;
224 myString.FromUnicode (theText.ToExtString());
227 // =======================================================================
228 // function : ~OpenGl_Text
230 // =======================================================================
231 OpenGl_Text::~OpenGl_Text()
236 // =======================================================================
237 // function : releaseVbos
239 // =======================================================================
240 void OpenGl_Text::releaseVbos (OpenGl_Context* theCtx)
242 for (Standard_Integer anIter = 0; anIter < myVertsVbo.Length(); ++anIter)
244 Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.ChangeValue (anIter);
245 Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.ChangeValue (anIter);
249 theCtx->DelayedRelease (aVerts);
250 theCtx->DelayedRelease (aTCrds);
256 && !myBndVertsVbo.IsNull())
258 theCtx->DelayedRelease (myBndVertsVbo);
264 myBndVertsVbo.Nullify();
267 // =======================================================================
268 // function : Release
270 // =======================================================================
271 void OpenGl_Text::Release (OpenGl_Context* theCtx)
273 releaseVbos (theCtx);
274 if (!myFont.IsNull())
276 const TCollection_AsciiString aKey = myFont->ResourceKey();
280 theCtx->ReleaseResource (aKey, Standard_True);
285 // =======================================================================
286 // function : StringSize
288 // =======================================================================
289 void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx,
290 const NCollection_String& theText,
291 const OpenGl_AspectText& theTextAspect,
292 const OpenGl_TextParam& theParams,
293 const unsigned int theResolution,
294 Standard_ShortReal& theWidth,
295 Standard_ShortReal& theAscent,
296 Standard_ShortReal& theDescent)
301 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, theParams.Height, theResolution);
302 Handle(OpenGl_Font) aFont = FindFont (theCtx, theTextAspect, theParams.Height, theResolution, aFontKey);
303 if (aFont.IsNull() || !aFont->IsValid())
308 theAscent = aFont->Ascender();
309 theDescent = aFont->Descender();
311 GLfloat aWidth = 0.0f;
312 for (NCollection_Utf8Iter anIter = theText.Iterator(); *anIter != 0;)
314 const Standard_Utf32Char aCharThis = *anIter;
315 const Standard_Utf32Char aCharNext = *++anIter;
317 if (aCharThis == '\x0D' // CR (carriage return)
318 || aCharThis == '\a' // BEL (alarm)
319 || aCharThis == '\f' // FF (form feed) NP (new page)
320 || aCharThis == '\b' // BS (backspace)
321 || aCharThis == '\v') // VT (vertical tab)
323 continue; // skip unsupported carriage control codes
325 else if (aCharThis == '\x0A') // LF (line feed, new line)
327 theWidth = Max (theWidth, aWidth);
331 else if (aCharThis == ' ')
333 aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
336 else if (aCharThis == '\t')
338 aWidth += aFont->FTFont()->AdvanceX (' ', aCharNext) * 8.0f;
342 aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
344 theWidth = Max (theWidth, aWidth);
346 Handle(OpenGl_Context) aCtx = theCtx;
348 aCtx->ReleaseResource (aFontKey, Standard_True);
351 // =======================================================================
354 // =======================================================================
355 void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
357 theWorkspace->SetAspectFace (&theWorkspace->FontFaceAspect());
358 theWorkspace->ApplyAspectFace();
359 const OpenGl_AspectText* aTextAspect = theWorkspace->ApplyAspectText();
360 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
361 const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
363 // Bind custom shader program or generate default version
364 aCtx->ShaderManager()->BindFontProgram (aTextAspect->ShaderProgramRes (aCtx));
366 myOrientationMatrix = theWorkspace->View()->Camera()->OrientationMatrix();
367 myProjMatrix.Convert (aCtx->ProjectionState.Current());
369 // use highlight color or colors from aspect
372 theWorkspace->TextColor(),
373 theWorkspace->TextSubtitleColor(),
377 if (!aPrevTexture.IsNull())
379 aCtx->BindTextures (aPrevTexture);
382 // restore Z buffer settings
383 if (theWorkspace->UseZBuffer())
385 glEnable (GL_DEPTH_TEST);
389 // =======================================================================
392 // =======================================================================
393 void OpenGl_Text::Render (const Handle(OpenGl_Context)& theCtx,
394 const OpenGl_AspectText& theTextAspect,
395 const unsigned int theResolution) const
397 render (theCtx, theTextAspect,
398 theTextAspect.Aspect()->ColorRGBA(),
399 theTextAspect.Aspect()->ColorSubTitleRGBA(),
403 // =======================================================================
404 // function : setupMatrix
406 // =======================================================================
407 void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
408 const OpenGl_AspectText& theTextAspect,
409 const OpenGl_Vec3 theDVec) const
411 OpenGl_Mat4d aModViewMat;
412 OpenGl_Mat4d aProjectMat;
413 if (myHasPlane && myHasAnchorPoint)
415 aProjectMat = myProjMatrix * myOrientationMatrix;
419 aProjectMat = myProjMatrix;
424 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.f);
425 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, 1.f, -1.f, 1.f);
426 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->GetTextAngle(), 0.f, 0.f, 1.f);
430 // align coordinates to the nearest integer
431 // to avoid extra interpolation issues
432 GLdouble anObjX, anObjY, anObjZ;
433 Graphic3d_TransformUtils::UnProject<Standard_Real> (std::floor (myWinX + theDVec.x()),
434 std::floor (myWinY + theDVec.y()),
435 myWinZ + theDVec.z(),
436 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
437 OpenGl_Mat4d::Map (aProjectMat),
445 const gp_Dir& aVectorDir = myOrientation.XDirection();
446 const gp_Dir& aVectorUp = myOrientation.Direction();
447 const gp_Dir& aVectorRight = myOrientation.YDirection();
449 aModViewMat.SetColumn (2, OpenGl_Vec3d (aVectorUp.X(), aVectorUp.Y(), aVectorUp.Z()));
450 aModViewMat.SetColumn (1, OpenGl_Vec3d (aVectorRight.X(), aVectorRight.Y(), aVectorRight.Z()));
451 aModViewMat.SetColumn (0, OpenGl_Vec3d (aVectorDir.X(), aVectorDir.Y(), aVectorDir.Z()));
453 if (!myHasAnchorPoint)
455 OpenGl_Mat4d aPosMat;
456 aPosMat.SetColumn (3, OpenGl_Vec3d (myPoint.x(), myPoint.y(), myPoint.z()));
457 aPosMat *= aModViewMat;
458 aModViewMat.SetColumn (3, aPosMat.GetColumn (3));
462 aModViewMat.SetColumn (3, OpenGl_Vec3d (anObjX, anObjY, anObjZ));
467 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
468 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->GetTextAngle(), 0.0, 0.0, 1.0);
471 if (!theTextAspect.Aspect()->GetTextZoomable())
473 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
475 else if (theCtx->HasRenderScale())
477 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, theCtx->RenderScaleInv(), theCtx->RenderScaleInv(), theCtx->RenderScaleInv());
481 if (myHasPlane && !myHasAnchorPoint)
483 OpenGl_Mat4d aCurrentWorldViewMat;
484 aCurrentWorldViewMat.Convert (theCtx->WorldViewState.Current());
485 theCtx->WorldViewState.SetCurrent<Standard_Real> (aCurrentWorldViewMat * aModViewMat);
489 theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
491 theCtx->ApplyWorldViewMatrix();
495 theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjectMat);
496 theCtx->ApplyProjectionMatrix();
499 // Upload updated state to shader program
500 theCtx->ShaderManager()->PushState (theCtx->ActiveProgram());
503 // =======================================================================
504 // function : drawText
506 // =======================================================================
507 void OpenGl_Text::drawText (const Handle(OpenGl_Context)& theCtx,
508 const OpenGl_AspectText& theTextAspect) const
510 (void )theTextAspect;
511 if (myVertsVbo.Length() != myTextures.Length()
512 || myTextures.IsEmpty())
517 for (Standard_Integer anIter = 0; anIter < myTextures.Length(); ++anIter)
519 const GLuint aTexId = myTextures.Value (anIter);
520 glBindTexture (GL_TEXTURE_2D, aTexId);
522 const Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.Value (anIter);
523 const Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.Value (anIter);
524 aVerts->BindAttribute (theCtx, Graphic3d_TOA_POS);
525 aTCrds->BindAttribute (theCtx, Graphic3d_TOA_UV);
527 glDrawArrays (GL_TRIANGLES, 0, GLsizei(aVerts->GetElemsNb()));
529 aTCrds->UnbindAttribute (theCtx, Graphic3d_TOA_UV);
530 aVerts->UnbindAttribute (theCtx, Graphic3d_TOA_POS);
532 glBindTexture (GL_TEXTURE_2D, 0);
535 // =======================================================================
536 // function : FontKey
538 // =======================================================================
539 TCollection_AsciiString OpenGl_Text::FontKey (const OpenGl_AspectText& theAspect,
540 const Standard_Integer theHeight,
541 const unsigned int theResolution)
543 const Font_FontAspect anAspect = theAspect.Aspect()->GetTextFontAspect() != Font_FA_Undefined
544 ? theAspect.Aspect()->GetTextFontAspect()
546 return theAspect.Aspect()->Font()
547 + TCollection_AsciiString(":") + Standard_Integer(anAspect)
548 + TCollection_AsciiString(":") + Standard_Integer(theResolution)
549 + TCollection_AsciiString(":") + theHeight;
552 // =======================================================================
553 // function : FindFont
555 // =======================================================================
556 Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
557 const OpenGl_AspectText& theAspect,
558 const Standard_Integer theHeight,
559 const unsigned int theResolution,
560 const TCollection_AsciiString theKey)
562 Handle(OpenGl_Font) aFont;
565 return aFont; // invalid parameters
568 if (!theCtx->GetResource (theKey, aFont))
570 Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
571 const Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (theAspect.Aspect()->Font());
572 const Font_FontAspect anAspect = theAspect.Aspect()->GetTextFontAspect() != Font_FA_Undefined
573 ? theAspect.Aspect()->GetTextFontAspect()
575 Handle(Font_SystemFont) aRequestedFont = aFontMgr->FindFont (aFontName, anAspect, theHeight);
576 Handle(Font_FTFont) aFontFt;
577 if (!aRequestedFont.IsNull())
579 aFontFt = new Font_FTFont (Handle(Font_FTLibrary)());
581 if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight, theResolution))
583 aFont = new OpenGl_Font (aFontFt, theKey);
584 if (!aFont->Init (theCtx))
586 TCollection_ExtendedString aMsg;
588 aMsg += theAspect.Aspect()->Font();
589 aMsg += "' - initialization of GL resources has failed!";
590 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
592 aFont->Release (theCtx.operator->());
593 aFont = new OpenGl_Font (aFontFt, theKey);
598 TCollection_ExtendedString aMsg;
600 aMsg += theAspect.Aspect()->Font();
601 aMsg += "' is broken or has incompatible format! File path: ";
602 aMsg += aRequestedFont->FontPath()->ToCString();
603 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
605 aFont = new OpenGl_Font (aFontFt, theKey);
610 TCollection_ExtendedString aMsg;
612 aMsg += theAspect.Aspect()->Font();
613 aMsg += "' is not found in the system!";
614 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
615 aFont = new OpenGl_Font (aFontFt, theKey);
618 theCtx->ShareResource (theKey, aFont);
623 // =======================================================================
624 // function : drawRect
626 // =======================================================================
627 void OpenGl_Text::drawRect (const Handle(OpenGl_Context)& theCtx,
628 const OpenGl_AspectText& theTextAspect,
629 const OpenGl_Vec4& theColorSubs) const
631 Handle(OpenGl_ShaderProgram) aPrevProgram = theCtx->ActiveProgram();
632 if (myBndVertsVbo.IsNull())
634 OpenGl_Vec2 aQuad[4] =
636 OpenGl_Vec2(myBndBox.Right, myBndBox.Bottom),
637 OpenGl_Vec2(myBndBox.Right, myBndBox.Top),
638 OpenGl_Vec2(myBndBox.Left, myBndBox.Bottom),
639 OpenGl_Vec2(myBndBox.Left, myBndBox.Top)
641 if (theCtx->ToUseVbo())
643 myBndVertsVbo = new OpenGl_VertexBuffer();
647 myBndVertsVbo = new OpenGl_VertexBufferCompat();
649 myBndVertsVbo->Init (theCtx, 2, 4, aQuad[0].GetData());
652 // bind unlit program
653 theCtx->ShaderManager()->BindFaceProgram (Handle(OpenGl_TextureSet)(), Graphic3d_TOSM_UNLIT,
654 Graphic3d_AlphaMode_Opaque, Standard_False, Standard_False,
655 Handle(OpenGl_ShaderProgram)());
657 #if !defined(GL_ES_VERSION_2_0)
658 if (theCtx->core11 != NULL
659 && theCtx->ActiveProgram().IsNull())
661 glBindTexture (GL_TEXTURE_2D, 0);
664 theCtx->SetColor4fv (theColorSubs);
665 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
666 myBndVertsVbo->BindAttribute (theCtx, Graphic3d_TOA_POS);
668 theCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
670 myBndVertsVbo->UnbindAttribute (theCtx, Graphic3d_TOA_POS);
671 theCtx->BindProgram (aPrevProgram);
674 // =======================================================================
677 // =======================================================================
678 void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
679 const OpenGl_AspectText& theTextAspect,
680 const OpenGl_Vec4& theColorText,
681 const OpenGl_Vec4& theColorSubs,
682 const unsigned int theResolution) const
684 if (myString.IsEmpty())
689 // Note that using difference resolution in different Views in same Viewer
690 // will lead to performance regression (for example, text will be recreated every time).
691 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, myParams.Height, theResolution);
693 && !myFont->ResourceKey().IsEqual (aFontKey))
696 const_cast<OpenGl_Text* > (this)->Release (theCtx.operator->());
701 myFont = FindFont (theCtx, theTextAspect, myParams.Height, theResolution, aFontKey);
703 if (!myFont->WasInitialized())
708 if (myTextures.IsEmpty())
710 Font_TextFormatter aFormatter;
711 aFormatter.SetupAlignment (myParams.HAlign, myParams.VAlign);
714 aFormatter.Append (myString, *myFont->FTFont().operator->());
717 OpenGl_TextBuilder aBuilder;
718 aBuilder.Perform (aFormatter,
720 *myFont.operator->(),
725 aFormatter.BndBox (myBndBox);
726 if (!myBndVertsVbo.IsNull())
728 myBndVertsVbo->Release (theCtx.get());
729 myBndVertsVbo.Nullify();
733 if (myTextures.IsEmpty())
738 myExportHeight = 1.0f;
739 myScaleHeight = 1.0f;
741 theCtx->WorldViewState.Push();
742 myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current());
744 const GLdouble aPointSize = (GLdouble )myFont->FTFont()->PointSize();
747 Graphic3d_TransformUtils::Project<Standard_Real> (myPoint.x(), myPoint.y(), myPoint.z(),
748 myModelMatrix, myProjMatrix, theCtx->Viewport(),
749 myWinX, myWinY, myWinZ);
751 // compute scale factor for constant text height
752 if (theTextAspect.Aspect()->GetTextZoomable())
754 myExportHeight = aPointSize;
758 Graphic3d_Vec3d aPnt1, aPnt2;
759 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, myWinY, myWinZ,
760 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), myProjMatrix, theCtx->Viewport(),
761 aPnt1.x(), aPnt1.y(), aPnt1.z());
762 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, myWinY + aPointSize, myWinZ,
763 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), myProjMatrix, theCtx->Viewport(),
764 aPnt2.x(), aPnt2.y(), aPnt2.z());
765 myScaleHeight = (aPnt2.y() - aPnt1.y()) / aPointSize;
768 myExportHeight = aPointSize / myExportHeight;
770 #if !defined(GL_ES_VERSION_2_0)
771 if (theCtx->core11 != NULL
772 && theCtx->caps->ffpEnable)
774 glDisable (GL_LIGHTING);
777 const Standard_Integer aPrevPolygonMode = theCtx->SetPolygonMode (GL_FILL);
778 const bool aPrevHatchingMode = theCtx->SetPolygonHatchEnabled (false);
782 const bool hasDepthTest = !myIs2d
783 && theTextAspect.Aspect()->Style() != Aspect_TOST_ANNOTATION;
786 glDisable (GL_DEPTH_TEST);
789 if (theCtx->core15fwd != NULL)
791 theCtx->core15fwd->glActiveTexture (GL_TEXTURE0);
793 #if !defined(GL_ES_VERSION_2_0)
794 // activate texture unit
795 GLint aTexEnvParam = GL_REPLACE;
796 if (theCtx->core11 != NULL)
798 glDisable (GL_TEXTURE_1D);
799 glEnable (GL_TEXTURE_2D);
800 glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam);
801 if (aTexEnvParam != GL_REPLACE)
803 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
810 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
811 const bool anAlphaToCoverageOld = theCtx->SetSampleAlphaToCoverage (false);
814 switch (theTextAspect.Aspect()->DisplayType())
816 case Aspect_TODT_BLEND:
818 #if !defined(GL_ES_VERSION_2_0)
819 glEnable (GL_COLOR_LOGIC_OP);
824 case Aspect_TODT_SUBTITLE:
826 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
827 drawRect (theCtx, theTextAspect, theColorSubs);
830 case Aspect_TODT_DEKALE:
832 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
833 theCtx->SetColor4fv (theColorSubs);
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);
840 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
841 drawText (theCtx, theTextAspect);
844 case Aspect_TODT_SHADOW:
846 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
847 theCtx->SetColor4fv (theColorSubs);
848 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
849 drawText (theCtx, theTextAspect);
852 case Aspect_TODT_DIMENSION:
853 case Aspect_TODT_NORMAL:
860 theCtx->SetColor4fv (theColorText);
861 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
862 drawText (theCtx, theTextAspect);
866 theCtx->ProjectionState.SetCurrent<Standard_Real> (myProjMatrix);
867 theCtx->ApplyProjectionMatrix();
870 #if !defined(GL_ES_VERSION_2_0)
871 if (theCtx->core11 != NULL)
873 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam);
877 if (theTextAspect.Aspect()->DisplayType() == Aspect_TODT_DIMENSION)
879 glDisable (GL_BLEND);
882 glDisable (GL_DEPTH_TEST);
884 #if !defined(GL_ES_VERSION_2_0)
885 if (theCtx->core11 != NULL)
887 glDisable (GL_TEXTURE_2D);
890 const bool aColorMaskBack = theCtx->SetColorMask (false);
892 glClear (GL_STENCIL_BUFFER_BIT);
893 glEnable (GL_STENCIL_TEST);
894 glStencilFunc (GL_ALWAYS, 1, 0xFF);
895 glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE);
897 drawRect (theCtx, theTextAspect, OpenGl_Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
899 glStencilFunc (GL_ALWAYS, 0, 0xFF);
901 theCtx->SetColorMask (aColorMaskBack);
904 // reset OpenGL state
905 glDisable (GL_BLEND);
906 glDisable (GL_STENCIL_TEST);
907 #if !defined(GL_ES_VERSION_2_0)
908 glDisable (GL_COLOR_LOGIC_OP);
910 theCtx->SetPolygonMode (aPrevPolygonMode);
911 theCtx->SetPolygonHatchEnabled (aPrevHatchingMode);
913 theCtx->SetSampleAlphaToCoverage (anAlphaToCoverageOld);
915 // model view matrix was modified
916 theCtx->WorldViewState.Pop();
917 theCtx->ApplyModelViewMatrix();