1 // File: OpenGl_Group.cxx
2 // Created: 1 August 2011
3 // Author: Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
6 #include <OpenGl_Group.hxx>
8 #include <OpenGl_TextureBox.hxx>
9 #include <OpenGl_PrimitiveArray.hxx>
11 /*----------------------------------------------------------------------*/
13 OpenGl_Group::OpenGl_Group ()
18 myFirst(NULL), myLast(NULL)
22 OpenGl_Group::~OpenGl_Group()
27 /*----------------------------------------------------------------------*/
29 void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theContext,
30 const Standard_Boolean theIsGlobal)
32 if (theIsGlobal || myFirst == NULL)
34 if (myAspectLine == NULL)
35 myAspectLine = new OpenGl_AspectLine();
36 myAspectLine->SetContext (theContext);
40 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
41 anAspectLine->SetContext (theContext);
42 AddElement (TelNil/*TelAspectLine*/, anAspectLine);
46 /*----------------------------------------------------------------------*/
48 void OpenGl_Group::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theContext,
49 const Standard_Boolean theIsGlobal)
51 if (theIsGlobal || myFirst == NULL)
53 if (myAspectFace == NULL)
54 myAspectFace = new OpenGl_AspectFace();
55 myAspectFace->SetContext (theContext);
59 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
60 anAspectFace->SetContext (theContext);
61 AddElement (TelNil/*TelAspectFace*/, anAspectFace);
65 /*----------------------------------------------------------------------*/
67 void OpenGl_Group::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theContext,
68 const Standard_Boolean theIsGlobal)
70 if (theIsGlobal || myFirst == NULL)
72 if (myAspectMarker == NULL)
73 myAspectMarker = new OpenGl_AspectMarker();
74 myAspectMarker->SetContext (theContext);
78 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
79 anAspectMarker->SetContext (theContext);
80 AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
84 /*----------------------------------------------------------------------*/
86 void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theContext,
87 const Standard_Boolean theIsGlobal)
89 if (theIsGlobal || myFirst == NULL)
91 if (myAspectText == NULL)
92 myAspectText = new OpenGl_AspectText();
93 myAspectText->SetContext (theContext);
97 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
98 anAspectText->SetContext (theContext);
99 AddElement ( TelNil/*TelAspectText*/, anAspectText);
103 /*----------------------------------------------------------------------*/
105 void OpenGl_Group::AddElement (const TelType AType, OpenGl_Element *AElem )
107 OpenGl_ElementNode *node = new OpenGl_ElementNode();
112 (myLast? myLast->next : myFirst) = node;
116 /*----------------------------------------------------------------------*/
118 void OpenGl_Group::Clear ()
122 // Delete line context
128 // Delete face context
134 // Delete marker context
135 delete myAspectMarker;
136 myAspectMarker = NULL;
140 // Delete text context
147 OpenGl_ElementNode *next = myFirst->next;
148 delete myFirst->elem;
155 /*----------------------------------------------------------------------*/
157 void OpenGl_Group::RemovePrimitiveArray (CALL_DEF_PARRAY *APArray)
159 OpenGl_ElementNode *prevnode = NULL, *node = myFirst;
162 if (node->type == TelParray)
164 CALL_DEF_PARRAY *aCurPArray = ((const OpenGl_PrimitiveArray *)node->elem)->PArray();
166 // validate for correct pointer
167 if (aCurPArray->num_bounds == APArray->num_bounds &&
168 aCurPArray->num_edges == APArray->num_edges &&
169 aCurPArray->num_vertexs == APArray->num_vertexs &&
170 aCurPArray->type == APArray->type)
172 (prevnode? prevnode->next : myFirst) = node->next;
173 if (!myFirst) myLast = NULL;
184 /*----------------------------------------------------------------------*/
186 void OpenGl_Group::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
188 // Is rendering in ADD or IMMEDIATE mode?
189 const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
192 const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False);
193 const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False);
194 const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False);
195 const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False);
197 AWorkspace->SetAspectLine(myAspectLine);
199 AWorkspace->SetAspectFace(myAspectFace);
201 AWorkspace->SetAspectMarker(myAspectMarker);
203 AWorkspace->SetAspectText(myAspectText);
205 // Render group elements
206 OpenGl_ElementNode *node = myFirst;
216 glDisable(GL_LIGHTING);
220 glDepthMask(GL_FALSE);
222 else if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
223 (AWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) == 0 &&
224 AWorkspace->DegenerateModel != 0 )
226 glDisable( GL_DEPTH_TEST );
227 if ( AWorkspace->NamedStatus & OPENGL_NS_TEXTURE ) DisableTexture();
228 AWorkspace->NamedStatus |= OPENGL_NS_WIREFRAME;
231 node->elem->Render( AWorkspace );
233 if ( !isImmediate && (AWorkspace->NamedStatus & OPENGL_NS_TEXTURE) != 0 ) EnableTexture();
238 case TelPolygonIndices:
240 case TelTriangleMesh:
244 glDepthMask(GL_FALSE);
246 else if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
247 (AWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) != 0 &&
248 AWorkspace->DegenerateModel < 2 )
250 if ( AWorkspace->NamedStatus & OPENGL_NS_TEXTURE ) EnableTexture ();
252 glEnable( GL_DEPTH_TEST );
253 AWorkspace->NamedStatus &= ~OPENGL_NS_WIREFRAME;
256 if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
257 AWorkspace->DisablePolygonOffset();
259 node->elem->Render( AWorkspace );
261 if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
262 AWorkspace->EnablePolygonOffset();
268 node->elem->Render( AWorkspace );
276 AWorkspace->SetAspectLine(aspect_line);
277 AWorkspace->SetAspectFace(aspect_face);
278 AWorkspace->SetAspectMarker(aspect_marker);
279 AWorkspace->SetAspectText(aspect_text);
282 /*----------------------------------------------------------------------*/