-// File: OpenGl_Group.cxx
-// Created: 1 August 2011
-// Author: Sergey ZERCHANINOV
-// Copyright: OPEN CASCADE 2011
+// Created on: 2011-08-01
+// Created by: Sergey ZERCHANINOV
+// Copyright (c) 2011-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
#include <OpenGl_Group.hxx>
-#include <OpenGl_TextureBox.hxx>
#include <OpenGl_PrimitiveArray.hxx>
+#include <OpenGl_Workspace.hxx>
/*----------------------------------------------------------------------*/
OpenGl_Group::~OpenGl_Group()
{
- Clear();
+ Release (Handle(OpenGl_Context)());
}
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
-void OpenGl_Group::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theContext,
- const Standard_Boolean theIsGlobal)
+void OpenGl_Group::SetAspectFace (const Handle(OpenGl_Context)& theCtx,
+ const CALL_DEF_CONTEXTFILLAREA& theAspect,
+ const Standard_Boolean theIsGlobal)
{
if (theIsGlobal || myFirst == NULL)
{
if (myAspectFace == NULL)
+ {
myAspectFace = new OpenGl_AspectFace();
- myAspectFace->SetContext (theContext);
+ }
+ myAspectFace->Init (theCtx, theAspect);
}
else
{
OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace();
- anAspectFace->SetContext (theContext);
+ anAspectFace->Init (theCtx, theAspect);
AddElement (TelNil/*TelAspectFace*/, anAspectFace);
}
}
/*----------------------------------------------------------------------*/
-void OpenGl_Group::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theContext,
+void OpenGl_Group::SetAspectMarker (const Handle(OpenGl_Context)& theCtx,
+ const CALL_DEF_CONTEXTMARKER& theAspect,
const Standard_Boolean theIsGlobal)
{
if (theIsGlobal || myFirst == NULL)
{
if (myAspectMarker == NULL)
+ {
myAspectMarker = new OpenGl_AspectMarker();
- myAspectMarker->SetContext (theContext);
+ }
+ myAspectMarker->Init (theCtx, theAspect);
}
else
{
OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker();
- anAspectMarker->SetContext (theContext);
+ anAspectMarker->Init (theCtx, theAspect);
AddElement (TelNil/*TelAspectMarker*/, anAspectMarker);
}
}
/*----------------------------------------------------------------------*/
-void OpenGl_Group::Clear ()
+void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
{
+ // Is rendering in ADD or IMMEDIATE mode?
+ const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
+
+ // Setup aspects
+ const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine (Standard_False);
+ const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace (Standard_False);
+ const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker (Standard_False);
+ const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText (Standard_False);
if (myAspectLine)
{
- // Delete line context
- delete myAspectLine;
- myAspectLine = NULL;
+ theWorkspace->SetAspectLine (myAspectLine);
}
if (myAspectFace)
{
- // Delete face context
- delete myAspectFace;
- myAspectFace = NULL;
+ theWorkspace->SetAspectFace (myAspectFace);
}
if (myAspectMarker)
{
- // Delete marker context
- delete myAspectMarker;
- myAspectMarker = NULL;
+ theWorkspace->SetAspectMarker (myAspectMarker);
}
if (myAspectText)
{
- // Delete text context
- delete myAspectText;
- myAspectText = NULL;
+ theWorkspace->SetAspectText (myAspectText);
}
- // Delete elements
- while (myFirst)
- {
- OpenGl_ElementNode *next = myFirst->next;
- delete myFirst->elem;
- delete myFirst;
- myFirst = next;
- }
- myLast = NULL;
-}
-
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Group::RemovePrimitiveArray (CALL_DEF_PARRAY *APArray)
-{
- OpenGl_ElementNode *prevnode = NULL, *node = myFirst;
- while (node)
- {
- if (node->type == TelParray)
- {
- CALL_DEF_PARRAY *aCurPArray = ((const OpenGl_PrimitiveArray *)node->elem)->PArray();
-
- // validate for correct pointer
- if (aCurPArray->num_bounds == APArray->num_bounds &&
- aCurPArray->num_edges == APArray->num_edges &&
- aCurPArray->num_vertexs == APArray->num_vertexs &&
- aCurPArray->type == APArray->type)
- {
- (prevnode? prevnode->next : myFirst) = node->next;
- if (!myFirst) myLast = NULL;
- delete node->elem;
- delete node;
- break;
- }
- }
- prevnode = node;
- node = node->next;
- }
-}
-
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Group::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
-{
- // Is rendering in ADD or IMMEDIATE mode?
- const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
-
- // Setup aspects
- const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False);
- const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False);
- const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False);
- const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False);
- if (myAspectLine)
- AWorkspace->SetAspectLine(myAspectLine);
- if (myAspectFace)
- AWorkspace->SetAspectFace(myAspectFace);
- if (myAspectMarker)
- AWorkspace->SetAspectMarker(myAspectMarker);
- if (myAspectText)
- AWorkspace->SetAspectText(myAspectText);
// Render group elements
- OpenGl_ElementNode *node = myFirst;
- while (node)
+ for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
{
- switch (node->type)
+ switch (aNodeIter->type)
{
- case TelPolyline:
case TelMarker:
case TelMarkerSet:
case TelText:
{
- glDisable(GL_LIGHTING);
-
- if (isImmediate)
- {
- glDepthMask(GL_FALSE);
- }
- else if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
- (AWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) == 0 &&
- AWorkspace->DegenerateModel != 0 )
- {
- glDisable( GL_DEPTH_TEST );
- if ( AWorkspace->NamedStatus & OPENGL_NS_TEXTURE ) DisableTexture();
- AWorkspace->NamedStatus |= OPENGL_NS_WIREFRAME;
- }
-
- node->elem->Render( AWorkspace );
-
- if ( !isImmediate && (AWorkspace->NamedStatus & OPENGL_NS_TEXTURE) != 0 ) EnableTexture();
- break;
- }
-
- case TelPolygon:
- case TelPolygonIndices:
- case TelQuadrangle:
- case TelTriangleMesh:
- {
+ glDisable (GL_LIGHTING);
if (isImmediate)
{
- glDepthMask(GL_FALSE);
- }
- else if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
- (AWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) != 0 &&
- AWorkspace->DegenerateModel < 2 )
- {
- if ( AWorkspace->NamedStatus & OPENGL_NS_TEXTURE ) EnableTexture ();
-
- glEnable( GL_DEPTH_TEST );
- AWorkspace->NamedStatus &= ~OPENGL_NS_WIREFRAME;
+ glDepthMask (GL_FALSE);
}
- if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
- AWorkspace->DisablePolygonOffset();
-
- node->elem->Render( AWorkspace );
-
- if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
- AWorkspace->EnablePolygonOffset();
+ aNodeIter->elem->Render (theWorkspace);
break;
}
-
default:
{
- node->elem->Render( AWorkspace );
+ aNodeIter->elem->Render (theWorkspace);
break;
}
}
- node = node->next;
}
// Restore aspects
- AWorkspace->SetAspectLine(aspect_line);
- AWorkspace->SetAspectFace(aspect_face);
- AWorkspace->SetAspectMarker(aspect_marker);
- AWorkspace->SetAspectText(aspect_text);
+ theWorkspace->SetAspectLine (aBackAspectLine);
+ theWorkspace->SetAspectFace (aBackAspectFace);
+ theWorkspace->SetAspectMarker (aBackAspectMarker);
+ theWorkspace->SetAspectText (aBackAspectText);
}
-/*----------------------------------------------------------------------*/
+void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
+{
+ // Delete elements
+ while (myFirst != NULL)
+ {
+ OpenGl_ElementNode* aNext = myFirst->next;
+ OpenGl_Element::Destroy (theGlCtx, myFirst->elem);
+ delete myFirst;
+ myFirst = aNext;
+ }
+ myLast = NULL;
+
+ OpenGl_Element::Destroy (theGlCtx, myAspectLine);
+ OpenGl_Element::Destroy (theGlCtx, myAspectFace);
+ OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
+ OpenGl_Element::Destroy (theGlCtx, myAspectText);
+}