// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#include <NCollection_Mat4.hxx>
+#include <OpenGl_View.hxx>
+#include <Aspect_RenderingContext.hxx>
+#include <Aspect_Window.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <Graphic3d_TextureEnv.hxx>
+#include <Graphic3d_Mat4d.hxx>
+#include <NCollection_Mat4.hxx>
#include <OpenGl_Context.hxx>
+#include <OpenGl_FrameBuffer.hxx>
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_GraduatedTrihedron.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_Texture.hxx>
#include <OpenGl_Trihedron.hxx>
-#include <OpenGl_transform_persistence.hxx>
-#include <OpenGl_View.hxx>
-#include <OpenGl_Utils.hxx>
+#include <OpenGl_Window.hxx>
#include <OpenGl_Workspace.hxx>
+#include <Standard_CLocaleSentry.hxx>
-#include <Graphic3d_TextureEnv.hxx>
-#include <Graphic3d_Mat4d.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
-IMPLEMENT_STANDARD_HANDLE(OpenGl_View,MMgt_TShared)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared)
+#ifdef HAVE_GL2PS
+#include <gl2ps.h>
+#endif
/*----------------------------------------------------------------------*/
-static const Tmatrix3 myDefaultMatrix = { { 1.F, 0.F, 0.F, 0.F }, { 0.F, 1.F, 0.F, 0.F }, { 0.F, 0.F, 1.F, 0.F }, { 0.F, 0.F, 0.F, 1.F } };
-static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } };
-
-static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
-static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F };
-static const GLdouble THE_IDENTITY_MATRIX[4][4] =
+namespace
{
- {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}
-};
-
-/*----------------------------------------------------------------------*/
+ static const OPENGL_ZCLIP myDefaultZClip = { { Standard_False, 0.F }, { Standard_False, 1.F } };
+ static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
+ static const TEL_COLOUR myDefaultBg = { { 0.F, 0.F, 0.F, 1.F } };
+}
-OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext,
- OpenGl_StateCounter* theCounter)
-: mySurfaceDetail(Visual3d_TOD_ALL),
- myBackfacing(0),
- //shield_indicator = TOn,
- //shield_colour = { { 0.F, 0.F, 0.F, 1.F } },
- //border_indicator = TOff,
- //border_colour = { { 0.F, 0.F, 0.F, 1.F } },
- //active_status = TOn,
- myZClip(myDefaultZClip),
- myCamera(AContext.Camera),
- myFog(myDefaultFog),
- myToShowTrihedron (false),
- myToShowGradTrihedron (false),
- myVisualization(AContext.Visualization),
- myShadingModel ((Visual3d_TypeOfModel )AContext.Model),
- myAntiAliasing(Standard_False),
- myTransPers(&myDefaultTransPers),
- myIsTransPers(Standard_False),
- myProjectionState (0),
- myModelViewState (0),
- myStateCounter (theCounter),
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
+ const Handle(OpenGl_GraphicDriver)& theDriver,
+ const Handle(OpenGl_Caps)& theCaps,
+ Standard_Boolean& theDeviceLostFlag,
+ OpenGl_StateCounter* theCounter)
+: Graphic3d_CView (theMgr),
+ myDriver (theDriver.operator->()),
+ myCaps (theCaps),
+ myDeviceLostFlag (theDeviceLostFlag),
+ myWasRedrawnGL (Standard_False),
+ myAntiAliasing (Standard_False),
+ myCulling (Standard_True),
+ myShadingModel (Graphic3d_TOSM_FACET),
+ myBackfacing (Graphic3d_TOBM_AUTOMATIC),
+ myBgColor (myDefaultBg),
+ myFog (myDefaultFog),
+ myZClip (myDefaultZClip),
+ myCamera (new Graphic3d_Camera()),
+ myUseGLLight (Standard_True),
+ myToShowTrihedron (false),
+ myToShowGradTrihedron (false),
+ myStateCounter (theCounter),
myLastLightSourceState (0, 0),
+ myFboColorFormat (GL_RGBA8),
+ myFboDepthFormat (GL_DEPTH24_STENCIL8),
+ myToFlipOutput (Standard_False),
+ myFrameCounter (0),
+ myHasFboBlit (Standard_True),
+ myTransientDrawToFront (Standard_True),
+ myBackBufferRestored (Standard_False),
+ myIsImmediateDrawn (Standard_False),
myTextureParams (new OpenGl_AspectFace()),
myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
// ray-tracing fields initialization
- myRaytraceInitStatus (OpenGl_RT_NONE),
- myIsRaytraceDataValid (Standard_False),
+ myRaytraceInitStatus (OpenGl_RT_NONE),
+ myIsRaytraceDataValid (Standard_False),
myIsRaytraceWarnTextures (Standard_False),
myToUpdateEnvironmentMap (Standard_False),
myLayerListState (0)
{
- myCurrLightSourceState = myStateCounter->Increment();
-}
+ myWorkspace = new OpenGl_Workspace (this, NULL);
-/*----------------------------------------------------------------------*/
+ // AA mode
+ const char* anAaEnv = ::getenv ("CALL_OPENGL_ANTIALIASING_MODE");
+ if (anAaEnv != NULL)
+ {
+ int v;
+ if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasing = v;
+ }
+ OpenGl_Light aLight;
+ aLight.Type = Graphic3d_TOLS_AMBIENT;
+ aLight.IsHeadlight = Standard_False;
+ aLight.Color.r() = 1.;
+ aLight.Color.g() = 1.;
+ aLight.Color.b() = 1.;
+ myNoShadingLight.Append (aLight);
+
+ myCurrLightSourceState = myStateCounter->Increment();
+ myMainSceneFbos[0] = new OpenGl_FrameBuffer();
+ myMainSceneFbos[1] = new OpenGl_FrameBuffer();
+ myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
+ myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
+ myOpenGlFBO = new OpenGl_FrameBuffer();
+ myOpenGlFBO2 = new OpenGl_FrameBuffer();
+ myRaytraceFBO1[0] = new OpenGl_FrameBuffer();
+ myRaytraceFBO1[1] = new OpenGl_FrameBuffer();
+ myRaytraceFBO2[0] = new OpenGl_FrameBuffer();
+ myRaytraceFBO2[1] = new OpenGl_FrameBuffer();
+}
+
+// =======================================================================
+// function : Destructor
+// purpose :
+// =======================================================================
OpenGl_View::~OpenGl_View()
{
ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
OpenGl_Element::Destroy (NULL, myTextureParams);
}
+// =======================================================================
+// function : ReleaseGlResources
+// purpose :
+// =======================================================================
void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
{
myTrihedron .Release (theCtx.operator->());
myBgTextureArray->Release (theCtx.operator->());
}
+ myMainSceneFbos[0] ->Release (theCtx.operator->());
+ myMainSceneFbos[1] ->Release (theCtx.operator->());
+ myImmediateSceneFbos[0]->Release (theCtx.operator->());
+ myImmediateSceneFbos[1]->Release (theCtx.operator->());
+ myOpenGlFBO ->Release (theCtx.operator->());
+ myOpenGlFBO2 ->Release (theCtx.operator->());
+ myFullScreenQuad .Release (theCtx.operator->());
+ myFullScreenQuadFlip .Release (theCtx.operator->());
+
releaseRaytraceResources (theCtx);
}
-void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
- const Handle(Graphic3d_TextureEnv)& theTexture)
+// =======================================================================
+// function : Remove
+// purpose :
+// =======================================================================
+void OpenGl_View::Remove()
{
- if (!myTextureEnv.IsNull())
- {
- theCtx->DelayedRelease (myTextureEnv);
- myTextureEnv.Nullify();
- }
-
- if (theTexture.IsNull())
+ if (IsRemoved())
{
return;
}
- myTextureEnv = new OpenGl_Texture (theTexture->GetParams());
- Handle(Image_PixMap) anImage = theTexture->GetImage();
- if (!anImage.IsNull())
- myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type());
+ myDriver->RemoveView (this);
+ myWindow.Nullify();
- myToUpdateEnvironmentMap = Standard_True;
+ Graphic3d_CView::Remove();
}
-void OpenGl_View::SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail theMode)
+// =======================================================================
+// function : SetTextureEnv
+// purpose :
+// =======================================================================
+void OpenGl_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv)
{
- mySurfaceDetail = theMode;
+ Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
+ if (!aCtx.IsNull() && !myTextureEnv.IsNull())
+ {
+ aCtx->DelayedRelease (myTextureEnv);
+ }
myToUpdateEnvironmentMap = Standard_True;
+ myTextureEnvData = theTextureEnv;
+ myTextureEnv.Nullify();
+ initTextureEnv (aCtx);
}
// =======================================================================
-// function : SetBackfacing
+// function : initTextureEnv
// purpose :
// =======================================================================
-void OpenGl_View::SetBackfacing (const Standard_Integer theMode)
+void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext)
{
- myBackfacing = theMode;
+ if (myTextureEnvData.IsNull()
+ || theContext.IsNull()
+ || !theContext->MakeCurrent())
+ {
+ return;
+ }
+
+ myTextureEnv = new OpenGl_Texture (myTextureEnvData->GetParams());
+ Handle(Image_PixMap) anImage = myTextureEnvData->GetImage();
+ if (!anImage.IsNull())
+ {
+ myTextureEnv->Init (theContext, *anImage.operator->(), myTextureEnvData->Type());
+ }
}
// =======================================================================
-// function : SetLights
+// function : SetImmediateModeDrawToFront
// purpose :
// =======================================================================
-void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT& theViewCtx)
+Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
{
- myLights.Clear();
- for (Standard_Integer aLightIt = 0; aLightIt < theViewCtx.NbActiveLight; ++aLightIt)
- {
- myLights.Append (theViewCtx.ActiveLight[aLightIt]);
- }
- myCurrLightSourceState = myStateCounter->Increment();
+ const Standard_Boolean aPrevMode = myTransientDrawToFront;
+ myTransientDrawToFront = theDrawToFrontBuffer;
+ return aPrevMode;
}
-/*----------------------------------------------------------------------*/
-
-//call_togl_setvisualisation
-void OpenGl_View::SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext)
+// =======================================================================
+// function : SetWindow
+// purpose :
+// =======================================================================
+void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
+ const Aspect_RenderingContext theContext)
{
- myVisualization = AContext.Visualization;
- myShadingModel = (Visual3d_TypeOfModel )AContext.Model;
-}
+ myWindow = myDriver->CreateRenderWindow (theWindow, theContext);
+ Standard_ASSERT_RAISE (!myWindow.IsNull(),
+ "OpenGl_View::SetWindow, "
+ "Failed to create OpenGl window.");
-/*----------------------------------------------------------------------*/
-
-//call_togl_cliplimit
-void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView)
-{
- myZClip.Back.Limit = theCView.Context.ZClipBackPlane;
- myZClip.Front.Limit = theCView.Context.ZClipFrontPlane;
+ myWorkspace = new OpenGl_Workspace (this, myWindow);
+ myWorldViewProjState.Reset();
+ myToUpdateEnvironmentMap = Standard_True;
+ myHasFboBlit = Standard_True;
+ Invalidate();
- myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0);
- myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0);
+ // Environment texture resource does not support lazy initialization.
+ initTextureEnv (myWorkspace->GetGlContext());
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_View::SetFog (const Graphic3d_CView& theCView,
- const Standard_Boolean theFlag)
+// =======================================================================
+// function : Resized
+// purpose :
+// =======================================================================
+void OpenGl_View::Resized()
{
- if (!theFlag)
- {
- myFog.IsOn = Standard_False;
- }
- else
- {
- myFog.IsOn = Standard_True;
-
- myFog.Front = theCView.Context.DepthFrontPlane;
- myFog.Back = theCView.Context.DepthBackPlane;
+ if (myWindow.IsNull())
+ return;
- myFog.Color.rgb[0] = theCView.DefWindow.Background.r;
- myFog.Color.rgb[1] = theCView.DefWindow.Background.g;
- myFog.Color.rgb[2] = theCView.DefWindow.Background.b;
- myFog.Color.rgb[3] = 1.0f;
- }
+ myWindow->Resize();
}
-/*----------------------------------------------------------------------*/
-
+// =======================================================================
+// function : TriedronDisplay
+// purpose :
+// =======================================================================
void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
const Quantity_NameOfColor theColor,
const Standard_Real theScale,
myTrihedron.SetLabelsColor (theColor);
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx)
+// =======================================================================
+// function : TriedronErase
+// purpose :
+// =======================================================================
+void OpenGl_View::TriedronErase()
{
myToShowTrihedron = false;
- myTrihedron.Release (theCtx.operator->());
+ myTrihedron.Release (myWorkspace->GetGlContext().operator->());
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
- const Graphic3d_GraduatedTrihedron& theData)
+// =======================================================================
+// function : ZBufferTriedronSetup
+// purpose :
+// =======================================================================
+void OpenGl_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
+ const Quantity_NameOfColor theYColor,
+ const Quantity_NameOfColor theZColor,
+ const Standard_Real theSizeRatio,
+ const Standard_Real theAxisDiametr,
+ const Standard_Integer theNbFacettes)
{
- myToShowGradTrihedron = true;
- myGraduatedTrihedron.SetValues (theCtx, theData);
+ myTrihedron.SetArrowsColors (theXColor, theYColor, theZColor);
+ myTrihedron.SetSizeRatio (theSizeRatio);
+ myTrihedron.SetNbFacets (theNbFacettes);
+ myTrihedron.SetArrowDiameter (theAxisDiametr);
}
-/*----------------------------------------------------------------------*/
+// =======================================================================
+// function : TriedronEcho
+// purpose :
+// =======================================================================
+void OpenGl_View::TriedronEcho (const Aspect_TypeOfTriedronEcho /*theType*/)
+{
+ // do nothing
+}
-void OpenGl_View::GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx)
+// =======================================================================
+// function : SetMinMaxValuesCallback
+// purpose :
+// =======================================================================
+static void SetMinMaxValuesCallback (Graphic3d_CView* theView)
{
- myToShowGradTrihedron = false;
- myGraduatedTrihedron.Release (theCtx.operator->());
+ OpenGl_View* aView = dynamic_cast<OpenGl_View*>(theView);
+ if (aView == NULL)
+ return;
+
+ Bnd_Box aBox = theView->MinMaxValues();
+ if (!aBox.IsVoid())
+ {
+ gp_Pnt aMin = aBox.CornerMin();
+ gp_Pnt aMax = aBox.CornerMax();
+
+ Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z());
+ Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
+ aView->GraduatedTrihedronMinMaxValues (aMinVec, aMaxVec);
+ }
}
-/*----------------------------------------------------------------------*/
+// =======================================================================
+// function : GraduatedTrihedronDisplay
+// purpose :
+// =======================================================================
+void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
+{
+ myGTrihedronData = theTrihedronData;
+ myGTrihedronData.PtrView = this;
+ myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
+ myGraduatedTrihedron.SetValues (myGTrihedronData);
+ myToShowGradTrihedron = true;
+}
-//transform_persistence_end
-void OpenGl_View::EndTransformPersistence(const Handle(OpenGl_Context)& theCtx)
+// =======================================================================
+// function : GraduatedTrihedronErase
+// purpose :
+// =======================================================================
+void OpenGl_View::GraduatedTrihedronErase()
{
- if (myIsTransPers)
- {
- theCtx->WorldViewState.Pop();
- theCtx->ProjectionState.Pop();
+ myGTrihedronData.PtrView = NULL;
+ myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
+ myToShowGradTrihedron = false;
+}
- theCtx->ApplyProjectionMatrix();
- theCtx->ApplyWorldViewMatrix();
+// =======================================================================
+// function : GraduatedTrihedronMinMaxValues
+// purpose :
+// =======================================================================
+void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
+{
+ myGraduatedTrihedron.SetMinMax (theMin, theMax);
+}
- myIsTransPers = Standard_False;
- }
+// =======================================================================
+// function : BufferDump
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType)
+{
+ return myWorkspace->BufferDump (myFBO, theImage, theBufferType);
}
-/*----------------------------------------------------------------------*/
+// =======================================================================
+// function : Background
+// purpose :
+// =======================================================================
+Aspect_Background OpenGl_View::Background() const
+{
+ return Aspect_Background (Quantity_Color (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], Quantity_TOC_RGB));
+}
-//transform_persistence_begin
-const TEL_TRANSFORM_PERSISTENCE* OpenGl_View::BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
- const TEL_TRANSFORM_PERSISTENCE* theTransPers,
- Standard_Integer theWidth,
- Standard_Integer theHeight)
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+void OpenGl_View::SetBackground (const Aspect_Background& theBackground)
{
- const TEL_TRANSFORM_PERSISTENCE* aTransPersPrev = myTransPers;
- myTransPers = theTransPers;
- if (theTransPers->mode == 0)
- {
- EndTransformPersistence (theCtx);
- return aTransPersPrev;
- }
+ Quantity_Color aBgColor = theBackground.Color();
+ myBgColor.rgb[0] = static_cast<float> (aBgColor.Red());
+ myBgColor.rgb[1] = static_cast<float> (aBgColor.Green());
+ myBgColor.rgb[2] = static_cast<float> (aBgColor.Blue());
+ myFog.Color = myBgColor;
+}
- GLint aViewport[4];
- OpenGl_Mat4d aModelMatrix, aProjMatrix;
- theCtx->core11fwd->glGetIntegerv (GL_VIEWPORT, aViewport);
- aModelMatrix.Convert (theCtx->ModelWorldState.Current() * theCtx->WorldViewState.Current());
- aProjMatrix .Convert (theCtx->ProjectionState.Current());
+// =======================================================================
+// function : GradientBackground
+// purpose :
+// =======================================================================
+Aspect_GradientBackground OpenGl_View::GradientBackground() const
+{
+ Quantity_Color aColor1, aColor2;
+ aColor1.SetValues (myBgGradientArray->GradientColor (0).r(),
+ myBgGradientArray->GradientColor (0).g(),
+ myBgGradientArray->GradientColor (0).b(), Quantity_TOC_RGB);
+ aColor2.SetValues (myBgGradientArray->GradientColor (1).r(),
+ myBgGradientArray->GradientColor (1).g(),
+ myBgGradientArray->GradientColor (1).b(), Quantity_TOC_RGB);
+ return Aspect_GradientBackground (aColor1, aColor2, myBgGradientArray->GradientFillMethod());
+}
- const GLdouble aViewportW = (GLdouble )aViewport[2];
- const GLdouble aViewportH = (GLdouble )aViewport[3];
+// =======================================================================
+// function : SetGradientBackground
+// purpose :
+// =======================================================================
+void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBackground)
+{
+ Quantity_Color aColor1, aColor2;
+ theBackground.Colors (aColor1, aColor2);
+ myBgGradientArray->SetGradientParameters (aColor1, aColor2, theBackground.BgGradientFillMethod());
+}
- if (myIsTransPers)
+// =======================================================================
+// function : SetBackgroundImage
+// purpose :
+// =======================================================================
+void OpenGl_View::SetBackgroundImage (const TCollection_AsciiString& theFilePath)
+{
+ // Prepare aspect for texture storage
+ myBackgroundImagePath = theFilePath;
+ Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
+ Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath));
+ aTextureMap->EnableRepeat();
+ aTextureMap->DisableModulate();
+ aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL,
+ Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
+ Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
+ anAspect->SetTextureMap (aTextureMap);
+ anAspect->SetInteriorStyle (Aspect_IS_SOLID);
+ // Enable texture mapping
+ if (aTextureMap->IsDone())
{
- // pop matrix stack - it will be overridden later
- theCtx->WorldViewState.Pop();
- theCtx->ProjectionState.Pop();
+ anAspect->SetTextureMapOn();
}
else
{
- myIsTransPers = Standard_True;
+ anAspect->SetTextureMapOff();
+ return;
}
- if (theTransPers->mode & TPF_2D)
- {
- GLfloat aLeft = -static_cast<GLfloat> (theWidth / 2);
- GLfloat aRight = static_cast<GLfloat> (theWidth / 2);
- GLfloat aBottom = -static_cast<GLfloat> (theHeight / 2);
- GLfloat aTop = static_cast<GLfloat> (theHeight / 2);
- GLfloat aGap = static_cast<GLfloat> (theTransPers->pointZ);
- if (theTransPers->pointX > 0)
- {
- aLeft -= static_cast<GLfloat> (theWidth / 2) - aGap;
- aRight -= static_cast<GLfloat> (theWidth / 2) - aGap;
- }
- else if (theTransPers->pointX < 0)
- {
- aLeft += static_cast<GLfloat> (theWidth / 2) - aGap;
- aRight += static_cast<GLfloat> (theWidth / 2) - aGap;
- }
- if (theTransPers->pointY > 0)
- {
- aBottom -= static_cast<GLfloat> (theHeight / 2) - aGap;
- aTop -= static_cast<GLfloat> (theHeight / 2) - aGap;
- }
- else if (theTransPers->pointY < 0)
- {
- aBottom += static_cast<GLfloat> (theHeight / 2) - aGap;
- aTop += static_cast<GLfloat> (theHeight / 2) - aGap;
- }
- if (theTransPers->mode == TPF_2D_ISTOPDOWN)
- {
- const GLfloat aTemp = aTop;
- aTop = aBottom;
- aBottom = aTemp;
- }
+ // Set texture parameters
+ myTextureParams->SetAspect (anAspect);
+}
- OpenGl_Mat4 aProjectMat;
- OpenGl_Utils::Ortho2D<Standard_ShortReal> (aProjectMat,
- aLeft, aRight,
- aBottom, aTop);
+// =======================================================================
+// function : BackgroundImageStyle
+// purpose :
+// =======================================================================
+Aspect_FillMethod OpenGl_View::BackgroundImageStyle() const
+{
+ return myBgTextureArray->TextureFillMethod();
+}
- theCtx->WorldViewState.Push();
- theCtx->ProjectionState.Push();
+// =======================================================================
+// function : SetBackgroundImageStyle
+// purpose :
+// =======================================================================
+void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle)
+{
+ myBgTextureArray->SetTextureFillMethod (theFillStyle);
+}
- theCtx->WorldViewState.SetIdentity();
- theCtx->ProjectionState.SetCurrent (aProjectMat);
+//=======================================================================
+//function : AddZLayer
+//purpose :
+//=======================================================================
+void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId)
+{
+ myZLayers.AddLayer (theLayerId);
+}
+
+//=======================================================================
+//function : RemoveZLayer
+//purpose :
+//=======================================================================
+void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
+{
+ myZLayers.RemoveLayer (theLayerId);
+}
+
+//=======================================================================
+//function : SetZLayerSettings
+//purpose :
+//=======================================================================
+void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
+ const Graphic3d_ZLayerSettings& theSettings)
+{
+ myZLayers.SetLayerSettings (theLayerId, theSettings);
+}
+
+//=======================================================================
+//function : FBO
+//purpose :
+//=======================================================================
+Handle(Standard_Transient) OpenGl_View::FBO() const
+{
+ return Handle(Standard_Transient)(myFBO);
+}
- theCtx->ApplyWorldViewMatrix();
- theCtx->ApplyProjectionMatrix();
- return aTransPersPrev;
+//=======================================================================
+//function : SetFBO
+//purpose :
+//=======================================================================
+void OpenGl_View::SetFBO (const Handle(Standard_Transient)& theFbo)
+{
+ myFBO = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
+}
+
+//=======================================================================
+//function : FBOCreate
+//purpose :
+//=======================================================================
+Handle(Standard_Transient) OpenGl_View::FBOCreate (const Standard_Integer theWidth,
+ const Standard_Integer theHeight)
+{
+ return myWorkspace->FBOCreate (theWidth, theHeight);
+}
+
+//=======================================================================
+//function : FBORelease
+//purpose :
+//=======================================================================
+void OpenGl_View::FBORelease (Handle(Standard_Transient)& theFbo)
+{
+ Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
+ if (aFrameBuffer.IsNull())
+ {
+ return;
}
- // push matrices into stack and reset them
- theCtx->WorldViewState.Push();
- theCtx->ProjectionState.Push();
+ myWorkspace->FBORelease (aFrameBuffer);
+ theFbo.Nullify();
+}
- // 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)
+//=======================================================================
+//function : FBOGetDimensions
+//purpose :
+//=======================================================================
+void OpenGl_View::FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
+ Standard_Integer& theWidth,
+ Standard_Integer& theHeight,
+ Standard_Integer& theWidthMax,
+ Standard_Integer& theHeightMax)
+{
+ const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
+ if (aFrameBuffer.IsNull())
{
- OpenGl_Utils::Project<Standard_Real> (theTransPers->pointX,
- theTransPers->pointY,
- theTransPers->pointZ,
- aModelMatrix,
- aProjMatrix,
- aViewport,
- aWinX,
- aWinY,
- aWinZ);
+ return;
}
- // prevent zooming
- if ((theTransPers->mode & TPF_ZOOM)
- || (theTransPers->mode == TPF_TRIEDRON))
+ theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
+ theHeight = aFrameBuffer->GetVPSizeY();
+ theWidthMax = aFrameBuffer->GetSizeX(); // texture size
+ theHeightMax = aFrameBuffer->GetSizeY();
+}
+
+//=======================================================================
+//function : FBOChangeViewport
+//purpose :
+//=======================================================================
+void OpenGl_View::FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight)
+{
+ const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
+ if (aFrameBuffer.IsNull())
{
- // compute fixed-zoom multiplier
- // actually function works ugly with TelPerspective!
- 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;
+ return;
}
- // prevent translation - annulate translate matrix
- if ((theTransPers->mode & TPF_PAN)
- || (theTransPers->mode == TPF_TRIEDRON))
+ aFrameBuffer->ChangeViewport (theWidth, theHeight);
+}
+
+// =======================================================================
+// function : Export
+// purpose :
+// =======================================================================
+#ifdef HAVE_GL2PS
+Standard_Boolean OpenGl_View::Export (const Standard_CString theFileName,
+ const Graphic3d_ExportFormat theFormat,
+ const Graphic3d_SortType theSortType)
+{
+ // gl2psBeginPage() will call OpenGL functions
+ // so we should activate correct GL context before redraw scene call
+ if (!myWorkspace->Activate())
{
- 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);
+ return Standard_False;
}
- // prevent scaling-on-axis
- if (theTransPers->mode & TPF_ZOOM)
+ Standard_Integer aFormat = -1;
+ Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
+ switch (theFormat)
{
- const gp_Pnt anAxialScale = myCamera->AxialScale();
- const double aScaleX = anAxialScale.X();
- const double aScaleY = anAxialScale.Y();
- const double aScaleZ = anAxialScale.Z();
- for (int i = 0; i < 3; ++i)
- {
- aModelMatrix.ChangeValue (0, i) /= aScaleX;
- aModelMatrix.ChangeValue (1, i) /= aScaleY;
- aModelMatrix.ChangeValue (2, i) /= aScaleZ;
- }
+ case Graphic3d_EF_PostScript:
+ aFormat = GL2PS_PS;
+ break;
+ case Graphic3d_EF_EnhPostScript:
+ aFormat = GL2PS_EPS;
+ break;
+ case Graphic3d_EF_TEX:
+ aFormat = GL2PS_TEX;
+ break;
+ case Graphic3d_EF_PDF:
+ aFormat = GL2PS_PDF;
+ break;
+ case Graphic3d_EF_SVG:
+ aFormat = GL2PS_SVG;
+ break;
+ case Graphic3d_EF_PGF:
+ aFormat = GL2PS_PGF;
+ break;
+ case Graphic3d_EF_EMF:
+ //aFormat = GL2PS_EMF;
+ aFormat = GL2PS_PGF + 1; // 6
+ break;
+ default:
+ // unsupported format
+ return Standard_False;
}
- // prevent rotating - annulate rotate matrix
- if (theTransPers->mode & TPF_ROTATE)
+ switch (theSortType)
{
- 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);
+ case Graphic3d_ST_Simple:
+ aSortType = GL2PS_SIMPLE_SORT;
+ break;
+ case Graphic3d_ST_BSP_Tree:
+ aSortType = GL2PS_BSP_SORT;
+ break;
}
- // load computed matrices
- theCtx->ModelWorldState.SetIdentity();
- theCtx->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
- theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
+ GLint aViewport[4];
+ aViewport[0] = 0;
+ aViewport[1] = 0;
+ aViewport[2] = myWindow->Width();
+ aViewport[3] = myWindow->Height();
+
+ GLint aBufferSize = 1024 * 1024;
+ GLint anErrCode = GL2PS_SUCCESS;
- if (theTransPers->mode == TPF_TRIEDRON)
+ // gl2ps uses standard write functions and do not check locale
+ Standard_CLocaleSentry aLocaleSentry;
+
+ while (aBufferSize > 0)
{
- // move to the window corner
- if (theTransPers->pointX != 0.0
- && theTransPers->pointY != 0.0)
+ // current patch for EMF support in gl2ps uses WinAPI functions to create file
+ FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
+ anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
+ GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
+ GL_RGBA, 0, NULL,
+ 0, 0, 0, aBufferSize, aFileH, theFileName);
+ if (anErrCode != GL2PS_SUCCESS)
{
- GLdouble aW1, aH1, 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;
-
- OpenGl_Utils::Translate<Standard_Real> (aProjMatrix, aMoveX, aMoveY, 0.0);
- theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
+ // initialization failed
+ if (aFileH != NULL)
+ fclose (aFileH);
+ break;
}
+ Redraw();
+
+ anErrCode = gl2psEndPage();
+ if (aFileH != NULL)
+ fclose (aFileH);
+
+ if (anErrCode == GL2PS_OVERFLOW)
+ aBufferSize *= 2;
+ else
+ break;
}
- else if ((theTransPers->mode & TPF_PAN) != TPF_PAN)
- {
- // move to thePoint using saved win-coordinates ('marker-behaviour')
- GLdouble aMoveX, aMoveY, aMoveZ;
-
- 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);
- }
+ return anErrCode == GL2PS_SUCCESS;
+}
+#else
+Standard_Boolean OpenGl_View::Export (const Standard_CString /*theFileName*/,
+ const Graphic3d_ExportFormat /*theFormat*/,
+ const Graphic3d_SortType /*theSortType*/)
+{
+ return Standard_False;
+}
+#endif
+
+//=======================================================================
+//function : displayStructure
+//purpose :
+//=======================================================================
+void OpenGl_View::displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
+ const Standard_Integer thePriority)
+{
+ const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
+ const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer();
+ myZLayers.AddStructure (aStruct, aZLayer, thePriority);
+}
- theCtx->ApplyProjectionMatrix();
- return aTransPersPrev;
+//=======================================================================
+//function : eraseStructure
+//purpose :
+//=======================================================================
+void OpenGl_View::eraseStructure (const Handle(Graphic3d_CStructure)& theStructure)
+{
+ const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
+ myZLayers.RemoveStructure (aStruct);
+}
+
+//=======================================================================
+//function : changeZLayer
+//purpose :
+//=======================================================================
+void OpenGl_View::changeZLayer (const Handle(Graphic3d_CStructure)& theStructure,
+ const Graphic3d_ZLayerId theNewLayerId)
+{
+ const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer();
+ const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
+ myZLayers.ChangeLayer (aStruct, anOldLayer, theNewLayerId);
+}
+
+//=======================================================================
+//function : changePriority
+//purpose :
+//=======================================================================
+void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructure,
+ const Standard_Integer theNewPriority)
+{
+ const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer();
+ const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
+ myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority);
}