From e5c11edd7bb9d776f7206b9785acbc9b19c487cf Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 4 Mar 2020 17:32:44 +0300 Subject: [PATCH] 0031405: Advanced wrappers, C# wrapper - dark colors in WPF sample D3DHost_FrameBuffer::IsSRGBReady() - added new propery defining if D3D application handles FBO as sRGB-ready texture or not. --- src/D3DHost/D3DHost_FrameBuffer.cxx | 4 +++- src/D3DHost/D3DHost_FrameBuffer.hxx | 8 ++++++++ src/OpenGl/OpenGl_Context.cxx | 5 +++-- src/OpenGl/OpenGl_Context.hxx | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/D3DHost/D3DHost_FrameBuffer.cxx b/src/D3DHost/D3DHost_FrameBuffer.cxx index fe691f42e9..6c2b96ebbf 100644 --- a/src/D3DHost/D3DHost_FrameBuffer.cxx +++ b/src/D3DHost/D3DHost_FrameBuffer.cxx @@ -34,7 +34,8 @@ D3DHost_FrameBuffer::D3DHost_FrameBuffer() myGlD3dDevice (NULL), myGlD3dSurf (NULL), myLockCount (0), - myD3dFallback (Standard_False) + myD3dFallback (Standard_False), + myIsSRGBReady (Standard_False) { // } @@ -277,6 +278,7 @@ void D3DHost_FrameBuffer::BindBuffer (const Handle(OpenGl_Context)& theCtx) } OpenGl_FrameBuffer::BindBuffer (theCtx); + theCtx->SetFrameBufferSRGB (true, myIsSRGBReady); if (myD3dFallback) { return; diff --git a/src/D3DHost/D3DHost_FrameBuffer.hxx b/src/D3DHost/D3DHost_FrameBuffer.hxx index 45234016a5..4f4f78021c 100644 --- a/src/D3DHost/D3DHost_FrameBuffer.hxx +++ b/src/D3DHost/D3DHost_FrameBuffer.hxx @@ -103,6 +103,13 @@ public: //! Returns TRUE if FBO has been initialized without WGL/D3D interop. Standard_Boolean D3dFallback() const { return myD3dFallback; } + //! Returns TRUE if color buffer is sRGB ready; FALSE by default. + //! Requires D3DSAMP_SRGBTEXTURE sampler parameter being set on D3D level for rendering D3D surface. + Standard_Boolean IsSRGBReady() const { return myIsSRGBReady; } + + //! Set if color buffer is sRGB ready. + void SetSRGBReady (Standard_Boolean theIsReady) { myIsSRGBReady = theIsReady; } + protected: using OpenGl_FrameBuffer::Init; @@ -115,6 +122,7 @@ protected: void* myGlD3dSurf; //!< WGL/D3D surface handle Standard_Integer myLockCount; //!< locking counter Standard_Boolean myD3dFallback; //!< indicates that FBO has been initialized without WGL/D3D interop + Standard_Boolean myIsSRGBReady; //!< indicates that color buffer is sRGB ready public: diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 86b763bf78..55dddf93b4 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -517,7 +517,7 @@ void OpenGl_Context::SetDrawBuffers (const Standard_Integer theNb, const Standar // function : SetFrameBufferSRGB // purpose : // ======================================================================= -void OpenGl_Context::SetFrameBufferSRGB (bool theIsFbo) +void OpenGl_Context::SetFrameBufferSRGB (bool theIsFbo, bool theIsFboSRgb) { if (!hasFboSRGB) { @@ -525,7 +525,8 @@ void OpenGl_Context::SetFrameBufferSRGB (bool theIsFbo) return; } myIsSRgbActive = ToRenderSRGB() - && (theIsFbo || myIsSRgbWindow); + && (theIsFbo || myIsSRgbWindow) + && theIsFboSRgb; if (!hasSRGBControl) { return; diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index 4d89de5eda..269be00cd1 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -584,6 +584,9 @@ public: //! (GL_FRAMEBUFFER_SRGB can be considered as always tuned ON). bool IsWindowSRGB() const { return myIsSRgbWindow; } + //! Overrides if window/surface buffer is sRGB-ready or not (initialized with the context). + void SetWindowSRGB (bool theIsSRgb) { myIsSRgbWindow = theIsSRgb; } + //! Convert Quantity_ColorRGBA into vec4 //! with conversion or no conversion into non-linear sRGB //! basing on ToRenderSRGB() flag. @@ -794,7 +797,8 @@ public: //! @name methods to alter or retrieve current state //! - FALSE if sRGB rendering is not supported or sRGB-not-ready window buffer is used for drawing. //! @param theIsFbo [in] flag indicating writing into offscreen FBO (always expected sRGB-ready when sRGB FBO is supported) //! or into window buffer (FALSE, sRGB-readiness might vary). - Standard_EXPORT void SetFrameBufferSRGB (bool theIsFbo); + //! @param theIsSRgb [in] flag indicating off-screen FBO is sRGB-ready + Standard_EXPORT void SetFrameBufferSRGB (bool theIsFbo, bool theIsFboSRgb = true); //! Return cached flag indicating writing into color buffer is enabled or disabled (glColorMask). bool ColorMask() const { return myColorMask; }