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> |
7fd59977 |
20 | |
21 | #include <Standard_Boolean.hxx> |
22 | #include <InterfaceGraphic.hxx> |
23 | |
fd4a6963 |
24 | //! Class implements FrameBuffer Object (FBO) resource |
25 | //! intended for off-screen rendering. |
26 | class OpenGl_FrameBuffer : public OpenGl_Resource |
7fd59977 |
27 | { |
28 | |
29 | public: |
30 | |
31 | //! Helpful constants |
32 | static const GLuint NO_TEXTURE = 0; |
33 | static const GLuint NO_FRAMEBUFFER = 0; |
34 | static const GLuint NO_RENDERBUFFER = 0; |
35 | |
7fd59977 |
36 | public: |
37 | |
fd4a6963 |
38 | //! Empty constructor |
39 | Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8); |
7fd59977 |
40 | |
fd4a6963 |
41 | //! Destructor |
42 | Standard_EXPORT virtual ~OpenGl_FrameBuffer(); |
43 | |
44 | //! Destroy object - will release GPU memory if any. |
45 | Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx); |
7fd59977 |
46 | |
47 | //! Texture width. |
48 | GLsizei GetSizeX() const |
49 | { |
50 | return mySizeX; |
51 | } |
52 | |
53 | //! Texture height. |
54 | GLsizei GetSizeY() const |
55 | { |
56 | return mySizeY; |
57 | } |
58 | |
59 | //! Viewport width. |
60 | GLsizei GetVPSizeX() const |
61 | { |
62 | return myVPSizeX; |
63 | } |
64 | |
65 | //! Viewport height. |
66 | GLsizei GetVPSizeY() const |
67 | { |
68 | return myVPSizeY; |
69 | } |
70 | |
71 | //! Returns true if current object was initialized |
72 | Standard_Boolean IsValid() const |
73 | { |
fd4a6963 |
74 | return isValidFrameBuffer() && isValidTexture() && isValidDepthBuffer() && isValidStencilBuffer(); |
7fd59977 |
75 | } |
76 | |
77 | //! Notice! Obsolete hardware (GeForce FX etc) |
78 | //! doesn't support rectangular textures! |
79 | //! There are 3 possible results if you are trying |
80 | //! to create non power-of-two FBO on these cards: |
81 | //! 1) FBO creation will fail, |
82 | //! current implementation will try to generate compatible FBO; |
83 | //! 2) FBO rendering will be done in software mode (ForceWare 'hack'); |
84 | //! 3) FBO rendering will be incorrect (some obsolete Catalyst drivers). |
fd4a6963 |
85 | Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx, |
86 | const GLsizei theViewportSizeX, |
87 | const GLsizei theViewportSizeY, |
88 | const GLboolean toForcePowerOfTwo = GL_FALSE); |
7fd59977 |
89 | |
90 | //! Setup viewport to render into FBO |
fd4a6963 |
91 | Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
92 | |
93 | //! Override viewport settings |
fd4a6963 |
94 | Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX, |
95 | const GLsizei theVPSizeY); |
7fd59977 |
96 | |
97 | //! Bind frame buffer (to render into the texture). |
fd4a6963 |
98 | Standard_EXPORT void BindBuffer (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
99 | |
100 | //! Unbind frame buffer. |
fd4a6963 |
101 | Standard_EXPORT void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
102 | |
103 | //! Bind the texture. |
fd4a6963 |
104 | Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
105 | |
106 | //! Unbind the texture. |
fd4a6963 |
107 | Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx); |
7fd59977 |
108 | |
109 | private: |
110 | |
111 | //! Check texture could be created |
fd4a6963 |
112 | Standard_Boolean isProxySuccess() const; |
7fd59977 |
113 | |
114 | //! Generate texture with undefined data |
fd4a6963 |
115 | Standard_Boolean initTrashTexture (const Handle(OpenGl_Context)& theGlContext); |
7fd59977 |
116 | |
fd4a6963 |
117 | Standard_Boolean isValidTexture() const |
7fd59977 |
118 | { |
119 | return myGlTextureId != NO_TEXTURE; |
120 | } |
121 | |
fd4a6963 |
122 | Standard_Boolean isValidFrameBuffer() const |
7fd59977 |
123 | { |
124 | return myGlFBufferId != NO_FRAMEBUFFER; |
125 | } |
126 | |
fd4a6963 |
127 | Standard_Boolean isValidDepthBuffer() const |
7fd59977 |
128 | { |
96352003 |
129 | return myGlDepthRBId != NO_RENDERBUFFER; |
7fd59977 |
130 | } |
131 | |
fd4a6963 |
132 | Standard_Boolean isValidStencilBuffer() const |
b859a34d |
133 | { |
134 | return myGlStencilRBId != NO_RENDERBUFFER; |
135 | } |
136 | |
7fd59977 |
137 | private: |
138 | |
fd4a6963 |
139 | GLsizei mySizeX; //!< texture width |
140 | GLsizei mySizeY; //!< texture height |
141 | GLsizei myVPSizeX; //!< viewport width (should be <= texture width) |
142 | GLsizei myVPSizeY; //!< viewport height (should be <= texture height) |
143 | GLint myTextFormat; //!< GL_RGB, GL_RGBA,... |
144 | GLuint myGlTextureId; //!< GL texture ID |
145 | GLuint myGlFBufferId; //!< FBO object ID |
146 | GLuint myGlDepthRBId; //!< RenderBuffer object for depth ID |
147 | GLuint myGlStencilRBId; //!< RenderBuffer object for stencil ID |
148 | |
149 | public: |
150 | |
151 | DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition |
7fd59977 |
152 | |
7fd59977 |
153 | }; |
154 | |
fd4a6963 |
155 | DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource) |
156 | |
157 | #endif // OPENGL_FRAME_BUFFER_H |