0024530: TKMesh - remove unused package IntPoly
[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//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public 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.
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#ifdef HAVE_CONFIG_H
17 #include <config.h>
18#endif
19
20#include <OpenGl_Group.hxx>
2166f0fa 21#include <OpenGl_PrimitiveArray.hxx>
e276548b 22#include <OpenGl_Structure.hxx>
bf75be98 23#include <OpenGl_Workspace.hxx>
2166f0fa 24
4269bd1b 25// =======================================================================
26// function : OpenGl_Group
27// purpose :
28// =======================================================================
e276548b 29#ifndef HAVE_OPENCL
30OpenGl_Group::OpenGl_Group()
31#else
32OpenGl_Group::OpenGl_Group (const OpenGl_Structure* theAncestorStructure)
33#endif
34: myAspectLine(NULL),
35 myAspectFace(NULL),
36 myAspectMarker(NULL),
37 myAspectText(NULL),
38 myFirst(NULL),
39 myLast(NULL)
2166f0fa 40{
e276548b 41#ifdef HAVE_OPENCL
42 myAncestorStructure = theAncestorStructure;
43 myIsRaytracable = Standard_False;
44 myModificationState = 0; // initial state
45#endif
2166f0fa
SK
46}
47
4269bd1b 48// =======================================================================
49// function : ~OpenGl_Group
50// purpose :
51// =======================================================================
2166f0fa
SK
52OpenGl_Group::~OpenGl_Group()
53{
5e27df78 54 Release (Handle(OpenGl_Context)());
2166f0fa
SK
55}
56
4269bd1b 57// =======================================================================
58// function : SetAspectLine
59// purpose :
60// =======================================================================
fd4a6963 61void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theAspect,
2166f0fa
SK
62 const Standard_Boolean theIsGlobal)
63{
64 if (theIsGlobal || myFirst == NULL)
65 {
66 if (myAspectLine == NULL)
fd4a6963 67 {
2166f0fa 68 myAspectLine = new OpenGl_AspectLine();
fd4a6963 69 }
70 myAspectLine->SetAspect (theAspect);
2166f0fa
SK
71 }
72 else
73 {
74 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
fd4a6963 75 anAspectLine->SetAspect (theAspect);
5322131b 76 AddElement (anAspectLine);
2166f0fa
SK
77 }
78}
79
4269bd1b 80// =======================================================================
81// function : SetAspectFace
82// purpose :
83// =======================================================================
fd4a6963 84void OpenGl_Group::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect,
bf75be98 85 const Standard_Boolean theIsGlobal)
2166f0fa
SK
86{
87 if (theIsGlobal || myFirst == NULL)
88 {
89 if (myAspectFace == NULL)
bf75be98 90 {
2166f0fa 91 myAspectFace = new OpenGl_AspectFace();
bf75be98 92 }
fd4a6963 93 myAspectFace->SetAspect (theAspect);
2166f0fa
SK
94 }
95 else
96 {
97 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
fd4a6963 98 anAspectFace->SetAspect (theAspect);
5322131b 99 AddElement (anAspectFace);
2166f0fa 100 }
e276548b 101
102#ifdef HAVE_OPENCL
103 if (myIsRaytracable)
104 {
105 myModificationState++;
106
107 if (myAncestorStructure != NULL)
108 {
109 myAncestorStructure->UpdateStateWithAncestorStructures();
110 }
111 }
112#endif
2166f0fa
SK
113}
114
4269bd1b 115// =======================================================================
116// function : SetAspectMarker
117// purpose :
118// =======================================================================
fd4a6963 119void OpenGl_Group::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect,
2166f0fa
SK
120 const Standard_Boolean theIsGlobal)
121{
122 if (theIsGlobal || myFirst == NULL)
123 {
124 if (myAspectMarker == NULL)
a577aaab 125 {
2166f0fa 126 myAspectMarker = new OpenGl_AspectMarker();
a577aaab 127 }
fd4a6963 128 myAspectMarker->SetAspect (theAspect);
2166f0fa
SK
129 }
130 else
131 {
132 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
fd4a6963 133 anAspectMarker->SetAspect (theAspect);
5322131b 134 AddElement (anAspectMarker);
2166f0fa
SK
135 }
136}
137
4269bd1b 138// =======================================================================
139// function : SetAspectText
140// purpose :
141// =======================================================================
fd4a6963 142void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theAspect,
2166f0fa
SK
143 const Standard_Boolean theIsGlobal)
144{
145 if (theIsGlobal || myFirst == NULL)
146 {
147 if (myAspectText == NULL)
fd4a6963 148 {
2166f0fa 149 myAspectText = new OpenGl_AspectText();
fd4a6963 150 }
151 myAspectText->SetAspect (theAspect);
2166f0fa
SK
152 }
153 else
154 {
155 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
fd4a6963 156 anAspectText->SetAspect (theAspect);
5322131b 157 AddElement (anAspectText);
2166f0fa
SK
158 }
159}
160
4269bd1b 161// =======================================================================
162// function : AddElement
163// purpose :
164// =======================================================================
5322131b 165void OpenGl_Group::AddElement (OpenGl_Element* theElem)
2166f0fa 166{
e276548b 167 OpenGl_ElementNode *aNode = new OpenGl_ElementNode();
168
e276548b 169 aNode->elem = theElem;
170 aNode->next = NULL;
171 (myLast? myLast->next : myFirst) = aNode;
172 myLast = aNode;
173
174#ifdef HAVE_OPENCL
175 if (OpenGl_Raytrace::IsRaytracedElement (aNode))
176 {
177 myModificationState++;
178 myIsRaytracable = Standard_True;
2166f0fa 179
e276548b 180 if (myAncestorStructure != NULL)
181 {
182 myAncestorStructure->UpdateStateWithAncestorStructures();
183 myAncestorStructure->SetRaytracableWithAncestorStructures();
184 }
185 }
186#endif
2166f0fa
SK
187}
188
4269bd1b 189// =======================================================================
190// function : Render
191// purpose :
192// =======================================================================
bf75be98 193void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa
SK
194{
195 // Is rendering in ADD or IMMEDIATE mode?
4269bd1b 196 const Handle(OpenGl_RenderFilter)& aFilter = theWorkspace->GetRenderFilter();
2166f0fa
SK
197
198 // Setup aspects
bf75be98 199 const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine (Standard_False);
200 const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace (Standard_False);
201 const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker (Standard_False);
202 const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText (Standard_False);
4269bd1b 203 Standard_Boolean isLineSet = myAspectLine && myAspectLine->RenderFiltered (theWorkspace, aFilter);
204 Standard_Boolean isFaceSet = myAspectFace && myAspectFace->RenderFiltered (theWorkspace, aFilter);
205 Standard_Boolean isMarkerSet = myAspectMarker && myAspectMarker->RenderFiltered (theWorkspace, aFilter);
206 Standard_Boolean isTextSet = myAspectText && myAspectText->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
207
208 // Render group elements
bf75be98 209 for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
2166f0fa 210 {
5322131b 211 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
212 }
213
214 // Restore aspects
4269bd1b 215 if (isLineSet)
216 theWorkspace->SetAspectLine (aBackAspectLine);
217 if (isFaceSet)
218 theWorkspace->SetAspectFace (aBackAspectFace);
219 if (isMarkerSet)
220 theWorkspace->SetAspectMarker (aBackAspectMarker);
221 if (isTextSet)
222 theWorkspace->SetAspectText (aBackAspectText);
2166f0fa
SK
223}
224
4269bd1b 225// =======================================================================
226// function : Release
227// purpose :
228// =======================================================================
5e27df78 229void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
230{
231 // Delete elements
232 while (myFirst != NULL)
233 {
234 OpenGl_ElementNode* aNext = myFirst->next;
235 OpenGl_Element::Destroy (theGlCtx, myFirst->elem);
236 delete myFirst;
237 myFirst = aNext;
238 }
239 myLast = NULL;
240
241 OpenGl_Element::Destroy (theGlCtx, myAspectLine);
242 OpenGl_Element::Destroy (theGlCtx, myAspectFace);
243 OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
244 OpenGl_Element::Destroy (theGlCtx, myAspectText);
245}