// Created on: 2011-09-20
// 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.
-
-
-#ifdef HAVE_CONFIG_H
- #include <config.h>
-#endif
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#include <NCollection_Mat4.hxx>
#include <OpenGl_Display.hxx>
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_GraduatedTrihedron.hxx>
+#include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_Texture.hxx>
#include <OpenGl_Trihedron.hxx>
#include <OpenGl_Workspace.hxx>
#include <Graphic3d_TextureEnv.hxx>
+#include <Graphic3d_Mat4d.hxx>
IMPLEMENT_STANDARD_HANDLE(OpenGl_View,MMgt_TShared)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared)
static const OPENGL_BG_GRADIENT myDefaultBgGradient = { {{ 0.F, 0.F, 0.F, 1.F }}, {{ 0.F, 0.F, 0.F, 1.F }}, Aspect_GFM_NONE };
static const Tmatrix3 myDefaultMatrix = { { 1.F, 0.F, 0.F, 0.F }, { 0.F, 1.F, 0.F, 0.F }, { 0.F, 0.F, 1.F, 0.F }, { 0.F, 0.F, 0.F, 1.F } };
static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } };
-static const OPENGL_EXTRA_REP myDefaultExtra =
-{
- //vrp
- { 0.F, 0.F, 0.F },
- //vpn
- { 0.F, 0.F, 1.F },
- //vup
- { 0.F, 1.F, 0.F },
- //map
- {
- //window
- { 0.F, 0.F, 1.F, 1.F },
- //viewport
- { 0.F, 0.F, 0.F, 1.F, 1.F, 1.F },
- //proj
- TelParallel,
- //prp
- { 0.F, 0.F, 0.F },
- //vpd
- 0.F,
- //fpd
- 0.F,
- //bpd
- -1.F
- },
- //scaleFactors
- { 1.F, 1.F, 1.F }
-};
static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F };
/*----------------------------------------------------------------------*/
-OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext)
+OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext,
+ OpenGl_StateCounter* theCounter)
: mySurfaceDetail(Visual3d_TOD_NONE),
myBackfacing(0),
myBgTexture(myDefaultBgTexture),
myBgGradient(myDefaultBgGradient),
- //myOrientationMatrix(myDefaultMatrix),
- //myMappingMatrix(myDefaultMatrix),
//shield_indicator = TOn,
//shield_colour = { { 0.F, 0.F, 0.F, 1.F } },
//border_indicator = TOff,
//border_colour = { { 0.F, 0.F, 0.F, 1.F } },
//active_status = TOn,
myZClip(myDefaultZClip),
- myExtra(myDefaultExtra),
+ myCamera(AContext.Camera),
myFog(myDefaultFog),
myTrihedron(NULL),
myGraduatedTrihedron(NULL),
myAntiAliasing(Standard_False),
myTransPers(&myDefaultTransPers),
myIsTransPers(Standard_False),
- myOrientationChanged (Standard_True),
- myViewMappingChanged (Standard_True),
- myLightSourcesChanged (Standard_True)
+ myProjectionState (0),
+ myModelViewState (0),
+ myStateCounter (theCounter),
+ myLastLightSourceState (0, 0)
{
- // Initialize matrices
- memcpy(myOrientationMatrix,myDefaultMatrix,sizeof(Tmatrix3));
- memcpy(myMappingMatrix,myDefaultMatrix,sizeof(Tmatrix3));
// Shading method
switch (AContext.Model)
break;
}
-#ifdef HAVE_OPENCL
+ myCurrLightSourceState = myStateCounter->Increment();
+
myModificationState = 1; // initial state
-#endif
}
/*----------------------------------------------------------------------*/
if (!anImage.IsNull())
myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type());
-#ifdef HAVE_OPENCL
myModificationState++;
-#endif
}
void OpenGl_View::SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail theMode)
{
mySurfaceDetail = theMode;
-#ifdef HAVE_OPENCL
myModificationState++;
-#endif
}
-/*----------------------------------------------------------------------*/
-
+// =======================================================================
+// function : SetBackfacing
+// purpose :
+// =======================================================================
void OpenGl_View::SetBackfacing (const Standard_Integer theMode)
{
myBackfacing = theMode;
}
-/*----------------------------------------------------------------------*/
-
-//call_togl_setlight
-void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT &AContext)
+// =======================================================================
+// function : SetLights
+// purpose :
+// =======================================================================
+void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT& theViewCtx)
{
myLights.Clear();
-
- const int nb_lights = AContext.NbActiveLight;
-
- int i = 0;
- const CALL_DEF_LIGHT *alight = &(AContext.ActiveLight[0]);
- for ( ; i < nb_lights; i++, alight++ )
+ for (Standard_Integer aLightIt = 0; aLightIt < theViewCtx.NbActiveLight; ++aLightIt)
{
- OpenGl_Light rep;
- memset(&rep,0,sizeof(rep));
-
- switch( alight->LightType )
- {
- case 0 : /* TOLS_AMBIENT */
- rep.type = TLightAmbient;
- rep.col.rgb[0] = alight->Color.r;
- rep.col.rgb[1] = alight->Color.g;
- rep.col.rgb[2] = alight->Color.b;
- break;
-
- case 1 : /* TOLS_DIRECTIONAL */
- rep.type = TLightDirectional;
- rep.col.rgb[0] = alight->Color.r;
- rep.col.rgb[1] = alight->Color.g;
- rep.col.rgb[2] = alight->Color.b;
- rep.dir[0] = alight->Direction.x;
- rep.dir[1] = alight->Direction.y;
- rep.dir[2] = alight->Direction.z;
- break;
-
- case 2 : /* TOLS_POSITIONAL */
- rep.type = TLightPositional;
- rep.col.rgb[0] = alight->Color.r;
- rep.col.rgb[1] = alight->Color.g;
- rep.col.rgb[2] = alight->Color.b;
- rep.pos[0] = alight->Position.x;
- rep.pos[1] = alight->Position.y;
- rep.pos[2] = alight->Position.z;
- rep.atten[0] = alight->Attenuation[0];
- rep.atten[1] = alight->Attenuation[1];
- break;
-
- case 3 : /* TOLS_SPOT */
- rep.type = TLightSpot;
- rep.col.rgb[0] = alight->Color.r;
- rep.col.rgb[1] = alight->Color.g;
- rep.col.rgb[2] = alight->Color.b;
- rep.pos[0] = alight->Position.x;
- rep.pos[1] = alight->Position.y;
- rep.pos[2] = alight->Position.z;
- rep.dir[0] = alight->Direction.x;
- rep.dir[1] = alight->Direction.y;
- rep.dir[2] = alight->Direction.z;
- rep.shine = alight->Concentration;
- rep.atten[0] = alight->Attenuation[0];
- rep.atten[1] = alight->Attenuation[1];
- rep.angle = alight->Angle;
- break;
- }
-
- rep.HeadLight = alight->Headlight;
-
- myLights.Append(rep);
+ myLights.Append (theViewCtx.ActiveLight[aLightIt]);
}
-
- myLightSourcesChanged = Standard_True;
+ myCurrLightSourceState = myStateCounter->Increment();
}
/*----------------------------------------------------------------------*/
//call_togl_cliplimit
void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView)
{
- myZClip.Back.Limit =
- (theCView.Context.ZClipBackPlane - theCView.Mapping.BackPlaneDistance) /
- (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
- myZClip.Front.Limit =
- (theCView.Context.ZClipFrontPlane - theCView.Mapping.BackPlaneDistance) /
- (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
- if (myZClip.Back.Limit < 0.0f)
- myZClip.Back.Limit = 0.0f;
- if (myZClip.Front.Limit > 1.0f)
- myZClip.Front.Limit = 1.0f;
- if (myZClip.Back.Limit > myZClip.Front.Limit)
- {
- myZClip.Back.Limit = 0.0f;
- myZClip.Front.Limit = 1.0f;
- }
+ myZClip.Back.Limit = theCView.Context.ZClipBackPlane;
+ myZClip.Front.Limit = theCView.Context.ZClipFrontPlane;
myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0);
myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0);
/*----------------------------------------------------------------------*/
-//call_togl_viewmapping
-void OpenGl_View::SetMapping (const Handle(OpenGl_Display)& theGlDisplay,
- const Graphic3d_CView& theCView)
-{
- const float ratio = theCView.DefWindow.dy / theCView.DefWindow.dx;
- const float r_ratio = theCView.DefWindow.dx / theCView.DefWindow.dy;
-
- TEL_VIEW_MAPPING Map;
-
- Map.window.xmin = theCView.Mapping.WindowLimit.um;
- Map.window.ymin = theCView.Mapping.WindowLimit.vm;
- Map.window.xmax = theCView.Mapping.WindowLimit.uM;
- Map.window.ymax = theCView.Mapping.WindowLimit.vM;
-
- Map.viewport.xmin = 0.F;
- Map.viewport.xmax = ( 1.F < r_ratio ? 1.F : r_ratio );
- Map.viewport.ymin = 0.F;
- Map.viewport.ymax = ( 1.F < ratio ? 1.F : ratio );
- Map.viewport.zmin = 0.F;
- Map.viewport.zmax = 1.F;
-
- // projection type
- switch (theCView.Mapping.Projection)
- {
- case 0 :
- Map.proj = TelPerspective;
- break;
- case 1 :
- Map.proj = TelParallel;
- break;
- }
-
- // projection reference point
- Map.prp[0] = theCView.Mapping.ProjectionReferencePoint.x;
- Map.prp[1] = theCView.Mapping.ProjectionReferencePoint.y;
- Map.prp[2] = theCView.Mapping.ProjectionReferencePoint.z;
- if (!theGlDisplay.IsNull() && !theGlDisplay->Walkthrough())
- Map.prp[2] += theCView.Mapping.FrontPlaneDistance;
-
- // view plane distance
- Map.vpd = theCView.Mapping.ViewPlaneDistance;
-
- // back plane distance
- Map.bpd = theCView.Mapping.BackPlaneDistance;
-
- // front plane distance
- Map.fpd = theCView.Mapping.FrontPlaneDistance;
-
- Tint err_ind = 0;
-
- // use user-defined matrix
- if (theCView.Mapping.IsCustomMatrix)
- {
- int i, j;
- for( i = 0; i < 4; i++ )
- for( j = 0; j < 4; j++ )
- myMappingMatrix[i][j] = theCView.Mapping.ProjectionMatrix[i][j];
- }
- else
- TelEvalViewMappingMatrix (theGlDisplay, &Map, &err_ind, myMappingMatrix);
-
- if (!err_ind)
- myExtra.map = Map;
-
- myViewMappingChanged = Standard_True;
-}
-
-/*----------------------------------------------------------------------*/
-
-//call_togl_vieworientation
-void OpenGl_View::SetOrientation (const Graphic3d_CView& theCView)
-{
- Tfloat Vrp[3];
- Tfloat Vpn[3];
- Tfloat Vup[3];
- Tfloat ScaleFactors[3];
-
- Vrp[0] = theCView.Orientation.ViewReferencePoint.x;
- Vrp[1] = theCView.Orientation.ViewReferencePoint.y;
- Vrp[2] = theCView.Orientation.ViewReferencePoint.z;
-
- Vpn[0] = theCView.Orientation.ViewReferencePlane.x;
- Vpn[1] = theCView.Orientation.ViewReferencePlane.y;
- Vpn[2] = theCView.Orientation.ViewReferencePlane.z;
-
- Vup[0] = theCView.Orientation.ViewReferenceUp.x;
- Vup[1] = theCView.Orientation.ViewReferenceUp.y;
- Vup[2] = theCView.Orientation.ViewReferenceUp.z;
-
- ScaleFactors[0] = theCView.Orientation.ViewScaleX;
- ScaleFactors[1] = theCView.Orientation.ViewScaleY;
- ScaleFactors[2] = theCView.Orientation.ViewScaleZ;
-
- Tint err_ind = 0;
-
- // use user-defined matrix
- if (theCView.Orientation.IsCustomMatrix)
- {
- int i, j;
- for( i = 0; i < 4; i++ )
- for( j = 0; j < 4; j++ )
- myOrientationMatrix[i][j] = theCView.Orientation.ModelViewMatrix[i][j];
- }
- else
- {
- TelEvalViewOrientationMatrix (Vrp, Vpn, Vup, ScaleFactors, &err_ind, myOrientationMatrix);
- }
-
- if (!err_ind)
- {
- myExtra.vrp[0] = Vrp[0];
- myExtra.vrp[1] = Vrp[1];
- myExtra.vrp[2] = Vrp[2];
-
- myExtra.vpn[0] = Vpn[0];
- myExtra.vpn[1] = Vpn[1];
- myExtra.vpn[2] = Vpn[2];
-
- myExtra.vup[0] = Vup[0];
- myExtra.vup[1] = Vup[1];
- myExtra.vup[2] = Vup[2];
-
- myExtra.scaleFactors[0] = ScaleFactors[0],
- myExtra.scaleFactors[1] = ScaleFactors[1],
- myExtra.scaleFactors[2] = ScaleFactors[2];
- }
-
- myOrientationChanged = Standard_True;
-}
-
-/*----------------------------------------------------------------------*/
-
void OpenGl_View::SetFog (const Graphic3d_CView& theCView,
const Standard_Boolean theFlag)
{
{
myFog.IsOn = Standard_True;
- myFog.Front =
- (theCView.Context.DepthFrontPlane - theCView.Mapping.BackPlaneDistance) /
- (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
-
- myFog.Back =
- (theCView.Context.DepthBackPlane - theCView.Mapping.BackPlaneDistance) /
- (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
-
- if (myFog.Front < 0.F)
- myFog.Front = 0.F;
- else if (myFog.Front > 1.F)
- myFog.Front = 1.F;
-
- if (myFog.Back < 0.F)
- myFog.Back = 0.F;
- else if (myFog.Back > 1.F)
- myFog.Back = 1.F;
-
- if (myFog.Back > myFog.Front)
- {
- myFog.Front = 1.F;
- myFog.Back = 0.F;
- }
+ myFog.Front = theCView.Context.DepthFrontPlane;
+ myFog.Back = theCView.Context.DepthBackPlane;
myFog.Color.rgb[0] = theCView.DefWindow.Background.r;
myFog.Color.rgb[1] = theCView.DefWindow.Background.g;
glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection);
// Set OCCT state uniform variables
- theCtx->ShaderManager()->RevertWorldViewStateTo (aResultWorldView);
- theCtx->ShaderManager()->RevertProjectionStateTo (aResultProjection);
+ theCtx->ShaderManager()->RevertWorldViewStateTo (&aResultWorldView);
+ theCtx->ShaderManager()->RevertProjectionStateTo (&aResultProjection);
}
}
// prevent scaling-on-axis
if (theTransPers->mode & TPF_ZOOM)
{
- const double aScaleX = myExtra.scaleFactors[0];
- const double aScaleY = myExtra.scaleFactors[1];
- const double aScaleZ = myExtra.scaleFactors[2];
+ const gp_Pnt anAxialScale = myCamera->AxialScale();
+ const double aScaleX = anAxialScale.X();
+ const double aScaleY = anAxialScale.Y();
+ const double aScaleZ = anAxialScale.Z();
for (int i = 0; i < 3; ++i)
{
aModelMatrix[0][i] /= aScaleX;
glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection);
// Set OCCT state uniform variables
- theCtx->ShaderManager()->UpdateWorldViewStateTo (aResultWorldView);
- theCtx->ShaderManager()->UpdateProjectionStateTo (aResultProjection);
+ theCtx->ShaderManager()->UpdateWorldViewStateTo (&aResultWorldView);
+ theCtx->ShaderManager()->UpdateProjectionStateTo (&aResultProjection);
return aTransPersPrev;
}
+
+/*----------------------------------------------------------------------*/
+
+void OpenGl_View::GetMatrices (TColStd_Array2OfReal& theMatOrient,
+ TColStd_Array2OfReal& theMatMapping) const
+{
+ const Graphic3d_Mat4d& aProj = myCamera->ProjectionMatrix();
+ const Graphic3d_Mat4d& aOrient = myCamera->OrientationMatrix();
+
+ for (Standard_Integer aRow = 0; aRow < 4; ++aRow)
+ {
+ for (Standard_Integer aCol = 0; aCol < 4; ++aCol)
+ {
+ theMatOrient (aRow, aCol) = aOrient.GetValue (aRow, aCol);
+ theMatMapping (aRow, aCol) = aProj .GetValue (aRow, aCol);
+ }
+ }
+}
+/*----------------------------------------------------------------------*/