// Created on: 2011-08-05
// Created by: Sergey ZERCHANINOV
-// Copyright (c) 2011-2012 OPEN CASCADE SAS
+// Copyright (c) 2011-2014 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.
+// This file is part of Open CASCADE Technology software library.
//
-// 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.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// 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.
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_AspectMarker.hxx>
#include <OpenGl_AspectText.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_telem_util.hxx>
/* OCC22218 NOTE: project dependency on gl2ps is specified by macro */
#ifdef HAVE_GL2PS
#include <gl2ps.h>
- /* OCC22216 NOTE: linker dependency can be switched off by undefining macro.
- Pragma comment for gl2ps.lib is defined only here. */
- #ifdef _MSC_VER
+ /* OCC22216 NOTE: linker dependency can be switched off by undefining macro.
+ Pragma comment for gl2ps.lib is defined only here. */
+ #ifdef _MSC_VER
#pragma comment( lib, "gl2ps.lib" )
#endif
#endif
-#include <OpenGl_TextureBox.hxx>
#include <Aspect_PolygonOffsetMode.hxx>
#include <OpenGl_View.hxx>
/*----------------------------------------------------------------------*/
-static void TelUpdatePolygonOffsets( const TEL_POFFSET_PARAM *pdata )
+static void TelUpdatePolygonOffsets (const TEL_POFFSET_PARAM& theOffsetData)
{
- if ( ( pdata->mode & Aspect_POM_Fill ) == Aspect_POM_Fill )
- glEnable ( GL_POLYGON_OFFSET_FILL );
- else
- glDisable ( GL_POLYGON_OFFSET_FILL );
+ if ((theOffsetData.mode & Aspect_POM_Fill) == Aspect_POM_Fill)
+ {
+ glEnable (GL_POLYGON_OFFSET_FILL);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_FILL);
+ }
- if ( ( pdata->mode & Aspect_POM_Line ) == Aspect_POM_Line )
- glEnable ( GL_POLYGON_OFFSET_LINE );
+ if ((theOffsetData.mode & Aspect_POM_Line) == Aspect_POM_Line)
+ {
+ glEnable (GL_POLYGON_OFFSET_LINE);
+ }
else
- glDisable( GL_POLYGON_OFFSET_LINE );
+ {
+ glDisable (GL_POLYGON_OFFSET_LINE);
+ }
- if ( ( pdata->mode & Aspect_POM_Point ) == Aspect_POM_Point )
- glEnable ( GL_POLYGON_OFFSET_POINT );
+ if ((theOffsetData.mode & Aspect_POM_Point) == Aspect_POM_Point)
+ {
+ glEnable (GL_POLYGON_OFFSET_POINT);
+ }
else
- glDisable( GL_POLYGON_OFFSET_POINT );
+ {
+ glDisable (GL_POLYGON_OFFSET_POINT);
+ }
- glPolygonOffset( pdata->factor, pdata->units );
+ glPolygonOffset (theOffsetData.factor, theOffsetData.units);
}
/*----------------------------------------------------------------------*/
-void OpenGl_Workspace::UpdateMaterial( const int flag )
+void OpenGl_Workspace::updateMaterial (const int theFlag)
{
- // Case of Hiddenline
- if (AspectFace_set->Context().InteriorStyle == Aspect_IS_HIDDENLINE)
+ // Case of hidden line
+ if (AspectFace_set->InteriorStyle() == Aspect_IS_HIDDENLINE)
{
- /* szvgl - IMPORTANT!!! */
- static TEL_CONTEXT_FACE hl_context_face;
- static OpenGl_AspectFace hl_aspect_face;
-
- hl_context_face = AspectFace_set->Context();
+ myAspectFaceHl = *AspectFace_set; // copy all values including line edge aspect
+ myAspectFaceHl.ChangeIntFront().matcol = BackgroundColor();
+ myAspectFaceHl.ChangeIntFront().color_mask = 0;
+ myAspectFaceHl.ChangeIntFront().color_mask = 0;
- hl_context_face.IntFront.matcol = BackgroundColor();
- hl_context_face.IntFront.color_mask = 0;
- hl_context_face.IntBack.color_mask = 0;
-
- hl_aspect_face.SetContext(hl_context_face);
- hl_aspect_face.SetAspectEdge(AspectFace_set->AspectEdge());
-
- AspectFace_set = &hl_aspect_face;
+ AspectFace_set = &myAspectFaceHl;
return;
}
- const OPENGL_SURF_PROP *prop = NULL;
- GLenum face = 0;
- if ( flag == TEL_FRONT_MATERIAL )
+ const OPENGL_SURF_PROP* aProps = &AspectFace_set->IntFront();
+ GLenum aFace = GL_FRONT_AND_BACK;
+ if (theFlag == TEL_BACK_MATERIAL)
{
- prop = &AspectFace_set->Context().IntFront;
- face = GL_FRONT_AND_BACK;
+ aFace = GL_BACK;
+ aProps = &AspectFace_set->IntBack();
}
- else
+ else if (AspectFace_set->DistinguishingMode() == TOn
+ && !(NamedStatus & OPENGL_NS_RESMAT))
{
- prop = &AspectFace_set->Context().IntBack;
- face = GL_BACK;
+ aFace = GL_FRONT;
}
- const unsigned int rm = prop->color_mask;
-
- if ( !rm ) return;
+ myMatTmp.Init (*aProps);
- // Handling transparency
- if ( (NamedStatus & OPENGL_NS_2NDPASSDO) == 0 )
+ // handling transparency
+ if (NamedStatus & OPENGL_NS_2NDPASSDO)
{
- if ( myUseTransparency && prop->trans != 1.0F )
- {
- // Render transparent
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glDepthMask (GL_FALSE);
- }
- else
- {
- // Render opaque
- if ( (NamedStatus & OPENGL_NS_ANTIALIASING) == 0 )
- {
- glBlendFunc (GL_ONE, GL_ZERO);
- glDisable (GL_BLEND);
- }
- glDepthMask (GL_TRUE);
- }
+ // second pass
+ myMatTmp.Diffuse.a() = aProps->env_reflexion;
}
-
- static float mAmb[4];
- static float mDiff[4];
- static float mSpec[4];
- static float mEmsv[4];
- static float mShin;
-
- static const float defspeccol[4] = { 1.F, 1.F, 1.F, 1.F };
-
- // Reset material
- if ( NamedStatus & OPENGL_NS_RESMAT )
- {
- // Ambient component
- if( rm & OPENGL_AMBIENT_MASK )
- {
- const float *c = prop->isphysic? prop->ambcol.rgb : prop->matcol.rgb;
-
- mAmb[0] = prop->amb * c[0];
- mAmb[1] = prop->amb * c[1];
- mAmb[2] = prop->amb * c[2];
- }
- else
- {
- mAmb[0] = 0.F;
- mAmb[1] = 0.F;
- mAmb[2] = 0.F;
- }
- mAmb[3] = 1.F;
-
- // Diffusion component
- if( rm & OPENGL_DIFFUSE_MASK )
- {
- const float *c = prop->isphysic? prop->difcol.rgb : prop->matcol.rgb;
-
- mDiff[0] = prop->diff * c[0];
- mDiff[1] = prop->diff * c[1];
- mDiff[2] = prop->diff * c[2];
- }
- else
- {
- mDiff[0] = 0.F;
- mDiff[1] = 0.F;
- mDiff[2] = 0.F;
- }
- mDiff[3] = 1.F;
-
- if (NamedStatus & OPENGL_NS_2NDPASSDO)
- {
- mDiff[3] = prop->env_reflexion;
- }
- else
- {
- if (myUseTransparency) mDiff[3] = prop->trans;
- // If the material reflects the environment scene, the second pass is needed
- if (prop->env_reflexion != 0.0) NamedStatus |= OPENGL_NS_2NDPASSNEED;
- }
-
- // Specular component
- if( rm & OPENGL_SPECULAR_MASK )
- {
- const float *c = prop->isphysic? prop->speccol.rgb : defspeccol;
-
- mSpec[0] = prop->spec * c[0];
- mSpec[1] = prop->spec * c[1];
- mSpec[2] = prop->spec * c[2];
- }
- else {
- mSpec[0] = 0.F;
- mSpec[1] = 0.F;
- mSpec[2] = 0.F;
- }
- mSpec[3] = 1.F;
-
- // Emissive component
- if( rm & OPENGL_EMISSIVE_MASK )
- {
- const float *c = prop->isphysic? prop->emscol.rgb : prop->matcol.rgb;
-
- mEmsv[0] = prop->emsv * c[0];
- mEmsv[1] = prop->emsv * c[1];
- mEmsv[2] = prop->emsv * c[2];
- }
- else {
- mEmsv[0] = 0.F;
- mEmsv[1] = 0.F;
- mEmsv[2] = 0.F;
- }
- mEmsv[3] = 1.F;
-
- /* Coeficient de brillance */
- mShin = prop->shine;
-
- glMaterialfv(face, GL_AMBIENT, mAmb );
- glMaterialfv(face, GL_DIFFUSE, mDiff );
- glMaterialfv(face, GL_SPECULAR, mSpec);
- glMaterialfv(face, GL_EMISSION, mEmsv);
- glMaterialf(face, GL_SHININESS, mShin);
-
- NamedStatus &= ~OPENGL_NS_RESMAT;
- }
-
- // Set Material Optimize
- else
+ else
{
- // Ambient component
- if( rm & OPENGL_AMBIENT_MASK )
- {
- const float *c = prop->isphysic? prop->ambcol.rgb : prop->matcol.rgb;
-
- if (mAmb[0] != prop->amb * c[0] ||
- mAmb[1] != prop->amb * c[1] ||
- mAmb[2] != prop->amb * c[2] )
- {
- mAmb[0] = prop->amb * c[0];
- mAmb[1] = prop->amb * c[1];
- mAmb[2] = prop->amb * c[2];
- mAmb[3] = 1.F;
-
- glMaterialfv(face, GL_AMBIENT, mAmb);
- }
- }
- else
+ if (aProps->env_reflexion != 0.0f)
{
- if ( mAmb[0] != 0.F || mAmb[1] != 0.F || mAmb[2] != 0.F )
- {
- mAmb[0] = 0.F;
- mAmb[1] = 0.F;
- mAmb[2] = 0.F;
- mAmb[3] = 1.F;
-
- glMaterialfv(face, GL_AMBIENT, mAmb);
- }
+ // if the material reflects the environment scene, the second pass is needed
+ NamedStatus |= OPENGL_NS_2NDPASSNEED;
}
- // Diffusion component
- if( rm & OPENGL_DIFFUSE_MASK )
+ if (myUseTransparency && aProps->trans != 1.0f)
{
- const float *c = prop->isphysic? prop->difcol.rgb : prop->matcol.rgb;
-
- if (mDiff[0] != prop->diff * c[0] ||
- mDiff[1] != prop->diff * c[1] ||
- mDiff[2] != prop->diff * c[2] ||
- mDiff[3] != ((NamedStatus & OPENGL_NS_2NDPASSDO)? prop->env_reflexion : (myUseTransparency? prop->trans : 1.0F)))
- {
- mDiff[0] = prop->diff * c[0];
- mDiff[1] = prop->diff * c[1];
- mDiff[2] = prop->diff * c[2];
- mDiff[3] = 1.F;
-
- if (NamedStatus & OPENGL_NS_2NDPASSDO)
- {
- mDiff[3] = prop->env_reflexion;
- }
- else
- {
- if (myUseTransparency) mDiff[3] = prop->trans;
- // If the material reflects the environment scene, the second pass is needed
- if (prop->env_reflexion != 0.0) NamedStatus |= OPENGL_NS_2NDPASSNEED;
- }
-
- glMaterialfv(face, GL_DIFFUSE, mDiff );
- }
+ // render transparent
+ myMatTmp.Diffuse.a() = aProps->trans;
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable (GL_BLEND);
+ glDepthMask (GL_FALSE);
}
else
{
- Tfloat newDiff3 = 1.F;
-
- if (NamedStatus & OPENGL_NS_2NDPASSDO)
- {
- newDiff3 = prop->env_reflexion;
- }
- else
+ // render opaque
+ if ((NamedStatus & OPENGL_NS_ANTIALIASING) == 0)
{
- if (myUseTransparency) newDiff3 = prop->trans;
- // If the material reflects the environment scene, the second pass is needed
- if (prop->env_reflexion != 0.0) NamedStatus |= OPENGL_NS_2NDPASSNEED;
- }
-
- /* OCC19915: Even if diffuse reflectance is disabled,
- still trying to update the current transparency if it
- differs from the previous value */
- if ( mDiff[0] != 0.F || mDiff[1] != 0.F || mDiff[2] != 0.F || fabs(mDiff[3] - newDiff3) > 0.01F )
- {
- mDiff[0] = 0.F;
- mDiff[1] = 0.F;
- mDiff[2] = 0.F;
- mDiff[3] = newDiff3;
-
- glMaterialfv(face, GL_DIFFUSE, mDiff);
+ glBlendFunc (GL_ONE, GL_ZERO);
+ glDisable (GL_BLEND);
}
+ glDepthMask (GL_TRUE);
}
+ }
- // Specular component
- if( rm & OPENGL_SPECULAR_MASK )
- {
- const float *c = prop->isphysic? prop->speccol.rgb : defspeccol;
+ // do not update material properties in case of zero reflection mode,
+ // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway.
+ if (aProps->color_mask == 0)
+ {
+ return;
+ }
- if (mSpec[0] != prop->spec * c[0] ||
- mSpec[1] != prop->spec * c[1] ||
- mSpec[2] != prop->spec * c[2])
- {
- mSpec[0] = prop->spec * c[0];
- mSpec[1] = prop->spec * c[1];
- mSpec[2] = prop->spec * c[2];
- mSpec[3] = 1.F;
+ // reset material
+ if (NamedStatus & OPENGL_NS_RESMAT)
+ {
+ glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData());
+ glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData());
+ glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData());
+ glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData());
+ glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine());
- glMaterialfv(face, GL_SPECULAR, mSpec);
- }
+ if (theFlag == TEL_FRONT_MATERIAL)
+ {
+ myMatFront = myMatTmp;
+ myMatBack = myMatTmp;
}
else
{
- if ( mSpec[0] != 0.F || mSpec[1] != 0.F || mSpec[2] != 0.F )
- {
- mSpec[0] = 0.F;
- mSpec[1] = 0.F;
- mSpec[2] = 0.F;
- mSpec[3] = 1.F;
-
- glMaterialfv(face, GL_SPECULAR, mSpec);
- }
+ myMatBack = myMatTmp;
}
- // Emissive component
- if( rm & OPENGL_EMISSIVE_MASK )
- {
- const float *c = prop->isphysic? prop->emscol.rgb : prop->matcol.rgb;
-
- if (mEmsv[0] != prop->emsv * c[0] ||
- mEmsv[1] != prop->emsv * c[1] ||
- mEmsv[2] != prop->emsv * c[2])
- {
- mEmsv[0] = prop->emsv * c[0];
- mEmsv[1] = prop->emsv * c[1];
- mEmsv[2] = prop->emsv * c[2];
- mEmsv[3] = 1.F;
+ NamedStatus &= ~OPENGL_NS_RESMAT;
+ return;
+ }
- glMaterialfv(face, GL_EMISSION, mEmsv);
- }
- }
- else
- {
- if ( mEmsv[0] != 0.F || mEmsv[1] != 0.F || mEmsv[2] != 0.F )
- {
- mEmsv[0] = 0.F;
- mEmsv[1] = 0.F;
- mEmsv[2] = 0.F;
- mEmsv[3] = 1.F;
+ // reduce updates
+ OpenGl_Material& anOld = (theFlag == TEL_FRONT_MATERIAL)
+ ? myMatFront
+ : myMatBack;
- glMaterialfv(face, GL_EMISSION, mEmsv);
- }
- }
-
- // Shining coefficient
- if( mShin != prop->shine )
- {
- mShin = prop->shine;
- glMaterialf(face, GL_SHININESS, mShin);
- }
+ if (myMatTmp.Ambient.r() != anOld.Ambient.r()
+ || myMatTmp.Ambient.g() != anOld.Ambient.g()
+ || myMatTmp.Ambient.b() != anOld.Ambient.b())
+ {
+ glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData());
+ }
+ if (myMatTmp.Diffuse.r() != anOld.Diffuse.r()
+ || myMatTmp.Diffuse.g() != anOld.Diffuse.g()
+ || myMatTmp.Diffuse.b() != anOld.Diffuse.b()
+ || fabs (myMatTmp.Diffuse.a() - anOld.Diffuse.a()) > 0.01f)
+ {
+ glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData());
+ }
+ if (myMatTmp.Specular.r() != anOld.Specular.r()
+ || myMatTmp.Specular.g() != anOld.Specular.g()
+ || myMatTmp.Specular.b() != anOld.Specular.b())
+ {
+ glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData());
+ }
+ if (myMatTmp.Emission.r() != anOld.Emission.r()
+ || myMatTmp.Emission.g() != anOld.Emission.g()
+ || myMatTmp.Emission.b() != anOld.Emission.b())
+ {
+ glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData());
+ }
+ if (myMatTmp.Shine() != anOld.Shine())
+ {
+ glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine());
+ }
+ anOld = myMatTmp;
+ if (aFace == GL_FRONT_AND_BACK)
+ {
+ myMatBack = myMatTmp;
}
}
/*----------------------------------------------------------------------*/
-const OpenGl_Matrix * OpenGl_Workspace::SetViewMatrix(const OpenGl_Matrix *AMatrix)
+const OpenGl_Matrix * OpenGl_Workspace::SetViewMatrix (const OpenGl_Matrix *AMatrix)
{
const OpenGl_Matrix *ViewMatrix_old = ViewMatrix_applied;
ViewMatrix_applied = AMatrix;
- OpenGl_Matrix lmat;
- OpenGl_Transposemat3( &lmat, StructureMatrix_applied );
-
- glMatrixMode (GL_MODELVIEW);
-
- if ( (NamedStatus & OPENGL_NS_ANIMATION) == 0 )
- {
- OpenGl_Matrix rmat;
- OpenGl_Multiplymat3( &rmat, &lmat, ViewMatrix_applied );
- glLoadMatrixf((const GLfloat *) rmat.mat);
- }
+ // Update model-view matrix with new view matrix
+ UpdateModelViewMatrix();
return ViewMatrix_old;
}
/*----------------------------------------------------------------------*/
-const OpenGl_Matrix * OpenGl_Workspace::SetStructureMatrix(const OpenGl_Matrix *AMatrix)
+const OpenGl_Matrix * OpenGl_Workspace::SetStructureMatrix (const OpenGl_Matrix *AMatrix, bool aRevert)
{
const OpenGl_Matrix *StructureMatrix_old = StructureMatrix_applied;
StructureMatrix_applied = AMatrix;
OpenGl_Matrix lmat;
OpenGl_Transposemat3( &lmat, AMatrix );
- glMatrixMode (GL_MODELVIEW);
+ // Update model-view matrix with new structure matrix
+ UpdateModelViewMatrix();
- if ( (NamedStatus & OPENGL_NS_ANIMATION) == 0 )
+ if (!myGlContext->ShaderManager()->IsEmpty())
{
- OpenGl_Matrix rmat;
- OpenGl_Multiplymat3( &rmat, &lmat, ViewMatrix_applied );
- glLoadMatrixf((const GLfloat *) rmat.mat);
- }
- else
- {
- glMultMatrixf((const GLfloat *) lmat.mat);
+ if (aRevert)
+ {
+ myGlContext->ShaderManager()->RevertModelWorldStateTo (&lmat.mat);
+ }
+ else
+ {
+ myGlContext->ShaderManager()->UpdateModelWorldStateTo (&lmat.mat);
+ }
}
return StructureMatrix_old;
/*----------------------------------------------------------------------*/
+const void OpenGl_Workspace::UpdateModelViewMatrix()
+{
+ OpenGl_Matrix aStructureMatT;
+ OpenGl_Transposemat3( &aStructureMatT, StructureMatrix_applied);
+
+ glMatrixMode (GL_MODELVIEW);
+ OpenGl_Multiplymat3 (&myModelViewMatrix, &aStructureMatT, ViewMatrix_applied);
+ glLoadMatrixf ((const GLfloat* )&myModelViewMatrix.mat);
+}
+
+/*----------------------------------------------------------------------*/
+
const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean WithApply)
{
if ( WithApply && (AspectLine_set != AspectLine_applied) )
if ( !AspectLine_applied || (AspectLine_set->Type() != AspectLine_applied->Type() ) )
{
- myDisplay->SetTypeOfLine(AspectLine_set->Type());
+ myLineAttribs->SetTypeOfLine (AspectLine_set->Type());
}
if ( !AspectLine_applied || ( AspectLine_set->Width() != AspectLine_applied->Width() ) )
/*----------------------------------------------------------------------*/
-const OpenGl_AspectFace * OpenGl_Workspace::AspectFace(const Standard_Boolean WithApply)
+const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean theToApply)
{
- if ( WithApply && (AspectFace_set != AspectFace_applied) )
+ if (!theToApply)
{
- const Aspect_InteriorStyle intstyle = AspectFace_set->Context().InteriorStyle;
- if ( !AspectFace_applied || AspectFace_applied->Context().InteriorStyle != intstyle )
- {
- switch( intstyle )
- {
- case Aspect_IS_EMPTY:
- case Aspect_IS_HOLLOW:
- glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
- break;
-
- case Aspect_IS_HATCH:
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
- myDisplay->SetTypeOfHatch(AspectFace_applied? AspectFace_applied->Context().Hatch : TEL_HS_SOLID);
- break;
-
- case Aspect_IS_SOLID:
- case Aspect_IS_HIDDENLINE:
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
- glDisable(GL_POLYGON_STIPPLE);
- break;
+ return AspectFace_set;
+ }
- case 5: //szvgl - no corresponding enumeration item Aspect_IS_POINT
- glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
- break;
- }
- }
- if( intstyle == Aspect_IS_HATCH )
+ if (!ActiveView()->Backfacing())
+ {
+ // manage back face culling mode, disable culling when clipping is enabled
+ TelCullMode aCullingMode = (myGlContext->Clipping().IsClippingOrCappingOn()
+ || AspectFace_set->InteriorStyle() == Aspect_IS_HATCH)
+ ? TelCullNone
+ : (TelCullMode )AspectFace_set->CullingMode();
+ if (aCullingMode != TelCullNone
+ && myUseTransparency && !(NamedStatus & OPENGL_NS_2NDPASSDO))
{
- const Tint hatchstyle = AspectFace_set->Context().Hatch;
- if( !AspectFace_applied || AspectFace_applied->Context().Hatch != hatchstyle )
+ // disable culling in case of translucent shading aspect
+ if (AspectFace_set->IntFront().trans != 1.0f)
{
- myDisplay->SetTypeOfHatch(hatchstyle);
+ aCullingMode = TelCullNone;
}
}
- if ( !ActiveView()->Backfacing() )
+ if (myCullingMode != aCullingMode)
{
- const Tint mode = AspectFace_set->Context().CullingMode;
- if( !AspectFace_applied || AspectFace_applied->Context().CullingMode != mode )
+ myCullingMode = aCullingMode;
+ switch (myCullingMode)
{
- switch( (TelCullMode)mode )
+ case TelCullNone:
+ case TelCullUndefined:
+ {
+ glDisable (GL_CULL_FACE);
+ break;
+ }
+ case TelCullFront:
{
- case TelCullNone:
- glDisable(GL_CULL_FACE);
- break;
-
- case TelCullFront:
- glCullFace(GL_FRONT);
- glEnable(GL_CULL_FACE);
- break;
-
- case TelCullBack:
- glCullFace(GL_BACK);
- glEnable(GL_CULL_FACE);
- break;
+ glCullFace (GL_FRONT);
+ glEnable (GL_CULL_FACE);
+ break;
+ }
+ case TelCullBack:
+ {
+ glCullFace (GL_BACK);
+ glEnable (GL_CULL_FACE);
+ break;
}
}
}
+ }
- // Aspect_POM_None means: do not change current settings
- if ( ( AspectFace_set->Context().PolygonOffset.mode & Aspect_POM_None ) != Aspect_POM_None )
+ if (AspectFace_set == AspectFace_applied)
+ {
+ return AspectFace_set;
+ }
+
+ const Aspect_InteriorStyle anIntstyle = AspectFace_set->InteriorStyle();
+ if (AspectFace_applied == NULL || AspectFace_applied->InteriorStyle() != anIntstyle)
+ {
+ switch (anIntstyle)
{
- if ( !PolygonOffset_applied ||
- PolygonOffset_applied->mode != AspectFace_set->Context().PolygonOffset.mode ||
- PolygonOffset_applied->factor != AspectFace_set->Context().PolygonOffset.factor ||
- PolygonOffset_applied->units != AspectFace_set->Context().PolygonOffset.units )
+ case Aspect_IS_EMPTY:
+ case Aspect_IS_HOLLOW:
+ {
+ glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+ break;
+ }
+ case Aspect_IS_HATCH:
+ {
+ glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+ myLineAttribs->SetTypeOfHatch (AspectFace_applied != NULL ? AspectFace_applied->Hatch() : TEL_HS_SOLID);
+ break;
+ }
+ case Aspect_IS_SOLID:
+ case Aspect_IS_HIDDENLINE:
+ {
+ glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+ glDisable (GL_POLYGON_STIPPLE);
+ break;
+ }
+ case Aspect_IS_POINT:
{
- PolygonOffset_applied = &AspectFace_set->Context().PolygonOffset;
- TelUpdatePolygonOffsets( PolygonOffset_applied );
+ glPolygonMode (GL_FRONT_AND_BACK, GL_POINT);
+ break;
}
}
+ }
- UpdateMaterial( TEL_FRONT_MATERIAL );
- if (AspectFace_set->Context().DistinguishingMode == TOn)
- UpdateMaterial( TEL_BACK_MATERIAL );
+ if (anIntstyle == Aspect_IS_HATCH)
+ {
+ const Tint hatchstyle = AspectFace_set->Hatch();
+ if (AspectFace_applied == NULL || AspectFace_applied->Hatch() != hatchstyle)
+ {
+ myLineAttribs->SetTypeOfHatch (hatchstyle);
+ }
+ }
- if ((NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
+ // Aspect_POM_None means: do not change current settings
+ if ((AspectFace_set->PolygonOffset().mode & Aspect_POM_None) != Aspect_POM_None)
+ {
+ if (PolygonOffset_applied.mode != AspectFace_set->PolygonOffset().mode
+ || PolygonOffset_applied.factor != AspectFace_set->PolygonOffset().factor
+ || PolygonOffset_applied.units != AspectFace_set->PolygonOffset().units)
{
- DisableTexture();
- if (AspectFace_set->Context().doTextureMap)
- {
- SetCurrentTexture(AspectFace_set->Context().TexId);
- EnableTexture();
- }
+ SetPolygonOffset (AspectFace_set->PolygonOffset().mode,
+ AspectFace_set->PolygonOffset().factor,
+ AspectFace_set->PolygonOffset().units);
}
+ }
+
+ updateMaterial (TEL_FRONT_MATERIAL);
+ if (AspectFace_set->DistinguishingMode() == TOn)
+ {
+ updateMaterial (TEL_BACK_MATERIAL);
+ }
- AspectFace_applied = AspectFace_set;
+ if ((NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
+ {
+ if (AspectFace_set->DoTextureMap())
+ {
+ EnableTexture (AspectFace_set->TextureRes (this),
+ AspectFace_set->TextureParams());
+ }
+ else
+ {
+ DisableTexture();
+ }
}
+
+ AspectFace_applied = AspectFace_set;
return AspectFace_set;
}
-/*----------------------------------------------------------------------*/
-
-const OpenGl_AspectMarker * OpenGl_Workspace::AspectMarker(const Standard_Boolean WithApply)
+//=======================================================================
+//function : SetPolygonOffset
+//purpose :
+//=======================================================================
+void OpenGl_Workspace::SetPolygonOffset (int theMode,
+ Standard_ShortReal theFactor,
+ Standard_ShortReal theUnits)
{
- if ( WithApply && (AspectMarker_set != AspectMarker_applied) )
- {
- AspectMarker_applied = AspectMarker_set;
- }
- return AspectMarker_set;
+ PolygonOffset_applied.mode = theMode;
+ PolygonOffset_applied.factor = theFactor;
+ PolygonOffset_applied.units = theUnits;
+
+ TelUpdatePolygonOffsets (PolygonOffset_applied);
}
/*----------------------------------------------------------------------*/
-const OpenGl_AspectText * OpenGl_Workspace::AspectText(const Standard_Boolean WithApply)
+const OpenGl_AspectMarker* OpenGl_Workspace::AspectMarker (const Standard_Boolean theToApply)
{
- if ( WithApply )
+ if (theToApply && (AspectMarker_set != AspectMarker_applied))
{
- Standard_Boolean toApply = Standard_False;
- if ( AspectText_set != AspectText_applied )
- {
- if ( !AspectText_applied )
- toApply = Standard_True;
- else if ( strcmp( AspectText_set->Font(), AspectText_applied->Font() ) ||
- ( AspectText_set->FontAspect() != AspectText_applied->FontAspect() ) )
- toApply = Standard_True;
-
- AspectText_applied = AspectText_set;
- }
- if ( TextParam_set != TextParam_applied )
- {
- if ( !TextParam_applied )
- toApply = Standard_True;
- else if ( TextParam_set->Height != TextParam_applied->Height )
- toApply = Standard_True;
-
- TextParam_applied = TextParam_set;
- }
- if ( toApply )
+ if (!AspectMarker_applied || (AspectMarker_set->Scale() != AspectMarker_applied->Scale()))
{
- FindFont(AspectText_applied->Font(), AspectText_applied->FontAspect(), TextParam_applied->Height);
+ glPointSize (AspectMarker_set->Scale());
+ #ifdef HAVE_GL2PS
+ gl2psPointSize (AspectMarker_set->Scale());
+ #endif
}
+ AspectMarker_applied = AspectMarker_set;
}
- return AspectText_set;
+ return AspectMarker_set;
}
/*----------------------------------------------------------------------*/
-//=======================================================================
-//function : ResetAppliedAspect
-//purpose :
-//=======================================================================
-
-void OpenGl_Workspace::ResetAppliedAspect()
+const OpenGl_AspectText* OpenGl_Workspace::AspectText (const Standard_Boolean theWithApply)
{
- AspectLine_applied = NULL;
- AspectFace_applied = NULL;
- AspectMarker_applied = NULL;
- AspectText_applied = NULL;
- TextParam_applied = NULL;
+ if (theWithApply)
+ {
+ AspectText_applied = AspectText_set;
+ TextParam_applied = TextParam_set;
+ }
+
+ return AspectText_set;
}