1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0032886: Visualization, V3d_View - introduce interface for creating a subview

V3d_View/Graphic3d_CView pair has been extended to define subview within the other V3d_View instance.
The initialization is done in form of V3d_View::SetWindow() taking parent V3d_View instance on input.

Subview definition includes dimensions defined as a fraction of a parent view and offset from a corner.
This scheme allows splitting window into several subviews automatically occupying entire viewport,
like splitting window into two vertial subviews (100%x50% + 100%x50%),
three horizontal subviews (33%x100% + 30%x100% + 30%x100%),
1 + 2 stacked subviews (50%x100% + 50%x50% + 50%x50%),
as well as thumbnail-alike subviews displayed on top of another larger view.

OpenGl_View::Redraw() blits content of subviews into the window within immediate redraw step.

AIS_ViewController::FlushViewEvents() has been extended
to re-calculate mouse input into local subview coordinates.
AIS_ViewController::handleViewRedraw() first redraws subviews and then parent views.
Introduced new callback AIS_ViewController::OnSubviewChanged()
to switch input focus to another subview on mouse click,
implemented by ViewerTest_EventManager (has to be done at application level).

vinit command has been extended with parameters -subview and -parent to create a subview.
In addition, view dimension arguments now can be defined as a fraction of screen size instead of pixels.
This commit is contained in:
kgv
2022-04-11 20:00:39 +03:00
committed by smoskvin
parent 179fb34661
commit 879768fbf2
34 changed files with 1706 additions and 496 deletions

View File

@@ -868,14 +868,16 @@ void OpenGl_GraphicDriver::RemoveView (const Handle(Graphic3d_CView)& theView)
}
// =======================================================================
// function : Window
// function : CreateRenderWindow
// purpose :
// =======================================================================
Handle(OpenGl_Window) OpenGl_GraphicDriver::CreateRenderWindow (const Handle(Aspect_Window)& theWindow,
Handle(OpenGl_Window) OpenGl_GraphicDriver::CreateRenderWindow (const Handle(Aspect_Window)& theNativeWindow,
const Handle(Aspect_Window)& theSizeWindow,
const Aspect_RenderingContext theContext)
{
Handle(OpenGl_Context) aShareCtx = GetSharedContext();
Handle(OpenGl_Window) aWindow = new OpenGl_Window (this, theWindow, theContext, myCaps, aShareCtx);
Handle(OpenGl_Window) aWindow = new OpenGl_Window();
aWindow->Init (this, theNativeWindow, theSizeWindow, theContext, myCaps, aShareCtx);
return aWindow;
}

View File

@@ -88,7 +88,13 @@ public:
Standard_EXPORT virtual void RemoveView (const Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
Standard_EXPORT virtual Handle(OpenGl_Window) CreateRenderWindow (const Handle(Aspect_Window)& theWindow, const Aspect_RenderingContext theContext);
//! Create OpenGL window from native window.
//! @param[in] theNativeWindow native window holder
//! @param[in] theSizeWindow object defining window dimensions
//! @param[in] theContext existing native rendering context
Standard_EXPORT virtual Handle(OpenGl_Window) CreateRenderWindow (const Handle(Aspect_Window)& theNativeWindow,
const Handle(Aspect_Window)& theSizeWindow,
const Aspect_RenderingContext theContext);
public:

View File

@@ -15,8 +15,8 @@
#include <OpenGl_View.hxx>
#include <Aspect_NeutralWindow.hxx>
#include <Aspect_RenderingContext.hxx>
#include <Aspect_Window.hxx>
#include <Aspect_XRSession.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
@@ -366,20 +366,57 @@ Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolea
// =======================================================================
Handle(Aspect_Window) OpenGl_View::Window() const
{
return myWindow->PlatformWindow();
return myWindow->SizeWindow();
}
// =======================================================================
// function : SetWindow
// purpose :
// =======================================================================
void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
void OpenGl_View::SetWindow (const Handle(Graphic3d_CView)& theParentVIew,
const Handle(Aspect_Window)& theWindow,
const Aspect_RenderingContext theContext)
{
myWindow = myDriver->CreateRenderWindow (theWindow, theContext);
Standard_ASSERT_RAISE (!myWindow.IsNull(),
"OpenGl_View::SetWindow, "
"Failed to create OpenGl window.");
if (theContext != nullptr
&& !theParentVIew.IsNull())
{
throw Standard_ProgramError ("OpenGl_View::SetWindow(), internal error");
}
if (myParentView != nullptr)
{
myParentView->RemoveSubview (this);
myParentView = nullptr;
}
OpenGl_View* aParentView = dynamic_cast<OpenGl_View*> (theParentVIew.get());
if (!theParentVIew.IsNull())
{
if (aParentView == nullptr
|| aParentView->GlWindow().IsNull()
|| aParentView->GlWindow()->GetGlContext().IsNull())
{
throw Standard_ProgramError ("OpenGl_View::SetWindow(), internal error");
}
myParentView = aParentView;
myParentView->AddSubview (this);
Handle(Aspect_NeutralWindow) aSubWindow = Handle(Aspect_NeutralWindow)::DownCast(theWindow);
SubviewResized (aSubWindow);
const Handle(OpenGl_Window)& aParentGlWindow = aParentView->GlWindow();
Aspect_RenderingContext aRendCtx = aParentGlWindow->GetGlContext()->RenderingContext();
myWindow = myDriver->CreateRenderWindow (aParentGlWindow->PlatformWindow(), theWindow, aRendCtx);
}
else
{
myWindow = myDriver->CreateRenderWindow (theWindow, theWindow, theContext);
}
if (myWindow.IsNull())
{
throw Standard_ProgramError ("OpenGl_View::SetWindow, Failed to create OpenGl window");
}
myWorkspace = new OpenGl_Workspace (this, myWindow);
myWorldViewProjState.Reset();
@@ -414,10 +451,11 @@ void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
// =======================================================================
void OpenGl_View::Resized()
{
if (myWindow.IsNull())
return;
myWindow->Resize();
base_type::Resized();
if (!myWindow.IsNull())
{
myWindow->Resize();
}
}
// =======================================================================
@@ -1157,9 +1195,10 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
const bool hasTextureMsaa = aCtx->HasTextureMultisampling();
bool toUseOit = myRenderParams.TransparencyMethod != Graphic3d_RTM_BLEND_UNORDERED
&& !myIsSubviewComposer
&& checkOitCompatibility (aCtx, aNbSamples > 0);
const bool toInitImmediateFbo = myTransientDrawToFront
const bool toInitImmediateFbo = myTransientDrawToFront && !myIsSubviewComposer
&& (!aCtx->caps->useSystemBuffer || (toUseOit && HasImmediateStructures()));
if ( aFrameBuffer == NULL
@@ -1662,7 +1701,7 @@ void OpenGl_View::Redraw()
OpenGl_FrameBuffer* aFrameBuffer = myFBO.get();
bool toSwap = aCtx->IsRender()
&& !aCtx->caps->buffersNoSwap
&& aFrameBuffer == NULL
&& aFrameBuffer == nullptr
&& (!IsActiveXR() || myRenderParams.ToMirrorComposer);
if ( aFrameBuffer == NULL
&& !aCtx->DefaultFrameBuffer().IsNull()
@@ -1738,7 +1777,9 @@ void OpenGl_View::Redraw()
{
toSwap = false;
}
else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip && toSwap)
else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
&& toSwap
&& myParentView == nullptr)
{
aCtx->SwapBuffers();
}
@@ -1863,7 +1904,8 @@ void OpenGl_View::Redraw()
}
// Swap the buffers
if (toSwap)
if (toSwap
&& myParentView == nullptr)
{
aCtx->SwapBuffers();
if (!myMainSceneFbos[0]->IsValid())
@@ -1969,8 +2011,9 @@ void OpenGl_View::RedrawImmediate()
Standard_True) || toSwap;
if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
&& toSwap
&& myFBO.get() == NULL
&& !aCtx->caps->buffersNoSwap)
&& myFBO.get() == nullptr
&& !aCtx->caps->buffersNoSwap
&& myParentView == nullptr)
{
aCtx->SwapBuffers();
}
@@ -2035,7 +2078,8 @@ void OpenGl_View::RedrawImmediate()
if (toSwap
&& myFBO.get() == NULL
&& !aCtx->caps->buffersNoSwap)
&& !aCtx->caps->buffersNoSwap
&& myParentView == nullptr)
{
aCtx->SwapBuffers();
}
@@ -2159,9 +2203,91 @@ bool OpenGl_View::redrawImmediate (const Graphic3d_Camera::Projection theProject
render (theProjection, theDrawFbo, theOitAccumFbo, Standard_True);
blitSubviews (theProjection, theDrawFbo);
return !toCopyBackToFront;
}
// =======================================================================
// function : blitSubviews
// purpose :
// =======================================================================
bool OpenGl_View::blitSubviews (const Graphic3d_Camera::Projection ,
OpenGl_FrameBuffer* theDrawFbo)
{
const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
if (aCtx->arbFBOBlit == nullptr)
{
return false;
}
bool isChanged = false;
for (const Handle(Graphic3d_CView)& aChildIter : mySubviews)
{
OpenGl_View* aSubView = dynamic_cast<OpenGl_View*> (aChildIter.get());
const Handle(OpenGl_FrameBuffer)& aChildFbo = !aSubView->myImmediateSceneFbos[0].IsNull()
? aSubView->myImmediateSceneFbos[0]
: aSubView->myMainSceneFbos[0];
if (aChildFbo.IsNull() || !aChildFbo->IsValid())
{
continue;
}
aChildFbo->BindReadBuffer (aCtx);
if (theDrawFbo != NULL
&& theDrawFbo->IsValid())
{
theDrawFbo->BindDrawBuffer (aCtx);
}
else
{
aCtx->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
aCtx->SetFrameBufferSRGB (false);
}
Graphic3d_Vec2i aWinSize (aCtx->Viewport()[2], aCtx->Viewport()[3]); //aSubView->GlWindow()->PlatformWindow()->Dimensions();
Graphic3d_Vec2i aSubViewSize = aChildFbo->GetVPSize();
Graphic3d_Vec2i aSubViewPos = aSubView->SubviewTopLeft();
Graphic3d_Vec2i aDestSize = aSubViewSize;
if (aSubView->RenderingParams().RenderResolutionScale != 1.0f)
{
aDestSize = Graphic3d_Vec2i (Graphic3d_Vec2d(aDestSize) / Graphic3d_Vec2d(aSubView->RenderingParams().RenderResolutionScale));
}
aSubViewPos.y() = aWinSize.y() - aDestSize.y() - aSubViewPos.y();
const GLint aFilterGl = aDestSize == aSubViewSize ? GL_NEAREST : GL_LINEAR;
aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, aSubViewSize.x(), aSubViewSize.y(),
aSubViewPos.x(), aSubViewPos.y(), aSubViewPos.x() + aDestSize.x(), aSubViewPos.y() + aDestSize.y(),
GL_COLOR_BUFFER_BIT, aFilterGl);
const int anErr = aCtx->core11fwd->glGetError();
if (anErr != GL_NO_ERROR)
{
TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "FBO blitting has failed [Error " + OpenGl_Context::FormatGlError (anErr) + "]\n"
+ " Please check your graphics driver settings or try updating driver.";
if (aChildFbo->NbSamples() != 0)
{
myToDisableMSAA = true;
aMsg += "\n MSAA settings should not be overridden by driver!";
}
aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
}
if (theDrawFbo != NULL
&& theDrawFbo->IsValid())
{
theDrawFbo->BindBuffer (aCtx);
}
else
{
aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
aCtx->SetFrameBufferSRGB (false);
}
isChanged = true;
}
return isChanged;
}
//=======================================================================
//function : renderShadowMap
//purpose :
@@ -2409,9 +2535,16 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theOitAccumFbo,
const Standard_Boolean theToDrawImmediate)
{
myZLayers.UpdateCulling (myWorkspace, theToDrawImmediate);
if ( myZLayers.NbStructures() <= 0 )
if (myIsSubviewComposer)
{
return;
}
myZLayers.UpdateCulling (myWorkspace, theToDrawImmediate);
if (myZLayers.NbStructures() <= 0)
{
return;
}
Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
Standard_Boolean toRenderGL = theToDrawImmediate ||

View File

@@ -85,9 +85,8 @@ public:
Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE;
//! Creates and maps rendering window to the view.
//! @param theWindow [in] the window.
//! @param theContext [in] the rendering context. If NULL the context will be created internally.
Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
Standard_EXPORT virtual void SetWindow (const Handle(Graphic3d_CView)& theParentVIew,
const Handle(Aspect_Window)& theWindow,
const Aspect_RenderingContext theContext) Standard_OVERRIDE;
//! Returns window associated with the view.
@@ -345,6 +344,10 @@ protected: //! @name low-level redrawing sub-routines
OpenGl_FrameBuffer* theOitAccumFbo,
const Standard_Boolean theIsPartialUpdate = Standard_False);
//! Blit subviews into this view.
Standard_EXPORT bool blitSubviews (const Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theDrawFbo);
//! Blit image from/to specified buffers.
Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo,
OpenGl_FrameBuffer* theDrawFbo,

View File

@@ -169,17 +169,31 @@ namespace
// function : OpenGl_Window
// purpose :
// =======================================================================
OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
const Handle(Aspect_Window)& thePlatformWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Caps)& theCaps,
const Handle(OpenGl_Context)& theShareCtx)
: myGlContext (new OpenGl_Context (theCaps)),
myOwnGContext (theGContext == 0),
myPlatformWindow (thePlatformWindow),
mySwapInterval (theCaps->swapInterval)
OpenGl_Window::OpenGl_Window()
: myOwnGContext (false),
mySwapInterval (0)
{
myPlatformWindow->Size (myWidth, myHeight);
//
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void OpenGl_Window::Init (const Handle(OpenGl_GraphicDriver)& theDriver,
const Handle(Aspect_Window)& thePlatformWindow,
const Handle(Aspect_Window)& theSizeWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Caps)& theCaps,
const Handle(OpenGl_Context)& theShareCtx)
{
myGlContext = new OpenGl_Context (theCaps);
myOwnGContext = (theGContext == 0);
myPlatformWindow = thePlatformWindow;
mySizeWindow = theSizeWindow;
mySwapInterval = theCaps->swapInterval;
mySizeWindow->Size (mySize.x(), mySize.y());
Standard_Boolean isCoreProfile = Standard_False;
@@ -193,7 +207,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
&& (EGLContext )theGContext == EGL_NO_CONTEXT))
{
throw Aspect_GraphicDeviceDefinitionError("OpenGl_Window, EGL does not provide compatible configurations!");
return;
}
EGLSurface anEglSurf = EGL_NO_SURFACE;
@@ -225,8 +238,8 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
#if !defined(__EMSCRIPTEN__) // eglCreatePbufferSurface() is not implemented by Emscripten EGL
const int aSurfAttribs[] =
{
EGL_WIDTH, myWidth,
EGL_HEIGHT, myHeight,
EGL_WIDTH, mySize.x(),
EGL_HEIGHT, mySize.y(),
// EGL_KHR_gl_colorspace extension specifies if OpenGL should write into window buffer as into sRGB or RGB framebuffer
//EGL_GL_COLORSPACE_KHR, !theCaps->sRGBDisable ? EGL_GL_COLORSPACE_SRGB_KHR : EGL_GL_COLORSPACE_LINEAR_KHR,
EGL_NONE
@@ -258,8 +271,8 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
#if !defined(__EMSCRIPTEN__) // eglCreatePbufferSurface() is not implemented by Emscripten EGL
const int aSurfAttribs[] =
{
EGL_WIDTH, myWidth,
EGL_HEIGHT, myHeight,
EGL_WIDTH, mySize.x(),
EGL_HEIGHT, mySize.y(),
// EGL_KHR_gl_colorspace extension specifies if OpenGL should write into window buffer as into sRGB or RGB framebuffer
//EGL_GL_COLORSPACE_KHR, !theCaps->sRGBDisable ? EGL_GL_COLORSPACE_SRGB_KHR : EGL_GL_COLORSPACE_LINEAR_KHR,
EGL_NONE
@@ -322,7 +335,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: ChoosePixelFormat failed. Error code: ");
aMsg += (int )GetLastError();
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
return;
}
DescribePixelFormat (aWindowDC, aPixelFrmtId, sizeof(aPixelFrmt), &aPixelFrmt);
@@ -435,7 +447,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
TCollection_AsciiString aMsg("OpenGl_Window::CreateWindow: SetPixelFormat failed. Error code: ");
aMsg += (int )GetLastError();
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
return;
}
// create GL context with extra options
@@ -526,7 +537,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: wglCreateContext failed. Error code: ");
aMsg += (int )GetLastError();
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
return;
}
}
@@ -536,7 +546,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: wglShareLists failed. Error code: ");
aMsg += (int )GetLastError();
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
return;
}
myGlContext->Init ((Aspect_Handle )aWindow, (Aspect_Handle )aWindowDC, (Aspect_RenderingContext )aGContext, isCoreProfile);
@@ -557,12 +566,10 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
if (aVis.get() == NULL)
{
throw Aspect_GraphicDeviceDefinitionError("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. ");
return;
}
else if (glXGetConfig (aDisp, aVis.get(), GLX_USE_GL, &isGl) != 0 || !isGl)
{
throw Aspect_GraphicDeviceDefinitionError("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!");
return;
}
// create new context
@@ -635,7 +642,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
if (aGContext == NULL)
{
throw Aspect_GraphicDeviceDefinitionError("OpenGl_Window::CreateWindow: glXCreateContext failed.");
return;
}
}
@@ -675,7 +681,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
#endif
myGlContext->Share (theShareCtx);
myGlContext->SetSwapInterval (mySwapInterval);
Init();
init();
}
// =======================================================================
@@ -758,29 +764,29 @@ Standard_Boolean OpenGl_Window::Activate()
// =======================================================================
void OpenGl_Window::Resize()
{
Standard_Integer aWidth = 0, aHeight = 0;
myPlatformWindow->Size (aWidth, aHeight);
if (myWidth == aWidth
&& myHeight == aHeight)
Graphic3d_Vec2i aWinSize;
mySizeWindow->Size (aWinSize.x(), aWinSize.y());
if (mySize == aWinSize)
{
// if the size is not changed - do nothing
return;
}
myWidth = aWidth;
myHeight = aHeight;
mySize = aWinSize;
Init();
init();
}
// =======================================================================
// function : Init
// function : init
// purpose :
// =======================================================================
void OpenGl_Window::Init()
void OpenGl_Window::init()
{
if (!Activate())
{
return;
}
#if defined(HAVE_EGL)
if ((EGLSurface )myGlContext->myWindow == EGL_NO_SURFACE)
@@ -800,7 +806,7 @@ void OpenGl_Window::Init()
OpenGl_ColorFormats aColorFormats;
aColorFormats.Append (GL_RGBA8);
if (!aDefFbo->InitRenderBuffer (myGlContext, Graphic3d_Vec2i (myWidth, myHeight), aColorFormats, GL_DEPTH24_STENCIL8))
if (!aDefFbo->InitRenderBuffer (myGlContext, mySize, aColorFormats, GL_DEPTH24_STENCIL8))
{
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: default FBO creation failed");
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
@@ -810,8 +816,8 @@ void OpenGl_Window::Init()
}
else if (!myPlatformWindow->IsVirtual())
{
eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_WIDTH, &myWidth);
eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_HEIGHT, &myHeight);
eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_WIDTH, &mySize.x());
eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_HEIGHT, &mySize.y());
}
#else
//
@@ -819,7 +825,7 @@ void OpenGl_Window::Init()
myGlContext->core11fwd->glDisable (GL_DITHER);
myGlContext->core11fwd->glDisable (GL_SCISSOR_TEST);
const Standard_Integer aViewport[4] = { 0, 0, myWidth, myHeight };
const Standard_Integer aViewport[4] = { 0, 0, mySize.x(), mySize.y() };
myGlContext->ResizeViewport (aViewport);
myGlContext->SetDrawBuffer (GL_BACK);
if (myGlContext->core11ffp != NULL)

View File

@@ -37,21 +37,26 @@
class OpenGl_Context;
class OpenGl_GraphicDriver;
class OpenGl_Window;
DEFINE_STANDARD_HANDLE(OpenGl_Window,Standard_Transient)
//! This class represents low-level wrapper over window with GL context.
//! The window itself should be provided to constructor.
class OpenGl_Window : public Standard_Transient
{
DEFINE_STANDARD_RTTIEXT(OpenGl_Window, Standard_Transient)
public:
//! Main constructor - prepare GL context for specified window.
Standard_EXPORT OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
const Handle(Aspect_Window)& thePlatformWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Caps)& theCaps,
const Handle(OpenGl_Context)& theShareCtx);
//! Empty constructor.
Standard_EXPORT OpenGl_Window();
//! Initialize the new window - prepare GL context for specified window.
//! Throws exception in case of failure.
Standard_EXPORT void Init (const Handle(OpenGl_GraphicDriver)& theDriver,
const Handle(Aspect_Window)& thePlatformWindow,
const Handle(Aspect_Window)& theSizeWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Caps)& theCaps,
const Handle(OpenGl_Context)& theShareCtx);
//! Destructor
Standard_EXPORT virtual ~OpenGl_Window();
@@ -59,44 +64,45 @@ public:
//! Resizes the window.
Standard_EXPORT virtual void Resize();
Handle(Aspect_Window) PlatformWindow() { return myPlatformWindow; }
//! Return platform window.
const Handle(Aspect_Window)& PlatformWindow() { return myPlatformWindow; }
Standard_Integer Width() const { return myWidth; }
Standard_Integer Height() const { return myHeight; }
//! Return window object defining dimensions.
const Handle(Aspect_Window)& SizeWindow() { return mySizeWindow; }
Standard_Integer Width() const { return mySize.x(); }
Standard_Integer Height() const { return mySize.y(); }
//! Return OpenGL context.
const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; }
//! Activates GL context and setup viewport.
Standard_EXPORT void Init();
//! Makes GL context for this window active in current thread
Standard_EXPORT virtual Standard_Boolean Activate();
//! Sets swap interval for this window according to the context's settings.
Standard_EXPORT void SetSwapInterval (Standard_Boolean theToForceNoSync);
protected:
//! Activates GL context and setup viewport.
Standard_EXPORT void init();
protected:
Handle(OpenGl_Context) myGlContext;
Standard_Boolean myOwnGContext; //!< set to TRUE if GL context was not created by this class
Standard_Boolean myOwnGContext; //!< set to TRUE if GL context was not created by this class
Handle(Aspect_Window) myPlatformWindow; //!< software platform window wrapper
Handle(Aspect_Window) mySizeWindow; //!< window object defining dimensions
#if defined(__APPLE__)
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
UIView* myUIView;
#endif
Standard_Integer myWidthPt; //!< window width in logical units
Standard_Integer myHeightPt; //!< window height in logical units
Graphic3d_Vec2i mySizePt; //!< window width x height in logical units
#endif
Standard_Integer myWidth; //!< window width in pixels
Standard_Integer myHeight; //!< window height in pixels
Graphic3d_Vec2i mySize; //!< window width x height in pixels
Standard_Integer mySwapInterval;//!< last assigned swap interval (VSync) for this window
public:
DEFINE_STANDARD_RTTIEXT(OpenGl_Window,Standard_Transient) // Type definition
DEFINE_STANDARD_ALLOC
};
#endif //_OpenGl_Window_Header

View File

@@ -56,25 +56,38 @@
// function : OpenGl_Window
// purpose :
// =======================================================================
OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
const Handle(Aspect_Window)& thePlatformWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Caps)& theCaps,
const Handle(OpenGl_Context)& theShareCtx)
: myGlContext (new OpenGl_Context (theCaps)),
myOwnGContext (theGContext == 0),
myPlatformWindow (thePlatformWindow),
#if defined(__APPLE__) && defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
myUIView (NULL),
#endif
mySwapInterval (theCaps->swapInterval)
OpenGl_Window::OpenGl_Window()
: myOwnGContext (false),
mySwapInterval (0)
{
//
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void OpenGl_Window::Init (const Handle(OpenGl_GraphicDriver)& theDriver,
const Handle(Aspect_Window)& thePlatformWindow,
const Handle(Aspect_Window)& theSizeWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Caps)& theCaps,
const Handle(OpenGl_Context)& theShareCtx)
{
myGlContext = new OpenGl_Context (theCaps);
myOwnGContext = (theGContext == 0);
myPlatformWindow = thePlatformWindow;
mySizeWindow = theSizeWindow;
#if defined(__APPLE__) && defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
myUIView = NULL;
#endif
mySwapInterval = theCaps->swapInterval;
(void )theDriver;
myPlatformWindow->Size (myWidth, myHeight);
mySizeWindow->Size (mySize.x(), mySize.y());
#if defined(__APPLE__)
myWidthPt = myWidth;
myHeightPt = myHeight;
mySizePt = mySize;
#endif
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
@@ -102,7 +115,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
{
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: EAGLContext creation failed");
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
return;
}
}
@@ -114,7 +126,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
{
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: EAGLContext can not be assigned");
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
return;
}
myGlContext->Init (aGLContext, Standard_False);
@@ -199,7 +210,6 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
{
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: NSOpenGLContext creation failed");
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
return;
}
if (aTryStereo == 0
@@ -227,7 +237,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
myGlContext->Share (theShareCtx);
myGlContext->SetSwapInterval (mySwapInterval);
Init();
init();
}
// =======================================================================
@@ -266,9 +276,9 @@ void OpenGl_Window::Resize()
// If the size is not changed - do nothing
Standard_Integer aWidthPt = 0;
Standard_Integer aHeightPt = 0;
myPlatformWindow->Size (aWidthPt, aHeightPt);
if (myWidthPt == aWidthPt
&& myHeightPt == aHeightPt)
mySizeWindow->Size (aWidthPt, aHeightPt);
if (mySizePt.x() == aWidthPt
&& mySizePt.y() == aHeightPt)
{
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
return;
@@ -285,25 +295,25 @@ void OpenGl_Window::Resize()
NSRect aBounds = [aView bounds];
NSSize aRes = [aView convertSizeToBacking: aBounds.size];
if (myWidth == Standard_Integer(aRes.width)
&& myHeight == Standard_Integer(aRes.height))
if (mySize.x() == Standard_Integer(aRes.width)
&& mySize.y() == Standard_Integer(aRes.height))
{
return;
}
#endif
}
myWidthPt = aWidthPt;
myHeightPt = aHeightPt;
mySizePt.x() = aWidthPt;
mySizePt.y() = aHeightPt;
Init();
init();
}
// =======================================================================
// function : Init
// function : init
// purpose :
// =======================================================================
void OpenGl_Window::Init()
void OpenGl_Window::init()
{
if (!Activate())
{
@@ -329,11 +339,11 @@ void OpenGl_Window::Init()
myGlContext->Functions()->glGenRenderbuffers (1, &aWinRBColor);
myGlContext->Functions()->glBindRenderbuffer (GL_RENDERBUFFER, aWinRBColor);
[aGLCtx renderbufferStorage: GL_RENDERBUFFER fromDrawable: anEaglLayer];
myGlContext->Functions()->glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &myWidth);
myGlContext->Functions()->glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &myHeight);
myGlContext->Functions()->glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &mySize.x());
myGlContext->Functions()->glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &mySize.y());
myGlContext->Functions()->glBindRenderbuffer (GL_RENDERBUFFER, 0);
if (!aDefFbo->InitWithRB (myGlContext, Graphic3d_Vec2i (myWidth, myHeight), GL_RGBA8, GL_DEPTH24_STENCIL8, aWinRBColor))
if (!aDefFbo->InitWithRB (myGlContext, mySize, GL_RGBA8, GL_DEPTH24_STENCIL8, aWinRBColor))
{
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: default FBO creation failed");
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
@@ -349,8 +359,8 @@ void OpenGl_Window::Init()
return;
}
myWidth = aDefFbo->GetVPSizeX();
myHeight = aDefFbo->GetVPSizeY();
mySize.x() = aDefFbo->GetVPSizeX();
mySize.y() = aDefFbo->GetVPSizeY();
}
myGlContext->SetDefaultFrameBuffer (aDefFbo);
aDefFbo->BindBuffer (myGlContext);
@@ -368,21 +378,21 @@ Standard_ENABLE_DEPRECATION_WARNINGS
if ([aView respondsToSelector: @selector(convertSizeToBacking:)])
{
NSSize aRes = [aView convertSizeToBacking: aBounds.size];
myWidth = Standard_Integer(aRes.width);
myHeight = Standard_Integer(aRes.height);
mySize.x() = Standard_Integer(aRes.width);
mySize.y() = Standard_Integer(aRes.height);
}
else
{
myWidth = Standard_Integer(aBounds.size.width);
myHeight = Standard_Integer(aBounds.size.height);
mySize.x() = Standard_Integer(aBounds.size.width);
mySize.y() = Standard_Integer(aBounds.size.height);
}
myWidthPt = Standard_Integer(aBounds.size.width);
myHeightPt = Standard_Integer(aBounds.size.height);
mySizePt.x() = Standard_Integer(aBounds.size.width);
mySizePt.y() = Standard_Integer(aBounds.size.height);
#endif
myGlContext->core11fwd->glDisable (GL_DITHER);
myGlContext->core11fwd->glDisable (GL_SCISSOR_TEST);
myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight);
myGlContext->core11fwd->glViewport (0, 0, mySize.x(), mySize.y());
if (myGlContext->GraphicsLibrary() != Aspect_GraphicsLibrary_OpenGLES)
{
myGlContext->core11fwd->glDrawBuffer (GL_BACK);