0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / OpenGl / OpenGl_FrameBuffer.hxx
CommitLineData
b311480e 1// Created by: Kirill GAVRILOV
973c2be1 2// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#ifndef OPENGL_FRAME_BUFFER_H
16#define OPENGL_FRAME_BUFFER_H
17
2166f0fa 18#include <OpenGl_Context.hxx>
fd4a6963 19#include <OpenGl_Resource.hxx>
18f4e8e2 20#include <OpenGl_Texture.hxx>
7fd59977 21
22#include <Standard_Boolean.hxx>
23#include <InterfaceGraphic.hxx>
24
c04c30b3 25class OpenGl_FrameBuffer;
26DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource)
a2e4f780 27
fd4a6963 28//! Class implements FrameBuffer Object (FBO) resource
29//! intended for off-screen rendering.
30class OpenGl_FrameBuffer : public OpenGl_Resource
7fd59977 31{
32
33public:
34
35 //! Helpful constants
a2e4f780 36 static const GLuint NO_FRAMEBUFFER = 0;
37 static const GLuint NO_RENDERBUFFER = 0;
7fd59977 38
7fd59977 39public:
40
fd4a6963 41 //! Empty constructor
3c4b62a4 42 Standard_EXPORT OpenGl_FrameBuffer();
7fd59977 43
fd4a6963 44 //! Destructor
45 Standard_EXPORT virtual ~OpenGl_FrameBuffer();
46
47 //! Destroy object - will release GPU memory if any.
79104795 48 Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
7fd59977 49
3c4b62a4 50 //! Number of multisampling samples.
51 GLsizei NbSamples() const
52 {
53 return myNbSamples;
54 }
55
56 //! Return true if FBO has been created with color attachment.
57 bool HasColor() const
58 {
59 return myColorFormat != 0;
60 }
61
62 //! Return true if FBO has been created with depth attachment.
63 bool HasDepth() const
64 {
65 return myDepthFormat != 0;
66 }
67
18f4e8e2 68 //! Textures width.
7fd59977 69 GLsizei GetSizeX() const
70 {
18f4e8e2 71 return myColorTexture->SizeX();
7fd59977 72 }
73
18f4e8e2 74 //! Textures height.
7fd59977 75 GLsizei GetSizeY() const
76 {
18f4e8e2 77 return myColorTexture->SizeY();
7fd59977 78 }
79
80 //! Viewport width.
81 GLsizei GetVPSizeX() const
82 {
83 return myVPSizeX;
84 }
85
86 //! Viewport height.
87 GLsizei GetVPSizeY() const
88 {
89 return myVPSizeY;
90 }
91
92 //! Returns true if current object was initialized
93 Standard_Boolean IsValid() const
94 {
18f4e8e2 95 return isValidFrameBuffer();
7fd59977 96 }
97
3c4b62a4 98 //! Initialize FBO for rendering into textures.
99 //! @param theGlCtx currently bound OpenGL context
100 //! @param theSizeX texture width
101 //! @param theSizeY texture height
102 //! @param theColorFormat color texture sized format (0 means no color attachment), e.g. GL_RGBA8
103 //! @param theDepthFormat depth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
104 //! @param theNbSamples MSAA number of samples (0 means normal texture)
105 //! @return true on success
fd4a6963 106 Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
3c4b62a4 107 const GLsizei theSizeX,
108 const GLsizei theSizeY,
109 const GLint theColorFormat,
110 const GLint theDepthFormat,
111 const GLsizei theNbSamples = 0);
7fd59977 112
38a0206f 113 //! (Re-)initialize FBO with specified dimensions.
114 Standard_EXPORT Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
115 const GLsizei theViewportSizeX,
3c4b62a4 116 const GLsizei theViewportSizeY,
117 const GLint theColorFormat,
118 const GLint theDepthFormat,
119 const GLsizei theNbSamples = 0);
120
121 //! (Re-)initialize FBO with properties taken from another FBO.
122 Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
123 const OpenGl_FrameBuffer& theFbo)
124 {
125 return InitLazy (theGlCtx, theFbo.myVPSizeX, theFbo.myVPSizeY, theFbo.myColorFormat, theFbo.myDepthFormat, theFbo.myNbSamples);
126 }
38a0206f 127
a2e4f780 128 //! (Re-)initialize FBO with specified dimensions.
129 //! The Render Buffer Objects will be used for Color, Depth and Stencil attachments (as opposite to textures).
3c4b62a4 130 //! @param theGlCtx currently bound OpenGL context
131 //! @param theSizeX render buffer width
132 //! @param theSizeY render buffer height
133 //! @param theColorFormat color render buffer sized format, e.g. GL_RGBA8
134 //! @param theDepthFormat depth-stencil render buffer sized format, e.g. GL_DEPTH24_STENCIL8
a2e4f780 135 //! @param theColorRBufferFromWindow when specified - should be ID of already initialized RB object, which will be released within this class
136 Standard_EXPORT Standard_Boolean InitWithRB (const Handle(OpenGl_Context)& theGlCtx,
3c4b62a4 137 const GLsizei theSizeX,
138 const GLsizei theSizeY,
139 const GLint theColorFormat,
140 const GLint theDepthFormat,
a2e4f780 141 const GLuint theColorRBufferFromWindow = 0);
142
143 //! Initialize class from currently bound FBO.
144 //! Retrieved OpenGL objects will not be destroyed on Release.
145 Standard_EXPORT Standard_Boolean InitWrapper (const Handle(OpenGl_Context)& theGlCtx);
146
7fd59977 147 //! Setup viewport to render into FBO
fd4a6963 148 Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx);
7fd59977 149
150 //! Override viewport settings
fd4a6963 151 Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX,
152 const GLsizei theVPSizeY);
7fd59977 153
b86bb3df 154 //! Bind frame buffer for drawing and reading (to render into the texture).
18f4e8e2 155 Standard_EXPORT virtual void BindBuffer (const Handle(OpenGl_Context)& theGlCtx);
7fd59977 156
b86bb3df 157 //! Bind frame buffer for drawing GL_DRAW_FRAMEBUFFER (to render into the texture).
158 Standard_EXPORT virtual void BindDrawBuffer (const Handle(OpenGl_Context)& theGlCtx);
159
160 //! Bind frame buffer for reading GL_READ_FRAMEBUFFER
161 Standard_EXPORT virtual void BindReadBuffer (const Handle(OpenGl_Context)& theGlCtx);
162
7fd59977 163 //! Unbind frame buffer.
18f4e8e2 164 Standard_EXPORT virtual void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx);
7fd59977 165
18f4e8e2 166 //! Returns the color texture.
167 inline const Handle(OpenGl_Texture)& ColorTexture() const
7fd59977 168 {
18f4e8e2 169 return myColorTexture;
7fd59977 170 }
171
18f4e8e2 172 //! Returns the depth-stencil texture.
173 inline const Handle(OpenGl_Texture)& DepthStencilTexture() const
7fd59977 174 {
18f4e8e2 175 return myDepthStencilTexture;
7fd59977 176 }
177
a2e4f780 178 //! Returns the color Render Buffer.
179 GLuint ColorRenderBuffer() const
180 {
181 return myGlColorRBufferId;
182 }
183
184 //! Returns the depth Render Buffer.
185 GLuint DepthStencilRenderBuffer() const
186 {
187 return myGlDepthRBufferId;
188 }
189
18f4e8e2 190protected:
191
18f4e8e2 192 Standard_Boolean isValidFrameBuffer() const
b859a34d 193 {
18f4e8e2 194 return myGlFBufferId != NO_FRAMEBUFFER;
b859a34d 195 }
196
18f4e8e2 197protected:
198
199 GLsizei myVPSizeX; //!< viewport width (should be <= texture width)
200 GLsizei myVPSizeY; //!< viewport height (should be <= texture height)
3c4b62a4 201 GLsizei myNbSamples; //!< number of MSAA samples
202 GLint myColorFormat; //!< sized format for color texture, GL_RGBA8 by default
203 GLint myDepthFormat; //!< sized format for depth-stencil texture, GL_DEPTH24_STENCIL8 by default
18f4e8e2 204 GLuint myGlFBufferId; //!< FBO object ID
a2e4f780 205 GLuint myGlColorRBufferId; //!< color Render Buffer object (alternative to myColorTexture)
206 GLuint myGlDepthRBufferId; //!< depth-stencil Render Buffer object (alternative to myDepthStencilTexture)
207 bool myIsOwnBuffer; //!< flag indicating that FBO should be deallocated by this class
18f4e8e2 208 Handle(OpenGl_Texture) myColorTexture; //!< color texture object
209 Handle(OpenGl_Texture) myDepthStencilTexture; //!< depth-stencil texture object
fd4a6963 210
211public:
212
92efcf78 213 DEFINE_STANDARD_RTTIEXT(OpenGl_FrameBuffer,OpenGl_Resource) // Type definition
7fd59977 214
7fd59977 215};
216
fd4a6963 217#endif // OPENGL_FRAME_BUFFER_H