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 #include "common/rotationmode.h"
30 
31 namespace OpenGL {
32 
33 class Pipeline;
34 
38 class Framebuffer {
39 public:
40  Framebuffer();
41  virtual ~Framebuffer() {};
42 
43 public:
44  enum BlendMode {
50 
56 
62 
71 
76 
82  };
83 
87  void setClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
88 
92  void enableBlend(BlendMode mode);
93 
97  void enableScissorTest(bool enable);
98 
102  void setScissorBox(GLint x, GLint y, GLsizei w, GLsizei h);
103 
107  const Math::Matrix4 &getProjectionMatrix() const { return _projectionMatrix; }
108 
109  enum CopyMask {
110  kCopyMaskClearColor = (1 << 0),
111  kCopyMaskBlendState = (1 << 1),
112  kCopyMaskScissorState = (1 << 2),
113  kCopyMaskScissorBox = (1 << 4),
114 
115  kCopyMaskAll = kCopyMaskClearColor | kCopyMaskBlendState |
116  kCopyMaskScissorState | kCopyMaskScissorBox,
117  };
118 
122  void copyRenderStateFrom(const Framebuffer &other, uint copyMask);
123 
124 protected:
125  bool isActive() const { return _pipeline != nullptr; }
126 
127  GLint _viewport[4];
128  void applyViewport();
129 
130  Math::Matrix4 _projectionMatrix;
131  void applyProjectionMatrix();
132 
138  virtual void activateInternal() = 0;
139 
146  virtual void deactivateInternal() {}
147 
148 public:
152  virtual bool setSize(uint width, uint height, Common::RotationMode rotation) = 0;
153 
157  void activate(Pipeline *pipeline);
158 
162  void deactivate();
163 
164 private:
165  Pipeline *_pipeline;
166 
167  GLfloat _clearColor[4];
168  void applyClearColor();
169 
170  BlendMode _blendState;
171  void applyBlendState();
172 
173  bool _scissorTestState;
174  void applyScissorTestState();
175 
176  GLint _scissorBox[4];
177  void applyScissorBox();
178 };
179 
183 class Backbuffer : public Framebuffer {
184 public:
188  bool setSize(uint width, uint height, Common::RotationMode rotation) override;
189 
190 protected:
191  void activateInternal() override;
192 };
193 
194 #if !USE_FORCED_GLES
195 class GLTexture;
196 
203 class TextureTarget : public Framebuffer {
204 public:
205  TextureTarget();
206  ~TextureTarget() override;
207 
211  void destroy();
212 
216  void create();
217 
221  bool setSize(uint width, uint height, Common::RotationMode rotation) override;
222 
226  GLTexture *getTexture() const { return _texture; }
227 
228 protected:
229  void activateInternal() override;
230 
231 private:
232  GLTexture *_texture;
233  GLuint _glFBO;
234  bool _needUpdate;
235 };
236 #endif
237 
238 } // End of namespace OpenGL
239 
240 #endif
Definition: framebuffer.h:183
void setClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Definition: framebuffer.h:38
void setScissorBox(GLint x, GLint y, GLsizei w, GLsizei h)
void copyRenderStateFrom(const Framebuffer &other, uint copyMask)
Definition: texture.h:49
Definition: framebuffer.h:55
GLTexture * getTexture() const
Definition: framebuffer.h:226
virtual void deactivateInternal()
Definition: framebuffer.h:146
virtual bool setSize(uint width, uint height, Common::RotationMode rotation)=0
BlendMode
Definition: framebuffer.h:44
const Math::Matrix4 & getProjectionMatrix() const
Definition: framebuffer.h:107
Definition: framebuffer.h:203
void enableScissorTest(bool enable)
void enableBlend(BlendMode mode)
Definition: framebuffer.h:49
void activate(Pipeline *pipeline)
Definition: renderbuffer.h:27
RotationMode
Definition: rotationmode.h:44
virtual void activateInternal()=0
Definition: framebuffer.h:75
Definition: pipeline.h:42