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 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public 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. |
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> |
5f8b738e |
19 | #include <OpenGl_ExtFBO.hxx> |
fd4a6963 |
20 | #include <OpenGl_Resource.hxx> |
7fd59977 |
21 | |
22 | #include <Standard_Boolean.hxx> |
23 | #include <InterfaceGraphic.hxx> |
24 | |
fd4a6963 |
25 | //! Class implements FrameBuffer Object (FBO) resource |
26 | //! intended for off-screen rendering. |
27 | class OpenGl_FrameBuffer : public OpenGl_Resource |
7fd59977 |
28 | { |
29 | |
30 | public: |
31 | |
32 | //! Helpful constants |
33 | static const GLuint NO_TEXTURE = 0; |
34 | static const GLuint NO_FRAMEBUFFER = 0; |
35 | static const GLuint NO_RENDERBUFFER = 0; |
36 | |
7fd59977 |
37 | public: |
38 | |
fd4a6963 |
39 | //! Empty constructor |
40 | Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8); |
7fd59977 |
41 | |
fd4a6963 |
42 | //! Destructor |
43 | Standard_EXPORT virtual ~OpenGl_FrameBuffer(); |
44 | |
45 | //! Destroy object - will release GPU memory if any. |
46 | Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx); |
7fd59977 |
47 | |
48 | //! Texture width. |
49 | GLsizei GetSizeX() const |
50 | { |
51 | return mySizeX; |
52 | } |
53 | |
54 | //! Texture height. |
55 | GLsizei GetSizeY() const |
56 | { |
57 | return mySizeY; |
58 | } |
59 | |
60 | //! Viewport width. |
61 | GLsizei GetVPSizeX() const |
62 | { |
63 | return myVPSizeX; |
64 | } |
65 | |
66 | //! Viewport height. |
67 | GLsizei GetVPSizeY() const |
68 | { |
69 | return myVPSizeY; |
70 | } |
71 | |
72 | //! Returns true if current object was initialized |
73 | Standard_Boolean IsValid() const |
74 | { |
fd4a6963 |
75 | return isValidFrameBuffer() && isValidTexture() && isValidDepthBuffer() && isValidStencilBuffer(); |
7fd59977 |
76 | } |
77 | |
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). |
fd4a6963 |
86 | Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx, |
87 | const GLsizei theViewportSizeX, |
88 | const GLsizei theViewportSizeY, |
89 | const GLboolean toForcePowerOfTwo = GL_FALSE); |
7fd59977 |
90 | |
91 | //! Setup viewport to render into FBO |
fd4a6963 |
92 | Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
93 | |
94 | //! Override viewport settings |
fd4a6963 |
95 | Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX, |
96 | const GLsizei theVPSizeY); |
7fd59977 |
97 | |
98 | //! Bind frame buffer (to render into the texture). |
fd4a6963 |
99 | Standard_EXPORT void BindBuffer (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
100 | |
101 | //! Unbind frame buffer. |
fd4a6963 |
102 | Standard_EXPORT void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
103 | |
104 | //! Bind the texture. |
fd4a6963 |
105 | Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
106 | |
107 | //! Unbind the texture. |
fd4a6963 |
108 | Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
109 | |
110 | private: |
111 | |
112 | //! Check texture could be created |
fd4a6963 |
113 | Standard_Boolean isProxySuccess() const; |
7fd59977 |
114 | |
115 | //! Generate texture with undefined data |
fd4a6963 |
116 | Standard_Boolean initTrashTexture (const Handle(OpenGl_Context)& theGlContext); |
7fd59977 |
117 | |
fd4a6963 |
118 | Standard_Boolean isValidTexture() const |
7fd59977 |
119 | { |
120 | return myGlTextureId != NO_TEXTURE; |
121 | } |
122 | |
fd4a6963 |
123 | Standard_Boolean isValidFrameBuffer() const |
7fd59977 |
124 | { |
125 | return myGlFBufferId != NO_FRAMEBUFFER; |
126 | } |
127 | |
fd4a6963 |
128 | Standard_Boolean isValidDepthBuffer() const |
7fd59977 |
129 | { |
96352003 |
130 | return myGlDepthRBId != NO_RENDERBUFFER; |
7fd59977 |
131 | } |
132 | |
fd4a6963 |
133 | Standard_Boolean isValidStencilBuffer() const |
b859a34d |
134 | { |
135 | return myGlStencilRBId != NO_RENDERBUFFER; |
136 | } |
137 | |
7fd59977 |
138 | private: |
139 | |
fd4a6963 |
140 | GLsizei mySizeX; //!< texture width |
141 | GLsizei mySizeY; //!< texture height |
142 | GLsizei myVPSizeX; //!< viewport width (should be <= texture width) |
143 | GLsizei myVPSizeY; //!< viewport height (should be <= texture height) |
144 | GLint myTextFormat; //!< GL_RGB, GL_RGBA,... |
145 | GLuint myGlTextureId; //!< GL texture ID |
146 | GLuint myGlFBufferId; //!< FBO object ID |
147 | GLuint myGlDepthRBId; //!< RenderBuffer object for depth ID |
148 | GLuint myGlStencilRBId; //!< RenderBuffer object for stencil ID |
149 | |
150 | public: |
151 | |
152 | DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition |
7fd59977 |
153 | |
7fd59977 |
154 | }; |
155 | |
fd4a6963 |
156 | DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource) |
157 | |
158 | #endif // OPENGL_FRAME_BUFFER_H |