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 under
7 // the terms of the GNU Lesser General Public License 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_Resource.hxx>
20 #include <OpenGl_Texture.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_FRAMEBUFFER = 0;
38 Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8);
41 Standard_EXPORT virtual ~OpenGl_FrameBuffer();
43 //! Destroy object - will release GPU memory if any.
44 Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx);
47 GLsizei GetSizeX() const
49 return myColorTexture->SizeX();
53 GLsizei GetSizeY() const
55 return myColorTexture->SizeY();
59 GLsizei GetVPSizeX() const
65 GLsizei GetVPSizeY() const
70 //! Returns true if current object was initialized
71 Standard_Boolean IsValid() const
73 return isValidFrameBuffer();
76 //! Notice! Obsolete hardware (GeForce FX etc)
77 //! doesn't support rectangular textures!
78 //! There are 3 possible results if you are trying
79 //! to create non power-of-two FBO on these cards:
80 //! 1) FBO creation will fail,
81 //! current implementation will try to generate compatible FBO;
82 //! 2) FBO rendering will be done in software mode (ForceWare 'hack');
83 //! 3) FBO rendering will be incorrect (some obsolete Catalyst drivers).
84 Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
85 const GLsizei theViewportSizeX,
86 const GLsizei theViewportSizeY);
88 //! Setup viewport to render into FBO
89 Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx);
91 //! Override viewport settings
92 Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX,
93 const GLsizei theVPSizeY);
95 //! Bind frame buffer (to render into the texture).
96 Standard_EXPORT virtual void BindBuffer (const Handle(OpenGl_Context)& theGlCtx);
98 //! Unbind frame buffer.
99 Standard_EXPORT virtual void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx);
101 //! Returns the color texture.
102 inline const Handle(OpenGl_Texture)& ColorTexture() const
104 return myColorTexture;
107 //! Returns the depth-stencil texture.
108 inline const Handle(OpenGl_Texture)& DepthStencilTexture() const
110 return myDepthStencilTexture;
115 //! Generate textures with undefined data
116 Standard_Boolean initTrashTextures (const Handle(OpenGl_Context)& theGlContext);
118 Standard_Boolean isValidFrameBuffer() const
120 return myGlFBufferId != NO_FRAMEBUFFER;
125 GLsizei myVPSizeX; //!< viewport width (should be <= texture width)
126 GLsizei myVPSizeY; //!< viewport height (should be <= texture height)
127 GLint myTextFormat; //!< GL_RGB, GL_RGBA,...
128 GLuint myGlFBufferId; //!< FBO object ID
129 Handle(OpenGl_Texture) myColorTexture; //!< color texture object
130 Handle(OpenGl_Texture) myDepthStencilTexture; //!< depth-stencil texture object
134 DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition
138 DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource)
140 #endif // OPENGL_FRAME_BUFFER_H