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_Aspects.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 OpenGl_Mat4d THE_IDENTITY_MATRIX;
36 static const TCollection_AsciiString THE_DEFAULT_FONT (Font_NOF_ASCII_MONO);
38 //! Auxiliary tool for setting polygon offset temporarily.
39 struct BackPolygonOffsetSentry
41 BackPolygonOffsetSentry (OpenGl_Context* theCtx)
46 myOffsetBack = theCtx->PolygonOffset();
47 Graphic3d_PolygonOffset aPolyOffset = myOffsetBack;
48 aPolyOffset.Mode = Aspect_POM_Fill;
49 aPolyOffset.Units += 1.0f;
50 theCtx->SetPolygonOffset (aPolyOffset);
54 ~BackPolygonOffsetSentry()
58 myCtx->SetPolygonOffset (myOffsetBack);
63 BackPolygonOffsetSentry (const BackPolygonOffsetSentry& );
64 BackPolygonOffsetSentry& operator= (const BackPolygonOffsetSentry& );
66 OpenGl_Context* myCtx;
67 Graphic3d_PolygonOffset myOffsetBack;
70 } // anonymous namespace
72 // =======================================================================
73 // function : OpenGl_Text
75 // =======================================================================
76 OpenGl_Text::OpenGl_Text()
77 : myScaleHeight (1.0f),
78 myIs2d (Standard_False)
80 myText = new Graphic3d_Text (10.);
84 // =======================================================================
85 // function : OpenGl_Text
87 // =======================================================================
88 OpenGl_Text::OpenGl_Text (const Handle(Graphic3d_Text)& theTextParams)
89 : myText (theTextParams),
91 myIs2d (Standard_False)
95 // =======================================================================
96 // function : SetPosition
98 // =======================================================================
99 void OpenGl_Text::SetPosition (const OpenGl_Vec3& thePoint)
101 myText->SetPosition (gp_Pnt (thePoint.x(), thePoint.y(), thePoint.z()));
104 // =======================================================================
105 // function : SetFontSize
107 // =======================================================================
108 void OpenGl_Text::SetFontSize (const Handle(OpenGl_Context)& theCtx,
109 const Standard_Integer theFontSize)
111 if (myText->Height() != theFontSize)
113 Release (theCtx.operator->());
115 myText->SetHeight ((Standard_ShortReal)theFontSize);
118 // =======================================================================
121 // =======================================================================
122 void OpenGl_Text::Reset (const Handle(OpenGl_Context)& theCtx)
124 if (!myFont.IsNull() && myFont->FTFont()->PointSize() != myText->Height())
126 Release (theCtx.operator->());
130 releaseVbos (theCtx.operator->());
134 // =======================================================================
137 // =======================================================================
138 void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx,
139 const Standard_Utf8Char* theText,
140 const OpenGl_Vec3& thePoint)
143 Set2D (Standard_False);
145 NCollection_String aText;
146 aText.FromUnicode (theText);
147 myText->SetText (aText);
148 myText->SetPosition (gp_Pnt (thePoint.x(), thePoint.y(), thePoint.z()));
151 // =======================================================================
152 // function : ~OpenGl_Text
154 // =======================================================================
155 OpenGl_Text::~OpenGl_Text()
160 // =======================================================================
161 // function : releaseVbos
163 // =======================================================================
164 void OpenGl_Text::releaseVbos (OpenGl_Context* theCtx)
166 for (Standard_Integer anIter = 0; anIter < myVertsVbo.Length(); ++anIter)
168 Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.ChangeValue (anIter);
169 Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.ChangeValue (anIter);
173 theCtx->DelayedRelease (aVerts);
174 theCtx->DelayedRelease (aTCrds);
180 && !myBndVertsVbo.IsNull())
182 theCtx->DelayedRelease (myBndVertsVbo);
188 myBndVertsVbo.Nullify();
191 // =======================================================================
192 // function : Release
194 // =======================================================================
195 void OpenGl_Text::Release (OpenGl_Context* theCtx)
197 releaseVbos (theCtx);
198 if (!myFont.IsNull())
200 const TCollection_AsciiString aKey = myFont->ResourceKey();
204 theCtx->ReleaseResource (aKey, Standard_True);
209 // =======================================================================
210 // function : StringSize
212 // =======================================================================
213 void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx,
214 const NCollection_String& theText,
215 const OpenGl_Aspects& theTextAspect,
216 const Standard_ShortReal theHeight,
217 const unsigned int theResolution,
218 Standard_ShortReal& theWidth,
219 Standard_ShortReal& theAscent,
220 Standard_ShortReal& theDescent)
225 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, (Standard_Integer)theHeight, theResolution);
226 Handle(OpenGl_Font) aFont = FindFont (theCtx, theTextAspect, (Standard_Integer)theHeight, theResolution, aFontKey);
227 if (aFont.IsNull() || !aFont->IsValid())
232 theAscent = aFont->Ascender();
233 theDescent = aFont->Descender();
235 GLfloat aWidth = 0.0f;
236 for (NCollection_Utf8Iter anIter = theText.Iterator(); *anIter != 0;)
238 const Standard_Utf32Char aCharThis = *anIter;
239 const Standard_Utf32Char aCharNext = *++anIter;
241 if (aCharThis == '\x0D' // CR (carriage return)
242 || aCharThis == '\a' // BEL (alarm)
243 || aCharThis == '\f' // FF (form feed) NP (new page)
244 || aCharThis == '\b' // BS (backspace)
245 || aCharThis == '\v') // VT (vertical tab)
247 continue; // skip unsupported carriage control codes
249 else if (aCharThis == '\x0A') // LF (line feed, new line)
251 theWidth = Max (theWidth, aWidth);
255 else if (aCharThis == ' ')
257 aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
260 else if (aCharThis == '\t')
262 aWidth += aFont->FTFont()->AdvanceX (' ', aCharNext) * 8.0f;
266 aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
268 theWidth = Max (theWidth, aWidth);
270 Handle(OpenGl_Context) aCtx = theCtx;
272 aCtx->ReleaseResource (aFontKey, Standard_True);
275 // =======================================================================
278 // =======================================================================
279 void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
281 const OpenGl_Aspects* aTextAspect = theWorkspace->ApplyAspects();
282 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
283 const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
285 // Bind custom shader program or generate default version
286 aCtx->ShaderManager()->BindFontProgram (aTextAspect->ShaderProgramRes (aCtx));
288 if (myText->HasPlane() && myText->HasOwnAnchorPoint())
290 myOrientationMatrix = theWorkspace->View()->Camera()->OrientationMatrix();
291 // reset translation part
292 myOrientationMatrix.ChangeValue (0, 3) = 0.0;
293 myOrientationMatrix.ChangeValue (1, 3) = 0.0;
294 myOrientationMatrix.ChangeValue (2, 3) = 0.0;
297 myProjMatrix.Convert (aCtx->ProjectionState.Current());
299 // use highlight color or colors from aspect
302 theWorkspace->TextColor(),
303 theWorkspace->TextSubtitleColor(),
307 if (!aPrevTexture.IsNull())
309 aCtx->BindTextures (aPrevTexture);
312 // restore Z buffer settings
313 if (theWorkspace->UseZBuffer())
315 glEnable (GL_DEPTH_TEST);
319 // =======================================================================
322 // =======================================================================
323 void OpenGl_Text::Render (const Handle(OpenGl_Context)& theCtx,
324 const OpenGl_Aspects& theTextAspect,
325 unsigned int theResolution) const
327 #if !defined(GL_ES_VERSION_2_0)
328 const Standard_Integer aPrevPolygonMode = theCtx->SetPolygonMode (GL_FILL);
329 const bool aPrevHatchingMode = theCtx->SetPolygonHatchEnabled (false);
332 render (theCtx, theTextAspect,
333 theTextAspect.Aspect()->ColorRGBA(),
334 theTextAspect.Aspect()->ColorSubTitleRGBA(),
337 #if !defined(GL_ES_VERSION_2_0)
338 theCtx->SetPolygonMode (aPrevPolygonMode);
339 theCtx->SetPolygonHatchEnabled (aPrevHatchingMode);
343 // =======================================================================
344 // function : setupMatrix
346 // =======================================================================
347 void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
348 const OpenGl_Aspects& theTextAspect,
349 const OpenGl_Vec3& theDVec) const
351 OpenGl_Mat4d aModViewMat, aProjectMat;
352 if (myText->HasPlane() && myText->HasOwnAnchorPoint())
354 aProjectMat = myProjMatrix * myOrientationMatrix;
358 aProjectMat = myProjMatrix;
363 const gp_Pnt& aPoint = myText->Position();
364 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, aPoint.X() + theDVec.x(), aPoint.Y() + theDVec.y(), 0.f);
365 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, 1.f, -1.f, 1.f);
366 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->TextAngle(), 0.f, 0.f, 1.f);
370 OpenGl_Vec3d anObjXYZ;
371 OpenGl_Vec3d aWinXYZ = myWinXYZ + OpenGl_Vec3d (theDVec);
372 if (!myText->HasPlane() && !theTextAspect.Aspect()->IsTextZoomable())
374 // Align coordinates to the nearest integer to avoid extra interpolation issues.
375 // Note that for better readability we could also try aligning freely rotated in 3D text (myHasPlane),
376 // when camera orientation co-aligned with horizontal text orientation,
377 // but this might look awkward while rotating camera.
378 aWinXYZ.x() = Floor (aWinXYZ.x());
379 aWinXYZ.y() = Floor (aWinXYZ.y());
381 Graphic3d_TransformUtils::UnProject<Standard_Real> (aWinXYZ.x(), aWinXYZ.y(), aWinXYZ.z(),
382 THE_IDENTITY_MATRIX, aProjectMat, theCtx->Viewport(),
383 anObjXYZ.x(), anObjXYZ.y(), anObjXYZ.z());
385 if (myText->HasPlane())
387 const gp_Ax2& anOrientation = myText->Orientation();
388 const gp_Dir& aVectorDir = anOrientation.XDirection();
389 const gp_Dir& aVectorUp = anOrientation.Direction();
390 const gp_Dir& aVectorRight = anOrientation.YDirection();
392 aModViewMat.SetColumn (2, OpenGl_Vec3d (aVectorUp.X(), aVectorUp.Y(), aVectorUp.Z()));
393 aModViewMat.SetColumn (1, OpenGl_Vec3d (aVectorRight.X(), aVectorRight.Y(), aVectorRight.Z()));
394 aModViewMat.SetColumn (0, OpenGl_Vec3d (aVectorDir.X(), aVectorDir.Y(), aVectorDir.Z()));
396 if (!myText->HasOwnAnchorPoint())
398 OpenGl_Mat4d aPosMat;
399 const gp_Pnt& aPoint = myText->Position();
400 aPosMat.SetColumn (3, OpenGl_Vec3d (aPoint.X(), aPoint.Y(), aPoint.Z()));
401 aPosMat *= aModViewMat;
402 aModViewMat.SetColumn (3, aPosMat.GetColumn (3));
406 aModViewMat.SetColumn (3, anObjXYZ);
411 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, anObjXYZ.x(), anObjXYZ.y(), anObjXYZ.z());
412 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->TextAngle(), 0.0, 0.0, 1.0);
415 if (!theTextAspect.Aspect()->IsTextZoomable())
417 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
419 else if (theCtx->HasRenderScale())
421 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, theCtx->RenderScaleInv(), theCtx->RenderScaleInv(), theCtx->RenderScaleInv());
425 if (myText->HasPlane() && !myText->HasOwnAnchorPoint())
427 OpenGl_Mat4d aCurrentWorldViewMat;
428 aCurrentWorldViewMat.Convert (theCtx->WorldViewState.Current());
429 theCtx->WorldViewState.SetCurrent<Standard_Real> (aCurrentWorldViewMat * aModViewMat);
433 theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
435 theCtx->ApplyWorldViewMatrix();
439 theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjectMat);
440 theCtx->ApplyProjectionMatrix();
443 // Upload updated state to shader program
444 theCtx->ShaderManager()->PushState (theCtx->ActiveProgram());
447 // =======================================================================
448 // function : drawText
450 // =======================================================================
451 void OpenGl_Text::drawText (const Handle(OpenGl_Context)& theCtx,
452 const OpenGl_Aspects& theTextAspect) const
454 (void )theTextAspect;
455 if (myVertsVbo.Length() != myTextures.Length()
456 || myTextures.IsEmpty())
461 for (Standard_Integer anIter = 0; anIter < myTextures.Length(); ++anIter)
463 const GLuint aTexId = myTextures.Value (anIter);
464 glBindTexture (GL_TEXTURE_2D, aTexId);
466 const Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.Value (anIter);
467 const Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.Value (anIter);
468 aVerts->BindAttribute (theCtx, Graphic3d_TOA_POS);
469 aTCrds->BindAttribute (theCtx, Graphic3d_TOA_UV);
471 glDrawArrays (GL_TRIANGLES, 0, GLsizei(aVerts->GetElemsNb()));
473 aTCrds->UnbindAttribute (theCtx, Graphic3d_TOA_UV);
474 aVerts->UnbindAttribute (theCtx, Graphic3d_TOA_POS);
476 glBindTexture (GL_TEXTURE_2D, 0);
479 // =======================================================================
480 // function : FontKey
482 // =======================================================================
483 TCollection_AsciiString OpenGl_Text::FontKey (const OpenGl_Aspects& theAspect,
484 Standard_Integer theHeight,
485 unsigned int theResolution)
487 const Font_FontAspect anAspect = theAspect.Aspect()->TextFontAspect() != Font_FA_Undefined
488 ? theAspect.Aspect()->TextFontAspect()
490 const TCollection_AsciiString& aFont = !theAspect.Aspect()->TextFont().IsNull() ? theAspect.Aspect()->TextFont()->String() : THE_DEFAULT_FONT;
492 + TCollection_AsciiString(":") + Standard_Integer(anAspect)
493 + TCollection_AsciiString(":") + Standard_Integer(theResolution)
494 + TCollection_AsciiString(":") + theHeight;
497 // =======================================================================
498 // function : FindFont
500 // =======================================================================
501 Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
502 const OpenGl_Aspects& theAspect,
503 Standard_Integer theHeight,
504 unsigned int theResolution,
505 const TCollection_AsciiString& theKey)
507 Handle(OpenGl_Font) aFont;
510 return aFont; // invalid parameters
513 if (!theCtx->GetResource (theKey, aFont))
515 Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
516 const TCollection_AsciiString& aFontName = !theAspect.Aspect()->TextFont().IsNull()
517 ? theAspect.Aspect()->TextFont()->String()
519 Font_FontAspect anAspect = theAspect.Aspect()->TextFontAspect() != Font_FA_Undefined
520 ? theAspect.Aspect()->TextFontAspect()
522 Font_FTFontParams aParams;
523 aParams.PointSize = theHeight;
524 aParams.Resolution = theResolution;
525 if (Handle(Font_FTFont) aFontFt = Font_FTFont::FindAndCreate (aFontName, anAspect, aParams, Font_StrictLevel_Any))
527 aFont = new OpenGl_Font (aFontFt, theKey);
528 if (!aFont->Init (theCtx))
530 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
531 TCollection_AsciiString ("Font '") + aFontName + "' - initialization of GL resources has failed!");
533 aFont->Release (theCtx.get());
534 aFont = new OpenGl_Font (aFontFt, theKey);
539 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
540 TCollection_AsciiString ("Font '") + aFontName + "' is not found in the system!");
541 aFont = new OpenGl_Font (aFontFt, theKey);
544 theCtx->ShareResource (theKey, aFont);
549 // =======================================================================
550 // function : drawRect
552 // =======================================================================
553 void OpenGl_Text::drawRect (const Handle(OpenGl_Context)& theCtx,
554 const OpenGl_Aspects& theTextAspect,
555 const OpenGl_Vec4& theColorSubs) const
557 Handle(OpenGl_ShaderProgram) aPrevProgram = theCtx->ActiveProgram();
558 if (myBndVertsVbo.IsNull())
560 OpenGl_Vec2 aQuad[4] =
562 OpenGl_Vec2(myBndBox.Right, myBndBox.Bottom),
563 OpenGl_Vec2(myBndBox.Right, myBndBox.Top),
564 OpenGl_Vec2(myBndBox.Left, myBndBox.Bottom),
565 OpenGl_Vec2(myBndBox.Left, myBndBox.Top)
567 if (theCtx->ToUseVbo())
569 myBndVertsVbo = new OpenGl_VertexBuffer();
573 myBndVertsVbo = new OpenGl_VertexBufferCompat();
575 myBndVertsVbo->Init (theCtx, 2, 4, aQuad[0].GetData());
578 // bind unlit program
579 theCtx->ShaderManager()->BindFaceProgram (Handle(OpenGl_TextureSet)(), Graphic3d_TOSM_UNLIT,
580 Graphic3d_AlphaMode_Opaque, Standard_False, Standard_False,
581 Handle(OpenGl_ShaderProgram)());
583 #if !defined(GL_ES_VERSION_2_0)
584 if (theCtx->core11 != NULL
585 && theCtx->ActiveProgram().IsNull())
587 glBindTexture (GL_TEXTURE_2D, 0);
590 theCtx->SetColor4fv (theColorSubs);
591 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
592 myBndVertsVbo->BindAttribute (theCtx, Graphic3d_TOA_POS);
594 theCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
596 myBndVertsVbo->UnbindAttribute (theCtx, Graphic3d_TOA_POS);
597 theCtx->BindProgram (aPrevProgram);
600 // =======================================================================
603 // =======================================================================
604 void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
605 const OpenGl_Aspects& theTextAspect,
606 const OpenGl_Vec4& theColorText,
607 const OpenGl_Vec4& theColorSubs,
608 unsigned int theResolution) const
610 if (myText->Text().IsEmpty())
615 // Note that using difference resolution in different Views in same Viewer
616 // will lead to performance regression (for example, text will be recreated every time).
617 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, (Standard_Integer)myText->Height(), theResolution);
619 && !myFont->ResourceKey().IsEqual (aFontKey))
622 const_cast<OpenGl_Text* > (this)->Release (theCtx.operator->());
627 myFont = FindFont (theCtx, theTextAspect, (Standard_Integer)myText->Height(), theResolution, aFontKey);
629 if (!myFont->WasInitialized())
634 if (myTextures.IsEmpty())
636 Font_TextFormatter aFormatter;
638 aFormatter.SetupAlignment (myText->HorizontalAlignment(), myText->VerticalAlignment());
641 aFormatter.Append (myText->Text(), *myFont->FTFont());
644 OpenGl_TextBuilder aBuilder;
645 aBuilder.Perform (aFormatter,
647 *myFont.operator->(),
652 aFormatter.BndBox (myBndBox);
653 if (!myBndVertsVbo.IsNull())
655 myBndVertsVbo->Release (theCtx.get());
656 myBndVertsVbo.Nullify();
660 if (myTextures.IsEmpty())
665 myScaleHeight = 1.0f;
667 theCtx->WorldViewState.Push();
668 myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current());
670 const GLdouble aPointSize = (GLdouble )myFont->FTFont()->PointSize();
673 const gp_Pnt& aPoint = myText->Position();
674 Graphic3d_TransformUtils::Project<Standard_Real> (aPoint.X(), aPoint.Y(), aPoint.Z(),
675 myModelMatrix, myProjMatrix, theCtx->Viewport(),
676 myWinXYZ.x(), myWinXYZ.y(), myWinXYZ.z());
678 // compute scale factor for constant text height
679 if (!theTextAspect.Aspect()->IsTextZoomable())
681 Graphic3d_Vec3d aPnt1, aPnt2;
682 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinXYZ.x(), myWinXYZ.y(), myWinXYZ.z(),
683 THE_IDENTITY_MATRIX, myProjMatrix, theCtx->Viewport(),
684 aPnt1.x(), aPnt1.y(), aPnt1.z());
685 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinXYZ.x(), myWinXYZ.y() + aPointSize, myWinXYZ.z(),
686 THE_IDENTITY_MATRIX, myProjMatrix, theCtx->Viewport(),
687 aPnt2.x(), aPnt2.y(), aPnt2.z());
688 myScaleHeight = (aPnt2.y() - aPnt1.y()) / aPointSize;
692 #if !defined(GL_ES_VERSION_2_0)
693 if (theCtx->core11 != NULL
694 && theCtx->caps->ffpEnable)
696 glDisable (GL_LIGHTING);
701 const bool hasDepthTest = !myIs2d
702 && theTextAspect.Aspect()->TextStyle() != Aspect_TOST_ANNOTATION;
705 glDisable (GL_DEPTH_TEST);
708 if (theCtx->core15fwd != NULL)
710 theCtx->core15fwd->glActiveTexture (GL_TEXTURE0);
712 #if !defined(GL_ES_VERSION_2_0)
713 // activate texture unit
714 GLint aTexEnvParam = GL_REPLACE;
715 if (theCtx->core11 != NULL)
717 glDisable (GL_TEXTURE_1D);
718 glEnable (GL_TEXTURE_2D);
719 glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam);
720 if (aTexEnvParam != GL_REPLACE)
722 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
729 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
731 // alpha to coverage makes text too thin
732 theCtx->SetSampleAlphaToCoverage (false);
735 switch (theTextAspect.Aspect()->TextDisplayType())
737 case Aspect_TODT_BLEND:
739 #if !defined(GL_ES_VERSION_2_0)
740 glEnable (GL_COLOR_LOGIC_OP);
745 case Aspect_TODT_SUBTITLE:
747 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx.get() : NULL);
748 drawRect (theCtx, theTextAspect, theColorSubs);
751 case Aspect_TODT_DEKALE:
753 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx.get() : NULL);
754 theCtx->SetColor4fv (theColorSubs);
755 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.0f));
756 drawText (theCtx, theTextAspect);
757 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.0f));
758 drawText (theCtx, theTextAspect);
759 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.0f));
760 drawText (theCtx, theTextAspect);
761 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
762 drawText (theCtx, theTextAspect);
765 case Aspect_TODT_SHADOW:
767 BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx.get() : NULL);
768 theCtx->SetColor4fv (theColorSubs);
769 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
770 drawText (theCtx, theTextAspect);
773 case Aspect_TODT_DIMENSION:
774 case Aspect_TODT_NORMAL:
781 theCtx->SetColor4fv (theColorText);
782 setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
783 drawText (theCtx, theTextAspect);
787 theCtx->ProjectionState.SetCurrent<Standard_Real> (myProjMatrix);
788 theCtx->ApplyProjectionMatrix();
791 #if !defined(GL_ES_VERSION_2_0)
792 if (theCtx->core11 != NULL)
794 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam);
798 if (theTextAspect.Aspect()->TextDisplayType() == Aspect_TODT_DIMENSION)
800 glDisable (GL_BLEND);
803 glDisable (GL_DEPTH_TEST);
805 #if !defined(GL_ES_VERSION_2_0)
806 if (theCtx->core11 != NULL)
808 glDisable (GL_TEXTURE_2D);
811 const bool aColorMaskBack = theCtx->SetColorMask (false);
813 glClear (GL_STENCIL_BUFFER_BIT);
814 glEnable (GL_STENCIL_TEST);
815 glStencilFunc (GL_ALWAYS, 1, 0xFF);
816 glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE);
818 drawRect (theCtx, theTextAspect, OpenGl_Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
820 glStencilFunc (GL_ALWAYS, 0, 0xFF);
822 theCtx->SetColorMask (aColorMaskBack);
825 // reset OpenGL state
826 glDisable (GL_BLEND);
827 glDisable (GL_STENCIL_TEST);
828 #if !defined(GL_ES_VERSION_2_0)
829 glDisable (GL_COLOR_LOGIC_OP);
832 // model view matrix was modified
833 theCtx->WorldViewState.Pop();
834 theCtx->ApplyModelViewMatrix();