0030153: Visualization, TKOpenGl - AIS_ColoredShape::SynchronizeAspects() doesn't...
[occt.git] / src / OpenGl / OpenGl_FrameStatsPrs.cxx
CommitLineData
15669413 1// Copyright (c) 2017 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <OpenGl_FrameStatsPrs.hxx>
15
16#include <OpenGl_View.hxx>
17#include <OpenGl_ShaderManager.hxx>
18#include <OpenGl_Workspace.hxx>
19
20// =======================================================================
21// function : OpenGl_FrameStatsPrs
22// purpose :
23// =======================================================================
24OpenGl_FrameStatsPrs::OpenGl_FrameStatsPrs()
25: myStatsPrev (new OpenGl_FrameStats())
26{
27 myParams.HAlign = Graphic3d_HTA_CENTER;
28 myParams.VAlign = Graphic3d_VTA_CENTER;
29 myHasPlane = false;
30}
31
32// =======================================================================
33// function : ~OpenGl_FrameStatsPrs
34// purpose :
35// =======================================================================
36OpenGl_FrameStatsPrs::~OpenGl_FrameStatsPrs()
37{
38 //
39}
40
41// =======================================================================
42// function : Release
43// purpose :
44// =======================================================================
45void OpenGl_FrameStatsPrs::Release (OpenGl_Context* theCtx)
46{
47 OpenGl_Text::Release (theCtx);
48}
49
50// =======================================================================
51// function : Update
52// purpose :
53// =======================================================================
54void OpenGl_FrameStatsPrs::Update (const Handle(OpenGl_Workspace)& theWorkspace)
55{
56 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
57 const Handle(OpenGl_FrameStats)& aStats = aCtx->FrameStats();
58 const Graphic3d_RenderingParams& aRendParams = theWorkspace->View()->RenderingParams();
59 myTrsfPers = theWorkspace->View()->RenderingParams().StatsPosition;
60 myTextAspect.SetAspect (aRendParams.StatsTextAspect);
61
62 // adjust text alignment depending on corner
63 const OpenGl_TextParam aParamsPrev = myParams;
64 myParams.Height = aRendParams.StatsTextHeight;
65 myParams.HAlign = Graphic3d_HTA_CENTER;
66 myParams.VAlign = Graphic3d_VTA_CENTER;
67 if (!myTrsfPers.IsNull() && (myTrsfPers->Corner2d() & Aspect_TOTP_LEFT) != 0)
68 {
69 myParams.HAlign = Graphic3d_HTA_LEFT;
70 }
71 else if (!myTrsfPers.IsNull() && (myTrsfPers->Corner2d() & Aspect_TOTP_RIGHT) != 0)
72 {
73 myParams.HAlign = Graphic3d_HTA_RIGHT;
74 }
75 if (!myTrsfPers.IsNull() && (myTrsfPers->Corner2d() & Aspect_TOTP_TOP) != 0)
76 {
77 myParams.VAlign = Graphic3d_VTA_TOP;
78 }
79 else if (!myTrsfPers.IsNull() && (myTrsfPers->Corner2d() & Aspect_TOTP_BOTTOM) != 0)
80 {
81 myParams.VAlign = Graphic3d_VTA_BOTTOM;
82 }
83 if (myParams.Height != aParamsPrev.Height
84 || myParams.HAlign != aParamsPrev.HAlign
85 || myParams.VAlign != aParamsPrev.VAlign)
86 {
87 Release (aCtx.operator->());
88 }
89
90 if (myStatsPrev->IsEqual (aStats)
91 && !myString.IsEmpty())
92 {
93 return;
94 }
95
96 myStatsPrev->CopyFrom (aStats);
97 const TCollection_AsciiString aText = aStats->FormatStats (aRendParams.CollectedStats);
98
99 releaseVbos (aCtx.operator->());
100 myString.FromUnicode (aText.ToCString());
101}
102
103// =======================================================================
104// function : Render
105// purpose :
106// =======================================================================
107void OpenGl_FrameStatsPrs::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
108{
109 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
110 const Standard_Boolean wasEnabledDepth = theWorkspace->UseDepthWrite();
111 if (theWorkspace->UseDepthWrite())
112 {
113 theWorkspace->UseDepthWrite() = Standard_False;
114 glDepthMask (GL_FALSE);
115 }
116
117 aCtx->ModelWorldState.Push();
118 aCtx->ModelWorldState.ChangeCurrent().InitIdentity();
119
120 aCtx->WorldViewState.Push();
121 OpenGl_Mat4& aWorldView = aCtx->WorldViewState.ChangeCurrent();
122 if (!myTrsfPers.IsNull())
123 {
124 myTrsfPers->Apply (theWorkspace->View()->Camera(),
125 aCtx->ProjectionState.Current(), aWorldView,
126 aCtx->VirtualViewport()[2], aCtx->VirtualViewport()[3]);
127 }
128
129 aCtx->ApplyModelViewMatrix();
130
131 const OpenGl_AspectText* aTextAspectBack = theWorkspace->SetAspectText (&myTextAspect);
132 OpenGl_Text::Render (theWorkspace);
133 theWorkspace->SetAspectText (aTextAspectBack);
134
135 aCtx->WorldViewState.Pop();
136 aCtx->ModelWorldState.Pop();
137 aCtx->ApplyWorldViewMatrix();
138
139 if (theWorkspace->UseDepthWrite() != wasEnabledDepth)
140 {
141 theWorkspace->UseDepthWrite() = wasEnabledDepth;
142 glDepthMask (wasEnabledDepth ? GL_TRUE : GL_FALSE);
143 }
144}