BRepMesh_CircleInspector - fix vc12 compiler error after #0026593
[occt.git] / src / OpenGl / OpenGl_Group.cxx
CommitLineData
b311480e 1// Created on: 2011-08-01
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
2166f0fa 15
e276548b 16#include <OpenGl_Group.hxx>
b64d84be 17
18#include <OpenGl_GraphicDriver.hxx>
19#include <OpenGl_Flipper.hxx>
2166f0fa 20#include <OpenGl_PrimitiveArray.hxx>
b64d84be 21#include <OpenGl_StencilTest.hxx>
e276548b 22#include <OpenGl_Structure.hxx>
b64d84be 23#include <OpenGl_Text.hxx>
bf75be98 24#include <OpenGl_Workspace.hxx>
2166f0fa 25
b64d84be 26#include <Graphic3d_ArrayOfPrimitives.hxx>
27#include <Graphic3d_CUserDraw.hxx>
28#include <Graphic3d_GroupDefinitionError.hxx>
29
b64d84be 30
4269bd1b 31// =======================================================================
32// function : OpenGl_Group
33// purpose :
34// =======================================================================
b64d84be 35OpenGl_Group::OpenGl_Group (const Handle(Graphic3d_Structure)& theStruct)
36: Graphic3d_Group (theStruct),
37 myAspectLine(NULL),
e276548b 38 myAspectFace(NULL),
39 myAspectMarker(NULL),
40 myAspectText(NULL),
41 myFirst(NULL),
b64d84be 42 myLast(NULL),
d4aaad5b 43 myIsRaytracable (Standard_False)
2166f0fa 44{
b64d84be 45 Handle(OpenGl_Structure) aStruct = Handle(OpenGl_Structure)::DownCast (myStructure->CStructure());
c04c30b3 46 if (aStruct.IsNull())
b64d84be 47 {
48 Graphic3d_GroupDefinitionError::Raise ("OpenGl_Group should be created by OpenGl_Structure!");
49 }
2166f0fa
SK
50}
51
4269bd1b 52// =======================================================================
53// function : ~OpenGl_Group
54// purpose :
55// =======================================================================
2166f0fa
SK
56OpenGl_Group::~OpenGl_Group()
57{
5e27df78 58 Release (Handle(OpenGl_Context)());
2166f0fa
SK
59}
60
4269bd1b 61// =======================================================================
b64d84be 62// function : UpdateAspectLine
4269bd1b 63// purpose :
64// =======================================================================
b64d84be 65void OpenGl_Group::UpdateAspectLine (const Standard_Boolean theIsGlobal)
2166f0fa 66{
b64d84be 67 if (!ContextLine.IsDef)
68 {
69 return;
70 }
71
2166f0fa
SK
72 if (theIsGlobal || myFirst == NULL)
73 {
74 if (myAspectLine == NULL)
fd4a6963 75 {
2166f0fa 76 myAspectLine = new OpenGl_AspectLine();
fd4a6963 77 }
b64d84be 78 myAspectLine->SetAspect (ContextLine);
2166f0fa
SK
79 }
80 else
81 {
82 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
b64d84be 83 anAspectLine->SetAspect (ContextLine);
5322131b 84 AddElement (anAspectLine);
2166f0fa
SK
85 }
86}
87
4269bd1b 88// =======================================================================
b64d84be 89// function : UpdateAspectFace
4269bd1b 90// purpose :
91// =======================================================================
b64d84be 92void OpenGl_Group::UpdateAspectFace (const Standard_Boolean theIsGlobal)
2166f0fa 93{
b64d84be 94 if (!ContextFillArea.IsDef)
95 {
96 return;
97 }
98
2166f0fa
SK
99 if (theIsGlobal || myFirst == NULL)
100 {
101 if (myAspectFace == NULL)
bf75be98 102 {
2166f0fa 103 myAspectFace = new OpenGl_AspectFace();
bf75be98 104 }
b64d84be 105 myAspectFace->SetAspect (ContextFillArea);
2166f0fa
SK
106 }
107 else
108 {
109 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
b64d84be 110 anAspectFace->SetAspect (ContextFillArea);
5322131b 111 AddElement (anAspectFace);
2166f0fa 112 }
e276548b 113
e276548b 114 if (myIsRaytracable)
115 {
b64d84be 116 OpenGl_Structure* aStruct = GlStruct();
117 if (aStruct != NULL)
e276548b 118 {
d4aaad5b 119 aStruct->UpdateStateIfRaytracable (Standard_False);
e276548b 120 }
121 }
2166f0fa
SK
122}
123
4269bd1b 124// =======================================================================
b64d84be 125// function : UpdateAspectMarker
4269bd1b 126// purpose :
127// =======================================================================
b64d84be 128void OpenGl_Group::UpdateAspectMarker (const Standard_Boolean theIsGlobal)
2166f0fa 129{
b64d84be 130 if (!ContextMarker.IsDef)
131 {
132 return;
133 }
134
2166f0fa
SK
135 if (theIsGlobal || myFirst == NULL)
136 {
137 if (myAspectMarker == NULL)
a577aaab 138 {
2166f0fa 139 myAspectMarker = new OpenGl_AspectMarker();
a577aaab 140 }
b64d84be 141 myAspectMarker->SetAspect (ContextMarker);
2166f0fa
SK
142 }
143 else
144 {
145 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
b64d84be 146 anAspectMarker->SetAspect (ContextMarker);
5322131b 147 AddElement (anAspectMarker);
2166f0fa
SK
148 }
149}
150
4269bd1b 151// =======================================================================
b64d84be 152// function : UpdateAspectText
4269bd1b 153// purpose :
154// =======================================================================
b64d84be 155void OpenGl_Group::UpdateAspectText (const Standard_Boolean theIsGlobal)
2166f0fa 156{
b64d84be 157 if (!ContextText.IsDef)
158 {
159 return;
160 }
161
2166f0fa
SK
162 if (theIsGlobal || myFirst == NULL)
163 {
164 if (myAspectText == NULL)
fd4a6963 165 {
2166f0fa 166 myAspectText = new OpenGl_AspectText();
fd4a6963 167 }
b64d84be 168 myAspectText->SetAspect (ContextText);
2166f0fa
SK
169 }
170 else
171 {
172 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
b64d84be 173 anAspectText->SetAspect (ContextText);
5322131b 174 AddElement (anAspectText);
2166f0fa
SK
175 }
176}
177
4269bd1b 178// =======================================================================
b64d84be 179// function : AddPrimitiveArray
180// purpose :
181// =======================================================================
871fa103 182void OpenGl_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
183 const Handle(Graphic3d_IndexBuffer)& theIndices,
184 const Handle(Graphic3d_Buffer)& theAttribs,
185 const Handle(Graphic3d_BoundBuffer)& theBounds,
186 const Standard_Boolean theToEvalMinMax)
b64d84be 187{
188 if (IsDeleted()
871fa103 189 || theAttribs.IsNull())
b64d84be 190 {
191 return;
192 }
193
8d3f219f 194 OpenGl_Structure* aStruct = GlStruct();
195 const OpenGl_GraphicDriver* aDriver = aStruct->GlDriver();
196
197 OpenGl_PrimitiveArray* anArray = new OpenGl_PrimitiveArray (aDriver, theType, theIndices, theAttribs, theBounds);
b64d84be 198 AddElement (anArray);
199
871fa103 200 Graphic3d_Group::AddPrimitiveArray (theType, theIndices, theAttribs, theBounds, theToEvalMinMax);
b64d84be 201}
202
203// =======================================================================
204// function : Text
205// purpose :
206// =======================================================================
207void OpenGl_Group::Text (const Standard_CString theTextUtf,
208 const Graphic3d_Vertex& thePoint,
209 const Standard_Real theHeight,
210 const Quantity_PlaneAngle theAngle,
211 const Graphic3d_TextPath theTp,
212 const Graphic3d_HorizontalTextAlignment theHta,
213 const Graphic3d_VerticalTextAlignment theVta,
214 const Standard_Boolean theToEvalMinMax)
215{
216 if (IsDeleted())
217 {
218 return;
219 }
220
221 OpenGl_TextParam aParams;
222 OpenGl_Structure* aStruct = GlStruct();
223 aParams.Height = int ((theHeight < 2.0) ? aStruct->GlDriver()->DefaultTextHeight() : theHeight);
224 aParams.HAlign = theHta;
225 aParams.VAlign = theVta;
226 const OpenGl_Vec3 aPoint (thePoint.X(), thePoint.Y(), thePoint.Z());
227 OpenGl_Text* aText = new OpenGl_Text (theTextUtf, aPoint, aParams);
228 AddElement (aText);
229 Graphic3d_Group::Text (theTextUtf, thePoint, theHeight, theAngle,
230 theTp, theHta, theVta, theToEvalMinMax);
231}
232
233// =======================================================================
234// function : UserDraw
235// purpose :
236// =======================================================================
237void OpenGl_Group::UserDraw (const Standard_Address theObject,
238 const Standard_Boolean theToEvalMinMax,
239 const Standard_Boolean theContainsFacet)
240{
241 if (IsDeleted())
242 {
243 return;
244 }
245
246 OpenGl_Structure* aStruct = GlStruct();
247 if (aStruct->GlDriver()->UserDrawCallback() == NULL)
248 {
249 return;
250 }
251
252 Graphic3d_CUserDraw aUserDraw;
253 aUserDraw.Data = theObject;
254 aUserDraw.Bounds = theToEvalMinMax ? &myBounds : NULL;
255 OpenGl_Element* aUserDrawElem = aStruct->GlDriver()->UserDrawCallback()(&aUserDraw);
256 if (aUserDrawElem != NULL)
257 {
258 AddElement (aUserDrawElem);
259 }
260 Graphic3d_Group::UserDraw (theObject, theToEvalMinMax, theContainsFacet);
261}
262
263// =======================================================================
264// function : SetFlippingOptions
265// purpose :
266// =======================================================================
267void OpenGl_Group::SetFlippingOptions (const Standard_Boolean theIsEnabled,
268 const gp_Ax2& theRefPlane)
269{
270 OpenGl_Flipper* aFlipper = new OpenGl_Flipper (theRefPlane);
271 aFlipper->SetOptions (theIsEnabled);
272 AddElement (aFlipper);
273}
274
275// =======================================================================
276// function : SetStencilTestOptions
277// purpose :
278// =======================================================================
279void OpenGl_Group::SetStencilTestOptions (const Standard_Boolean theIsEnabled)
280{
281 OpenGl_StencilTest* aStencilTest = new OpenGl_StencilTest();
282 aStencilTest->SetOptions (theIsEnabled);
283 AddElement (aStencilTest);
284}
285
286// =======================================================================
4269bd1b 287// function : AddElement
288// purpose :
289// =======================================================================
5322131b 290void OpenGl_Group::AddElement (OpenGl_Element* theElem)
2166f0fa 291{
e276548b 292 OpenGl_ElementNode *aNode = new OpenGl_ElementNode();
293
e276548b 294 aNode->elem = theElem;
295 aNode->next = NULL;
296 (myLast? myLast->next : myFirst) = aNode;
297 myLast = aNode;
298
e276548b 299 if (OpenGl_Raytrace::IsRaytracedElement (aNode))
300 {
e276548b 301 myIsRaytracable = Standard_True;
2166f0fa 302
b64d84be 303 OpenGl_Structure* aStruct = GlStruct();
304 if (aStruct != NULL)
e276548b 305 {
d4aaad5b 306 aStruct->UpdateStateIfRaytracable (Standard_False);
e276548b 307 }
308 }
2166f0fa
SK
309}
310
4269bd1b 311// =======================================================================
312// function : Render
313// purpose :
314// =======================================================================
bf75be98 315void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa
SK
316{
317 // Is rendering in ADD or IMMEDIATE mode?
4269bd1b 318 const Handle(OpenGl_RenderFilter)& aFilter = theWorkspace->GetRenderFilter();
2166f0fa
SK
319
320 // Setup aspects
bf75be98 321 const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine (Standard_False);
322 const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace (Standard_False);
323 const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker (Standard_False);
324 const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText (Standard_False);
4269bd1b 325 Standard_Boolean isLineSet = myAspectLine && myAspectLine->RenderFiltered (theWorkspace, aFilter);
326 Standard_Boolean isFaceSet = myAspectFace && myAspectFace->RenderFiltered (theWorkspace, aFilter);
327 Standard_Boolean isMarkerSet = myAspectMarker && myAspectMarker->RenderFiltered (theWorkspace, aFilter);
328 Standard_Boolean isTextSet = myAspectText && myAspectText->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
329
330 // Render group elements
bf75be98 331 for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
2166f0fa 332 {
5322131b 333 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
334 }
335
336 // Restore aspects
4269bd1b 337 if (isLineSet)
338 theWorkspace->SetAspectLine (aBackAspectLine);
339 if (isFaceSet)
340 theWorkspace->SetAspectFace (aBackAspectFace);
341 if (isMarkerSet)
342 theWorkspace->SetAspectMarker (aBackAspectMarker);
343 if (isTextSet)
344 theWorkspace->SetAspectText (aBackAspectText);
2166f0fa
SK
345}
346
4269bd1b 347// =======================================================================
b64d84be 348// function : Clear
349// purpose :
350// =======================================================================
351void OpenGl_Group::Clear (const Standard_Boolean theToUpdateStructureMgr)
352{
353 if (IsDeleted())
354 {
355 return;
356 }
357
358 OpenGl_Structure* aStruct = GlStruct();
359 const Handle(OpenGl_Context)& aCtx = aStruct->GlDriver()->GetSharedContext();
360
361 Release (aCtx);
362 Graphic3d_Group::Clear (theToUpdateStructureMgr);
d4aaad5b 363
364 myIsRaytracable = Standard_False;
b64d84be 365}
366
367// =======================================================================
4269bd1b 368// function : Release
369// purpose :
370// =======================================================================
5e27df78 371void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
372{
373 // Delete elements
374 while (myFirst != NULL)
375 {
376 OpenGl_ElementNode* aNext = myFirst->next;
10b9c7df 377 OpenGl_Element::Destroy (theGlCtx.operator->(), myFirst->elem);
5e27df78 378 delete myFirst;
379 myFirst = aNext;
380 }
381 myLast = NULL;
382
10b9c7df 383 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectLine);
384 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectFace);
385 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectMarker);
386 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectText);
5e27df78 387}