0024070: OpenGL capped object-level clipping planes
[occt.git] / src / OpenGl / OpenGl_Group.cxx
CommitLineData
b311480e 1// Created on: 2011-08-01
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
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.
9//
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.
12//
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.
19
2166f0fa
SK
20#include <OpenGl_Group.hxx>
21
2166f0fa 22#include <OpenGl_PrimitiveArray.hxx>
bf75be98 23#include <OpenGl_Workspace.hxx>
2166f0fa 24
4269bd1b 25// =======================================================================
26// function : OpenGl_Group
27// purpose :
28// =======================================================================
2166f0fa
SK
29OpenGl_Group::OpenGl_Group ()
30: myAspectLine(NULL),
31 myAspectFace(NULL),
32 myAspectMarker(NULL),
33 myAspectText(NULL),
34 myFirst(NULL), myLast(NULL)
35{
36}
37
4269bd1b 38// =======================================================================
39// function : ~OpenGl_Group
40// purpose :
41// =======================================================================
2166f0fa
SK
42OpenGl_Group::~OpenGl_Group()
43{
5e27df78 44 Release (Handle(OpenGl_Context)());
2166f0fa
SK
45}
46
4269bd1b 47// =======================================================================
48// function : SetAspectLine
49// purpose :
50// =======================================================================
2166f0fa
SK
51void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theContext,
52 const Standard_Boolean theIsGlobal)
53{
54 if (theIsGlobal || myFirst == NULL)
55 {
56 if (myAspectLine == NULL)
57 myAspectLine = new OpenGl_AspectLine();
58 myAspectLine->SetContext (theContext);
59 }
60 else
61 {
62 OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine();
63 anAspectLine->SetContext (theContext);
64 AddElement (TelNil/*TelAspectLine*/, anAspectLine);
65 }
66}
67
4269bd1b 68// =======================================================================
69// function : SetAspectFace
70// purpose :
71// =======================================================================
bf75be98 72void OpenGl_Group::SetAspectFace (const Handle(OpenGl_Context)& theCtx,
73 const CALL_DEF_CONTEXTFILLAREA& theAspect,
74 const Standard_Boolean theIsGlobal)
2166f0fa
SK
75{
76 if (theIsGlobal || myFirst == NULL)
77 {
78 if (myAspectFace == NULL)
bf75be98 79 {
2166f0fa 80 myAspectFace = new OpenGl_AspectFace();
bf75be98 81 }
82 myAspectFace->Init (theCtx, theAspect);
2166f0fa
SK
83 }
84 else
85 {
86 OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
bf75be98 87 anAspectFace->Init (theCtx, theAspect);
2166f0fa
SK
88 AddElement (TelNil/*TelAspectFace*/, anAspectFace);
89 }
90}
91
4269bd1b 92// =======================================================================
93// function : SetAspectMarker
94// purpose :
95// =======================================================================
a577aaab 96void OpenGl_Group::SetAspectMarker (const Handle(OpenGl_Context)& theCtx,
97 const CALL_DEF_CONTEXTMARKER& theAspect,
2166f0fa
SK
98 const Standard_Boolean theIsGlobal)
99{
100 if (theIsGlobal || myFirst == NULL)
101 {
102 if (myAspectMarker == NULL)
a577aaab 103 {
2166f0fa 104 myAspectMarker = new OpenGl_AspectMarker();
a577aaab 105 }
106 myAspectMarker->Init (theCtx, theAspect);
2166f0fa
SK
107 }
108 else
109 {
110 OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
a577aaab 111 anAspectMarker->Init (theCtx, theAspect);
2166f0fa
SK
112 AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
113 }
114}
115
4269bd1b 116// =======================================================================
117// function : SetAspectText
118// purpose :
119// =======================================================================
2166f0fa
SK
120void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theContext,
121 const Standard_Boolean theIsGlobal)
122{
123 if (theIsGlobal || myFirst == NULL)
124 {
125 if (myAspectText == NULL)
126 myAspectText = new OpenGl_AspectText();
127 myAspectText->SetContext (theContext);
128 }
129 else
130 {
131 OpenGl_AspectText* anAspectText = new OpenGl_AspectText();
132 anAspectText->SetContext (theContext);
133 AddElement ( TelNil/*TelAspectText*/, anAspectText);
134 }
135}
136
4269bd1b 137// =======================================================================
138// function : AddElement
139// purpose :
140// =======================================================================
2166f0fa
SK
141void OpenGl_Group::AddElement (const TelType AType, OpenGl_Element *AElem )
142{
143 OpenGl_ElementNode *node = new OpenGl_ElementNode();
144
145 node->type = AType;
146 node->elem = AElem;
147 node->next = NULL;
148 (myLast? myLast->next : myFirst) = node;
149 myLast = node;
150}
151
4269bd1b 152// =======================================================================
153// function : Render
154// purpose :
155// =======================================================================
bf75be98 156void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa
SK
157{
158 // Is rendering in ADD or IMMEDIATE mode?
bf75be98 159 const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
4269bd1b 160 const Handle(OpenGl_RenderFilter)& aFilter = theWorkspace->GetRenderFilter();
2166f0fa
SK
161
162 // Setup aspects
bf75be98 163 const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine (Standard_False);
164 const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace (Standard_False);
165 const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker (Standard_False);
166 const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText (Standard_False);
4269bd1b 167 Standard_Boolean isLineSet = myAspectLine && myAspectLine->RenderFiltered (theWorkspace, aFilter);
168 Standard_Boolean isFaceSet = myAspectFace && myAspectFace->RenderFiltered (theWorkspace, aFilter);
169 Standard_Boolean isMarkerSet = myAspectMarker && myAspectMarker->RenderFiltered (theWorkspace, aFilter);
170 Standard_Boolean isTextSet = myAspectText && myAspectText->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
171
172 // Render group elements
bf75be98 173 for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
2166f0fa 174 {
bf75be98 175 switch (aNodeIter->type)
2166f0fa 176 {
2166f0fa
SK
177 case TelMarker:
178 case TelMarkerSet:
179 case TelText:
180 {
bf75be98 181 glDisable (GL_LIGHTING);
2166f0fa
SK
182 if (isImmediate)
183 {
bf75be98 184 glDepthMask (GL_FALSE);
2166f0fa 185 }
2166f0fa 186
4269bd1b 187 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
188 break;
189 }
2166f0fa
SK
190 default:
191 {
4269bd1b 192 aNodeIter->elem->RenderFiltered (theWorkspace, aFilter);
2166f0fa
SK
193 break;
194 }
195 }
2166f0fa
SK
196 }
197
198 // Restore aspects
4269bd1b 199 if (isLineSet)
200 theWorkspace->SetAspectLine (aBackAspectLine);
201 if (isFaceSet)
202 theWorkspace->SetAspectFace (aBackAspectFace);
203 if (isMarkerSet)
204 theWorkspace->SetAspectMarker (aBackAspectMarker);
205 if (isTextSet)
206 theWorkspace->SetAspectText (aBackAspectText);
2166f0fa
SK
207}
208
4269bd1b 209// =======================================================================
210// function : Release
211// purpose :
212// =======================================================================
5e27df78 213void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
214{
215 // Delete elements
216 while (myFirst != NULL)
217 {
218 OpenGl_ElementNode* aNext = myFirst->next;
219 OpenGl_Element::Destroy (theGlCtx, myFirst->elem);
220 delete myFirst;
221 myFirst = aNext;
222 }
223 myLast = NULL;
224
225 OpenGl_Element::Destroy (theGlCtx, myAspectLine);
226 OpenGl_Element::Destroy (theGlCtx, myAspectFace);
227 OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
228 OpenGl_Element::Destroy (theGlCtx, myAspectText);
229}