1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #ifndef OPENGL_FRAME_BUFFER_H
20 #define OPENGL_FRAME_BUFFER_H
22 #include <OpenGl_Context.hxx>
23 #include <OpenGl_ExtFBO.hxx>
24 #include <OpenGl_Resource.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <InterfaceGraphic.hxx>
29 //! Class implements FrameBuffer Object (FBO) resource
30 //! intended for off-screen rendering.
31 class OpenGl_FrameBuffer : public OpenGl_Resource
37 static const GLuint NO_TEXTURE = 0;
38 static const GLuint NO_FRAMEBUFFER = 0;
39 static const GLuint NO_RENDERBUFFER = 0;
44 Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8);
47 Standard_EXPORT virtual ~OpenGl_FrameBuffer();
49 //! Destroy object - will release GPU memory if any.
50 Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx);
53 GLsizei GetSizeX() const
59 GLsizei GetSizeY() const
65 GLsizei GetVPSizeX() const
71 GLsizei GetVPSizeY() const
76 //! Returns true if current object was initialized
77 Standard_Boolean IsValid() const
79 return isValidFrameBuffer() && isValidTexture() && isValidDepthBuffer() && isValidStencilBuffer();
82 //! Notice! Obsolete hardware (GeForce FX etc)
83 //! doesn't support rectangular textures!
84 //! There are 3 possible results if you are trying
85 //! to create non power-of-two FBO on these cards:
86 //! 1) FBO creation will fail,
87 //! current implementation will try to generate compatible FBO;
88 //! 2) FBO rendering will be done in software mode (ForceWare 'hack');
89 //! 3) FBO rendering will be incorrect (some obsolete Catalyst drivers).
90 Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
91 const GLsizei theViewportSizeX,
92 const GLsizei theViewportSizeY,
93 const GLboolean toForcePowerOfTwo = GL_FALSE);
95 //! Setup viewport to render into FBO
96 Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx);
98 //! Override viewport settings
99 Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX,
100 const GLsizei theVPSizeY);
102 //! Bind frame buffer (to render into the texture).
103 Standard_EXPORT void BindBuffer (const Handle(OpenGl_Context)& theGlCtx);
105 //! Unbind frame buffer.
106 Standard_EXPORT void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx);
108 //! Bind the texture.
109 Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx);
111 //! Unbind the texture.
112 Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx);
116 //! Check texture could be created
117 Standard_Boolean isProxySuccess() const;
119 //! Generate texture with undefined data
120 Standard_Boolean initTrashTexture (const Handle(OpenGl_Context)& theGlContext);
122 Standard_Boolean isValidTexture() const
124 return myGlTextureId != NO_TEXTURE;
127 Standard_Boolean isValidFrameBuffer() const
129 return myGlFBufferId != NO_FRAMEBUFFER;
132 Standard_Boolean isValidDepthBuffer() const
134 return myGlDepthRBId != NO_RENDERBUFFER;
137 Standard_Boolean isValidStencilBuffer() const
139 return myGlStencilRBId != NO_RENDERBUFFER;
144 GLsizei mySizeX; //!< texture width
145 GLsizei mySizeY; //!< texture height
146 GLsizei myVPSizeX; //!< viewport width (should be <= texture width)
147 GLsizei myVPSizeY; //!< viewport height (should be <= texture height)
148 GLint myTextFormat; //!< GL_RGB, GL_RGBA,...
149 GLuint myGlTextureId; //!< GL texture ID
150 GLuint myGlFBufferId; //!< FBO object ID
151 GLuint myGlDepthRBId; //!< RenderBuffer object for depth ID
152 GLuint myGlStencilRBId; //!< RenderBuffer object for stencil ID
156 DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition
160 DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource)
162 #endif // OPENGL_FRAME_BUFFER_H