0024588: Fix some ICC warning fixes
[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);
2166f0fa
SK
76 AddElement (TelNil/*TelAspectLine*/, anAspectLine);
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);
2166f0fa
SK
99 AddElement (TelNil/*TelAspectFace*/, anAspectFace);
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);
2166f0fa
SK
134 AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
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);
2166f0fa
SK
157 AddElement ( TelNil/*TelAspectText*/, anAspectText);
158 }
159}
160
4269bd1b 161// =======================================================================
162// function : AddElement
163// purpose :
164// =======================================================================
e276548b 165void OpenGl_Group::AddElement (const TelType theType, OpenGl_Element *theElem)
2166f0fa 166{
e276548b 167 OpenGl_ElementNode *aNode = new OpenGl_ElementNode();
168
169 aNode->type = theType;
170 aNode->elem = theElem;
171 aNode->next = NULL;
172 (myLast? myLast->next : myFirst) = aNode;
173 myLast = aNode;
174
175#ifdef HAVE_OPENCL
176 if (OpenGl_Raytrace::IsRaytracedElement (aNode))
177 {
178 myModificationState++;
179 myIsRaytracable = Standard_True;
2166f0fa 180
e276548b 181 if (myAncestorStructure != NULL)
182 {
183 myAncestorStructure->UpdateStateWithAncestorStructures();
184 myAncestorStructure->SetRaytracableWithAncestorStructures();
185 }
186 }
187#endif
2166f0fa
SK
188}
189
4269bd1b 190// =======================================================================
191// function : Render
192// purpose :
193// =======================================================================
bf75be98 194void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa
SK
195{
196 // Is rendering in ADD or IMMEDIATE mode?
bf75be98 197 const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
4269bd1b 198 const Handle(OpenGl_RenderFilter)& aFilter = theWorkspace->GetRenderFilter();
2166f0fa
SK
199
200 // Setup aspects
bf75be98 201 const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine (Standard_False);
202 const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace (Standard_False);
203 const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker (Standard_False);
204 const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText (Standard_False);
4269bd1b 205 Standard_Boolean isLineSet = myAspectLine && myAspectLine->RenderFiltered (theWorkspace, aFilter);
206 Standard_Boolean isFaceSet = myAspectFace && myAspectFace->RenderFiltered (theWorkspace, aFilter);
207 Standard_Boolean isMarkerSet = myAspectMarker && myAspectMarker->RenderFiltered (theWorkspace, aFilter);
208 Standard_Boolean isTextSet = myAspectText && myAspectText->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
209
210 // Render group elements
bf75be98 211 for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
2166f0fa 212 {
bf75be98 213 switch (aNodeIter->type)
2166f0fa 214 {
2166f0fa
SK
215 case TelMarker:
216 case TelMarkerSet:
217 case TelText:
218 {
bf75be98 219 glDisable (GL_LIGHTING);
2166f0fa
SK
220 if (isImmediate)
221 {
bf75be98 222 glDepthMask (GL_FALSE);
2166f0fa 223 }
2166f0fa 224
4269bd1b 225 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
226 break;
227 }
2166f0fa
SK
228 default:
229 {
4269bd1b 230 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
231 break;
232 }
233 }
2166f0fa
SK
234 }
235
236 // Restore aspects
4269bd1b 237 if (isLineSet)
238 theWorkspace->SetAspectLine (aBackAspectLine);
239 if (isFaceSet)
240 theWorkspace->SetAspectFace (aBackAspectFace);
241 if (isMarkerSet)
242 theWorkspace->SetAspectMarker (aBackAspectMarker);
243 if (isTextSet)
244 theWorkspace->SetAspectText (aBackAspectText);
2166f0fa
SK
245}
246
4269bd1b 247// =======================================================================
248// function : Release
249// purpose :
250// =======================================================================
5e27df78 251void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
252{
253 // Delete elements
254 while (myFirst != NULL)
255 {
256 OpenGl_ElementNode* aNext = myFirst->next;
257 OpenGl_Element::Destroy (theGlCtx, myFirst->elem);
258 delete myFirst;
259 myFirst = aNext;
260 }
261 myLast = NULL;
262
263 OpenGl_Element::Destroy (theGlCtx, myAspectLine);
264 OpenGl_Element::Destroy (theGlCtx, myAspectFace);
265 OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
266 OpenGl_Element::Destroy (theGlCtx, myAspectText);
267}