1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
25 #include <OpenGl_Group.hxx>
26 #include <OpenGl_PrimitiveArray.hxx>
27 #include <OpenGl_Structure.hxx>
28 #include <OpenGl_Workspace.hxx>
30 // =======================================================================
31 // function : OpenGl_Group
33 // =======================================================================
35 OpenGl_Group::OpenGl_Group()
37 OpenGl_Group::OpenGl_Group (const OpenGl_Structure* theAncestorStructure)
47 myAncestorStructure = theAncestorStructure;
48 myIsRaytracable = Standard_False;
49 myModificationState = 0; // initial state
53 // =======================================================================
54 // function : ~OpenGl_Group
56 // =======================================================================
57 OpenGl_Group::~OpenGl_Group()
59 Release (Handle(OpenGl_Context)());
62 // =======================================================================
63 // function : SetAspectLine
65 // =======================================================================
66 void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theAspect,
67 const Standard_Boolean theIsGlobal)
69 if (theIsGlobal || myFirst == NULL)
71 if (myAspectLine == NULL)
73 myAspectLine = new OpenGl_AspectLine();
75 myAspectLine->SetAspect (theAspect);
79 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
80 anAspectLine->SetAspect (theAspect);
81 AddElement (TelNil/*TelAspectLine*/, anAspectLine);
85 // =======================================================================
86 // function : SetAspectFace
88 // =======================================================================
89 void OpenGl_Group::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect,
90 const Standard_Boolean theIsGlobal)
92 if (theIsGlobal || myFirst == NULL)
94 if (myAspectFace == NULL)
96 myAspectFace = new OpenGl_AspectFace();
98 myAspectFace->SetAspect (theAspect);
102 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
103 anAspectFace->SetAspect (theAspect);
104 AddElement (TelNil/*TelAspectFace*/, anAspectFace);
110 myModificationState++;
112 if (myAncestorStructure != NULL)
114 myAncestorStructure->UpdateStateWithAncestorStructures();
120 // =======================================================================
121 // function : SetAspectMarker
123 // =======================================================================
124 void OpenGl_Group::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect,
125 const Standard_Boolean theIsGlobal)
127 if (theIsGlobal || myFirst == NULL)
129 if (myAspectMarker == NULL)
131 myAspectMarker = new OpenGl_AspectMarker();
133 myAspectMarker->SetAspect (theAspect);
137 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
138 anAspectMarker->SetAspect (theAspect);
139 AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
143 // =======================================================================
144 // function : SetAspectText
146 // =======================================================================
147 void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theAspect,
148 const Standard_Boolean theIsGlobal)
150 if (theIsGlobal || myFirst == NULL)
152 if (myAspectText == NULL)
154 myAspectText = new OpenGl_AspectText();
156 myAspectText->SetAspect (theAspect);
160 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
161 anAspectText->SetAspect (theAspect);
162 AddElement ( TelNil/*TelAspectText*/, anAspectText);
166 // =======================================================================
167 // function : AddElement
169 // =======================================================================
170 void OpenGl_Group::AddElement (const TelType theType, OpenGl_Element *theElem)
172 OpenGl_ElementNode *aNode = new OpenGl_ElementNode();
174 aNode->type = theType;
175 aNode->elem = theElem;
177 (myLast? myLast->next : myFirst) = aNode;
181 if (OpenGl_Raytrace::IsRaytracedElement (aNode))
183 myModificationState++;
184 myIsRaytracable = Standard_True;
186 if (myAncestorStructure != NULL)
188 myAncestorStructure->UpdateStateWithAncestorStructures();
189 myAncestorStructure->SetRaytracableWithAncestorStructures();
195 // =======================================================================
198 // =======================================================================
199 void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
201 // Is rendering in ADD or IMMEDIATE mode?
202 const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
203 const Handle(OpenGl_RenderFilter)& aFilter = theWorkspace->GetRenderFilter();
206 const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine (Standard_False);
207 const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace (Standard_False);
208 const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker (Standard_False);
209 const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText (Standard_False);
210 Standard_Boolean isLineSet = myAspectLine && myAspectLine->RenderFiltered (theWorkspace, aFilter);
211 Standard_Boolean isFaceSet = myAspectFace && myAspectFace->RenderFiltered (theWorkspace, aFilter);
212 Standard_Boolean isMarkerSet = myAspectMarker && myAspectMarker->RenderFiltered (theWorkspace, aFilter);
213 Standard_Boolean isTextSet = myAspectText && myAspectText->RenderFiltered (theWorkspace, aFilter);
215 // Render group elements
216 for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
218 switch (aNodeIter->type)
224 glDisable (GL_LIGHTING);
227 glDepthMask (GL_FALSE);
230 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
235 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
243 theWorkspace->SetAspectLine (aBackAspectLine);
245 theWorkspace->SetAspectFace (aBackAspectFace);
247 theWorkspace->SetAspectMarker (aBackAspectMarker);
249 theWorkspace->SetAspectText (aBackAspectText);
252 // =======================================================================
253 // function : Release
255 // =======================================================================
256 void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
259 while (myFirst != NULL)
261 OpenGl_ElementNode* aNext = myFirst->next;
262 OpenGl_Element::Destroy (theGlCtx, myFirst->elem);
268 OpenGl_Element::Destroy (theGlCtx, myAspectLine);
269 OpenGl_Element::Destroy (theGlCtx, myAspectFace);
270 OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
271 OpenGl_Element::Destroy (theGlCtx, myAspectText);