mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0024228: TKOpenGL - destroy GL context at view close
- OpenGl_Display - release GL resources correctly on closing views - OpenGl_AspectFace, OpenGl_AspectText, OpenGl_AspectLine, OpenGl_AspectMarker - initialize OpenGl resources on demand, when context is available. - Graphic3d_TextureRoot - use const modifier for GetId method to avoid asynchronous resource state at OpenGl. - Do not call OpenGL functions if no active GL context has been left - Reset thread's context before deletion for Mesa WNT
This commit is contained in:
@@ -16,17 +16,19 @@
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
|
||||
#ifndef OPENGL_FRAME_BUFFER_H
|
||||
#define OPENGL_FRAME_BUFFER_H
|
||||
|
||||
#include <OpenGl_Context.hxx>
|
||||
#include <OpenGl_ExtFBO.hxx>
|
||||
#include <OpenGl_Resource.hxx>
|
||||
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <InterfaceGraphic.hxx>
|
||||
|
||||
class OpenGl_FrameBuffer
|
||||
//! Class implements FrameBuffer Object (FBO) resource
|
||||
//! intended for off-screen rendering.
|
||||
class OpenGl_FrameBuffer : public OpenGl_Resource
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -38,12 +40,14 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8);
|
||||
//! Empty constructor
|
||||
Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8);
|
||||
|
||||
virtual ~OpenGl_FrameBuffer()
|
||||
{
|
||||
Release (Handle(OpenGl_Context)());
|
||||
}
|
||||
//! Destructor
|
||||
Standard_EXPORT virtual ~OpenGl_FrameBuffer();
|
||||
|
||||
//! Destroy object - will release GPU memory if any.
|
||||
Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx);
|
||||
|
||||
//! Texture width.
|
||||
GLsizei GetSizeX() const
|
||||
@@ -72,7 +76,7 @@ public:
|
||||
//! Returns true if current object was initialized
|
||||
Standard_Boolean IsValid() const
|
||||
{
|
||||
return IsValidFrameBuffer() && IsValidTexture() && IsValidDepthBuffer() && IsValidStencilBuffer();
|
||||
return isValidFrameBuffer() && isValidTexture() && isValidDepthBuffer() && isValidStencilBuffer();
|
||||
}
|
||||
|
||||
//! Notice! Obsolete hardware (GeForce FX etc)
|
||||
@@ -83,94 +87,76 @@ public:
|
||||
//! current implementation will try to generate compatible FBO;
|
||||
//! 2) FBO rendering will be done in software mode (ForceWare 'hack');
|
||||
//! 3) FBO rendering will be incorrect (some obsolete Catalyst drivers).
|
||||
Standard_Boolean Init (const Handle(OpenGl_Context)& theGlContext,
|
||||
GLsizei theViewportSizeX,
|
||||
GLsizei theViewportSizeY,
|
||||
GLboolean toForcePowerOfTwo = GL_FALSE);
|
||||
|
||||
//! Release GL objects
|
||||
void Release (const Handle(OpenGl_Context)& theGlContext);
|
||||
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||
const GLsizei theViewportSizeX,
|
||||
const GLsizei theViewportSizeY,
|
||||
const GLboolean toForcePowerOfTwo = GL_FALSE);
|
||||
|
||||
//! Setup viewport to render into FBO
|
||||
void SetupViewport()
|
||||
{
|
||||
glViewport (0, 0, myVPSizeX, myVPSizeY);
|
||||
}
|
||||
Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx);
|
||||
|
||||
//! Override viewport settings
|
||||
void ChangeViewport (const GLsizei theVPSizeX,
|
||||
const GLsizei theVPSizeY)
|
||||
{
|
||||
myVPSizeX = theVPSizeX;
|
||||
myVPSizeY = theVPSizeY;
|
||||
}
|
||||
Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX,
|
||||
const GLsizei theVPSizeY);
|
||||
|
||||
//! Bind frame buffer (to render into the texture).
|
||||
void BindBuffer (const Handle(OpenGl_Context)& theGlContext)
|
||||
{
|
||||
theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, myGlFBufferId);
|
||||
}
|
||||
Standard_EXPORT void BindBuffer (const Handle(OpenGl_Context)& theGlCtx);
|
||||
|
||||
//! Unbind frame buffer.
|
||||
void UnbindBuffer (const Handle(OpenGl_Context)& theGlContext)
|
||||
{
|
||||
theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, NO_FRAMEBUFFER);
|
||||
}
|
||||
Standard_EXPORT void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx);
|
||||
|
||||
//! Bind the texture.
|
||||
void BindTexture ()
|
||||
{
|
||||
glEnable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering
|
||||
glBindTexture (GL_TEXTURE_2D, myGlTextureId);
|
||||
}
|
||||
Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx);
|
||||
|
||||
//! Unbind the texture.
|
||||
void UnbindTexture()
|
||||
{
|
||||
glBindTexture (GL_TEXTURE_2D, NO_TEXTURE);
|
||||
glDisable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering
|
||||
}
|
||||
Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx);
|
||||
|
||||
private:
|
||||
|
||||
//! Check texture could be created
|
||||
Standard_Boolean IsProxySuccess() const;
|
||||
Standard_Boolean isProxySuccess() const;
|
||||
|
||||
//! Generate texture with undefined data
|
||||
Standard_Boolean InitTrashTexture (const Handle(OpenGl_Context)& theGlContext);
|
||||
Standard_Boolean initTrashTexture (const Handle(OpenGl_Context)& theGlContext);
|
||||
|
||||
Standard_Boolean IsValidTexture() const
|
||||
Standard_Boolean isValidTexture() const
|
||||
{
|
||||
return myGlTextureId != NO_TEXTURE;
|
||||
}
|
||||
|
||||
Standard_Boolean IsValidFrameBuffer() const
|
||||
Standard_Boolean isValidFrameBuffer() const
|
||||
{
|
||||
return myGlFBufferId != NO_FRAMEBUFFER;
|
||||
}
|
||||
|
||||
Standard_Boolean IsValidDepthBuffer() const
|
||||
Standard_Boolean isValidDepthBuffer() const
|
||||
{
|
||||
return myGlDepthRBId != NO_RENDERBUFFER;
|
||||
}
|
||||
|
||||
Standard_Boolean IsValidStencilBuffer() const
|
||||
Standard_Boolean isValidStencilBuffer() const
|
||||
{
|
||||
return myGlStencilRBId != NO_RENDERBUFFER;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
GLsizei mySizeX; // texture width
|
||||
GLsizei mySizeY; // texture height
|
||||
GLsizei myVPSizeX; // viewport width (should be <= texture width)
|
||||
GLsizei myVPSizeY; // viewport height (should be <= texture height)
|
||||
GLint myTextFormat; // GL_RGB, GL_RGBA,...
|
||||
GLuint myGlTextureId; // GL texture ID
|
||||
GLuint myGlFBufferId; // FBO object ID
|
||||
GLuint myGlDepthRBId; // RenderBuffer object for depth ID
|
||||
GLuint myGlStencilRBId; // RenderBuffer object for stencil ID
|
||||
GLsizei mySizeX; //!< texture width
|
||||
GLsizei mySizeY; //!< texture height
|
||||
GLsizei myVPSizeX; //!< viewport width (should be <= texture width)
|
||||
GLsizei myVPSizeY; //!< viewport height (should be <= texture height)
|
||||
GLint myTextFormat; //!< GL_RGB, GL_RGBA,...
|
||||
GLuint myGlTextureId; //!< GL texture ID
|
||||
GLuint myGlFBufferId; //!< FBO object ID
|
||||
GLuint myGlDepthRBId; //!< RenderBuffer object for depth ID
|
||||
GLuint myGlStencilRBId; //!< RenderBuffer object for stencil ID
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition
|
||||
|
||||
};
|
||||
|
||||
#endif //OPENGL_FRAME_BUFFER_H
|
||||
DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource)
|
||||
|
||||
#endif // OPENGL_FRAME_BUFFER_H
|
||||
|
Reference in New Issue
Block a user