b311480e |
1 | // Created by: Kirill GAVRILOV |
2 | // Copyright (c) 2011-2012 OPEN CASCADE SAS |
3 | // |
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. |
8 | // |
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. |
11 | // |
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. |
18 | |
7fd59977 |
19 | #ifndef OPENGL_FRAME_BUFFER_H |
20 | #define OPENGL_FRAME_BUFFER_H |
21 | |
2166f0fa |
22 | #include <OpenGl_Context.hxx> |
5f8b738e |
23 | #include <OpenGl_ExtFBO.hxx> |
fd4a6963 |
24 | #include <OpenGl_Resource.hxx> |
7fd59977 |
25 | |
26 | #include <Standard_Boolean.hxx> |
27 | #include <InterfaceGraphic.hxx> |
28 | |
fd4a6963 |
29 | //! Class implements FrameBuffer Object (FBO) resource |
30 | //! intended for off-screen rendering. |
31 | class OpenGl_FrameBuffer : public OpenGl_Resource |
7fd59977 |
32 | { |
33 | |
34 | public: |
35 | |
36 | //! Helpful constants |
37 | static const GLuint NO_TEXTURE = 0; |
38 | static const GLuint NO_FRAMEBUFFER = 0; |
39 | static const GLuint NO_RENDERBUFFER = 0; |
40 | |
7fd59977 |
41 | public: |
42 | |
fd4a6963 |
43 | //! Empty constructor |
44 | Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8); |
7fd59977 |
45 | |
fd4a6963 |
46 | //! Destructor |
47 | Standard_EXPORT virtual ~OpenGl_FrameBuffer(); |
48 | |
49 | //! Destroy object - will release GPU memory if any. |
50 | Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx); |
7fd59977 |
51 | |
52 | //! Texture width. |
53 | GLsizei GetSizeX() const |
54 | { |
55 | return mySizeX; |
56 | } |
57 | |
58 | //! Texture height. |
59 | GLsizei GetSizeY() const |
60 | { |
61 | return mySizeY; |
62 | } |
63 | |
64 | //! Viewport width. |
65 | GLsizei GetVPSizeX() const |
66 | { |
67 | return myVPSizeX; |
68 | } |
69 | |
70 | //! Viewport height. |
71 | GLsizei GetVPSizeY() const |
72 | { |
73 | return myVPSizeY; |
74 | } |
75 | |
76 | //! Returns true if current object was initialized |
77 | Standard_Boolean IsValid() const |
78 | { |
fd4a6963 |
79 | return isValidFrameBuffer() && isValidTexture() && isValidDepthBuffer() && isValidStencilBuffer(); |
7fd59977 |
80 | } |
81 | |
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). |
fd4a6963 |
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); |
7fd59977 |
94 | |
95 | //! Setup viewport to render into FBO |
fd4a6963 |
96 | Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
97 | |
98 | //! Override viewport settings |
fd4a6963 |
99 | Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX, |
100 | const GLsizei theVPSizeY); |
7fd59977 |
101 | |
102 | //! Bind frame buffer (to render into the texture). |
fd4a6963 |
103 | Standard_EXPORT void BindBuffer (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
104 | |
105 | //! Unbind frame buffer. |
fd4a6963 |
106 | Standard_EXPORT void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
107 | |
108 | //! Bind the texture. |
fd4a6963 |
109 | Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
110 | |
111 | //! Unbind the texture. |
fd4a6963 |
112 | Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
113 | |
114 | private: |
115 | |
116 | //! Check texture could be created |
fd4a6963 |
117 | Standard_Boolean isProxySuccess() const; |
7fd59977 |
118 | |
119 | //! Generate texture with undefined data |
fd4a6963 |
120 | Standard_Boolean initTrashTexture (const Handle(OpenGl_Context)& theGlContext); |
7fd59977 |
121 | |
fd4a6963 |
122 | Standard_Boolean isValidTexture() const |
7fd59977 |
123 | { |
124 | return myGlTextureId != NO_TEXTURE; |
125 | } |
126 | |
fd4a6963 |
127 | Standard_Boolean isValidFrameBuffer() const |
7fd59977 |
128 | { |
129 | return myGlFBufferId != NO_FRAMEBUFFER; |
130 | } |
131 | |
fd4a6963 |
132 | Standard_Boolean isValidDepthBuffer() const |
7fd59977 |
133 | { |
96352003 |
134 | return myGlDepthRBId != NO_RENDERBUFFER; |
7fd59977 |
135 | } |
136 | |
fd4a6963 |
137 | Standard_Boolean isValidStencilBuffer() const |
b859a34d |
138 | { |
139 | return myGlStencilRBId != NO_RENDERBUFFER; |
140 | } |
141 | |
7fd59977 |
142 | private: |
143 | |
fd4a6963 |
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 |
153 | |
154 | public: |
155 | |
156 | DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition |
7fd59977 |
157 | |
7fd59977 |
158 | }; |
159 | |
fd4a6963 |
160 | DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource) |
161 | |
162 | #endif // OPENGL_FRAME_BUFFER_H |