ScummVM API documentation
framebuffer.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_GRAPHICS_OPENGL_FRAMEBUFFER_H
23 #define BACKENDS_GRAPHICS_OPENGL_FRAMEBUFFER_H
24 
25 #include "graphics/opengl/system_headers.h"
26 
27 #include "math/matrix4.h"
28 
29 namespace OpenGL {
30 
31 class Pipeline;
32 
36 class Framebuffer {
37 public:
38  Framebuffer();
39  virtual ~Framebuffer() {};
40 
41 public:
42  enum BlendMode {
48 
54 
60 
69 
74 
80  };
81 
85  void setClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
86 
90  void enableBlend(BlendMode mode);
91 
95  void enableScissorTest(bool enable);
96 
100  void setScissorBox(GLint x, GLint y, GLsizei w, GLsizei h);
101 
105  const Math::Matrix4 &getProjectionMatrix() const { return _projectionMatrix; }
106 
107  enum CopyMask {
108  kCopyMaskClearColor = (1 << 0),
109  kCopyMaskBlendState = (1 << 1),
110  kCopyMaskScissorState = (1 << 2),
111  kCopyMaskScissorBox = (1 << 4),
112 
113  kCopyMaskAll = kCopyMaskClearColor | kCopyMaskBlendState |
114  kCopyMaskScissorState | kCopyMaskScissorBox,
115  };
116 
120  void copyRenderStateFrom(const Framebuffer &other, uint copyMask);
121 
122 protected:
123  bool isActive() const { return _pipeline != nullptr; }
124 
125  GLint _viewport[4];
126  void applyViewport();
127 
128  Math::Matrix4 _projectionMatrix;
129  void applyProjectionMatrix();
130 
136  virtual void activateInternal() = 0;
137 
144  virtual void deactivateInternal() {}
145 
146 public:
150  virtual bool setSize(uint width, uint height) = 0;
151 
155  void activate(Pipeline *pipeline);
156 
160  void deactivate();
161 
162 private:
163  Pipeline *_pipeline;
164 
165  GLfloat _clearColor[4];
166  void applyClearColor();
167 
168  BlendMode _blendState;
169  void applyBlendState();
170 
171  bool _scissorTestState;
172  void applyScissorTestState();
173 
174  GLint _scissorBox[4];
175  void applyScissorBox();
176 };
177 
181 class Backbuffer : public Framebuffer {
182 public:
186  bool setSize(uint width, uint height) override;
187 
188 protected:
189  void activateInternal() override;
190 };
191 
192 #if !USE_FORCED_GLES
193 class GLTexture;
194 
201 class TextureTarget : public Framebuffer {
202 public:
203  TextureTarget();
204  ~TextureTarget() override;
205 
209  void destroy();
210 
214  void create();
215 
219  bool setSize(uint width, uint height) override;
220 
224  GLTexture *getTexture() const { return _texture; }
225 
226 protected:
227  void activateInternal() override;
228 
229 private:
230  GLTexture *_texture;
231  GLuint _glFBO;
232  bool _needUpdate;
233 };
234 #endif
235 
236 } // End of namespace OpenGL
237 
238 #endif
Definition: framebuffer.h:181
virtual bool setSize(uint width, uint height)=0
void setClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Definition: framebuffer.h:36
void setScissorBox(GLint x, GLint y, GLsizei w, GLsizei h)
void copyRenderStateFrom(const Framebuffer &other, uint copyMask)
Definition: texture.h:49
Definition: framebuffer.h:53
GLTexture * getTexture() const
Definition: framebuffer.h:224
virtual void deactivateInternal()
Definition: framebuffer.h:144
BlendMode
Definition: framebuffer.h:42
const Math::Matrix4 & getProjectionMatrix() const
Definition: framebuffer.h:105
Definition: framebuffer.h:201
void enableScissorTest(bool enable)
void enableBlend(BlendMode mode)
Definition: framebuffer.h:47
void activate(Pipeline *pipeline)
Definition: renderbuffer.h:27
virtual void activateInternal()=0
Definition: framebuffer.h:73
Definition: pipeline.h:42