1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef OPENGL_FRAME_BUFFER_H
16 #define OPENGL_FRAME_BUFFER_H
18 #include <OpenGl_Context.hxx>
19 #include <OpenGl_ExtFBO.hxx>
20 #include <OpenGl_Resource.hxx>
22 #include <Standard_Boolean.hxx>
23 #include <InterfaceGraphic.hxx>
25 //! Class implements FrameBuffer Object (FBO) resource
26 //! intended for off-screen rendering.
27 class OpenGl_FrameBuffer : public OpenGl_Resource
33 static const GLuint NO_TEXTURE = 0;
34 static const GLuint NO_FRAMEBUFFER = 0;
35 static const GLuint NO_RENDERBUFFER = 0;
40 Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8);
43 Standard_EXPORT virtual ~OpenGl_FrameBuffer();
45 //! Destroy object - will release GPU memory if any.
46 Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx);
49 GLsizei GetSizeX() const
55 GLsizei GetSizeY() const
61 GLsizei GetVPSizeX() const
67 GLsizei GetVPSizeY() const
72 //! Returns true if current object was initialized
73 Standard_Boolean IsValid() const
75 return isValidFrameBuffer() && isValidTexture() && isValidDepthBuffer() && isValidStencilBuffer();
78 //! Notice! Obsolete hardware (GeForce FX etc)
79 //! doesn't support rectangular textures!
80 //! There are 3 possible results if you are trying
81 //! to create non power-of-two FBO on these cards:
82 //! 1) FBO creation will fail,
83 //! current implementation will try to generate compatible FBO;
84 //! 2) FBO rendering will be done in software mode (ForceWare 'hack');
85 //! 3) FBO rendering will be incorrect (some obsolete Catalyst drivers).
86 Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
87 const GLsizei theViewportSizeX,
88 const GLsizei theViewportSizeY,
89 const GLboolean toForcePowerOfTwo = GL_FALSE);
91 //! Setup viewport to render into FBO
92 Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx);
94 //! Override viewport settings
95 Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX,
96 const GLsizei theVPSizeY);
98 //! Bind frame buffer (to render into the texture).
99 Standard_EXPORT void BindBuffer (const Handle(OpenGl_Context)& theGlCtx);
101 //! Unbind frame buffer.
102 Standard_EXPORT void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx);
104 //! Bind the texture.
105 Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx);
107 //! Unbind the texture.
108 Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx);
112 //! Check texture could be created
113 Standard_Boolean isProxySuccess() const;
115 //! Generate texture with undefined data
116 Standard_Boolean initTrashTexture (const Handle(OpenGl_Context)& theGlContext);
118 Standard_Boolean isValidTexture() const
120 return myGlTextureId != NO_TEXTURE;
123 Standard_Boolean isValidFrameBuffer() const
125 return myGlFBufferId != NO_FRAMEBUFFER;
128 Standard_Boolean isValidDepthBuffer() const
130 return myGlDepthRBId != NO_RENDERBUFFER;
133 Standard_Boolean isValidStencilBuffer() const
135 return myGlStencilRBId != NO_RENDERBUFFER;
140 GLsizei mySizeX; //!< texture width
141 GLsizei mySizeY; //!< texture height
142 GLsizei myVPSizeX; //!< viewport width (should be <= texture width)
143 GLsizei myVPSizeY; //!< viewport height (should be <= texture height)
144 GLint myTextFormat; //!< GL_RGB, GL_RGBA,...
145 GLuint myGlTextureId; //!< GL texture ID
146 GLuint myGlFBufferId; //!< FBO object ID
147 GLuint myGlDepthRBId; //!< RenderBuffer object for depth ID
148 GLuint myGlStencilRBId; //!< RenderBuffer object for stencil ID
152 DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition
156 DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource)
158 #endif // OPENGL_FRAME_BUFFER_H