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.
21 #include <OpenGl_Group.hxx>
23 #include <OpenGl_TextureBox.hxx>
24 #include <OpenGl_PrimitiveArray.hxx>
26 /*----------------------------------------------------------------------*/
28 OpenGl_Group::OpenGl_Group ()
33 myFirst(NULL), myLast(NULL)
37 OpenGl_Group::~OpenGl_Group()
42 /*----------------------------------------------------------------------*/
44 void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theContext,
45 const Standard_Boolean theIsGlobal)
47 if (theIsGlobal || myFirst == NULL)
49 if (myAspectLine == NULL)
50 myAspectLine = new OpenGl_AspectLine();
51 myAspectLine->SetContext (theContext);
55 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
56 anAspectLine->SetContext (theContext);
57 AddElement (TelNil/*TelAspectLine*/, anAspectLine);
61 /*----------------------------------------------------------------------*/
63 void OpenGl_Group::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theContext,
64 const Standard_Boolean theIsGlobal)
66 if (theIsGlobal || myFirst == NULL)
68 if (myAspectFace == NULL)
69 myAspectFace = new OpenGl_AspectFace();
70 myAspectFace->SetContext (theContext);
74 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
75 anAspectFace->SetContext (theContext);
76 AddElement (TelNil/*TelAspectFace*/, anAspectFace);
80 /*----------------------------------------------------------------------*/
82 void OpenGl_Group::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theContext,
83 const Standard_Boolean theIsGlobal)
85 if (theIsGlobal || myFirst == NULL)
87 if (myAspectMarker == NULL)
88 myAspectMarker = new OpenGl_AspectMarker();
89 myAspectMarker->SetContext (theContext);
93 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
94 anAspectMarker->SetContext (theContext);
95 AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
99 /*----------------------------------------------------------------------*/
101 void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theContext,
102 const Standard_Boolean theIsGlobal)
104 if (theIsGlobal || myFirst == NULL)
106 if (myAspectText == NULL)
107 myAspectText = new OpenGl_AspectText();
108 myAspectText->SetContext (theContext);
112 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
113 anAspectText->SetContext (theContext);
114 AddElement ( TelNil/*TelAspectText*/, anAspectText);
118 /*----------------------------------------------------------------------*/
120 void OpenGl_Group::AddElement (const TelType AType, OpenGl_Element *AElem )
122 OpenGl_ElementNode *node = new OpenGl_ElementNode();
127 (myLast? myLast->next : myFirst) = node;
131 /*----------------------------------------------------------------------*/
133 void OpenGl_Group::Clear ()
137 // Delete line context
143 // Delete face context
149 // Delete marker context
150 delete myAspectMarker;
151 myAspectMarker = NULL;
155 // Delete text context
162 OpenGl_ElementNode *next = myFirst->next;
163 delete myFirst->elem;
170 /*----------------------------------------------------------------------*/
172 void OpenGl_Group::RemovePrimitiveArray (CALL_DEF_PARRAY *APArray)
174 OpenGl_ElementNode *prevnode = NULL, *node = myFirst;
177 if (node->type == TelParray)
179 CALL_DEF_PARRAY *aCurPArray = ((const OpenGl_PrimitiveArray *)node->elem)->PArray();
181 // validate for correct pointer
182 if (aCurPArray->num_bounds == APArray->num_bounds &&
183 aCurPArray->num_edges == APArray->num_edges &&
184 aCurPArray->num_vertexs == APArray->num_vertexs &&
185 aCurPArray->type == APArray->type)
187 (prevnode? prevnode->next : myFirst) = node->next;
188 if (!myFirst) myLast = NULL;
199 /*----------------------------------------------------------------------*/
201 void OpenGl_Group::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
203 // Is rendering in ADD or IMMEDIATE mode?
204 const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
207 const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False);
208 const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False);
209 const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False);
210 const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False);
212 AWorkspace->SetAspectLine(myAspectLine);
214 AWorkspace->SetAspectFace(myAspectFace);
216 AWorkspace->SetAspectMarker(myAspectMarker);
218 AWorkspace->SetAspectText(myAspectText);
220 // Render group elements
221 OpenGl_ElementNode *node = myFirst;
231 glDisable(GL_LIGHTING);
235 glDepthMask(GL_FALSE);
237 else if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
238 (AWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) == 0 &&
239 AWorkspace->DegenerateModel != 0 )
241 glDisable( GL_DEPTH_TEST );
242 if ( AWorkspace->NamedStatus & OPENGL_NS_TEXTURE ) DisableTexture();
243 AWorkspace->NamedStatus |= OPENGL_NS_WIREFRAME;
246 node->elem->Render( AWorkspace );
248 if ( !isImmediate && (AWorkspace->NamedStatus & OPENGL_NS_TEXTURE) != 0 ) EnableTexture();
253 case TelPolygonIndices:
255 case TelTriangleMesh:
259 glDepthMask(GL_FALSE);
261 else if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
262 (AWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) != 0 &&
263 AWorkspace->DegenerateModel < 2 )
265 if ( AWorkspace->NamedStatus & OPENGL_NS_TEXTURE ) EnableTexture ();
267 glEnable( GL_DEPTH_TEST );
268 AWorkspace->NamedStatus &= ~OPENGL_NS_WIREFRAME;
271 if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
272 AWorkspace->DisablePolygonOffset();
274 node->elem->Render( AWorkspace );
276 if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
277 AWorkspace->EnablePolygonOffset();
283 node->elem->Render( AWorkspace );
291 AWorkspace->SetAspectLine(aspect_line);
292 AWorkspace->SetAspectFace(aspect_face);
293 AWorkspace->SetAspectMarker(aspect_marker);
294 AWorkspace->SetAspectText(aspect_text);
297 /*----------------------------------------------------------------------*/