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.
20 #include <OpenGl_Group.hxx>
22 #include <OpenGl_PrimitiveArray.hxx>
23 #include <OpenGl_Workspace.hxx>
25 /*----------------------------------------------------------------------*/
27 OpenGl_Group::OpenGl_Group ()
32 myFirst(NULL), myLast(NULL)
36 OpenGl_Group::~OpenGl_Group()
38 Release (Handle(OpenGl_Context)());
41 /*----------------------------------------------------------------------*/
43 void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theContext,
44 const Standard_Boolean theIsGlobal)
46 if (theIsGlobal || myFirst == NULL)
48 if (myAspectLine == NULL)
49 myAspectLine = new OpenGl_AspectLine();
50 myAspectLine->SetContext (theContext);
54 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
55 anAspectLine->SetContext (theContext);
56 AddElement (TelNil/*TelAspectLine*/, anAspectLine);
60 /*----------------------------------------------------------------------*/
62 void OpenGl_Group::SetAspectFace (const Handle(OpenGl_Context)& theCtx,
63 const CALL_DEF_CONTEXTFILLAREA& theAspect,
64 const Standard_Boolean theIsGlobal)
66 if (theIsGlobal || myFirst == NULL)
68 if (myAspectFace == NULL)
70 myAspectFace = new OpenGl_AspectFace();
72 myAspectFace->Init (theCtx, theAspect);
76 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
77 anAspectFace->Init (theCtx, theAspect);
78 AddElement (TelNil/*TelAspectFace*/, anAspectFace);
82 /*----------------------------------------------------------------------*/
84 void OpenGl_Group::SetAspectMarker (const Handle(OpenGl_Context)& theCtx,
85 const CALL_DEF_CONTEXTMARKER& theAspect,
86 const Standard_Boolean theIsGlobal)
88 if (theIsGlobal || myFirst == NULL)
90 if (myAspectMarker == NULL)
92 myAspectMarker = new OpenGl_AspectMarker();
94 myAspectMarker->Init (theCtx, theAspect);
98 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
99 anAspectMarker->Init (theCtx, theAspect);
100 AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
104 /*----------------------------------------------------------------------*/
106 void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theContext,
107 const Standard_Boolean theIsGlobal)
109 if (theIsGlobal || myFirst == NULL)
111 if (myAspectText == NULL)
112 myAspectText = new OpenGl_AspectText();
113 myAspectText->SetContext (theContext);
117 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
118 anAspectText->SetContext (theContext);
119 AddElement ( TelNil/*TelAspectText*/, anAspectText);
123 /*----------------------------------------------------------------------*/
125 void OpenGl_Group::AddElement (const TelType AType, OpenGl_Element *AElem )
127 OpenGl_ElementNode *node = new OpenGl_ElementNode();
132 (myLast? myLast->next : myFirst) = node;
136 /*----------------------------------------------------------------------*/
138 void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
140 // Is rendering in ADD or IMMEDIATE mode?
141 const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
144 const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine (Standard_False);
145 const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace (Standard_False);
146 const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker (Standard_False);
147 const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText (Standard_False);
150 theWorkspace->SetAspectLine (myAspectLine);
154 theWorkspace->SetAspectFace (myAspectFace);
158 theWorkspace->SetAspectMarker (myAspectMarker);
162 theWorkspace->SetAspectText (myAspectText);
165 // Render group elements
166 for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
168 switch (aNodeIter->type)
174 glDisable (GL_LIGHTING);
177 glDepthMask (GL_FALSE);
180 aNodeIter->elem->Render (theWorkspace);
185 aNodeIter->elem->Render (theWorkspace);
192 theWorkspace->SetAspectLine (aBackAspectLine);
193 theWorkspace->SetAspectFace (aBackAspectFace);
194 theWorkspace->SetAspectMarker (aBackAspectMarker);
195 theWorkspace->SetAspectText (aBackAspectText);
198 void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
201 while (myFirst != NULL)
203 OpenGl_ElementNode* aNext = myFirst->next;
204 OpenGl_Element::Destroy (theGlCtx, myFirst->elem);
210 OpenGl_Element::Destroy (theGlCtx, myAspectLine);
211 OpenGl_Element::Destroy (theGlCtx, myAspectFace);
212 OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
213 OpenGl_Element::Destroy (theGlCtx, myAspectText);