ScummVM API documentation
texture.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_TEXTURE_H
23 #define BACKENDS_GRAPHICS_OPENGL_TEXTURE_H
24 
25 #include "graphics/opengl/system_headers.h"
26 #include "graphics/opengl/context.h"
27 #include "graphics/opengl/texture.h"
28 
29 #include "graphics/pixelformat.h"
30 #include "graphics/surface.h"
31 
32 #include "common/rect.h"
33 
34 class Scaler;
35 
36 namespace OpenGL {
37 
41 class Surface {
42 public:
43  Surface();
44  virtual ~Surface() {}
45 
49  virtual void destroy() = 0;
50 
54  virtual void recreate() = 0;
55 
61  virtual void enableLinearFiltering(bool enable) = 0;
62 
69  virtual void allocate(uint width, uint height) = 0;
70 
76  virtual void setMask(const byte *mask) {}
77 
91  void copyRectToTexture(uint x, uint y, uint w, uint h, const void *src, uint srcPitch);
92 
98  void fill(uint32 color);
99  void fill(const Common::Rect &r, uint32 color);
100 
101  void flagDirty() { _allDirty = true; }
102  virtual bool isDirty() const { return _allDirty || !_dirtyArea.isEmpty(); }
103 
104  virtual uint getWidth() const = 0;
105  virtual uint getHeight() const = 0;
106 
110  virtual Graphics::PixelFormat getFormat() const = 0;
111 
112  virtual Graphics::Surface *getSurface() = 0;
113  virtual const Graphics::Surface *getSurface() const = 0;
114 
118  virtual bool hasPalette() const { return false; }
119 
127  virtual void setColorKey(uint colorKey) {}
128  virtual void setPalette(uint start, uint colors, const byte *palData) {}
129 
130  virtual void setScaler(uint scalerIndex, int scaleFactor) {}
131 
135  virtual void updateGLTexture() = 0;
136 
140  virtual const Texture &getGLTexture() const = 0;
141 protected:
142  void clearDirty() { _allDirty = false; _dirtyArea = Common::Rect(); }
143 
144  void addDirtyArea(const Common::Rect &r);
145  Common::Rect getDirtyArea() const;
146 private:
147  bool _allDirty;
148  Common::Rect _dirtyArea;
149 };
150 
155 class TextureSurface : public Surface {
156 public:
165  TextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format);
166  ~TextureSurface() override;
167 
168  void destroy() override;
169 
170  void recreate() override;
171 
172  void enableLinearFiltering(bool enable) override;
173 
174  void allocate(uint width, uint height) override;
175 
176  uint getWidth() const override { return _userPixelData.w; }
177  uint getHeight() const override { return _userPixelData.h; }
178 
182  Graphics::PixelFormat getFormat() const override { return _format; }
183 
184  Graphics::Surface *getSurface() override { return &_userPixelData; }
185  const Graphics::Surface *getSurface() const override { return &_userPixelData; }
186 
187  void updateGLTexture() override;
188  const Texture &getGLTexture() const override { return _glTexture; }
189 protected:
190  const Graphics::PixelFormat _format;
191 
192  void updateGLTexture(Common::Rect &dirtyArea);
193 
194 private:
195  Texture _glTexture;
196 
197  Graphics::Surface _textureData;
198  Graphics::Surface _userPixelData;
199 };
200 
202 public:
203  FakeTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
204  ~FakeTextureSurface() override;
205 
206  void allocate(uint width, uint height) override;
207  void setMask(const byte *mask) override;
208 
209  Graphics::PixelFormat getFormat() const override { return _fakeFormat; }
210 
211  bool hasPalette() const override { return (_palette != nullptr); }
212 
213  void setColorKey(uint colorKey) override;
214  void setPalette(uint start, uint colors, const byte *palData) override;
215 
216  Graphics::Surface *getSurface() override { return &_rgbData; }
217  const Graphics::Surface *getSurface() const override { return &_rgbData; }
218 
219  void updateGLTexture() override;
220 protected:
221  void applyPaletteAndMask(byte *dst, const byte *src, uint dstPitch, uint srcPitch, uint srcWidth, const Common::Rect &dirtyArea, const Graphics::PixelFormat &dstFormat, const Graphics::PixelFormat &srcFormat) const;
222 
223  Graphics::Surface _rgbData;
224  Graphics::PixelFormat _fakeFormat;
225  uint32 *_palette;
226  uint8 *_mask;
227 };
228 
230 public:
232  ~TextureSurfaceRGB555() override {}
233 
234  void updateGLTexture() override;
235 };
236 
238 public:
240  ~TextureSurfaceRGBA8888Swap() override {}
241 
242  void updateGLTexture() override;
243 };
244 
245 #ifdef USE_SCALERS
246 class ScaledTextureSurface : public FakeTextureSurface {
247 public:
248  ScaledTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
249  ~ScaledTextureSurface() override;
250 
251  void allocate(uint width, uint height) override;
252 
253  uint getWidth() const override { return _rgbData.w; }
254  uint getHeight() const override { return _rgbData.h; }
255  Graphics::PixelFormat getFormat() const override { return _fakeFormat; }
256 
257  bool hasPalette() const override { return (_palette != nullptr); }
258 
259  Graphics::Surface *getSurface() override { return &_rgbData; }
260  const Graphics::Surface *getSurface() const override { return &_rgbData; }
261 
262  void updateGLTexture() override;
263 
264  void setScaler(uint scalerIndex, int scaleFactor) override;
265 protected:
266  Graphics::Surface *_convData;
267  Scaler *_scaler;
268  uint _scalerIndex;
269  uint _extraPixels;
270  uint _scaleFactor;
271 };
272 #endif
273 
274 #if !USE_FORCED_GLES
275 class TextureTarget;
276 class CLUT8LookUpPipeline;
277 
279 public:
281  ~TextureSurfaceCLUT8GPU() override;
282 
283  void destroy() override;
284 
285  void recreate() override;
286 
287  void enableLinearFiltering(bool enable) override;
288 
289  void allocate(uint width, uint height) override;
290 
291  bool isDirty() const override { return _paletteDirty || Surface::isDirty(); }
292 
293  uint getWidth() const override { return _userPixelData.w; }
294  uint getHeight() const override { return _userPixelData.h; }
295 
296  Graphics::PixelFormat getFormat() const override;
297 
298  bool hasPalette() const override { return true; }
299 
300  void setColorKey(uint colorKey) override;
301  void setPalette(uint start, uint colors, const byte *palData) override;
302 
303  Graphics::Surface *getSurface() override { return &_userPixelData; }
304  const Graphics::Surface *getSurface() const override { return &_userPixelData; }
305 
306  void updateGLTexture() override;
307  const Texture &getGLTexture() const override;
308 
309  static bool isSupportedByContext() {
310  return OpenGLContext.shadersSupported
311  && OpenGLContext.multitextureSupported
312  && OpenGLContext.framebufferObjectSupported;
313  }
314 private:
315  void lookUpColors();
316 
317  Texture _clut8Texture;
318  Texture _paletteTexture;
319 
320  TextureTarget *_target;
321  CLUT8LookUpPipeline *_clut8Pipeline;
322 
323  GLfloat _clut8Vertices[4*2];
324 
325  Graphics::Surface _clut8Data;
326  Graphics::Surface _userPixelData;
327 
328  byte _palette[4 * 256];
329  bool _paletteDirty;
330 };
331 #endif // !USE_FORCED_GLES
332 
333 } // End of namespace OpenGL
334 
335 #endif
Definition: surface.h:67
virtual void setColorKey(uint colorKey)
Definition: texture.h:127
Definition: texture.h:201
virtual bool hasPalette() const
Definition: texture.h:118
Definition: pixelformat.h:138
const Texture & getGLTexture() const override
Definition: texture.h:188
Graphics::PixelFormat getFormat() const override
Definition: texture.h:209
Definition: rect.h:144
virtual void recreate()=0
virtual void setMask(const byte *mask)
Definition: texture.h:76
Graphics::PixelFormat getFormat() const override
Definition: texture.h:182
bool hasPalette() const override
Definition: texture.h:298
bool hasPalette() const override
Definition: texture.h:211
virtual void allocate(uint width, uint height)=0
void copyRectToTexture(uint x, uint y, uint w, uint h, const void *src, uint srcPitch)
Definition: framebuffer.h:203
virtual void enableLinearFiltering(bool enable)=0
Definition: renderbuffer.h:27
Definition: texture.h:47
virtual void updateGLTexture()=0
Definition: texture.h:229
virtual Graphics::PixelFormat getFormat() const =0
Definition: texture.h:155
Definition: texture.h:278
Definition: texture.h:41
Definition: scalerplugin.h:28
Definition: clut8.h:30
Definition: texture.h:237
virtual const Texture & getGLTexture() const =0
void fill(uint32 color)
bool isEmpty() const
Definition: rect.h:330
virtual void destroy()=0