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.
20 #ifndef OPENGL_FRAME_BUFFER_H
21 #define OPENGL_FRAME_BUFFER_H
23 #include <OpenGl_Context.hxx>
24 #include <OpenGl_ExtFBO.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <InterfaceGraphic.hxx>
29 class OpenGl_FrameBuffer
35 static const GLuint NO_TEXTURE = 0;
36 static const GLuint NO_FRAMEBUFFER = 0;
37 static const GLuint NO_RENDERBUFFER = 0;
41 OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8);
43 virtual ~OpenGl_FrameBuffer()
45 Release (Handle(OpenGl_Context)());
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();
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_Boolean Init (const Handle(OpenGl_Context)& theGlContext,
87 GLsizei theViewportSizeX,
88 GLsizei theViewportSizeY,
89 GLboolean toForcePowerOfTwo = GL_FALSE);
91 //! Release GL objects
92 void Release (const Handle(OpenGl_Context)& theGlContext);
94 //! Setup viewport to render into FBO
97 glViewport (0, 0, myVPSizeX, myVPSizeY);
100 //! Override viewport settings
101 void ChangeViewport (const GLsizei theVPSizeX,
102 const GLsizei theVPSizeY)
104 myVPSizeX = theVPSizeX;
105 myVPSizeY = theVPSizeY;
108 //! Bind frame buffer (to render into the texture).
109 void BindBuffer (const Handle(OpenGl_Context)& theGlContext)
111 theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, myGlFBufferId);
114 //! Unbind frame buffer.
115 void UnbindBuffer (const Handle(OpenGl_Context)& theGlContext)
117 theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, NO_FRAMEBUFFER);
120 //! Bind the texture.
123 glEnable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering
124 glBindTexture (GL_TEXTURE_2D, myGlTextureId);
127 //! Unbind the texture.
130 glBindTexture (GL_TEXTURE_2D, NO_TEXTURE);
131 glDisable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering
136 //! Check texture could be created
137 Standard_Boolean IsProxySuccess() const;
139 //! Generate texture with undefined data
140 Standard_Boolean InitTrashTexture (const Handle(OpenGl_Context)& theGlContext);
142 Standard_Boolean IsValidTexture() const
144 return myGlTextureId != NO_TEXTURE;
147 Standard_Boolean IsValidFrameBuffer() const
149 return myGlFBufferId != NO_FRAMEBUFFER;
152 Standard_Boolean IsValidDepthBuffer() const
154 return myGlDepthRBId != NO_RENDERBUFFER;
159 GLsizei mySizeX; // texture width
160 GLsizei mySizeY; // texture height
161 GLsizei myVPSizeX; // viewport width (should be <= texture width)
162 GLsizei myVPSizeY; // viewport height (should be <= texture height)
163 GLint myTextFormat; // GL_RGB, GL_RGBA,...
164 GLuint myGlTextureId; // GL texture ID
165 GLuint myGlFBufferId; // FBO object ID
166 GLuint myGlDepthRBId; // RenderBuffer object for depth ID
170 #endif //OPENGL_FRAME_BUFFER_H