1 // File: OpenGl_FrameBuffer.hxx
2 // Author: Kirill GAVRILOV
3 // Copyright: OPEN CASCADE 2011
5 #ifndef OPENGL_FRAME_BUFFER_H
6 #define OPENGL_FRAME_BUFFER_H
8 #include <OpenGl_Context.hxx>
9 #include <OpenGl_ExtFBO.hxx>
11 #include <Standard_Boolean.hxx>
12 #include <InterfaceGraphic.hxx>
14 class OpenGl_FrameBuffer
20 static const GLuint NO_TEXTURE = 0;
21 static const GLuint NO_FRAMEBUFFER = 0;
22 static const GLuint NO_RENDERBUFFER = 0;
26 OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8);
28 virtual ~OpenGl_FrameBuffer()
30 Release (Handle(OpenGl_Context)());
34 GLsizei GetSizeX() const
40 GLsizei GetSizeY() const
46 GLsizei GetVPSizeX() const
52 GLsizei GetVPSizeY() const
57 //! Returns true if current object was initialized
58 Standard_Boolean IsValid() const
60 return IsValidFrameBuffer() && IsValidTexture() && IsValidDepthBuffer();
63 //! Notice! Obsolete hardware (GeForce FX etc)
64 //! doesn't support rectangular textures!
65 //! There are 3 possible results if you are trying
66 //! to create non power-of-two FBO on these cards:
67 //! 1) FBO creation will fail,
68 //! current implementation will try to generate compatible FBO;
69 //! 2) FBO rendering will be done in software mode (ForceWare 'hack');
70 //! 3) FBO rendering will be incorrect (some obsolete Catalyst drivers).
71 Standard_Boolean Init (const Handle(OpenGl_Context)& theGlContext,
72 GLsizei theViewportSizeX,
73 GLsizei theViewportSizeY,
74 GLboolean toForcePowerOfTwo = GL_FALSE);
76 //! Release GL objects
77 void Release (const Handle(OpenGl_Context)& theGlContext);
79 //! Setup viewport to render into FBO
82 glViewport (0, 0, myVPSizeX, myVPSizeY);
85 //! Override viewport settings
86 void ChangeViewport (const GLsizei theVPSizeX,
87 const GLsizei theVPSizeY)
89 myVPSizeX = theVPSizeX;
90 myVPSizeY = theVPSizeY;
93 //! Bind frame buffer (to render into the texture).
94 void BindBuffer (const Handle(OpenGl_Context)& theGlContext)
96 theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, myGlFBufferId);
99 //! Unbind frame buffer.
100 void UnbindBuffer (const Handle(OpenGl_Context)& theGlContext)
102 theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, NO_FRAMEBUFFER);
105 //! Bind the texture.
108 glEnable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering
109 glBindTexture (GL_TEXTURE_2D, myGlTextureId);
112 //! Unbind the texture.
115 glBindTexture (GL_TEXTURE_2D, NO_TEXTURE);
116 glDisable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering
121 //! Check texture could be created
122 Standard_Boolean IsProxySuccess() const;
124 //! Generate texture with undefined data
125 Standard_Boolean InitTrashTexture (const Handle(OpenGl_Context)& theGlContext);
127 Standard_Boolean IsValidTexture() const
129 return myGlTextureId != NO_TEXTURE;
132 Standard_Boolean IsValidFrameBuffer() const
134 return myGlFBufferId != NO_FRAMEBUFFER;
137 Standard_Boolean IsValidDepthBuffer() const
139 return myGlTextureId != 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
155 #endif //OPENGL_FRAME_BUFFER_H