return true;
}
+ // Converts NCollection_Mat4 with different element type.
+ template <typename Other_t>
+ void Convert (const NCollection_Mat4<Other_t>& theOther)
+ {
+ for (int anIdx = 0; anIdx < 16; ++anIdx)
+ {
+ myMat[anIdx] = static_cast<Element_t> (theOther.myMat[anIdx]);
+ }
+ }
+
+ //! Maps plain C array to matrix type.
+ static NCollection_Mat4<Element_t>& Map (Element_t* theData)
+ {
+ return *reinterpret_cast<NCollection_Mat4<Element_t>*> (theData);
+ }
+
+ //! Maps plain C array to matrix type.
+ static const NCollection_Mat4<Element_t>& Map (const Element_t* theData)
+ {
+ return *reinterpret_cast<const NCollection_Mat4<Element_t>*> (theData);
+ }
+
private:
Element_t myMat[16];
private:
static Element_t myIdentityArray[16];
+
+ // All instantiations are friend to each other
+ template<class OtherType> friend class NCollection_Mat4;
+
};
template<typename Element_t>
Handle_OpenGl_Sampler.hxx
OpenGl_Sampler.hxx
OpenGl_Sampler.cxx
+OpenGl_Utils.hxx
+OpenGl_Quadric.hxx
+OpenGl_Quadric.cxx
+OpenGl_Cylinder.hxx
+OpenGl_Cylinder.cxx
+OpenGl_Disk.hxx
+OpenGl_Disk.cxx
+OpenGl_Sphere.hxx
+OpenGl_Sphere.cxx
theWorkspace->AspectFace (Standard_True);
// set identity model matrix
- const OpenGl_Matrix* aModelMatrix = theWorkspace->SetStructureMatrix (&OpenGl_IdentityMatrix);
+ aContext->ModelWorldState.Push();
+ aContext->ModelWorldState.SetCurrent (OpenGl_Mat4::Map (*aPlaneRes->Orientation()->mat));
+ aContext->ApplyModelViewMatrix();
+
#if !defined(GL_ES_VERSION_2_0)
- glMultMatrixf ((const GLfloat*)aPlaneRes->Orientation());
glNormal3f (0.0f, 1.0f, 0.0f);
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (4, GL_FLOAT, 0, (GLfloat* )&THE_CAPPING_PLN_VERTS);
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
#endif
- theWorkspace->SetStructureMatrix (aModelMatrix, true);
+ aContext->ModelWorldState.Pop();
+ aContext->ApplyModelViewMatrix();
+
theWorkspace->SetAspectFace (aFaceAspect);
// set delayed resource release
const EquationCoords& theCoordSpace,
const Handle(OpenGl_Workspace)& theWS)
{
-#if !defined(GL_ES_VERSION_2_0)
- GLint aMatrixMode;
- glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
-
- OpenGl_Matrix aCurrentMx;
- glGetFloatv (GL_MODELVIEW_MATRIX, (GLfloat*) &aCurrentMx);
+ Handle(OpenGl_Context) aContext = theWS->GetGlContext();
- if (aMatrixMode != GL_MODELVIEW)
+ if (EquationCoords_View == theCoordSpace)
{
- glMatrixMode (GL_MODELVIEW);
+ aContext->WorldViewState.Push();
+ aContext->WorldViewState.SetIdentity();
}
- switch (theCoordSpace)
- {
- case EquationCoords_View: glLoadMatrixf ((const GLfloat*) &OpenGl_IdentityMatrix); break;
- case EquationCoords_World: glLoadMatrixf ((const GLfloat*) theWS->ViewMatrix()); break;
- }
+ // Set either identity or pure view matrix.
+ aContext->ApplyWorldViewMatrix();
Add (thePlanes, theCoordSpace);
- // restore model-view matrix
- glLoadMatrixf ((GLfloat*) &aCurrentMx);
-
- // restore context matrix state
- if (aMatrixMode != GL_MODELVIEW)
+ if (EquationCoords_View == theCoordSpace)
{
- glMatrixMode (aMatrixMode);
+ aContext->WorldViewState.Pop();
}
-#else
- Add (thePlanes, theCoordSpace);
-#endif
+
+ // Restore combined model-view matrix.
+ aContext->ApplyModelViewMatrix();
+
}
// =======================================================================
return anOldGlNormalize;
}
+
+// =======================================================================
+// function : ApplyModelWorldMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::ApplyModelWorldMatrix()
+{
+#if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
+ {
+ core11->glMatrixMode (GL_MODELVIEW);
+ core11->glLoadMatrixf (ModelWorldState.Current());
+ }
+#endif
+
+ if (!myShaderManager->IsEmpty())
+ {
+ myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
+ }
+}
+
+// =======================================================================
+// function : ApplyWorldViewMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::ApplyWorldViewMatrix()
+{
+#if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
+ {
+ core11->glMatrixMode (GL_MODELVIEW);
+ core11->glLoadMatrixf (WorldViewState.Current());
+ }
+#endif
+
+ if (!myShaderManager->IsEmpty())
+ {
+ myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
+ }
+}
+
+// =======================================================================
+// function : ApplyModelViewMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::ApplyModelViewMatrix()
+{
+#if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
+ {
+ OpenGl_Mat4 aModelView = WorldViewState.Current() * ModelWorldState.Current();
+ core11->glMatrixMode (GL_MODELVIEW);
+ core11->glLoadMatrixf (aModelView.GetData());
+ }
+#endif
+
+ if (!myShaderManager->IsEmpty())
+ {
+ myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
+ myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
+ }
+}
+
+// =======================================================================
+// function : ApplyProjectionMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::ApplyProjectionMatrix()
+{
+#if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
+ {
+ core11->glMatrixMode (GL_PROJECTION);
+ core11->glLoadMatrixf (ProjectionState.Current().GetData());
+ }
+#endif
+
+ if (!myShaderManager->IsEmpty())
+ {
+ myShaderManager->UpdateProjectionStateTo (ProjectionState.Current());
+ }
+}
#include <Handle_OpenGl_Context.hxx>
#include <OpenGl_Clipping.hxx>
#include <OpenGl_GlCore11.hxx>
+#include <OpenGl_Utils.hxx>
//! Forward declarations
struct OpenGl_GlFunctions;
//! @return old value of the flag
Standard_EXPORT Standard_Boolean SetGlNormalizeEnabled (Standard_Boolean isEnabled);
+ //! Applies matrix stored in ModelWorldState to OpenGl.
+ void ApplyModelWorldMatrix();
+
+ //! Applies matrix stored in WorldViewState to OpenGl.
+ void ApplyWorldViewMatrix();
+
+ //! Applies combination of matrices stored in ModelWorldState and WorldViewState to OpenGl.
+ void ApplyModelViewMatrix();
+
+ //! Applies matrix stored in ProjectionState to OpenGl.
+ void ApplyProjectionMatrix();
+
public:
//! @return messenger instance
Standard_Integer myRenderMode; //!< value for active rendering mode
Standard_Integer myDrawBuffer; //!< current draw buffer
+public:
+
+ OpenGl_Utils::MatrixState<Standard_ShortReal> ModelWorldState; //!< state of orientation matrix
+ OpenGl_Utils::MatrixState<Standard_ShortReal> WorldViewState; //!< state of orientation matrix
+ OpenGl_Utils::MatrixState<Standard_ShortReal> ProjectionState; //!< state of projection matrix
+
private:
//! Copying allowed only within Handles
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <OpenGl_Cylinder.hxx>
+
+// =======================================================================
+// function : OpenGl_Cylinder
+// purpose :
+// =======================================================================
+OpenGl_Cylinder::OpenGl_Cylinder()
+: myBotRad (1.0f),
+ myTopRad (1.0f),
+ myHeight (1.0f)
+{
+ //
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Cylinder::Init (const Standard_ShortReal theBotRad,
+ const Standard_ShortReal theTopRad,
+ const Standard_ShortReal theHeight,
+ const Standard_Integer theNbSlices,
+ const Standard_Integer theNbStacks)
+{
+ myBotRad = theBotRad;
+ myTopRad = theTopRad;
+ myHeight = theHeight;
+ return OpenGl_Quadric::init (theNbSlices, theNbStacks);
+}
+
+// =======================================================================
+// function : evalVertex
+// purpose :
+// =======================================================================
+OpenGl_Vec3 OpenGl_Cylinder::evalVertex (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const
+{
+ const Standard_ShortReal aU = static_cast<Standard_ShortReal> (theU * M_PI * 2.0);
+ const Standard_ShortReal aRadius = myBotRad + (myTopRad - myBotRad) * theV;
+ return OpenGl_Vec3 (cosf (aU) * aRadius,
+ sinf (aU) * aRadius,
+ theV * myHeight);
+}
+
+// =======================================================================
+// function : evalNormal
+// purpose :
+// =======================================================================
+OpenGl_Vec3 OpenGl_Cylinder::evalNormal (const Standard_ShortReal theU,
+ const Standard_ShortReal /*theV*/) const
+{
+ const Standard_ShortReal aU = static_cast<Standard_ShortReal> (theU * M_PI * 2.0);
+ return OpenGl_Vec3 (cosf (aU) * myHeight,
+ sinf (aU) * myHeight,
+ myBotRad - myTopRad).Normalized();
+}
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef OpenGl_Cylinder_Header
+#define OpenGl_Cylinder_Header
+
+#include <OpenGl_Quadric.hxx>
+
+//! Tool class for generating cylinder tessellation of quadric surface.
+class OpenGl_Cylinder : public OpenGl_Quadric
+{
+public:
+
+ //! Create undefined cylinder primitive.
+ Standard_EXPORT OpenGl_Cylinder();
+
+ //! Initialize cylinder primitive.
+ Standard_EXPORT Standard_Boolean Init (const Standard_ShortReal theBotRad,
+ const Standard_ShortReal theTopRad,
+ const Standard_ShortReal theHeight,
+ const Standard_Integer theNbSlices = 10,
+ const Standard_Integer theNbStacks = 10);
+
+protected:
+
+ //! Returns surface point for the given parameters.
+ Standard_EXPORT virtual OpenGl_Vec3 evalVertex (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const Standard_OVERRIDE;
+
+ //! Returns surface normal for the given parameters.
+ Standard_EXPORT virtual OpenGl_Vec3 evalNormal (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const Standard_OVERRIDE;
+
+private:
+
+ Standard_ShortReal myBotRad; //!< Radius of the cylinder at bottom
+ Standard_ShortReal myTopRad; //!< Radius of the cylinder at top
+ Standard_ShortReal myHeight; //!< Height of the cylinder
+
+};
+
+#endif // OpenGl_Cylinder_Header
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <OpenGl_Disk.hxx>
+
+// =======================================================================
+// function : OpenGl_Disk
+// purpose :
+// =======================================================================
+OpenGl_Disk::OpenGl_Disk()
+: myInnerRadius (1.0f),
+ myOuterRadius (1.0f)
+{
+ //
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Disk::Init (const Standard_ShortReal theInnerRadius,
+ const Standard_ShortReal theOuterRadius,
+ const Standard_Integer theNbSlices,
+ const Standard_Integer theNbStacks)
+{
+ myInnerRadius = theInnerRadius;
+ myOuterRadius = theOuterRadius;
+ return OpenGl_Quadric::init (theNbSlices, theNbStacks);
+}
+
+// =======================================================================
+// function : evalVertex
+// purpose :
+// =======================================================================
+OpenGl_Vec3 OpenGl_Disk::evalVertex (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const
+{
+ const Standard_ShortReal aU = static_cast<Standard_ShortReal> (theU * M_PI * 2.0);
+ const Standard_ShortReal aRadius = myInnerRadius + (myOuterRadius - myInnerRadius) * theV;
+ return OpenGl_Vec3 (cosf (aU) * aRadius, sinf (aU) * aRadius, 0.0f);
+}
+
+// =======================================================================
+// function : evalNormal
+// purpose :
+// =======================================================================
+OpenGl_Vec3 OpenGl_Disk::evalNormal (const Standard_ShortReal /*theU*/,
+ const Standard_ShortReal /*theV*/) const
+{
+ return OpenGl_Vec3 (0.0f, 0.0f, -1.0f);
+}
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef OpenGl_Disk_Header
+#define OpenGl_Disk_Header
+
+#include <OpenGl_Quadric.hxx>
+
+//! Tool class for generating disk (circle) tessellation.
+class OpenGl_Disk : public OpenGl_Quadric
+{
+public:
+
+ //! Create uninitialized disk (circle) primitive.
+ Standard_EXPORT OpenGl_Disk();
+
+ //! Initialize disk (circle) primitive.
+ Standard_EXPORT Standard_Boolean Init (const Standard_ShortReal theInnerRadius,
+ const Standard_ShortReal theOuterRadius,
+ const Standard_Integer theNbSlices = 10,
+ const Standard_Integer theNbStacks = 10);
+
+protected:
+
+ //! Returns surface point for the given parameters.
+ Standard_EXPORT virtual OpenGl_Vec3 evalVertex (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const Standard_OVERRIDE;
+
+ //! Returns surface normal for the given parameters.
+ Standard_EXPORT virtual OpenGl_Vec3 evalNormal (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const Standard_OVERRIDE;
+
+private:
+
+ Standard_ShortReal myInnerRadius; //!< Inner radius of the disk
+ Standard_ShortReal myOuterRadius; //!< Outer radius of the disk
+
+};
+
+#endif // OpenGl_Disk_Header
void OpenGl_Flipper::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
{
// Check if rendering is to be in immediate mode
- const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & OPENGL_NS_IMMEDIATE) != 0;
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
#if !defined(GL_ES_VERSION_2_0)
if (!myIsEnabled)
{
- // Restore transformation
- if (isImmediate)
- {
- if (aCurrMode != GL_MODELVIEW)
- {
- glMatrixMode (GL_MODELVIEW);
- }
-
- glPopMatrix();
-
- if (aCurrMode != GL_MODELVIEW)
- {
- glMatrixMode (aCurrMode);
- }
-
- Tmatrix3 aModelWorldState = { { 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 } };
-
- aContext->ShaderManager()->RevertModelWorldStateTo (&aModelWorldState);
- }
- else
- {
- // Update current model-view matrix in the top of the stack
- // replacing it with StructureMatrixT*ViewMatrix from the workspace.
- theWorkspace->UpdateModelViewMatrix();
- }
- return;
- }
-
- if (isImmediate)
- {
-
- if (!aContext->ShaderManager()->IsEmpty())
- {
- Tmatrix3 aWorldView;
- glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView);
-
- Tmatrix3 aProjection;
- glGetFloatv (GL_PROJECTION_MATRIX, *aProjection);
-
- aContext->ShaderManager()->UpdateWorldViewStateTo (&aWorldView);
- aContext->ShaderManager()->UpdateProjectionStateTo (&aProjection);
- }
+ // restore matrix state
+ aContext->WorldViewState.Pop();
- if (aCurrMode != GL_MODELVIEW)
- {
- glMatrixMode (GL_MODELVIEW);
- }
+ // Apply since we probably in the middle of something.
+ aContext->ApplyModelViewMatrix();
- glPushMatrix();
-
- if (aCurrMode != GL_MODELVIEW)
- {
- glMatrixMode (aCurrMode);
- }
+ return;
}
- OpenGl_Mat4 aMatrixMV;
- glGetFloatv (GL_MODELVIEW_MATRIX, aMatrixMV.ChangeData());
+ aContext->WorldViewState.Push();
+ OpenGl_Mat4 aMatrixMV = aContext->WorldViewState.Current() * aContext->ModelWorldState.Current();
const OpenGl_Vec4 aMVReferenceOrigin = aMatrixMV * myReferenceOrigin;
const OpenGl_Vec4 aMVReferenceX = aMatrixMV * OpenGl_Vec4 (myReferenceX.xyz() + myReferenceOrigin.xyz(), 1.0f);
aMatrixMV = aMatrixMV * aTransform;
// load transformed model-view matrix
- if (aCurrMode != GL_MODELVIEW)
- {
- glMatrixMode (GL_MODELVIEW);
- }
+ aContext->WorldViewState.SetCurrent (aMatrixMV);
+ aContext->ApplyWorldViewMatrix();
- glLoadMatrixf ((GLfloat*) aMatrixMV);
-
- if (aCurrMode != GL_MODELVIEW)
- {
- glMatrixMode (aCurrMode);
- }
#endif
}
#include <OpenGl_GlCore11.hxx>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-
#include <InterfaceGraphic_Graphic3d.hxx>
#include <InterfaceGraphic_Aspect.hxx>
#include <InterfaceGraphic_Visual3d.hxx>
#include <string.h>
#endif
+#include <OpenGl_AspectLine.hxx>
+#include <OpenGl_GraduatedTrihedron.hxx>
+#include <OpenGl_Utils.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_View.hxx>
-#include <OpenGl_GraduatedTrihedron.hxx>
-#include <OpenGl_AspectLine.hxx>
const OpenGl_AspectLine myDefaultAspectLine;
glGetIntegerv(GL_VIEWPORT, viewport);
double x1, y1, z1, x2, y2, z2, x3, y3, z3;
- gluUnProject(viewport[0], viewport[1], 0., model_matrix, proj_matrix, viewport, &x1, &y1, &z1);
- gluUnProject(viewport[0] + viewport[2], viewport[1], 0., model_matrix, proj_matrix, viewport, &x2, &y2, &z2);
- gluUnProject(viewport[0], viewport[1] + viewport[3], 0., model_matrix, proj_matrix, viewport, &x3, &y3, &z3);
+ OpenGl_Utils::UnProject<Standard_Real> (viewport[0],
+ viewport[1],
+ 0.0,
+ OpenGl_Mat4d::Map (model_matrix),
+ OpenGl_Mat4d::Map (proj_matrix),
+ viewport,
+ x1,
+ y1,
+ z1);
+
+ OpenGl_Utils::UnProject<Standard_Real> (viewport[0] + viewport[2],
+ viewport[1],
+ 0.0,
+ OpenGl_Mat4d::Map (model_matrix),
+ OpenGl_Mat4d::Map (proj_matrix),
+ viewport,
+ x2,
+ y2,
+ z2);
+
+ OpenGl_Utils::UnProject<Standard_Real> (viewport[0],
+ viewport[1] + viewport[3],
+ 0.0,
+ OpenGl_Mat4d::Map (model_matrix),
+ OpenGl_Mat4d::Map (proj_matrix),
+ viewport,
+ x3,
+ y3,
+ z3);
/* Normal out of user is p1p3^p1p2 */
const double dx1 = x3 - x1;
myAttribs (theAttribs),
myBounds (theBounds),
myDrawMode (DRAW_MODE_NONE),
- myIsVboInit (Standard_False),
- myUID (theDriver->GetNextPrimitiveArrayUID())
+ myIsVboInit (Standard_False)
{
+ if (theDriver != NULL)
+ {
+ myUID = theDriver->GetNextPrimitiveArrayUID();
+ }
+
if (!myIndices.IsNull()
&& myIndices->NbElements < 1)
{
// =======================================================================
void OpenGl_PrimitiveArray::Release (OpenGl_Context* theContext)
{
+ myIsVboInit = Standard_False;
if (!myVboIndices.IsNull())
{
if (theContext)
}
// =======================================================================
-// function : LoadProjTransformation
+// function : ProjTransformation
// purpose :
// =======================================================================
-void OpenGl_PrinterContext::LoadProjTransformation()
+OpenGl_Mat4 OpenGl_PrinterContext::ProjTransformation()
{
-#if !defined(GL_ES_VERSION_2_0)
- glLoadMatrixf ((GLfloat* )myProjMatrixGl);
-#endif
+ return OpenGl_Mat4::Map (myProjMatrixGl);
}
// =======================================================================
#include <Standard_DefineHandle.hxx>
#include <TColStd_Array2OfReal.hxx>
#include <Handle_Standard_Transient.hxx>
+#include <OpenGl_Vec.hxx>
//! Class provides specific information for redrawing view to offscreen buffer
//! on printing. The information is: projection matrixes for tiling,
//! theProjTransform parameter should be an 4x4 array.
bool SetProjTransformation (const TColStd_Array2OfReal& theProjTransform);
- //! Setup view projection transformation matrix (glLoadMatrixf).
- void LoadProjTransformation();
+ //! Returns projection matrix.
+ OpenGl_Mat4 ProjTransformation();
//! Get text/markers scale factor
inline void GetScale (Standard_ShortReal& theScaleX,
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <OpenGl_Quadric.hxx>
+
+#include <NCollection_AlignedAllocator.hxx>
+
+// =======================================================================
+// function : OpenGl_Quadric
+// purpose :
+// =======================================================================
+OpenGl_Quadric::OpenGl_Quadric()
+: OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_TRIANGLES, NULL, NULL, NULL),
+ myNbSlices (0),
+ myNbStacks (0)
+{
+ myDrawMode = GL_TRIANGLES;
+}
+
+// =======================================================================
+// function : init
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Quadric::init (const Standard_Integer theNbSlices,
+ const Standard_Integer theNbStacks)
+{
+ myNbSlices = theNbSlices;
+ myNbStacks = theNbStacks;
+ return createArrays();
+}
+
+// =======================================================================
+// function : Release
+// purpose :
+// =======================================================================
+void OpenGl_Quadric::Release (OpenGl_Context* theContext)
+{
+ myNbSlices = 0;
+ myNbStacks = 0;
+ OpenGl_PrimitiveArray::Release (theContext);
+}
+
+// =======================================================================
+// function : createArrays
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Quadric::createArrays() const
+{
+ // Evaluate surface points and normals
+ Graphic3d_Attribute anAttribsInfo[] =
+ {
+ { Graphic3d_TOA_POS, Graphic3d_TOD_VEC3 },
+ { Graphic3d_TOA_NORM, Graphic3d_TOD_VEC3 }
+ };
+ Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
+ myAttribs = new Graphic3d_Buffer (anAlloc);
+ myIndices = new Graphic3d_IndexBuffer (anAlloc);
+ if (!myAttribs->Init (NbVertices(), anAttribsInfo, 2)
+ || !myIndices->Init<GLuint> (NbTriangles() * 3))
+ {
+ return Standard_False;
+ }
+
+ const Standard_ShortReal aStepU = 1.0f / myNbSlices;
+ const Standard_ShortReal aStepV = 1.0f / myNbStacks;
+ for (Standard_Integer aU = 0; aU <= myNbSlices; ++aU)
+ {
+ const Standard_ShortReal aParamU = aU * aStepU;
+ for (Standard_Integer aV = 0; aV <= myNbStacks; ++aV)
+ {
+ const Standard_ShortReal aParamV = aV * aStepV;
+ const Standard_Integer aVertId = aU * (myNbStacks + 1) + aV;
+ Graphic3d_Vec3* aVertData = reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (aVertId));
+ aVertData[0] = evalVertex (aParamU, aParamV);
+ aVertData[1] = evalNormal (aParamU, aParamV);
+ }
+ }
+
+ // Extract triangle indices
+ for (Standard_Integer aU = 0, aLastIndex = -1; aU < myNbSlices; ++aU)
+ {
+ for (Standard_Integer aV = 0; aV < myNbStacks; ++aV)
+ {
+ myIndices->ChangeValue<GLuint> (++aLastIndex) = aU * (myNbStacks + 1) + aV;
+ myIndices->ChangeValue<GLuint> (++aLastIndex) = (aU + 1) * (myNbStacks + 1) + aV;
+ myIndices->ChangeValue<GLuint> (++aLastIndex) = (aU + 1) * (myNbStacks + 1) + (aV + 1);
+ myIndices->ChangeValue<GLuint> (++aLastIndex) = (aU + 1) * (myNbStacks + 1) + (aV + 1);
+ myIndices->ChangeValue<GLuint> (++aLastIndex) = aU * (myNbStacks + 1) + (aV + 1);
+ myIndices->ChangeValue<GLuint> (++aLastIndex) = aU * (myNbStacks + 1) + aV;
+ }
+ }
+ return Standard_True;
+}
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef OpenGl_Quadric_Header
+#define OpenGl_Quadric_Header
+
+#include <OpenGl_PrimitiveArray.hxx>
+
+//! Class for rendering of arbitrary primitive array.
+//! Tool class for generating tessellation of quadric surface.
+class OpenGl_Quadric : public OpenGl_PrimitiveArray
+{
+public:
+
+ //! Creates undefined abstract quadric surface
+ Standard_EXPORT OpenGl_Quadric();
+
+ //! Returns true if quadric has been defined
+ Standard_Boolean IsDefined() const { return myNbSlices != 0; }
+
+ //! Returns number of slices
+ Standard_Integer NbSlices() const { return myNbSlices; }
+
+ //! Returns number of stacks
+ Standard_Integer NbStacks() const { return myNbStacks; }
+
+ //! Returns total number of vertices
+ Standard_Integer NbVertices() const { return (myNbSlices + 1) * (myNbStacks + 1); }
+
+ //! Returns total number of triangles
+ Standard_Integer NbTriangles() const { return myNbSlices * myNbStacks * 2; }
+
+ //! Release GL resources
+ virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
+
+protected:
+
+ //! Returns surface point for the given parameters.
+ virtual OpenGl_Vec3 evalVertex (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const = 0;
+
+ //! Returns surface normal for the given parameters.
+ virtual OpenGl_Vec3 evalNormal (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const = 0;
+
+ //! Initialize primitive.
+ Standard_EXPORT Standard_Boolean init (const Standard_Integer theNbSlices,
+ const Standard_Integer theNbStacks);
+
+private:
+
+ //! Initialize arrays.
+ Standard_Boolean createArrays() const;
+
+private:
+
+ Standard_Integer myNbSlices; //!< Number of slices (u partitions)
+ Standard_Integer myNbStacks; //!< Number of stacks (v partitions)
+
+};
+
+#endif // OpenGl_Quadric_Header
// function : SetProjectionState
// purpose : Sets new state of OCCT projection transform
// =======================================================================
-void OpenGl_ShaderManager::UpdateProjectionStateTo (const Tmatrix3* theProjectionMatrix)
+void OpenGl_ShaderManager::UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix)
{
myProjectionState.Set (theProjectionMatrix);
myProjectionState.Update();
// function : SetModelWorldState
// purpose : Sets new state of OCCT model-world transform
// =======================================================================
-void OpenGl_ShaderManager::UpdateModelWorldStateTo (const Tmatrix3* theModelWorldMatrix)
+void OpenGl_ShaderManager::UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix)
{
myModelWorldState.Set (theModelWorldMatrix);
myModelWorldState.Update();
// function : SetWorldViewState
// purpose : Sets new state of OCCT world-view transform
// =======================================================================
-void OpenGl_ShaderManager::UpdateWorldViewStateTo (const Tmatrix3* theWorldViewMatrix)
+void OpenGl_ShaderManager::UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix)
{
myWorldViewState.Set (theWorldViewMatrix);
myWorldViewState.Update();
// function : RevertProjectionStateTo
// purpose : Reverts state of OCCT projection transform
// =======================================================================
-void OpenGl_ShaderManager::RevertProjectionStateTo (const Tmatrix3* theProjectionMatrix)
+void OpenGl_ShaderManager::RevertProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix)
{
myProjectionState.Set (theProjectionMatrix);
myProjectionState.Revert();
// function : RevertModelWorldStateTo
// purpose : Reverts state of OCCT model-world transform
// =======================================================================
-void OpenGl_ShaderManager::RevertModelWorldStateTo (const Tmatrix3* theModelWorldMatrix)
+void OpenGl_ShaderManager::RevertModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix)
{
myModelWorldState.Set (theModelWorldMatrix);
myModelWorldState.Revert();
// function : RevertWorldViewStateTo
// purpose : Reverts state of OCCT world-view transform
// =======================================================================
-void OpenGl_ShaderManager::RevertWorldViewStateTo (const Tmatrix3* theWorldViewMatrix)
+void OpenGl_ShaderManager::RevertWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix)
{
myWorldViewState.Set (theWorldViewMatrix);
myWorldViewState.Revert();
Standard_EXPORT const OpenGl_ProjectionState& ProjectionState() const;
//! Updates state of OCCT projection transform.
- Standard_EXPORT void UpdateProjectionStateTo (const Tmatrix3* theProjectionMatrix);
+ Standard_EXPORT void UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix);
//! Reverts state of OCCT projection transform.
- Standard_EXPORT void RevertProjectionStateTo (const Tmatrix3* theProjectionMatrix);
+ Standard_EXPORT void RevertProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix);
//! Pushes current state of OCCT projection transform to specified program.
Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
Standard_EXPORT const OpenGl_ModelWorldState& ModelWorldState() const;
//! Updates state of OCCT model-world transform.
- Standard_EXPORT void UpdateModelWorldStateTo (const Tmatrix3* theModelWorldMatrix);
+ Standard_EXPORT void UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix);
//! Reverts state of OCCT model-world transform.
- Standard_EXPORT void RevertModelWorldStateTo (const Tmatrix3* theModelWorldMatrix);
+ Standard_EXPORT void RevertModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix);
//! Pushes current state of OCCT model-world transform to specified program.
Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
Standard_EXPORT const OpenGl_WorldViewState& WorldViewState() const;
//! Updates state of OCCT world-view transform.
- Standard_EXPORT void UpdateWorldViewStateTo (const Tmatrix3* theWorldViewMatrix);
+ Standard_EXPORT void UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix);
//! Reverts state of OCCT world-view transform.
- Standard_EXPORT void RevertWorldViewStateTo (const Tmatrix3* theWorldViewMatrix);
+ Standard_EXPORT void RevertWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix);
//! Pushes current state of OCCT world-view transform to specified program.
Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
return Standard_False;
}
- theCtx->core20->glUniformMatrix4fv (theLocation, 1, theTranspose, theValue);
+ theCtx->core20->glUniformMatrix4fv (theLocation, 1, GL_FALSE, theTranspose ? theValue.Transposed() : theValue);
return Standard_True;
}
const OpenGl_Matrix& theValue,
GLboolean theTranspose)
{
- if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
- {
- return Standard_False;
- }
-
- theCtx->core20->glUniformMatrix4fv (theLocation, 1, theTranspose, *theValue.mat);
- return Standard_True;
-}
-
-// =======================================================================
-// function : SetUniform
-// purpose : Specifies the value of the floating-point uniform 4x4 matrix
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
- const GLchar* theName,
- const Tmatrix3& theValue,
- GLboolean theTranspose)
-{
- return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
-}
-
-// =======================================================================
-// function : SetUniform
-// purpose : Specifies the value of the floating-point uniform 4x4 matrix
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
- GLint theLocation,
- const Tmatrix3& theValue,
- GLboolean theTranspose)
-{
- if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
- {
- return Standard_False;
- }
-
- theCtx->core20->glUniformMatrix4fv (theLocation, 1, theTranspose, *theValue);
- return Standard_True;
+ return SetUniform (theCtx, theLocation, OpenGl_Mat4::Map (*theValue.mat), theTranspose);
}
// =======================================================================
const OpenGl_Matrix& theValue,
GLboolean theTranspose = GL_FALSE);
- //! Specifies the value of the float uniform 4x4 matrix.
- Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
- const GLchar* theName,
- const Tmatrix3& theValue,
- GLboolean theTranspose = GL_FALSE);
-
- //! Specifies the value of the float uniform 4x4 matrix.
- Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
- GLint theLocation,
- const Tmatrix3& theValue,
- GLboolean theTranspose = GL_FALSE);
-
//! Specifies the value of the float uniform array
Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
GLint theLocation,
// function : Set
// purpose : Sets new OCCT projection state
// =======================================================================
-void OpenGl_ProjectionState::Set (const Tmatrix3* theProjectionMatrix)
+void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
{
- memcpy (myProjectionMatrix, theProjectionMatrix, sizeof (Tmatrix3));
+ myProjectionMatrix = theProjectionMatrix;
myInverseNeedUpdate = true;
}
// function : ProjectionMatrix
// purpose : Returns current projection matrix
// =======================================================================
-const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrix() const
+const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrix() const
{
return myProjectionMatrix;
}
// function : ProjectionMatrixInverse
// purpose : Returns inverse of current projection matrix
// =======================================================================
-const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrixInverse() const
+const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
{
if (!myInverseNeedUpdate)
{
return myProjectionMatrixInverse;
}
- reinterpret_cast<const NCollection_Mat4<float>*> (*myProjectionMatrix)->Inverted (
- *(reinterpret_cast<NCollection_Mat4<float>*> (*myProjectionMatrixInverse)));
+ myProjectionMatrix.Inverted (myProjectionMatrixInverse);
+
return myProjectionMatrixInverse;
}
// function : Set
// purpose : Sets new model-world matrix
// =======================================================================
-void OpenGl_ModelWorldState::Set (const Tmatrix3* theModelWorldMatrix)
+void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
{
- memcpy (myModelWorldMatrix, theModelWorldMatrix, sizeof (Tmatrix3));
+ myModelWorldMatrix = theModelWorldMatrix;
myInverseNeedUpdate = true;
}
// function : ModelWorldMatrix
// purpose : Returns current model-world matrix
// =======================================================================
-const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrix() const
+const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrix() const
{
return myModelWorldMatrix;
}
// function : ModelWorldMatrixInverse
// purpose : Returns inverse of current model-world matrix
// =======================================================================
-const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
+const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
{
if (!myInverseNeedUpdate)
{
return myModelWorldMatrix;
}
- reinterpret_cast<const NCollection_Mat4<float>*> (*myModelWorldMatrix)->Inverted (
- *(reinterpret_cast<NCollection_Mat4<float>*> (*myModelWorldMatrixInverse)));
+ myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
+
return myModelWorldMatrixInverse;
}
// function : Set
// purpose : Sets new world-view matrix
// =======================================================================
-void OpenGl_WorldViewState::Set (const Tmatrix3* theWorldViewMatrix)
+void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
{
- memcpy (myWorldViewMatrix, theWorldViewMatrix, sizeof (Tmatrix3));
+ myWorldViewMatrix = theWorldViewMatrix;
myInverseNeedUpdate = true;
}
// function : WorldViewMatrix
// purpose : Returns current world-view matrix
// =======================================================================
-const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrix() const
+const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrix() const
{
return myWorldViewMatrix;
}
// function : WorldViewMatrixInverse
// purpose : Returns inverse of current world-view matrix
// =======================================================================
-const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrixInverse() const
+const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
{
if (!myInverseNeedUpdate)
{
return myWorldViewMatrix;
}
- reinterpret_cast<const NCollection_Mat4<float>*> (*myWorldViewMatrix)->Inverted (
- *(reinterpret_cast<NCollection_Mat4<float>*> (*myWorldViewMatrixInverse)));
+ myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
+
return myWorldViewMatrixInverse;
}
#include <OpenGl_Element.hxx>
#include <OpenGl_Light.hxx>
+#include <OpenGl_Vec.hxx>
#include <NCollection_List.hxx>
OpenGl_ProjectionState();
//! Sets new projection matrix.
- void Set (const Tmatrix3* theProjectionMatrix);
+ void Set (const OpenGl_Mat4& theProjectionMatrix);
//! Returns current projection matrix.
- const Tmatrix3& ProjectionMatrix() const;
+ const OpenGl_Mat4& ProjectionMatrix() const;
//! Returns inverse of current projection matrix.
- const Tmatrix3& ProjectionMatrixInverse() const;
+ const OpenGl_Mat4& ProjectionMatrixInverse() const;
private:
- Tmatrix3 myProjectionMatrix; //!< OCCT projection matrix
- mutable Tmatrix3 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
- bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
+ OpenGl_Mat4 myProjectionMatrix; //!< OCCT projection matrix
+ mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
+ bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
};
OpenGl_ModelWorldState();
//! Sets new model-world matrix.
- void Set (const Tmatrix3* theModelWorldMatrix);
+ void Set (const OpenGl_Mat4& theModelWorldMatrix);
//! Returns current model-world matrix.
- const Tmatrix3& ModelWorldMatrix() const;
+ const OpenGl_Mat4& ModelWorldMatrix() const;
//! Returns inverse of current model-world matrix.
- const Tmatrix3& ModelWorldMatrixInverse() const;
+ const OpenGl_Mat4& ModelWorldMatrixInverse() const;
private:
- Tmatrix3 myModelWorldMatrix; //!< OCCT model-world matrix
- mutable Tmatrix3 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
- bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
+ OpenGl_Mat4 myModelWorldMatrix; //!< OCCT model-world matrix
+ mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
+ bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
};
OpenGl_WorldViewState();
//! Sets new world-view matrix.
- void Set (const Tmatrix3* theWorldViewMatrix);
+ void Set (const OpenGl_Mat4& theWorldViewMatrix);
//! Returns current world-view matrix.
- const Tmatrix3& WorldViewMatrix() const;
+ const OpenGl_Mat4& WorldViewMatrix() const;
//! Returns inverse of current world-view matrix.
- const Tmatrix3& WorldViewMatrixInverse() const;
+ const OpenGl_Mat4& WorldViewMatrixInverse() const;
private:
- Tmatrix3 myWorldViewMatrix; //!< OCCT world-view matrix
- mutable Tmatrix3 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
- bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
+ OpenGl_Mat4 myWorldViewMatrix; //!< OCCT world-view matrix
+ mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
+ bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
};
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <OpenGl_Sphere.hxx>
+
+// =======================================================================
+// function : OpenGl_Sphere
+// purpose :
+// =======================================================================
+OpenGl_Sphere::OpenGl_Sphere()
+: myRadius (1.0f)
+{
+ //
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Sphere::Init (const Standard_ShortReal theRadius,
+ const Standard_Integer theNbSlices,
+ const Standard_Integer theNbStacks)
+{
+ myRadius = theRadius;
+ return OpenGl_Quadric::init (theNbSlices, theNbStacks);
+}
+
+// =======================================================================
+// function : evalVertex
+// purpose :
+// =======================================================================
+OpenGl_Vec3 OpenGl_Sphere::evalVertex (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const
+{
+ const Standard_ShortReal aU = static_cast<Standard_ShortReal> (theU * M_PI * 2.0);
+ const Standard_ShortReal aV = static_cast<Standard_ShortReal> (theV * M_PI);
+ return OpenGl_Vec3 (myRadius * cosf (aU) * sinf (aV),
+ -myRadius * sinf (aU) * sinf (aV),
+ myRadius * cosf (aV));
+}
+
+// =======================================================================
+// function : evalNormal
+// purpose :
+// =======================================================================
+OpenGl_Vec3 OpenGl_Sphere::evalNormal (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const
+{
+ const Standard_ShortReal aU = static_cast<Standard_ShortReal> (theU * M_PI * 2.0);
+ const Standard_ShortReal aV = static_cast<Standard_ShortReal> (theV * M_PI);
+ return OpenGl_Vec3 (cosf (aU) * sinf (aV),
+ -sinf (aU) * sinf (aV),
+ cosf (aV));
+}
--- /dev/null
+// Created on: 2014-10-15
+// Created by: Denis Bogolepov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef OpenGl_Sphere_Header
+#define OpenGl_Sphere_Header
+
+#include <OpenGl_Quadric.hxx>
+
+//! Tool class for generating sphere tessellation.
+class OpenGl_Sphere : public OpenGl_Quadric
+{
+public:
+
+ //! Creates undefined sphere primitive.
+ Standard_EXPORT OpenGl_Sphere();
+
+ //! Initialize sphere primitive.
+ Standard_EXPORT Standard_Boolean Init (const Standard_ShortReal theRadius,
+ const Standard_Integer theNbSlices = 10,
+ const Standard_Integer theNbStacks = 10);
+
+protected:
+
+ //! Returns surface point for the given parameters.
+ Standard_EXPORT virtual OpenGl_Vec3 evalVertex (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const Standard_OVERRIDE;
+
+ //! Returns surface normal for the given parameters.
+ Standard_EXPORT virtual OpenGl_Vec3 evalNormal (const Standard_ShortReal theU,
+ const Standard_ShortReal theV) const Standard_OVERRIDE;
+
+protected:
+
+ Standard_ShortReal myRadius; //!< Sphere radius
+
+};
+
+#endif // OpenGl_Sphere_Header
/*----------------------------------------------------------------------*/
-// =======================================================================
-// function : call_util_transpose_mat
-// purpose :
-// =======================================================================
-static void call_util_transpose_mat (float tmat[16], float mat[4][4])
-{
- int i, j;
-
- for (i=0; i<4; i++)
- for (j=0; j<4; j++)
- tmat[j*4+i] = mat[i][j];
-}
-
// =======================================================================
// function : OpenGl_Structure
// purpose :
return;
}
- const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
// Render named status
const Standard_Integer aNamedStatus = theWorkspace->NamedStatus;
theWorkspace->NamedStatus |= myNamedStatus;
- // Is rendering in ADD or IMMEDIATE mode?
- const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & OPENGL_NS_IMMEDIATE) != 0;
-
// Do we need to restore GL_NORMALIZE?
- Standard_Boolean anOldGlNormalize = aContext->IsGlNormalizeEnabled();
+ const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
// Apply local transformation
- GLint aMatrixMode = 0;
- const OpenGl_Matrix* aLocalTrsf = NULL;
if (myTransformation)
{
- #if !defined(GL_ES_VERSION_2_0)
+ OpenGl_Matrix aModelWorld;
+ OpenGl_Transposemat3 (&aModelWorld, myTransformation);
+ aCtx->ModelWorldState.Push();
+ aCtx->ModelWorldState.SetCurrent (OpenGl_Mat4::Map ((Standard_ShortReal* )aModelWorld.mat));
Standard_ShortReal aScaleX = OpenGl_Vec3 (myTransformation->mat[0][0],
myTransformation->mat[0][1],
// Scale transform detected.
if (Abs (aScaleX - 1.f) > Precision::Confusion())
{
- anOldGlNormalize = aContext->SetGlNormalizeEnabled (Standard_True);
+ aCtx->SetGlNormalizeEnabled (Standard_True);
}
-
- if (isImmediate)
- {
- Tmatrix3 aModelWorld;
- call_util_transpose_mat (*aModelWorld, myTransformation->mat);
-
- glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
-
- if (!aContext->ShaderManager()->IsEmpty())
- {
- Tmatrix3 aWorldView;
- glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView);
-
- Tmatrix3 aProjection;
- glGetFloatv (GL_PROJECTION_MATRIX, *aProjection);
-
- aContext->ShaderManager()->UpdateModelWorldStateTo (&aModelWorld);
- aContext->ShaderManager()->UpdateWorldViewStateTo (&aWorldView);
- aContext->ShaderManager()->UpdateProjectionStateTo (&aProjection);
- }
-
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix ();
- glScalef (1.0f, 1.0f, 1.0f);
- glMultMatrixf (*aModelWorld);
- }
- else
- {
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
-
- aLocalTrsf = theWorkspace->SetStructureMatrix (myTransformation);
- }
- #endif
}
// Apply transform persistence
const TEL_TRANSFORM_PERSISTENCE *aTransPersistence = NULL;
if ( myTransPers && myTransPers->mode != 0 )
{
- aTransPersistence = theWorkspace->ActiveView()->BeginTransformPersistence (aContext, myTransPers);
+ aTransPersistence = theWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers);
}
+ // Take into account transform persistence
+ aCtx->ApplyModelViewMatrix();
+
// Apply aspects
const OpenGl_AspectLine *anAspectLine = theWorkspace->AspectLine (Standard_False);
const OpenGl_AspectFace *anAspectFace = theWorkspace->AspectFace (Standard_False);
// Apply correction for mirror transform
if (myIsMirrored)
{
- glFrontFace (GL_CW);
+ aCtx->core11fwd->glFrontFace (GL_CW);
}
// Apply highlight color
if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
{
// add planes at loaded view matrix state
- aContext->ChangeClipping().AddWorld (*aUserPlanes, theWorkspace);
+ aCtx->ChangeClipping().AddWorld (*aUserPlanes, theWorkspace);
// Set OCCT state uniform variables
- if (!aContext->ShaderManager()->IsEmpty())
+ if (!aCtx->ShaderManager()->IsEmpty())
{
- aContext->ShaderManager()->UpdateClippingState();
+ aCtx->ShaderManager()->UpdateClippingState();
}
}
// Reset correction for mirror transform
if (myIsMirrored)
- glFrontFace (GL_CCW); // default
+ {
+ aCtx->core11fwd->glFrontFace (GL_CCW);
+ }
// Render capping for structure groups
- if (!aContext->Clipping().Planes().IsEmpty())
+ if (!aCtx->Clipping().Planes().IsEmpty())
{
OpenGl_CappingAlgo::RenderCapping (theWorkspace, aGroups);
}
// Revert structure clippings
if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
{
- aContext->ChangeClipping().Remove (*aUserPlanes);
+ aCtx->ChangeClipping().Remove (*aUserPlanes);
// Set OCCT state uniform variables
- if (!aContext->ShaderManager()->IsEmpty())
+ if (!aCtx->ShaderManager()->IsEmpty())
{
- aContext->ShaderManager()->RevertClippingState();
+ aCtx->ShaderManager()->RevertClippingState();
}
}
+ // Apply local transformation
+ if (myTransformation)
+ {
+ aCtx->ModelWorldState.Pop();
+ aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
+ }
+
// Restore highlight color
theWorkspace->HighlightColor = aHighlightColor;
// Restore transform persistence
if ( myTransPers && myTransPers->mode != 0 )
{
- theWorkspace->ActiveView()->BeginTransformPersistence (aContext, aTransPersistence);
- }
-
- // Restore local transformation
- if (myTransformation)
- {
- #if !defined(GL_ES_VERSION_2_0)
-
- aContext->SetGlNormalizeEnabled (anOldGlNormalize);
-
- if (isImmediate)
- {
- glPopMatrix ();
- glMatrixMode (aMatrixMode);
-
- Tmatrix3 aModelWorldState = { { 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 } };
-
- aContext->ShaderManager()->RevertModelWorldStateTo (&aModelWorldState);
- }
- else
- {
- theWorkspace->SetStructureMatrix (aLocalTrsf, true);
-
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
- }
- #endif
+ theWorkspace->ActiveView()->BeginTransformPersistence (aCtx, aTransPersistence);
}
// Apply highlight box
#include <OpenGl_ShaderStates.hxx>
#include <OpenGl_Sampler.hxx>
#include <OpenGl_Text.hxx>
+#include <OpenGl_Utils.hxx>
#include <OpenGl_Workspace.hxx>
#include <Font_FontMgr.hxx>
namespace
{
- static const GLdouble THE_IDENTITY_MATRIX[4][4] =
+ static const GLdouble THE_IDENTITY_MATRIX[16] =
{
- {1.,0.,0.,0.},
- {0.,1.,0.,0.},
- {0.,0.,1.,0.},
- {0.,0.,0.,1.}
+ 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0
};
#ifdef HAVE_GL2PS
{
// setup matrix
#if !defined(GL_ES_VERSION_2_0)
+
+ OpenGl_Mat4d aModViewMat;
+
if (myIs2d)
{
- glLoadIdentity();
- glTranslatef (myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.0f);
- glScalef (1.0f, -1.0f, 1.0f);
- glRotatef (theTextAspect.Angle(), 0.0, 0.0, 1.0);
+ OpenGl_Utils::Translate<GLdouble> (aModViewMat, myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.f);
+ OpenGl_Utils::Scale<GLdouble> (aModViewMat, 1.f, -1.f, 1.f);
+ OpenGl_Utils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.f, 0.f, 1.f);
}
else
{
// align coordinates to the nearest integer
// to avoid extra interpolation issues
GLdouble anObjX, anObjY, anObjZ;
- gluUnProject (std::floor (myWinX + (GLdouble )theDVec.x()),
- std::floor (myWinY + (GLdouble )theDVec.y()),
- myWinZ + (GLdouble )theDVec.z(),
- (GLdouble* )THE_IDENTITY_MATRIX, myProjMatrix, myViewport,
- &anObjX, &anObjY, &anObjZ);
-
- glLoadIdentity();
- theCtx->core11->glTranslated (anObjX, anObjY, anObjZ);
- theCtx->core11->glRotated (theTextAspect.Angle(), 0.0, 0.0, 1.0);
+ OpenGl_Utils::UnProject<Standard_Real> (std::floor (myWinX + theDVec.x()),
+ std::floor (myWinY + theDVec.y()),
+ myWinZ + theDVec.z(),
+ OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
+ OpenGl_Mat4d::Map (myProjMatrix),
+ myViewport,
+ anObjX,
+ anObjY,
+ anObjZ);
+
+ OpenGl_Utils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
+ OpenGl_Utils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0);
+
if (!theTextAspect.IsZoomable())
{
#ifdef _WIN32
// text should be scaled in all directions with same
// factor to save its proportions, so use height (y) scaling
// as it is better for keeping text/3d graphics proportions
- theCtx->core11->glScaled ((GLfloat )aTextScaley, (GLfloat )aTextScaley, (GLfloat )aTextScaley);
+ OpenGl_Utils::Scale<GLdouble> (aModViewMat, aTextScaley, aTextScaley, aTextScaley);
}
#endif
- theCtx->core11->glScaled (myScaleHeight, myScaleHeight, myScaleHeight);
+ OpenGl_Utils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
}
}
+
+ theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
+ theCtx->ApplyWorldViewMatrix();
#endif
}
myExportHeight = 1.0f;
myScaleHeight = 1.0f;
+ theCtx->WorldViewState.Push();
+
#if !defined(GL_ES_VERSION_2_0)
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
+ myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current());
+
if (!myIs2d)
{
- // retrieve active matrices for project/unproject calls
- glGetDoublev (GL_MODELVIEW_MATRIX, myModelMatrix);
- glGetDoublev (GL_PROJECTION_MATRIX, myProjMatrix);
glGetIntegerv (GL_VIEWPORT, myViewport);
- gluProject (myPoint.x(), myPoint.y(), myPoint.z(),
- myModelMatrix, myProjMatrix, myViewport,
- &myWinX, &myWinY, &myWinZ);
+ myProjMatrix.Convert (theCtx->ProjectionState.Current());
+
+ OpenGl_Utils::Project<Standard_Real> (myPoint.x(),
+ myPoint.y(),
+ myPoint.z(),
+ myModelMatrix,
+ myProjMatrix,
+ myViewport,
+ myWinX,
+ myWinY,
+ myWinZ);
// compute scale factor for constant text height
GLdouble x1, y1, z1;
- gluUnProject (myWinX, myWinY, myWinZ,
- (GLdouble* )THE_IDENTITY_MATRIX, myProjMatrix, myViewport,
- &x1, &y1, &z1);
+ OpenGl_Utils::UnProject<Standard_Real> (myWinX,
+ myWinY,
+ myWinZ,
+ OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
+ myProjMatrix,
+ myViewport,
+ x1,
+ y1,
+ z1);
GLdouble x2, y2, z2;
const GLdouble h = (GLdouble )myFont->FTFont()->PointSize();
- gluUnProject (myWinX, myWinY + h, myWinZ,
- (GLdouble* )THE_IDENTITY_MATRIX, myProjMatrix, myViewport,
- &x2, &y2, &z2);
+ OpenGl_Utils::UnProject<Standard_Real> (myWinX,
+ myWinY + h,
+ myWinZ,
+ OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
+ myProjMatrix,
+ myViewport,
+ x2,
+ y2,
+ z2);
myScaleHeight = (y2 - y1) / h;
if (theTextAspect.IsZoomable())
glDisable (GL_DEPTH_TEST);
}
-
// setup alpha test
GLint aTexEnvParam = GL_REPLACE;
glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam);
// revert OpenGL state
glPopAttrib(); // enable bit
- glPopMatrix(); // model view matrix was modified
+
+ // model view matrix was modified
+ theCtx->WorldViewState.Pop();
+ theCtx->ApplyModelViewMatrix();
// revert custom OpenGL sampler
if (!aSampler.IsNull() && aSampler->IsValid())
protected:
- mutable GLdouble myProjMatrix[16];
- mutable GLdouble myModelMatrix[16];
+ mutable OpenGl_Mat4d myProjMatrix;
+ mutable OpenGl_Mat4d myModelMatrix;
mutable GLint myViewport[4];
mutable GLdouble myWinX;
mutable GLdouble myWinY;
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#include <OpenGl_GlCore11.hxx>
-
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <InterfaceGraphic_Graphic3d.hxx> /* pour CALL_DEF_STRUCTURE */
-#include <InterfaceGraphic_Aspect.hxx> /* pour CALL_DEF_VIEW */
-#include <InterfaceGraphic_Visual3d.hxx>
+#include <OpenGl_Trihedron.hxx>
-#include <OpenGl_transform_persistence.hxx>
+#include <OpenGl_GlCore11.hxx>
-#include <OpenGl_Workspace.hxx>
#include <OpenGl_View.hxx>
-#include <OpenGl_Trihedron.hxx>
+#include <OpenGl_Workspace.hxx>
static const OpenGl_TextParam THE_LABEL_PARAMS =
{
Font_FA_Regular //TextFontAspect
};
-/*----------------------------------------------------------------------*/
-/*
-* Variables statiques
-*/
-
-/* Default parameters for ZBUFFER triheron */
static TEL_COLOUR theXColor = {{ 1.F, 0.F, 0.F, 0.6F }};
static TEL_COLOUR theYColor = {{ 0.F, 1.F, 0.F, 0.6F }};
static TEL_COLOUR theZColor = {{ 0.F, 0.F, 1.F, 0.6F }};
static float theDiameter = 0.05f;
static int theNbFacettes = 12;
-/*----------------------------------------------------------------------*/
-
-/*
-* affichage d'un triedre non zoomable a partir des index dans les tables
-* des structures non zoomables.
-*
-* Triedre = Objet non Zoomable :
-* on recalcule ses dimensions et son origine en fonction de la taille
-* de la fenetre; on positionne selon le choix de l'init;
-* et on inhibe seulement les translations.
-*
-*/
-
-//call_triedron_redraw
+// =======================================================================
+// function : redraw
+// purpose :
+// =======================================================================
void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) const
{
#if !defined(GL_ES_VERSION_2_0)
const Standard_Real U = theWorkspace->ActiveView()->Height();
const Standard_Real V = theWorkspace->ActiveView()->Width();
+ Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext();
+
/* la taille des axes est 1 proportion (fixee a l'init du triedre) */
/* de la dimension la plus petite de la window. */
const GLdouble L = ( U < V ? U : V ) * myScale;
* On inhibe les translations; on conserve les autres transformations.
*/
+ aContext->WorldViewState.Push();
+ aContext->ProjectionState.Push();
+
/* on lit les matrices de transformation et de projection de la vue */
/* pour annuler les translations (dernieres colonnes des matrices). */
- GLdouble modelMatrix[4][4];
- glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix );
- GLdouble projMatrix[4][4];
- glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
+ OpenGl_Mat4d aModelMatrix;
+ aModelMatrix.Convert (aContext->WorldViewState.Current());
+
+ OpenGl_Mat4d aProjMatrix;
/* on annule la translation qui peut etre affectee a la vue */
- modelMatrix[3][0] = 0.;
- modelMatrix[3][1] = 0.;
- modelMatrix[3][2] = 0.;
-
- projMatrix[0][0] = 2.0 / U;
- projMatrix[0][1] = 0.0;
- projMatrix[0][2] = 0.0;
- projMatrix[0][3] = 0.0;
-
- projMatrix[1][0] = 0.0;
- projMatrix[1][1] = 2.0 / V;
- projMatrix[1][2] = 0.0;
- projMatrix[1][3] = 0.0;
-
- projMatrix[2][0] = 0.0;
- projMatrix[2][1] = 0.0;
- projMatrix[2][2] = -2.0 * 1e-7;
- projMatrix[2][3] = 0.0;
-
- projMatrix[3][0] = 0.0;
- projMatrix[3][1] = 0.0;
- projMatrix[3][2] = 0.0;
- projMatrix[3][3] = 1.0;
-
- /* sauvegarde du contexte des matrices avant chargement */
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix ();
- glLoadMatrixd( (GLdouble *) modelMatrix );
- glMatrixMode ( GL_PROJECTION );
- glPushMatrix ();
- glLoadMatrixd( (GLdouble *) projMatrix );
+ aModelMatrix.ChangeValue (0, 3) = 0.0;
+ aModelMatrix.ChangeValue (1, 3) = 0.0;
+ aModelMatrix.ChangeValue (2, 3) = 0.0;
+
+ aProjMatrix.ChangeValue (0, 0) = 2.0 / U;
+ aProjMatrix.ChangeValue (1, 0) = 0.0;
+ aProjMatrix.ChangeValue (2, 0) = 0.0;
+ aProjMatrix.ChangeValue (3, 0) = 0.0;
+
+ aProjMatrix.ChangeValue (0, 1) = 0.0;
+ aProjMatrix.ChangeValue (1, 1) = 2.0 / V;
+ aProjMatrix.ChangeValue (2, 1) = 0.0;
+ aProjMatrix.ChangeValue (3, 1) = 0.0;
+
+ aProjMatrix.ChangeValue (0, 2) = 0.0;
+ aProjMatrix.ChangeValue (1, 2) = 0.0;
+ aProjMatrix.ChangeValue (2, 2) = -2.0 * 1e-7;
+ aProjMatrix.ChangeValue (3, 2) = 0.0;
+
+ aProjMatrix.ChangeValue (0, 3) = 0.0;
+ aProjMatrix.ChangeValue (1, 3) = 0.0;
+ aProjMatrix.ChangeValue (2, 3) = 0.0;
+ aProjMatrix.ChangeValue (3, 3) = 1.0;
/*
* Positionnement de l'origine du triedre selon le choix de l'init
switch (myPos)
{
case Aspect_TOTP_LEFT_LOWER :
- glTranslated( -0.5*U + L , -0.5*V + L , 0. );
- break;
+ {
+ OpenGl_Utils::Translate (aProjMatrix,
+ -0.5 * U + L, -0.5 * V + L, 0.0);
+ }
+ break;
case Aspect_TOTP_LEFT_UPPER :
- glTranslated( -0.5*U + L , +0.5*V - L -L/3., 0. );
- break;
+ {
+ OpenGl_Utils::Translate (aProjMatrix,
+ -0.5 * U + L, 0.5 * V - L - L/3.0, 0.0);
+ }
+ break;
case Aspect_TOTP_RIGHT_LOWER :
- glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. );
- break;
+ {
+ OpenGl_Utils::Translate (aProjMatrix,
+ 0.5 * U - L - L/3.0, -0.5 * V + L, 0.0);
+ }
+ break;
case Aspect_TOTP_RIGHT_UPPER :
- glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. );
- break;
+ {
+ OpenGl_Utils::Translate (aProjMatrix,
+ 0.5 * U - L - L/3.0, 0.5 * V - L - L/3.0, 0.0);
+ }
+ break;
//case Aspect_TOTP_CENTER :
default :
break;
}
+ aContext->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
+ aContext->ApplyProjectionMatrix();
+ aContext->ApplyWorldViewMatrix();
+
/*
* Creation du triedre
*/
/*
* restauration du contexte des matrices
*/
- glMatrixMode (GL_PROJECTION);
- glPopMatrix ();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix ();
+
+ aContext->WorldViewState.Pop();
+ aContext->ProjectionState.Pop();
+ aContext->ApplyProjectionMatrix();
#endif
}
-
-/*******************************************************
-* Draws ZBUFFER trihedron mode
-*******************************************************/
-//call_zbuffer_triedron_redraw
+// =======================================================================
+// function : redrawZBuffer
+// purpose :
+// =======================================================================
void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const
{
-#if !defined(GL_ES_VERSION_2_0)
- const Standard_Real U = theWorkspace->ActiveView()->Height();
- const Standard_Real V = theWorkspace->ActiveView()->Width();
-
- GLdouble modelMatrix[4][4];
- glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix );
- GLdouble projMatrix[4][4];
- glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
-
- /* Check position in the ViewPort */
- /* PCD 29/09/2008 */
- /* Simple code modification recommended by Fotis Sioutis and Peter Dolbey */
- /* to remove the irritating default behaviour of triedrons using V3d_ZBUFFER */
- /* which causes the glyph to jump around the screen when the origin moves offscreen. */
- GLboolean isWithinView = GL_FALSE;
+ Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext();
+ const Handle(OpenGl_View)& aView = theWorkspace->ActiveView();
- /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
- /* de la dimension la plus petite de la window. */
- GLdouble L = ( U < V ? U : V ) * myScale;
+ OpenGl_Mat4d aModelMatrix, aProjMatrix;
+ aContext->WorldViewState.Push();
+ aContext->ProjectionState.Push();
+ aModelMatrix.Convert (aContext->WorldViewState.Current());
- if (!isWithinView)
+ GLdouble U = 1.0;
+ GLdouble V = 1.0;
+ if (aView->Height() < aView->Width())
{
- /* Annulate translation matrix */
- modelMatrix[3][0] = 0.;
- modelMatrix[3][1] = 0.;
- modelMatrix[3][2] = 0.;
-
- projMatrix[0][0] = 2.0 / U;
- projMatrix[0][1] = 0.0;
- projMatrix[0][2] = 0.0;
- projMatrix[0][3] = 0.0;
-
- projMatrix[1][0] = 0.0;
- projMatrix[1][1] = 2.0 / V;
- projMatrix[1][2] = 0.0;
- projMatrix[1][3] = 0.0;
-
- projMatrix[2][0] = 0.0;
- projMatrix[2][1] = 0.0;
- projMatrix[2][2] = -2.0 * 1e-7;
- projMatrix[2][3] = 0.0;
-
- projMatrix[3][0] = 0.0;
- projMatrix[3][1] = 0.0;
- projMatrix[3][2] = 0.0;
- projMatrix[3][3] = 1.0;
-
- /* save matrix */
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix ();
- //glLoadIdentity ();
- glLoadMatrixd( (GLdouble *) modelMatrix);
- glMatrixMode ( GL_PROJECTION );
- glPushMatrix ();
- //glLoadIdentity();
- glLoadMatrixd( (GLdouble *) projMatrix);
-
- /*
- * Define position in the view
- */
- switch (myPos)
- {
- case Aspect_TOTP_LEFT_LOWER :
- glTranslated( -0.5*U + L , -0.5*V + L , 0. );
- break;
-
- case Aspect_TOTP_LEFT_UPPER :
- glTranslated( -0.5*U + L , +0.5*V - L -L/3. , 0. );
- break;
-
- case Aspect_TOTP_RIGHT_LOWER :
- glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. );
- break;
-
- case Aspect_TOTP_RIGHT_UPPER :
- glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. );
- break;
-
- //case Aspect_TOTP_CENTER :
- default :
- break;
- }
- L *= myRatio;
+ V = aView->Width() / aView->Height();
+ }
+ else
+ {
+ U = aView->Height() / aView->Width();
}
- const OpenGl_AspectLine *AspectLine = theWorkspace->AspectLine( Standard_True );
- const TEL_COLOUR &aLineColor = AspectLine->Color();
+ GLdouble aScale = myScale;
- /*
- * Creation the trihedron
- */
-#define CYLINDER_LENGTH 0.75f
-
- const GLuint startList = glGenLists(4);
- GLUquadricObj* aQuadric = gluNewQuadric();
-
- const GLboolean aIsDepthEnabled = glIsEnabled(GL_DEPTH_TEST);
-
- GLboolean aIsDepthMaskEnabled;
- /*PCD 02/07/07 */
- /* GL_DEPTH_WRITEMASK is not a valid argument to glIsEnabled, the */
- /* original code is shown to be broken when run under an OpenGL debugger */
- /* like GLIntercept. This is the correct way to retrieve the mask value. */
- glGetBooleanv(GL_DEPTH_WRITEMASK, &aIsDepthMaskEnabled);
-
- const GLdouble aCylinderLength = L * CYLINDER_LENGTH;
- const GLdouble aCylinderDiametr = L * myDiameter;
- const GLdouble aConeDiametr = aCylinderDiametr * 2.;
- const GLdouble aConeLength = L * (1 - CYLINDER_LENGTH);
- /* Correct for owerlapping */
- /* aCylinderLength += aConeLength - 1.2*aCylinderDiametr*aConeLength/aConeDiametr;*/
-
- /* Create cylinder for axis */
- gluQuadricDrawStyle(aQuadric, GLU_FILL); /* smooth shaded */
- gluQuadricNormals(aQuadric, GLU_FLAT);
- /* Axis */
- glNewList(startList, GL_COMPILE);
- gluCylinder(aQuadric, aCylinderDiametr, aCylinderDiametr, aCylinderLength, myNbFacettes, 1);
- glEndList();
- /* Cone */
- glNewList(startList + 1, GL_COMPILE);
- gluCylinder(aQuadric, aConeDiametr, 0., aConeLength, myNbFacettes, 1);
- glEndList();
- /* Central sphere */
- glNewList(startList + 2, GL_COMPILE);
- gluSphere(aQuadric, aCylinderDiametr * 2., myNbFacettes, myNbFacettes);
- glEndList();
- /* End disk */
- gluQuadricOrientation(aQuadric,GLU_INSIDE); /*szv*/
- glNewList(startList + 3, GL_COMPILE);
- gluDisk(aQuadric, aCylinderDiametr, aConeDiametr, myNbFacettes, 1/*szv:2*/);
- glEndList();
-
- /* Store previous attributes */
- glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT);
- glEnable(GL_LIGHTING);
-
- glCullFace(GL_BACK);
- glEnable(GL_CULL_FACE);
-
- /*Fotis Sioutis | 2008-01-21 10:55
- In the function call_zbuffer_triedron_redraw of TKOpengl,
- the z buffered trihedron changes colors in case there
- is an object in the scene that has an explicit material
- attached to it.In the trihedron display loop,
- GL_COLOR_MATERIAL is enabled, but only the GL_DIFFUSE
- parameter is utilized in glColorMaterial(...).
- This causes the last ambient,specular and emission values
- used, to stay at the stack and applied to the trihedron
- (which causes the color change).
- A fix is proposed , to change GL_DIFFUSE to
- GL_AMBIENT_AND_DIFFUSE in glColorMaterial call in
- line 946.The above of course will leave unchanged
- the SPECULAR and EMISSION values.
- Another proposal which would fix 100% the problem
- is to use glMaterial instead of glColor on the trihedron
- drawing loop. */
- const GLfloat aNULLColor[] = { 0.f, 0.f, 0.f, 0.f }; /* FS 21/01/08 */
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, aNULLColor);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, aNULLColor);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, aNULLColor);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.f);
-
- glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
-
- if (!aIsDepthEnabled) {
- glEnable(GL_DEPTH_TEST);
- glClear(GL_DEPTH_BUFFER_BIT);
- }
+ // Annulate translation matrix
+ aModelMatrix.ChangeValue (0, 3) = 0.0;
+ aModelMatrix.ChangeValue (1, 3) = 0.0;
+ aModelMatrix.ChangeValue (2, 3) = 0.0;
- if (!aIsDepthMaskEnabled) {
- /* This is how the depthmask needs to be re-enabled...*/
- glDepthMask(GL_TRUE);
- /* ...and not this stuff below */
- }
+ aProjMatrix.ChangeValue (0, 0) = 2.0 / U;
+ aProjMatrix.ChangeValue (1, 0) = 0.0;
+ aProjMatrix.ChangeValue (2, 0) = 0.0;
+ aProjMatrix.ChangeValue (3, 0) = 0.0;
- /* Position des Axes */
- GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
- GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
- TriedronAxeX[0] = L;
- TriedronAxeY[1] = L;
+ aProjMatrix.ChangeValue (0, 1) = 0.0;
+ aProjMatrix.ChangeValue (1, 1) = 2.0 / V;
+ aProjMatrix.ChangeValue (2, 1) = 0.0;
+ aProjMatrix.ChangeValue (3, 1) = 0.0;
- glMatrixMode(GL_MODELVIEW);
+ aProjMatrix.ChangeValue (0, 2) = 0.0;
+ aProjMatrix.ChangeValue (1, 2) = 0.0;
+ aProjMatrix.ChangeValue (2, 2) = -2.0 * 1e-2;
+ aProjMatrix.ChangeValue (3, 2) = 0.0;
- /* PCD 17/06/07 */
- GLint df;
- glGetIntegerv (GL_DEPTH_FUNC, &df);
+ aProjMatrix.ChangeValue (0, 3) = 0.0;
+ aProjMatrix.ChangeValue (1, 3) = 0.0;
+ aProjMatrix.ChangeValue (2, 3) = 0.0;
+ aProjMatrix.ChangeValue (3, 3) = 1.0;
- int i;
- for (i = 0; i < 2; i++) /* PCD 11/02/08 Two pass method */
+ // Define position in the view
+ switch (myPos)
{
- if (i == 0) /* First pass */
+ case Aspect_TOTP_LEFT_LOWER:
+ {
+ OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
+ -0.5 * U + aScale, -0.5 * V + aScale, 0.0);
+ break;
+ }
+ case Aspect_TOTP_LEFT_UPPER:
{
- glDepthFunc(GL_ALWAYS);
+ OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
+ -0.5 * U + aScale, 0.5 * V - aScale - aScale / 3.0, 0.0);
+ break;
}
- else
+ case Aspect_TOTP_RIGHT_LOWER:
{
- glDepthFunc(GL_LEQUAL);
+ OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
+ 0.5 * U - aScale - aScale / 3.0, -0.5 * V + aScale, 0.0);
+ break;
}
+ case Aspect_TOTP_RIGHT_UPPER:
+ {
+ OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
+ 0.5 * U - aScale - aScale / 3.0, 0.5 * V - aScale - aScale / 3.0, 0.0);
+ break;
+ }
+ //case Aspect_TOTP_CENTER:
+ default:
+ break;
+ }
+ aScale *= myRatio;
- glPushMatrix();
- glPushMatrix();
- glPushMatrix();
+ aContext->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
+ aContext->ApplyProjectionMatrix();
- glColor3fv(aLineColor.rgb);
- glCallList(startList+2);
+ const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
+ const TEL_COLOUR& aLineColor = anAspectLine->Color();
- // Z axis
- glColor4fv(myZColor.rgb);
- glCallList(startList);
- glTranslated(0, 0, L * CYLINDER_LENGTH);
- glCallList(startList + 3);
- glCallList(startList + 1);
- glPopMatrix();
+ // Create the trihedron
+ const Standard_Real THE_CYLINDER_LENGTH = 0.75;
+ const GLdouble aCylinderLength = aScale * THE_CYLINDER_LENGTH;
+ const GLdouble aCylinderDiametr = aScale * myDiameter;
+ const GLdouble aConeDiametr = aCylinderDiametr * 2.0;
+ const GLdouble aConeLength = aScale * (1.0 - THE_CYLINDER_LENGTH);
- // X axis
- glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]);
- glColor4fv(myXColor.rgb);
- glCallList(startList);
- glTranslated(0, 0, L * CYLINDER_LENGTH);
- glCallList(startList + 3);
- glCallList(startList + 1);
- glPopMatrix();
+ // Position des Axes
+ GLdouble aTriedronAxeX[3] = { aScale, 0.0, 0.0 };
+ GLdouble aTriedronAxeY[3] = { 0.0, aScale, 0.0 };
+ if (!myDisk.IsDefined())
+ {
+ myDisk.Init (static_cast<GLfloat> (aCylinderDiametr),
+ static_cast<GLfloat> (aConeDiametr),
+ myNbFacettes, 1);
+ }
- // Y axis
- glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
- glColor4fv(myYColor.rgb);
- glCallList(startList);
- glTranslated(0, 0, L * CYLINDER_LENGTH);
- glCallList(startList + 3);
- glCallList(startList + 1);
- glPopMatrix();
+ if (!mySphere.IsDefined())
+ {
+ mySphere.Init (static_cast<GLfloat> (aCylinderDiametr * 2.0), myNbFacettes, myNbFacettes);
+ }
+
+ if (!myCone.IsDefined())
+ {
+ myCone.Init (static_cast<GLfloat> (aConeDiametr), 0.0f, static_cast<GLfloat> (aConeLength), myNbFacettes, 1);
}
- if (!aIsDepthEnabled)
- glDisable(GL_DEPTH_TEST);
+ if (!myCylinder.IsDefined())
+ {
+ myCylinder.Init (static_cast<GLfloat> (aCylinderDiametr),
+ static_cast<GLfloat> (aCylinderDiametr),
+ static_cast<GLfloat> (aCylinderLength),
+ myNbFacettes, 1);
+ }
- if (!aIsDepthMaskEnabled)
- glDepthMask(GL_FALSE);
+ GLboolean wasDepthMaskEnabled = GL_FALSE;
+ GLint aDepthFuncBack = 0, aCullFaceModeBack = GL_BACK;
+ const GLboolean wasDepthEnabled = aContext->core11fwd->glIsEnabled (GL_DEPTH_TEST);
+ const GLboolean wasCullFaceEnabled = aContext->core11fwd->glIsEnabled (GL_CULL_FACE);
+ aContext->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncBack);
+ aContext->core11fwd->glGetIntegerv (GL_CULL_FACE_MODE, &aCullFaceModeBack);
+ aContext->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &wasDepthMaskEnabled);
+ if (!wasDepthEnabled)
+ {
+ aContext->core11fwd->glEnable (GL_DEPTH_TEST);
+ aContext->core11fwd->glClear (GL_DEPTH_BUFFER_BIT);
+ }
+ if (!wasDepthMaskEnabled)
+ {
+ aContext->core11fwd->glDepthMask (GL_TRUE);
+ }
+ aContext->core11fwd->glCullFace (GL_BACK);
+ if (!wasCullFaceEnabled)
+ {
+ aContext->core11fwd->glEnable (GL_CULL_FACE);
+ }
- glDisable(GL_CULL_FACE);
- glDisable(GL_COLOR_MATERIAL);
+ OpenGl_AspectFace anAspectC;
+ OpenGl_AspectFace anAspectX;
+ OpenGl_AspectFace anAspectY;
+ OpenGl_AspectFace anAspectZ;
+ memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.rgb, sizeof (TEL_COLOUR));
+ memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.rgb, sizeof (TEL_COLOUR));
+ memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.rgb, sizeof (TEL_COLOUR));
+ memcpy (anAspectC.ChangeIntFront().matcol.rgb, aLineColor.rgb, sizeof (TEL_COLOUR));
+ for (Standard_Integer aPass = 0; aPass < 2; ++aPass)
+ {
+ OpenGl_Mat4d aModelViewX (aModelMatrix);
+ OpenGl_Mat4d aModelViewY (aModelMatrix);
+ OpenGl_Mat4d aModelViewZ (aModelMatrix);
+ aContext->core11fwd->glDepthFunc (aPass == 0 ? GL_ALWAYS : GL_LEQUAL);
- gluDeleteQuadric(aQuadric);
- glColor3fv (aLineColor.rgb);
+ const OpenGl_AspectFace* anOldAspect = theWorkspace->SetAspectFace (&anAspectC);
- /* Always write the text */
- glDepthFunc(GL_ALWAYS);
+ // Origin
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
+ aContext->ApplyWorldViewMatrix();
+ mySphere.Render (theWorkspace);
- glPopAttrib();
+ // Z axis
+ theWorkspace->SetAspectFace (&anAspectZ);
+ myCylinder.Render (theWorkspace);
+ OpenGl_Utils::Translate (aModelViewZ, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewZ);
+ aContext->ApplyWorldViewMatrix();
+ myDisk.Render (theWorkspace);
+ myCone.Render (theWorkspace);
- /* fleches au bout des axes (= cones de la couleur demandee) */
- //const GLdouble l = 0.75*L; /* distance a l'origine */
- const GLdouble rayon = L/30. ; /* rayon de la base du cone */
- //const double Angle = 2. * M_PI/ myNbFacettes;
+ // X axis
+ theWorkspace->SetAspectFace (&anAspectX);
+ OpenGl_Utils::Rotate (aModelViewX, 90.0, aTriedronAxeY[0], aTriedronAxeY[1], aTriedronAxeY[2]);
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
+ aContext->ApplyWorldViewMatrix();
+ myCylinder.Render (theWorkspace);
+ OpenGl_Utils::Translate (aModelViewX, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
+ aContext->ApplyWorldViewMatrix();
+ myDisk.Render (theWorkspace);
+ myCone.Render (theWorkspace);
- glDeleteLists(startList, 4);
+ // Y axis
+ theWorkspace->SetAspectFace (&anAspectY);
+ OpenGl_Utils::Rotate (aModelViewY, -90.0, aTriedronAxeX[0], aTriedronAxeX[1], aTriedronAxeX[2]);
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
+ aContext->ApplyWorldViewMatrix();
+ myCylinder.Render (theWorkspace);
+ OpenGl_Utils::Translate (aModelViewY, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
+ aContext->ApplyWorldViewMatrix();
+ myDisk.Render (theWorkspace);
+ myCone.Render (theWorkspace);
+
+ theWorkspace->SetAspectFace (anOldAspect);
+ }
- glDisable(GL_LIGHTING);
+ if (!wasDepthEnabled)
+ {
+ aContext->core11fwd->glDisable (GL_DEPTH_TEST);
+ }
+ if (!wasDepthMaskEnabled)
+ {
+ aContext->core11fwd->glDepthMask (GL_FALSE);
+ }
+ if (!wasCullFaceEnabled)
+ {
+ aContext->core11fwd->glDisable (GL_CULL_FACE);
+ }
+ aContext->core11fwd->glCullFace (aCullFaceModeBack);
+
+ // Always write the text
+ aContext->core11fwd->glDepthFunc (GL_ALWAYS);
// draw axes labels
- myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon)));
- myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon)));
- myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon)));
+ const GLdouble rayon = aScale / 30.0;
+ myLabelX.SetPosition (OpenGl_Vec3(float(aScale + 2.0 * rayon), 0.0f, float(-rayon)));
+ myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(aScale + 3.0 * rayon), float(2.0 * rayon)));
+ myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(aScale + 3.0 * rayon)));
+ aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
+ aContext->ApplyWorldViewMatrix();
myLabelX.Render (theWorkspace);
myLabelY.Render (theWorkspace);
myLabelZ.Render (theWorkspace);
- /*PCD 17/06/07 */
- glDepthFunc(df);
+ aContext->core11fwd->glDepthFunc (aDepthFuncBack);
- if (!isWithinView) { /* restore matrix */
- glMatrixMode (GL_PROJECTION);
- glPopMatrix ();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix ();
- }
-#endif
+ aContext->WorldViewState.Pop();
+ aContext->ProjectionState.Pop();
+ aContext->ApplyProjectionMatrix();
}
-
-/*----------------------------------------------------------------------*/
-
-/*----------------------------------------------------------------------*/
-/*
-* Fonctions publiques
-*/
-
-
-/*
-* initialisation d'un triedre non zoomable dans une vue.
-* ou modification des valeurs deja initialisees.
-*/
-
-//call_triedron_init
+// =======================================================================
+// function : OpenGl_Trihedron
+// purpose :
+// =======================================================================
OpenGl_Trihedron::OpenGl_Trihedron (const Aspect_TypeOfTriedronPosition thePosition,
const Quantity_NameOfColor theColor,
const Standard_Real theScale,
myNbFacettes = theNbFacettes;
}
-/*----------------------------------------------------------------------*/
-
-/*
-* destruction du triedre non zoomable d'une vue.
-*/
-
-//call_triedron_erase
+// =======================================================================
+// function : ~OpenGl_Trihedron
+// purpose :
+// =======================================================================
OpenGl_Trihedron::~OpenGl_Trihedron()
{
}
myLabelZ.Release (theCtx);
myAspectLine.Release (theCtx);
myAspectText.Release (theCtx);
+ myCone .Release (theCtx);
+ myDisk .Release (theCtx);
+ mySphere .Release (theCtx);
+ myCylinder.Release (theCtx);
}
-/*----------------------------------------------------------------------*/
-
-/*
-* affichage d'un triedre non zoomable dans la wks awsid
-*
-* Triedre = Objet non Zoomable;
-* on cree cette fonction pour pouvoir travailler par les structures
-* utilisees par les fonctions Tsm* et TEL_VIEW_REP
-*
-*/
-
-//call_triedron_redraw_from_wsid
+// =======================================================================
+// function : Render
+// purpose :
+// =======================================================================
void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
{
const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->SetAspectLine (&myAspectLine);
#include <Aspect_TypeOfTriedronPosition.hxx>
#include <OpenGl_AspectLine.hxx>
#include <OpenGl_AspectText.hxx>
+#include <OpenGl_Cylinder.hxx>
+#include <OpenGl_Disk.hxx>
+#include <OpenGl_Sphere.hxx>
#include <OpenGl_Text.hxx>
#include <Quantity_NameOfColor.hxx>
+//! Class render trihedron
class OpenGl_Trihedron : public OpenGl_Element
{
public:
Aspect_TypeOfTriedronPosition myPos;
Standard_Real myScale;
Standard_Boolean myIsWireframe;
- // Parameters for zbuffered mode
+ // Parameters for z-buffered mode
TEL_COLOUR myXColor;
TEL_COLOUR myYColor;
TEL_COLOUR myZColor;
float myDiameter;
int myNbFacettes;
- OpenGl_AspectLine myAspectLine;
- OpenGl_AspectText myAspectText;
- mutable OpenGl_Text myLabelX;
- mutable OpenGl_Text myLabelY;
- mutable OpenGl_Text myLabelZ;
+ OpenGl_AspectLine myAspectLine;
+ OpenGl_AspectText myAspectText;
+ mutable OpenGl_Text myLabelX;
+ mutable OpenGl_Text myLabelY;
+ mutable OpenGl_Text myLabelZ;
+ mutable OpenGl_Cylinder myCylinder;
+ mutable OpenGl_Sphere mySphere;
+ mutable OpenGl_Cylinder myCone;
+ mutable OpenGl_Disk myDisk;
public:
--- /dev/null
+// Created on: 2014-09-30
+// Created by: Denis BOGOLEPOV
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _OpenGl_Utils_H__
+#define _OpenGl_Utils_H__
+
+#include <OpenGl_Vec.hxx>
+#include <NCollection_Vector.hxx>
+
+//! Helper class that implements some functionality of GLU library.
+namespace OpenGl_Utils
+{
+
+ //! Matrix type selector.
+ template<class T>
+ struct MatrixType {
+ //
+ };
+
+ template<>
+ struct MatrixType<Standard_Real> {
+ typedef OpenGl_Mat4d Mat4;
+ };
+
+ template<>
+ struct MatrixType<Standard_ShortReal> {
+ typedef OpenGl_Mat4 Mat4;
+ };
+
+ //! Vector type selector.
+ template<class T>
+ struct VectorType {
+ //
+ };
+
+ template<>
+ struct VectorType<Standard_Real> {
+ typedef OpenGl_Vec2d Vec2;
+ typedef OpenGl_Vec3d Vec3;
+ typedef OpenGl_Vec4d Vec4;
+ };
+
+ template<>
+ struct VectorType<Standard_ShortReal> {
+ typedef OpenGl_Vec2 Vec2;
+ typedef OpenGl_Vec3 Vec3;
+ typedef OpenGl_Vec4 Vec4;
+ };
+
+ //! Software implementation for OpenGL matrix stack.
+ template<class T>
+ class MatrixState
+ {
+ public:
+
+ //! Constructs matrix state object.
+ MatrixState()
+ : myStack (8),
+ myStackHead (-1)
+ {
+ //
+ }
+
+ //! Pushes current matrix into stack.
+ void Push()
+ {
+ if (++myStackHead >= myStack.Size())
+ {
+ myStack.Append (myCurrent);
+ }
+ else
+ {
+ myStack.SetValue (myStackHead, myCurrent);
+ }
+ }
+
+ //! Pops matrix from stack to current.
+ void Pop()
+ {
+ Standard_ASSERT_RETURN (myStackHead != -1, "Matrix stack already empty when MatrixState.Pop() called.", );
+ myCurrent = myStack.Value (myStackHead--);
+ }
+
+ //! @return current matrix.
+ const typename MatrixType<T>::Mat4& Current()
+ {
+ return myCurrent;
+ }
+
+ //! Sets given matrix as current.
+ void SetCurrent (const typename MatrixType<T>::Mat4& theNewCurrent)
+ {
+ myCurrent = theNewCurrent;
+ }
+
+ //! Sets given matrix as current.
+ template <typename Other_t>
+ void SetCurrent (const typename MatrixType<Other_t>::Mat4& theNewCurrent)
+ {
+ myCurrent.Convert (theNewCurrent);
+ }
+
+ //! Sets current matrix to identity.
+ void SetIdentity()
+ {
+ myCurrent = typename MatrixType<T>::Mat4();
+ }
+
+ private:
+
+ NCollection_Vector<typename MatrixType<T>::Mat4> myStack; //!< Collection used to maintenance matrix stack
+ typename MatrixType<T>::Mat4 myCurrent; //!< Current matrix
+ Standard_Integer myStackHead; //!< Index of stack head
+
+ };
+
+ //! Constructs a 3D orthographic projection matrix.
+ template<class T>
+ static void Ortho (typename MatrixType<T>::Mat4& theOut,
+ const T theLeft, const T theRight, const T theBottom, const T theTop, const T theZNear, const T theZFar);
+
+ //! Constructs a 2D orthographic projection matrix.
+ template<class T>
+ static void Ortho2D (typename MatrixType<T>::Mat4& theOut,
+ const T theLeft, const T theRight, const T theBottom, const T theTop);
+
+ //! Maps object coordinates to window coordinates.
+ template<class T>
+ static Standard_Boolean Project (const T theObjX,
+ const T theObjY,
+ const T theObjZ,
+ const typename MatrixType<T>::Mat4& theModViewMat,
+ const typename MatrixType<T>::Mat4& theProjectMat,
+ const Standard_Integer theViewport[4],
+ T& theWinX,
+ T& theWinY,
+ T& theWinZ);
+
+ //! Maps window coordinates to object coordinates.
+ template<class T>
+ static Standard_Boolean UnProject (const T theWinX,
+ const T theWinY,
+ const T theWinZ,
+ const typename MatrixType<T>::Mat4& theModViewMat,
+ const typename MatrixType<T>::Mat4& theProjectMat,
+ const Standard_Integer theViewport[4],
+ T& theObjX,
+ T& theObjY,
+ T& theObjZ);
+
+ //! Constructs a 4x4 rotation matrix.
+ template<class T>
+ static void ConstructRotate (typename MatrixType<T>::Mat4& theOut,
+ T theA,
+ T theX,
+ T theY,
+ T theZ);
+
+ //! Constructs a 4x4 rotation matrix.
+ template<class T>
+ static void Rotate (typename MatrixType<T>::Mat4& theOut,
+ T theA,
+ T theX,
+ T theY,
+ T theZ);
+
+ //! Constructs a 4x4 scaling matrix.
+ template<class T>
+ static void Scale (typename MatrixType<T>::Mat4& theOut,
+ T theX,
+ T theY,
+ T theZ);
+
+ //! Constructs a 4x4 translation matrix.
+ template<class T>
+ static void Translate (typename MatrixType<T>::Mat4& theOut,
+ T theX,
+ T theY,
+ T theZ);
+
+}
+
+// =======================================================================
+// function : Rotate
+// purpose : Constructs a 4x4 rotation matrix
+// =======================================================================
+template<class T>
+void OpenGl_Utils::Rotate (typename MatrixType<T>::Mat4& theOut,
+ T theA,
+ T theX,
+ T theY,
+ T theZ)
+{
+ typename MatrixType<T>::Mat4 aMat;
+ ConstructRotate (aMat, theA, theX, theY, theZ);
+ theOut = theOut * aMat;
+}
+
+// =======================================================================
+// function : Translate
+// purpose : Constructs a 4x4 translation matrix
+// =======================================================================
+template<class T>
+void OpenGl_Utils::Translate (typename MatrixType<T>::Mat4& theOut,
+ T theX,
+ T theY,
+ T theZ)
+{
+ theOut.ChangeValue (0, 3) = theOut.GetValue (0, 0) * theX +
+ theOut.GetValue (0, 1) * theY +
+ theOut.GetValue (0, 2) * theZ +
+ theOut.GetValue (0, 3);
+
+ theOut.ChangeValue (1, 3) = theOut.GetValue (1, 0) * theX +
+ theOut.GetValue (1, 1) * theY +
+ theOut.GetValue (1, 2) * theZ +
+ theOut.GetValue (1, 3);
+
+ theOut.ChangeValue (2, 3) = theOut.GetValue (2, 0) * theX +
+ theOut.GetValue (2, 1) * theY +
+ theOut.GetValue (2, 2) * theZ +
+ theOut.GetValue (2, 3);
+
+ theOut.ChangeValue (3, 3) = theOut.GetValue (3, 0) * theX +
+ theOut.GetValue (3, 1) * theY +
+ theOut.GetValue (3, 2) * theZ +
+ theOut.GetValue (3, 3);
+}
+
+// =======================================================================
+// function : Scale
+// purpose : Constructs a 4x4 scaling matrix
+// =======================================================================
+template<class T>
+void OpenGl_Utils::Scale (typename MatrixType<T>::Mat4& theOut,
+ T theX,
+ T theY,
+ T theZ)
+{
+ theOut.ChangeValue (0, 0) *= theX;
+ theOut.ChangeValue (1, 0) *= theX;
+ theOut.ChangeValue (2, 0) *= theX;
+ theOut.ChangeValue (3, 0) *= theX;
+
+ theOut.ChangeValue (0, 1) *= theY;
+ theOut.ChangeValue (1, 1) *= theY;
+ theOut.ChangeValue (2, 1) *= theY;
+ theOut.ChangeValue (3, 1) *= theY;
+
+ theOut.ChangeValue (0, 2) *= theZ;
+ theOut.ChangeValue (1, 2) *= theZ;
+ theOut.ChangeValue (2, 2) *= theZ;
+ theOut.ChangeValue (3, 2) *= theZ;
+}
+
+// =======================================================================
+// function : ConstructRotate
+// purpose : Constructs a 4x4 rotation matrix
+// =======================================================================
+template<class T>
+void OpenGl_Utils::ConstructRotate (typename MatrixType<T>::Mat4& theOut, T theA, T theX, T theY, T theZ)
+{
+ const T aSin = std::sin (theA * static_cast<T> (M_PI / 180.0));
+ const T aCos = std::cos (theA * static_cast<T> (M_PI / 180.0));
+
+ const Standard_Boolean isOnlyX = (theX != static_cast<T> (0.0))
+ && (theY == static_cast<T> (0.0))
+ && (theZ == static_cast<T> (0.0));
+
+ const Standard_Boolean isOnlyY = (theX == static_cast<T> (0.0))
+ && (theY != static_cast<T> (0.0))
+ && (theZ == static_cast<T> (0.0));
+
+ const Standard_Boolean isOnlyZ = (theX == static_cast<T> (0.0))
+ && (theY == static_cast<T> (0.0))
+ && (theZ != static_cast<T> (0.0));
+
+ if (isOnlyX) // Rotation only around X
+ {
+ theOut.SetValue (1, 1, aCos);
+ theOut.SetValue (2, 2, aCos);
+
+ if (theX < static_cast<T> (0.0))
+ {
+ theOut.SetValue (1, 2, aSin);
+ theOut.SetValue (2, 1, -aSin);
+ }
+ else
+ {
+ theOut.SetValue (1, 2, -aSin);
+ theOut.SetValue (2, 1, aSin);
+ }
+
+ return;
+ }
+ else if (isOnlyY) // Rotation only around Y
+ {
+ theOut.SetValue (0, 0, aCos);
+ theOut.SetValue (2, 2, aCos);
+
+ if (theY < static_cast<T> (0.0))
+ {
+ theOut.SetValue (0, 2, -aSin);
+ theOut.SetValue (2, 0, aSin);
+ }
+ else
+ {
+ theOut.SetValue (0, 2, aSin);
+ theOut.SetValue (2, 0, -aSin);
+ }
+
+ return;
+ }
+ else if (isOnlyZ) // Rotation only around Z
+ {
+ theOut.SetValue (0, 0, aCos);
+ theOut.SetValue (1, 1, aCos);
+
+ if (theZ < static_cast<T> (0.0))
+ {
+ theOut.SetValue (0, 1, aSin);
+ theOut.SetValue (1, 0, -aSin);
+ }
+ else
+ {
+ theOut.SetValue (0, 1, -aSin);
+ theOut.SetValue (1, 0, aSin);
+ }
+
+ return;
+ }
+
+ T aNorm = std::sqrt (theX * theX + theY * theY + theZ * theZ);
+
+ if (aNorm <= static_cast<T> (1.0e-4))
+ {
+ return; // negligible rotation
+ }
+
+ aNorm = static_cast<T> (1.0) / aNorm;
+
+ theX *= aNorm;
+ theY *= aNorm;
+ theZ *= aNorm;
+
+ const T aXX = theX * theX;
+ const T aYY = theY * theY;
+ const T aZZ = theZ * theZ;
+ const T aXY = theX * theY;
+ const T aYZ = theY * theZ;
+ const T aZX = theZ * theX;
+ const T aSinX = theX * aSin;
+ const T aSinY = theY * aSin;
+ const T aSinZ = theZ * aSin;
+
+ const T aOneMinusCos = static_cast<T> (1.0) - aCos;
+
+ theOut.SetValue (0, 0, aOneMinusCos * aXX + aCos);
+ theOut.SetValue (0, 1, aOneMinusCos * aXY - aSinZ);
+ theOut.SetValue (0, 2, aOneMinusCos * aZX + aSinY);
+
+ theOut.SetValue (1, 0, aOneMinusCos * aXY + aSinZ);
+ theOut.SetValue (1, 1, aOneMinusCos * aYY + aCos);
+ theOut.SetValue (1, 2, aOneMinusCos * aYZ - aSinX);
+
+ theOut.SetValue (2, 0, aOneMinusCos * aZX - aSinY);
+ theOut.SetValue (2, 1, aOneMinusCos * aYZ + aSinX);
+ theOut.SetValue (2, 2, aOneMinusCos * aZZ + aCos);
+}
+
+// =======================================================================
+// function : Ortho
+// purpose : Constructs a 3D orthographic projection matrix
+// =======================================================================
+template<class T>
+void OpenGl_Utils::Ortho (typename MatrixType<T>::Mat4& theOut,
+ const T theLeft, const T theRight, const T theBottom, const T theTop, const T theZNear, const T theZFar)
+{
+ theOut.InitIdentity();
+
+ T* aData = theOut.ChangeData();
+
+ const T anInvDx = static_cast<T> (1.0) / (theRight - theLeft);
+ const T anInvDy = static_cast<T> (1.0) / (theTop - theBottom);
+ const T anInvDz = static_cast<T> (1.0) / (theZFar - theZNear);
+
+ aData[0] = static_cast<T> ( 2.0) * anInvDx;
+ aData[5] = static_cast<T> ( 2.0) * anInvDy;
+ aData[10] = static_cast<T> (-2.0) * anInvDz;
+
+ aData[12] = -(theRight + theLeft) * anInvDx;
+ aData[13] = -(theTop + theBottom) * anInvDy;
+ aData[14] = -(theZFar + theZNear) * anInvDz;
+}
+
+// =======================================================================
+// function : Ortho2D
+// purpose : Constructs a 2D orthographic projection matrix
+// =======================================================================
+template<class T>
+void OpenGl_Utils::Ortho2D (typename MatrixType<T>::Mat4& theOut,
+ const T theLeft, const T theRight, const T theBottom, const T theTop)
+{
+ Ortho (theOut, theLeft, theRight, theBottom, theTop, static_cast<T> (-1.0), static_cast<T> (1.0));
+}
+
+// =======================================================================
+// function : Project
+// purpose : Maps object coordinates to window coordinates
+// =======================================================================
+template<class T>
+static Standard_Boolean OpenGl_Utils::Project (const T theObjX,
+ const T theObjY,
+ const T theObjZ,
+ const typename MatrixType<T>::Mat4& theModViewMat,
+ const typename MatrixType<T>::Mat4& theProjectMat,
+ const Standard_Integer theViewport[4],
+ T& theWinX,
+ T& theWinY,
+ T& theWinZ)
+{
+ typename VectorType<T>::Vec4 anIn (theObjX, theObjY, theObjZ, static_cast<T> (1.0));
+
+ typename VectorType<T>::Vec4 anOut = theProjectMat * (theModViewMat * anIn);
+
+ if (anOut.w() == static_cast<T> (0.0))
+ {
+ return Standard_False;
+ }
+
+ anOut.w() = static_cast<T> (1.0) / anOut.w();
+
+ anOut.x() *= anOut.w();
+ anOut.y() *= anOut.w();
+ anOut.z() *= anOut.w();
+
+ // Map x, y and z to range 0-1
+ anOut.x() = anOut.x() * 0.5 + 0.5;
+ anOut.y() = anOut.y() * 0.5 + 0.5;
+ anOut.z() = anOut.z() * 0.5 + 0.5;
+
+ // Map x,y to viewport
+ anOut.x() = anOut.x() * theViewport[2] + theViewport[0];
+ anOut.y() = anOut.y() * theViewport[3] + theViewport[1];
+
+ theWinX = anOut.x();
+ theWinY = anOut.y();
+ theWinZ = anOut.z();
+
+ return Standard_True;
+}
+
+// =======================================================================
+// function : UnProject
+// purpose : Maps window coordinates to object coordinates
+// =======================================================================
+template<class T>
+static Standard_Boolean OpenGl_Utils::UnProject (const T theWinX,
+ const T theWinY,
+ const T theWinZ,
+ const typename MatrixType<T>::Mat4& theModViewMat,
+ const typename MatrixType<T>::Mat4& theProjectMat,
+ const Standard_Integer theViewport[4],
+ T& theObjX,
+ T& theObjY,
+ T& theObjZ)
+{
+ typename MatrixType<T>::Mat4 anUnviewMat;
+
+ if (!(theProjectMat * theModViewMat).Inverted (anUnviewMat))
+ {
+ return Standard_False;
+ }
+
+ typename VectorType<T>::Vec4 anIn (theWinX, theWinY, theWinZ, static_cast<T> (1.0));
+
+ // Map x and y from window coordinates
+ anIn.x() = (anIn.x() - theViewport[0]) / theViewport[2];
+ anIn.y() = (anIn.y() - theViewport[1]) / theViewport[3];
+
+ // Map to range -1 to 1
+ anIn.x() = anIn.x() * static_cast<T> (2.0) - static_cast<T> (1.0);
+ anIn.y() = anIn.y() * static_cast<T> (2.0) - static_cast<T> (1.0);
+ anIn.z() = anIn.z() * static_cast<T> (2.0) - static_cast<T> (1.0);
+
+ typename VectorType<T>::Vec4 anOut = anUnviewMat * anIn;
+
+ if (anOut.w() == static_cast<T> (0.0))
+ {
+ return Standard_False;
+ }
+
+ anOut.w() = static_cast<T> (1.0) / anOut.w();
+
+ anOut.x() *= anOut.w();
+ anOut.y() *= anOut.w();
+ anOut.z() *= anOut.w();
+
+ theObjX = anOut.x();
+ theObjY = anOut.y();
+ theObjZ = anOut.z();
+
+ return Standard_True;
+}
+
+#endif // _OpenGl_Utils_H__
#include <OpenGl_Trihedron.hxx>
#include <OpenGl_transform_persistence.hxx>
#include <OpenGl_View.hxx>
+#include <OpenGl_Utils.hxx>
#include <OpenGl_Workspace.hxx>
#include <Graphic3d_TextureEnv.hxx>
OpenGl_View::~OpenGl_View ()
{
ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
+ OpenGl_Element::Destroy (NULL, myTrihedron);
+ OpenGl_Element::Destroy (NULL, myGraduatedTrihedron);
}
void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
{
- OpenGl_Element::Destroy (theCtx.operator->(), myTrihedron);
- OpenGl_Element::Destroy (theCtx.operator->(), myGraduatedTrihedron);
+ if (myTrihedron != NULL)
+ {
+ myTrihedron->Release (theCtx.operator->());
+ }
+ if (myGraduatedTrihedron != NULL)
+ {
+ myGraduatedTrihedron->Release (theCtx.operator->());
+ }
if (!myTextureEnv.IsNull())
{
{
if (myIsTransPers)
{
- #if !defined(GL_ES_VERSION_2_0)
- // restore matrix
- glMatrixMode (GL_PROJECTION);
- glPopMatrix();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
- myIsTransPers = Standard_False;
+ theCtx->WorldViewState.Pop();
+ theCtx->ProjectionState.Pop();
- // Note: the approach of accessing OpenGl matrices is used now since the matrix
- // manipulation are made with help of OpenGl methods. This might be replaced by
- // direct computation of matrices by OCC subroutines.
- Tmatrix3 aResultWorldView;
- glGetFloatv (GL_MODELVIEW_MATRIX, *aResultWorldView);
+ theCtx->ApplyProjectionMatrix();
- Tmatrix3 aResultProjection;
- glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection);
-
- // Set OCCT state uniform variables
- theCtx->ShaderManager()->RevertWorldViewStateTo (&aResultWorldView);
- theCtx->ShaderManager()->RevertProjectionStateTo (&aResultProjection);
- #endif
+ myIsTransPers = Standard_False;
}
}
return aTransPersPrev;
}
-#if !defined(GL_ES_VERSION_2_0)
GLint aViewport[4];
- GLdouble aModelMatrix[4][4];
- GLdouble aProjMatrix[4][4];
- glGetIntegerv (GL_VIEWPORT, aViewport);
- glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix);
- glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble *)aProjMatrix);
+ OpenGl_Mat4d aModelMatrix, aProjMatrix;
+ theCtx->core11fwd->glGetIntegerv (GL_VIEWPORT, aViewport);
+ aModelMatrix.Convert (theCtx->ModelWorldState.Current() * theCtx->WorldViewState.Current());
+ aProjMatrix .Convert (theCtx->ProjectionState.Current());
const GLdouble aViewportW = (GLdouble )aViewport[2];
const GLdouble aViewportH = (GLdouble )aViewport[3];
-
if (myIsTransPers)
{
// pop matrix stack - it will be overridden later
- glMatrixMode (GL_PROJECTION);
- glPopMatrix();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
+ theCtx->WorldViewState.Pop();
+ theCtx->ProjectionState.Pop();
}
else
{
}
// push matrices into stack and reset them
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- glMatrixMode (GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
+ theCtx->WorldViewState.Push();
+ theCtx->ProjectionState.Push();
// get the window's (fixed) coordinates for theTransPers->point before matrixes modifications
GLdouble aWinX = 0.0, aWinY = 0.0, aWinZ = 0.0;
if ((theTransPers->mode & TPF_PAN) != TPF_PAN)
{
- gluProject (theTransPers->pointX, theTransPers->pointY, theTransPers->pointZ,
- (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport,
- &aWinX, &aWinY, &aWinZ);
+ OpenGl_Utils::Project<Standard_Real> (theTransPers->pointX,
+ theTransPers->pointY,
+ theTransPers->pointZ,
+ aModelMatrix,
+ aProjMatrix,
+ aViewport,
+ aWinZ,
+ aWinY,
+ aWinZ);
}
// prevent zooming
{
// compute fixed-zoom multiplier
// actually function works ugly with TelPerspective!
- const GLdouble aDet2 = 0.002 / (aViewportW > aViewportH ? aProjMatrix[1][1] : aProjMatrix[0][0]);
- aProjMatrix[0][0] *= aDet2;
- aProjMatrix[1][1] *= aDet2;
- aProjMatrix[2][2] *= aDet2;
+ const GLdouble aDet2 = 0.002 / (aViewportW > aViewportH ? aProjMatrix.GetValue (1, 1) : aProjMatrix.GetValue (0, 0));
+ aProjMatrix.ChangeValue (0, 0) *= aDet2;
+ aProjMatrix.ChangeValue (1, 1) *= aDet2;
+ aProjMatrix.ChangeValue (2, 2) *= aDet2;
}
// prevent translation - annulate translate matrix
if ((theTransPers->mode & TPF_PAN)
|| (theTransPers->mode == TPF_TRIEDRON))
{
- aModelMatrix[3][0] = 0.0;
- aModelMatrix[3][1] = 0.0;
- aModelMatrix[3][2] = 0.0;
- aProjMatrix [3][0] = 0.0;
- aProjMatrix [3][1] = 0.0;
- aProjMatrix [3][2] = 0.0;
+ aModelMatrix.SetValue (0, 3, 0.0);
+ aModelMatrix.SetValue (1, 3, 0.0);
+ aModelMatrix.SetValue (2, 3, 0.0);
+ aProjMatrix .SetValue (0, 3, 0.0);
+ aProjMatrix .SetValue (1, 3, 0.0);
+ aProjMatrix .SetValue (2, 3, 0.0);
}
// prevent scaling-on-axis
const double aScaleZ = anAxialScale.Z();
for (int i = 0; i < 3; ++i)
{
- aModelMatrix[0][i] /= aScaleX;
- aModelMatrix[1][i] /= aScaleY;
- aModelMatrix[2][i] /= aScaleZ;
+ aModelMatrix.ChangeValue (0, i) /= aScaleX;
+ aModelMatrix.ChangeValue (1, i) /= aScaleY;
+ aModelMatrix.ChangeValue (2, i) /= aScaleZ;
}
}
// prevent rotating - annulate rotate matrix
if (theTransPers->mode & TPF_ROTATE)
{
- aModelMatrix[0][0] = 1.0;
- aModelMatrix[1][1] = 1.0;
- aModelMatrix[2][2] = 1.0;
-
- aModelMatrix[1][0] = 0.0;
- aModelMatrix[2][0] = 0.0;
- aModelMatrix[0][1] = 0.0;
- aModelMatrix[2][1] = 0.0;
- aModelMatrix[0][2] = 0.0;
- aModelMatrix[1][2] = 0.0;
+ aModelMatrix.SetValue (0, 0, 1.0);
+ aModelMatrix.SetValue (1, 1, 1.0);
+ aModelMatrix.SetValue (2, 2, 1.0);
+
+ aModelMatrix.SetValue (1, 0, 0.0);
+ aModelMatrix.SetValue (2, 0, 0.0);
+ aModelMatrix.SetValue (0, 1, 0.0);
+ aModelMatrix.SetValue (2, 1, 0.0);
+ aModelMatrix.SetValue (0, 2, 0.0);
+ aModelMatrix.SetValue (1, 2, 0.0);
}
// load computed matrices
- glMatrixMode (GL_MODELVIEW);
- glMultMatrixd ((GLdouble* )aModelMatrix);
-
- glMatrixMode (GL_PROJECTION);
- glMultMatrixd ((GLdouble* )aProjMatrix);
+ theCtx->ModelWorldState.SetIdentity();
+ theCtx->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
+ theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
if (theTransPers->mode == TPF_TRIEDRON)
{
&& theTransPers->pointY != 0.0)
{
GLdouble aW1, aH1, aW2, aH2, aDummy;
- glMatrixMode (GL_PROJECTION);
- gluUnProject ( 0.5 * aViewportW, 0.5 * aViewportH, 0.0,
- (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport,
- &aW1, &aH1, &aDummy);
- gluUnProject (-0.5 * aViewportW, -0.5 * aViewportH, 0.0,
- (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport,
- &aW2, &aH2, &aDummy);
+
+ OpenGl_Mat4d anIdentity;
+
+ OpenGl_Utils::UnProject<Standard_Real> (0.5 * aViewportW,
+ 0.5 * aViewportH,
+ 0.0,
+ anIdentity,
+ aProjMatrix,
+ aViewport,
+ aW1,
+ aH1,
+ aDummy);
+
+ OpenGl_Utils::UnProject<Standard_Real> (-0.5 * aViewportW,
+ -0.5 * aViewportH,
+ 0.0,
+ anIdentity,
+ aProjMatrix,
+ aViewport,
+ aW2,
+ aH2,
+ aDummy);
GLdouble aMoveX = 0.5 * (aW1 - aW2 - theTransPers->pointZ);
GLdouble aMoveY = 0.5 * (aH1 - aH2 - theTransPers->pointZ);
aMoveX = (theTransPers->pointX > 0.0) ? aMoveX : -aMoveX;
aMoveY = (theTransPers->pointY > 0.0) ? aMoveY : -aMoveY;
- theCtx->core11->glTranslated (aMoveX, aMoveY, 0.0);
+
+ OpenGl_Utils::Translate<Standard_Real> (aProjMatrix, aMoveX, aMoveY, 0.0);
+ theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
}
}
else if ((theTransPers->mode & TPF_PAN) != TPF_PAN)
{
// move to thePoint using saved win-coordinates ('marker-behaviour')
GLdouble aMoveX, aMoveY, aMoveZ;
- glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix);
- glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble* )aProjMatrix);
- gluUnProject (aWinX, aWinY, aWinZ,
- (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport,
- &aMoveX, &aMoveY, &aMoveZ);
-
- glMatrixMode (GL_MODELVIEW);
- theCtx->core11->glTranslated (aMoveX, aMoveY, aMoveZ);
- }
- // Note: the approach of accessing OpenGl matrices is used now since the matrix
- // manipulation are made with help of OpenGl methods. This might be replaced by
- // direct computation of matrices by OCC subroutines.
- Tmatrix3 aResultWorldView;
- glGetFloatv (GL_MODELVIEW_MATRIX, *aResultWorldView);
-
- Tmatrix3 aResultProjection;
- glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection);
+ OpenGl_Utils::UnProject<Standard_Real> (aWinX,
+ aWinY,
+ aWinZ,
+ aModelMatrix,
+ aProjMatrix,
+ aViewport,
+ aMoveX,
+ aMoveY,
+ aMoveZ);
+
+ OpenGl_Utils::Translate<Standard_Real> (aModelMatrix, aMoveX, aMoveY, aMoveZ);
+ theCtx->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
+ }
- // Set OCCT state uniform variables
- theCtx->ShaderManager()->UpdateWorldViewStateTo (&aResultWorldView);
- theCtx->ShaderManager()->UpdateProjectionStateTo (&aResultProjection);
-#endif
+ theCtx->ApplyProjectionMatrix();
return aTransPersPrev;
}
void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
+ const Handle(Graphic3d_Camera)& Camera() { return myCamera; }
void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
void SetClipLimit (const Graphic3d_CView& theCView);
void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
+ const Handle(OpenGl_Workspace) &theWorkspace,
const Graphic3d_CView& theCView,
const Aspect_CLayer2d& theCLayer);
void RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
//! @param theProjection [in] view projection matrix.
//! @param theOrientation [in] view orientation matrix.
void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
- const Handle(OpenGl_Workspace)& theWorkspace,
- const OpenGl_Matrix* theProjection,
- const OpenGl_Matrix* theOrientation);
+ const Handle(OpenGl_Workspace)& theWorkspace);
Handle(OpenGl_LineAttributes) myLineAttribs;
Handle(OpenGl_Texture) myTextureEnv;
/*
* Set des lumieres
*/
-static void bind_light (const OpenGl_Light& theLight,
- GLenum& theLightGlId,
- Graphic3d_Vec4& theAmbientColor)
+static void bindLight (const OpenGl_Light& theLight,
+ GLenum& theLightGlId,
+ Graphic3d_Vec4& theAmbientColor,
+ const Handle(OpenGl_Workspace)& theWorkspace)
{
// Only 8 lights in OpenGL...
if (theLightGlId > GL_LIGHT7)
return;
}
+ const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
+
// the light is a headlight?
- GLint aMatrixModeOld = 0;
if (theLight.IsHeadlight)
{
- glGetIntegerv (GL_MATRIX_MODE, &aMatrixModeOld);
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+
+ aContext->WorldViewState.Push();
+ aContext->WorldViewState.SetIdentity();
+
+ aContext->ApplyWorldViewMatrix();
}
// setup light type
// restore matrix in case of headlight
if (theLight.IsHeadlight)
{
- glPopMatrix();
- glMatrixMode (aMatrixModeOld);
+ aContext->WorldViewState.Pop();
}
glEnable (theLightGlId++);
glPushAttrib( GL_ENABLE_BIT | GL_TEXTURE_BIT );
- glMatrixMode( GL_PROJECTION );
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode( GL_MODELVIEW );
- glPushMatrix();
- glLoadIdentity();
+ const Handle(OpenGl_Context)& aContext = theWorkspace.GetGlContext();
+
+ aContext->WorldViewState.Push();
+ aContext->ProjectionState.Push();
+
+ aContext->WorldViewState.SetIdentity();
+ aContext->ProjectionState.SetIdentity();
+
+ aContext->ApplyProjectionMatrix();
+ aContext->ApplyWorldViewMatrix();
if ( glIsEnabled( GL_DEPTH_TEST ) )
glDisable( GL_DEPTH_TEST ); //push GL_ENABLE_BIT
glEnd();
}
- glPopMatrix();
- glMatrixMode( GL_PROJECTION );
- glPopMatrix();
- glMatrixMode( GL_MODELVIEW );
+ aContext->WorldViewState.Pop();
+ aContext->ProjectionState.Pop();
+
+ aContext->ApplyProjectionMatrix();
glPopAttrib(); //GL_ENABLE_BIT | GL_TEXTURE_BIT
}
#endif
+ // Update states of OpenGl_BVHTreeSelector (frustum culling algorithm).
Standard_Boolean isProjectionMatUpdateNeeded = Standard_False;
Standard_Boolean isOrientationMatUpdateNeeded = Standard_False;
if (myBVHSelector.ProjectionState() != myCamera->ProjectionState())
myBVHSelector.ChangeModelViewState() = myCamera->ModelViewState();
}
- // Set OCCT state uniform variables
+ if (isProjectionMatUpdateNeeded
+ || isOrientationMatUpdateNeeded)
+ {
+ myBVHSelector.SetViewVolume (myCamera);
+ }
+
const Handle(OpenGl_ShaderManager) aManager = aContext->ShaderManager();
const Standard_Boolean isSameView = aManager->IsSameView (this); // force camera state update when needed
if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState)
|| !isSameView)
{
myProjectionState = myCamera->ProjectionState();
- aManager->UpdateProjectionStateTo ((const Tmatrix3*)myCamera->ProjectionMatrixF().GetData());
+ aContext->ProjectionState.SetCurrent (myCamera->ProjectionMatrixF());
+ aContext->ApplyProjectionMatrix();
}
if (myModelViewState != myCamera->ModelViewState()
|| !isSameView)
{
myModelViewState = myCamera->ModelViewState();
- aManager->UpdateWorldViewStateTo ((const Tmatrix3*)myCamera->OrientationMatrixF().GetData());
+ aContext->WorldViewState.SetCurrent (myCamera->OrientationMatrixF());
+ aContext->ApplyWorldViewMatrix();
}
if (aManager->ModelWorldState().Index() == 0)
{
- Tmatrix3 aModelWorldState = { { 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 } };
-
- aContext->ShaderManager()->UpdateModelWorldStateTo (&aModelWorldState);
- }
-
- if (isProjectionMatUpdateNeeded
- || isOrientationMatUpdateNeeded)
- {
- myBVHSelector.SetViewVolume (myCamera);
+ aContext->ShaderManager()->UpdateModelWorldStateTo (OpenGl_Mat4());
}
// ====================================
// Step 3: Draw underlayer
// =================================
- RedrawLayer2d (thePrintContext, theCView, theCUnderLayer);
+ RedrawLayer2d (thePrintContext, theWorkspace, theCView, theCUnderLayer);
// =================================
// Step 4: Redraw main plane
if (!myCamera->IsStereo() || !aContext->HasStereoBuffers())
{
// single-pass monographic rendering
- const OpenGl_Matrix* aProj = (const OpenGl_Matrix*) &myCamera->ProjectionMatrixF();
-
- const OpenGl_Matrix* aOrient = (const OpenGl_Matrix*) &myCamera->OrientationMatrixF();
-
// redraw scene with normal orientation and projection
- RedrawScene (thePrintContext, theWorkspace, aProj, aOrient);
+ RedrawScene (thePrintContext, theWorkspace);
}
else
{
// two stereographic passes
- const OpenGl_Matrix* aLProj = (const OpenGl_Matrix*) &myCamera->ProjectionStereoLeftF();
- const OpenGl_Matrix* aRProj = (const OpenGl_Matrix*) &myCamera->ProjectionStereoRightF();
- const OpenGl_Matrix* aOrient = (const OpenGl_Matrix*) &myCamera->OrientationMatrixF();
// safely switch to left Eye buffer
aContext->SetDrawBufferLeft();
+ aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoLeftF());
+ aContext->ApplyProjectionMatrix();
+
// redraw left Eye
- RedrawScene (thePrintContext, theWorkspace, aLProj, aOrient);
+ RedrawScene (thePrintContext, theWorkspace);
// reset depth buffer of first rendering pass
if (theWorkspace->UseDepthTest())
// safely switch to right Eye buffer
aContext->SetDrawBufferRight();
+ aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoRightF());
+ aContext->ApplyProjectionMatrix();
+
// redraw right Eye
- RedrawScene (thePrintContext, theWorkspace, aRProj, aOrient);
+ RedrawScene (thePrintContext, theWorkspace);
// switch back to monographic rendering
aContext->SetDrawBufferMono();
const int aMode = 0;
theWorkspace->DisplayCallback (theCView, (aMode | OCC_PRE_OVERLAY));
- RedrawLayer2d (thePrintContext, theCView, theCOverLayer);
+ RedrawLayer2d (thePrintContext, theWorkspace, theCView, theCOverLayer);
theWorkspace->DisplayCallback (theCView, aMode);
//call_togl_redraw_layer2d
void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
+ const Handle(OpenGl_Workspace)& theWorkspace,
const Graphic3d_CView& ACView,
const Aspect_CLayer2d& ACLayer)
{
|| ACLayer.ptrLayer == NULL
|| ACLayer.ptrLayer->listIndex == 0) return;
+ const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
+
GLsizei dispWidth = (GLsizei )ACLayer.viewport[0];
GLsizei dispHeight = (GLsizei )ACLayer.viewport[1];
- glMatrixMode( GL_MODELVIEW );
- glPushMatrix ();
- glLoadIdentity ();
+ aContext->WorldViewState.Push();
+ aContext->ProjectionState.Push();
- glMatrixMode (GL_PROJECTION);
- glPushMatrix ();
- glLoadIdentity ();
+ aContext->WorldViewState.SetIdentity();
+ aContext->ProjectionState.SetIdentity();
+
+ aContext->ApplyWorldViewMatrix();
+ aContext->ApplyProjectionMatrix();
if (!ACLayer.sizeDependent)
glViewport (0, 0, dispWidth, dispHeight);
// tiling; scaling of graphics by matrix helps render a
// part of a view (frame) in same viewport, but with higher
// resolution
- thePrintContext->LoadProjTransformation();
+
+ // set printing scale/tiling transformation
+ aContext->ProjectionState.SetCurrent (thePrintContext->ProjTransformation());
+ aContext->ApplyProjectionMatrix();
// printing operation also assumes other viewport dimension
// to comply with transformation matrix or graphics scaling
glPopAttrib ();
- glMatrixMode (GL_PROJECTION);
- glPopMatrix ();
+ aContext->WorldViewState.Pop();
+ aContext->ProjectionState.Pop();
- glMatrixMode( GL_MODELVIEW );
- glPopMatrix ();
+ aContext->ApplyProjectionMatrix();
+ aContext->ApplyWorldViewMatrix();
if (!ACLayer.sizeDependent)
glViewport (0, 0, (GLsizei) ACView.DefWindow.dx, (GLsizei) ACView.DefWindow.dy);
//=======================================================================
void OpenGl_View::RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
- const Handle(OpenGl_Workspace)& theWorkspace,
- const OpenGl_Matrix* theProjection,
- const OpenGl_Matrix* theOrientation)
+ const Handle(OpenGl_Workspace)& theWorkspace)
{
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
}
}
-#if !defined(GL_ES_VERSION_2_0)
- // Setup view projection
- glMatrixMode (GL_PROJECTION);
-
#ifdef _WIN32
- // add printing scale/tiling transformation
- if (!thePrintContext.IsNull())
- {
- thePrintContext->LoadProjTransformation();
- }
- else
-#endif
- glLoadIdentity();
-
- glMultMatrixf ((const GLfloat*)theProjection);
-
+ // set printing scale/tiling transformation
if (!thePrintContext.IsNull())
{
- // update shader uniform projection matrix with new data
- Tmatrix3 aResultProjection;
- glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection);
- aContext->ShaderManager()->UpdateProjectionStateTo (&aResultProjection);
-
- // force shader uniform restore on next frame
- myProjectionState = 0;
+ aContext->ProjectionState.Push();
+ aContext->ProjectionState.SetCurrent (thePrintContext->ProjTransformation() * aContext->ProjectionState.Current());
+ aContext->ApplyProjectionMatrix();
}
#endif
- // Setup view orientation
- theWorkspace->SetViewMatrix (theOrientation);
-
// Specify clipping planes in view transformation space
if (!myClipPlanes.IsEmpty())
{
for (OpenGl_ListOfLight::Iterator aLightIt (myLights);
aLightIt.More(); aLightIt.Next())
{
- bind_light (aLightIt.Value(), aLightGlId, anAmbientColor);
+ bindLight (aLightIt.Value(), aLightGlId, anAmbientColor, theWorkspace);
}
// apply accumulated ambient color
}
break;
}
+
+ // Apply restored view matrix.
+ aContext->ApplyWorldViewMatrix();
+
+#ifdef _WIN32
+ // set printing scale/tiling transformation
+ if (!thePrintContext.IsNull())
+ {
+ aContext->ProjectionState.Pop();
+ aContext->ApplyProjectionMatrix();
+ }
+#endif
+
}
// commercial license or contractual agreement.
#include <OpenGl_GlCore12.hxx>
-
#include <InterfaceGraphic.hxx>
-#include <OpenGl_Window.hxx>
-
#include <OpenGl_Context.hxx>
#include <OpenGl_GraphicDriver.hxx>
+#include <OpenGl_Window.hxx>
+#include <OpenGl_Utils.hxx>
#include <Aspect_GraphicDeviceDefinitionError.hxx>
#include <TCollection_AsciiString.hxx>
if (theDepths == NULL || !Activate())
return;
-#if !defined(GL_ES_VERSION_2_0)
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D (0.0, (GLdouble )myWidth, 0.0, (GLdouble )myHeight);
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity();
+ OpenGl_Mat4 aProjectMat;
+ OpenGl_Utils::Ortho2D<Standard_ShortReal> (aProjectMat,
+ 0.f, static_cast<GLfloat> (myWidth), 0.f, static_cast<GLfloat> (myHeight));
+ myGlContext->WorldViewState.Push();
+ myGlContext->ProjectionState.Push();
+
+ myGlContext->WorldViewState.SetIdentity();
+ myGlContext->ProjectionState.SetCurrent (aProjectMat);
+
+ myGlContext->ApplyProjectionMatrix();
+ myGlContext->ApplyWorldViewMatrix();
+
+#if !defined(GL_ES_VERSION_2_0)
glRasterPos2i (theX, theY);
DisableFeatures();
glReadPixels (theX, theY, theWidth, theHeight, GL_DEPTH_COMPONENT, GL_FLOAT, theDepths);
EnableFeatures();
#endif
+
+ myGlContext->WorldViewState.Pop();
+ myGlContext->ProjectionState.Pop();
+
+ myGlContext->ApplyProjectionMatrix();
}
// =======================================================================
#include <OpenGl_Structure.hxx>
#include <OpenGl_Sampler.hxx>
#include <OpenGl_Texture.hxx>
+#include <OpenGl_Utils.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Workspace.hxx>
// setup texture matrix
glMatrixMode (GL_TEXTURE);
- glLoadIdentity();
+ OpenGl_Mat4 aTextureMat;
const Graphic3d_Vec2& aScale = aParams->Scale();
const Graphic3d_Vec2& aTrans = aParams->Translation();
- glScalef ( aScale.x(), aScale.y(), 1.0f);
- glTranslatef (-aTrans.x(), -aTrans.y(), 0.0f);
- glRotatef (-aParams->Rotation(), 0.0f, 0.0f, 1.0f);
+ OpenGl_Utils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f);
+ OpenGl_Utils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f);
+ OpenGl_Utils::Rotate (aTextureMat, -aParams->Rotation(), 0.0f, 0.0f, 1.0f);
+ glLoadMatrixf (aTextureMat);
// setup generation of texture coordinates
switch (aParams->GenMode())
}
case Graphic3d_TOTM_EYE:
{
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ myGlContext->WorldViewState.Push();
+
+ myGlContext->WorldViewState.SetIdentity();
+ myGlContext->ApplyWorldViewMatrix();
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv (GL_S, GL_EYE_PLANE, aParams->GenPlaneS().GetData());
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv (GL_T, GL_EYE_PLANE, aParams->GenPlaneT().GetData());
}
- glPopMatrix();
+
+ myGlContext->WorldViewState.Pop();
+
break;
}
case Graphic3d_TOTM_SPRITE:
void OpenGl_Workspace::copyBackToFront()
{
#if !defined(GL_ES_VERSION_2_0)
- glMatrixMode (GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- gluOrtho2D (0.0, (GLdouble )myWidth, 0.0, (GLdouble )myHeight);
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ OpenGl_Mat4 aProjectMat;
+ OpenGl_Utils::Ortho2D<Standard_ShortReal> (aProjectMat,
+ 0.f, static_cast<GLfloat> (myWidth), 0.f, static_cast<GLfloat> (myHeight));
+
+ myGlContext->WorldViewState.Push();
+ myGlContext->ProjectionState.Push();
+
+ myGlContext->WorldViewState.SetIdentity();
+ myGlContext->ProjectionState.SetCurrent (aProjectMat);
+
+ myGlContext->ApplyProjectionMatrix();
+ myGlContext->ApplyWorldViewMatrix();
DisableFeatures();
EnableFeatures();
- glMatrixMode (GL_PROJECTION);
- glPopMatrix();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
-
+ myGlContext->WorldViewState.Pop();
+ myGlContext->ProjectionState.Pop();
+ myGlContext->ApplyProjectionMatrix();
glDrawBuffer (GL_BACK);
#endif
{
if (aRevert)
{
- myGlContext->ShaderManager()->RevertModelWorldStateTo (&lmat.mat);
+ myGlContext->ShaderManager()->RevertModelWorldStateTo (OpenGl_Mat4::Map (*lmat.mat));
}
else
{
- myGlContext->ShaderManager()->UpdateModelWorldStateTo (&lmat.mat);
+ myGlContext->ShaderManager()->UpdateModelWorldStateTo (OpenGl_Mat4::Map (*lmat.mat));
}
}
myView->DrawBackground (*this);
- myView->RedrawLayer2d (myPrintContext, theCView, theCUnderLayer);
+ myView->RedrawLayer2d (myPrintContext, this, theCView, theCUnderLayer);
-#if !defined(GL_ES_VERSION_2_0)
- // Generate ray-traced image
- glMatrixMode (GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
+ myGlContext->WorldViewState.Push();
+ myGlContext->ProjectionState.Push();
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-#endif
+ myGlContext->WorldViewState.SetIdentity();
+ myGlContext->ProjectionState.SetIdentity();
+
+ myGlContext->ApplyProjectionMatrix();
+ myGlContext->ApplyWorldViewMatrix();
glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_SRC_ALPHA);
+ // Generate ray-traced image
if (myIsRaytraceDataValid)
{
myRaytraceScreenQuad.Bind (myGlContext);
if (wasDepthTestEnabled)
glEnable (GL_DEPTH_TEST);
-#if !defined(GL_ES_VERSION_2_0)
- glMatrixMode (GL_PROJECTION);
- glPopMatrix();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
-#endif
+ myGlContext->WorldViewState.Pop();
+ myGlContext->ProjectionState.Pop();
+
+ myGlContext->ApplyProjectionMatrix();
// Redraw trihedron
myView->RedrawTrihedron (this);
// Redraw overlay
const int aMode = 0;
DisplayCallback (theCView, (aMode | OCC_PRE_OVERLAY));
- myView->RedrawLayer2d (myPrintContext, theCView, theCOverLayer);
+ myView->RedrawLayer2d (myPrintContext, this, theCView, theCOverLayer);
DisplayCallback (theCView, aMode);
// Swap the buffers