1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
20 #include <OpenGl_Group.hxx>
21 #include <OpenGl_PrimitiveArray.hxx>
22 #include <OpenGl_Structure.hxx>
23 #include <OpenGl_Workspace.hxx>
25 // =======================================================================
26 // function : OpenGl_Group
28 // =======================================================================
30 OpenGl_Group::OpenGl_Group()
32 OpenGl_Group::OpenGl_Group (const OpenGl_Structure* theAncestorStructure)
42 myAncestorStructure = theAncestorStructure;
43 myIsRaytracable = Standard_False;
44 myModificationState = 0; // initial state
48 // =======================================================================
49 // function : ~OpenGl_Group
51 // =======================================================================
52 OpenGl_Group::~OpenGl_Group()
54 Release (Handle(OpenGl_Context)());
57 // =======================================================================
58 // function : SetAspectLine
60 // =======================================================================
61 void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theAspect,
62 const Standard_Boolean theIsGlobal)
64 if (theIsGlobal || myFirst == NULL)
66 if (myAspectLine == NULL)
68 myAspectLine = new OpenGl_AspectLine();
70 myAspectLine->SetAspect (theAspect);
74 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
75 anAspectLine->SetAspect (theAspect);
76 AddElement (TelNil/*TelAspectLine*/, anAspectLine);
80 // =======================================================================
81 // function : SetAspectFace
83 // =======================================================================
84 void OpenGl_Group::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect,
85 const Standard_Boolean theIsGlobal)
87 if (theIsGlobal || myFirst == NULL)
89 if (myAspectFace == NULL)
91 myAspectFace = new OpenGl_AspectFace();
93 myAspectFace->SetAspect (theAspect);
97 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
98 anAspectFace->SetAspect (theAspect);
99 AddElement (TelNil/*TelAspectFace*/, anAspectFace);
105 myModificationState++;
107 if (myAncestorStructure != NULL)
109 myAncestorStructure->UpdateStateWithAncestorStructures();
115 // =======================================================================
116 // function : SetAspectMarker
118 // =======================================================================
119 void OpenGl_Group::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect,
120 const Standard_Boolean theIsGlobal)
122 if (theIsGlobal || myFirst == NULL)
124 if (myAspectMarker == NULL)
126 myAspectMarker = new OpenGl_AspectMarker();
128 myAspectMarker->SetAspect (theAspect);
132 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
133 anAspectMarker->SetAspect (theAspect);
134 AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
138 // =======================================================================
139 // function : SetAspectText
141 // =======================================================================
142 void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theAspect,
143 const Standard_Boolean theIsGlobal)
145 if (theIsGlobal || myFirst == NULL)
147 if (myAspectText == NULL)
149 myAspectText = new OpenGl_AspectText();
151 myAspectText->SetAspect (theAspect);
155 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
156 anAspectText->SetAspect (theAspect);
157 AddElement ( TelNil/*TelAspectText*/, anAspectText);
161 // =======================================================================
162 // function : AddElement
164 // =======================================================================
165 void OpenGl_Group::AddElement (const TelType theType, OpenGl_Element *theElem)
167 OpenGl_ElementNode *aNode = new OpenGl_ElementNode();
169 aNode->type = theType;
170 aNode->elem = theElem;
172 (myLast? myLast->next : myFirst) = aNode;
176 if (OpenGl_Raytrace::IsRaytracedElement (aNode))
178 myModificationState++;
179 myIsRaytracable = Standard_True;
181 if (myAncestorStructure != NULL)
183 myAncestorStructure->UpdateStateWithAncestorStructures();
184 myAncestorStructure->SetRaytracableWithAncestorStructures();
190 // =======================================================================
193 // =======================================================================
194 void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
196 // Is rendering in ADD or IMMEDIATE mode?
197 const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
198 const Handle(OpenGl_RenderFilter)& aFilter = theWorkspace->GetRenderFilter();
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);
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);
210 // Render group elements
211 for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
213 switch (aNodeIter->type)
219 glDisable (GL_LIGHTING);
222 glDepthMask (GL_FALSE);
225 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
230 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
238 theWorkspace->SetAspectLine (aBackAspectLine);
240 theWorkspace->SetAspectFace (aBackAspectFace);
242 theWorkspace->SetAspectMarker (aBackAspectMarker);
244 theWorkspace->SetAspectText (aBackAspectText);
247 // =======================================================================
248 // function : Release
250 // =======================================================================
251 void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
254 while (myFirst != NULL)
256 OpenGl_ElementNode* aNext = myFirst->next;
257 OpenGl_Element::Destroy (theGlCtx, myFirst->elem);
263 OpenGl_Element::Destroy (theGlCtx, myAspectLine);
264 OpenGl_Element::Destroy (theGlCtx, myAspectFace);
265 OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
266 OpenGl_Element::Destroy (theGlCtx, myAspectText);