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#include "graphics/blit.h"
32
33#include "common/rect.h"
34#include "common/rotationmode.h"
35
36class Scaler;
37
38namespace OpenGL {
39
43class Surface {
44public:
45 Surface();
46 virtual ~Surface() {}
47
51 virtual void destroy() = 0;
52
56 virtual void recreate() = 0;
57
63 virtual void enableLinearFiltering(bool enable) = 0;
64
70 virtual void setRotation(Common::RotationMode rotation) = 0;
71
78 virtual void allocate(uint width, uint height) = 0;
79
85 virtual void setMask(const byte *mask) {}
86
100 void copyRectToTexture(uint x, uint y, uint w, uint h, const void *src, uint srcPitch);
101
107 void fill(uint32 color);
108 void fill(const Common::Rect &r, uint32 color);
109
110 void flagDirty() { _allDirty = true; }
111 virtual bool isDirty() const { return _allDirty || !_dirtyArea.isEmpty(); }
112
113 virtual uint getWidth() const = 0;
114 virtual uint getHeight() const = 0;
115
119 virtual Graphics::PixelFormat getFormat() const = 0;
120
121 virtual Graphics::Surface *getSurface() = 0;
122 virtual const Graphics::Surface *getSurface() const = 0;
123
127 virtual bool hasPalette() const { return false; }
128
136 virtual void setColorKey(uint colorKey) {}
137 virtual void setPalette(uint start, uint colors, const byte *palData) {}
138
139 virtual void setScaler(uint scalerIndex, int scaleFactor) {}
140
144 virtual void updateGLTexture() = 0;
145
149 virtual const Texture &getGLTexture() const = 0;
150protected:
151 void clearDirty() { _allDirty = false; _dirtyArea = Common::Rect(); }
152
153 void addDirtyArea(const Common::Rect &r);
154 Common::Rect getDirtyArea() const;
155private:
156 bool _allDirty;
157 Common::Rect _dirtyArea;
158};
159
164class TextureSurface : public Surface {
165public:
174 TextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format);
175 ~TextureSurface() override;
176
177 void destroy() override;
178
179 void recreate() override;
180
181 void enableLinearFiltering(bool enable) override;
182 void setRotation(Common::RotationMode rotation) override;
183
184 void allocate(uint width, uint height) override;
185
186 uint getWidth() const override { return _userPixelData.w; }
187 uint getHeight() const override { return _userPixelData.h; }
188
192 Graphics::PixelFormat getFormat() const override { return _format; }
193
194 Graphics::Surface *getSurface() override { return &_userPixelData; }
195 const Graphics::Surface *getSurface() const override { return &_userPixelData; }
196
197 void updateGLTexture() override;
198 const Texture &getGLTexture() const override { return _glTexture; }
199protected:
200 const Graphics::PixelFormat _format;
201
202 void updateGLTexture(Common::Rect &dirtyArea);
203
204private:
205 Texture _glTexture;
206
207 Graphics::Surface _textureData;
208 Graphics::Surface _userPixelData;
209};
210
212public:
213 FakeTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
214 ~FakeTextureSurface() override;
215
216 void allocate(uint width, uint height) override;
217 void setMask(const byte *mask) override;
218
219 Graphics::PixelFormat getFormat() const override { return _fakeFormat; }
220
221 bool hasPalette() const override { return (_palette != nullptr); }
222
223 void setColorKey(uint colorKey) override;
224 void setPalette(uint start, uint colors, const byte *palData) override;
225
226 Graphics::Surface *getSurface() override { return &_rgbData; }
227 const Graphics::Surface *getSurface() const override { return &_rgbData; }
228
229 void updateGLTexture() override;
230protected:
231 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;
232
233 Graphics::Surface _rgbData;
234 Graphics::PixelFormat _fakeFormat;
235 Graphics::FastBlitFunc _blitFunc;
236 uint32 *_palette;
237 uint8 *_mask;
238};
239
240#ifdef USE_SCALERS
241class ScaledTextureSurface : public FakeTextureSurface {
242public:
243 ScaledTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
244 ~ScaledTextureSurface() override;
245
246 void allocate(uint width, uint height) override;
247
248 uint getWidth() const override { return _rgbData.w; }
249 uint getHeight() const override { return _rgbData.h; }
250 Graphics::PixelFormat getFormat() const override { return _fakeFormat; }
251
252 bool hasPalette() const override { return (_palette != nullptr); }
253
254 Graphics::Surface *getSurface() override { return &_rgbData; }
255 const Graphics::Surface *getSurface() const override { return &_rgbData; }
256
257 void updateGLTexture() override;
258
259 void setScaler(uint scalerIndex, int scaleFactor) override;
260protected:
261 Graphics::Surface *_convData;
262 Scaler *_scaler;
263 uint _scalerIndex;
264 uint _extraPixels;
265 uint _scaleFactor;
266};
267#endif
268
269#if !USE_FORCED_GLES
270class TextureTarget;
271class CLUT8LookUpPipeline;
272
274public:
276 ~TextureSurfaceCLUT8GPU() override;
277
278 void destroy() override;
279
280 void recreate() override;
281
282 void enableLinearFiltering(bool enable) override;
283 void setRotation(Common::RotationMode rotation) override;
284
285 void allocate(uint width, uint height) override;
286
287 bool isDirty() const override { return _paletteDirty || Surface::isDirty(); }
288
289 uint getWidth() const override { return _userPixelData.w; }
290 uint getHeight() const override { return _userPixelData.h; }
291
293
294 bool hasPalette() const override { return true; }
295
296 void setColorKey(uint colorKey) override;
297 void setPalette(uint start, uint colors, const byte *palData) override;
298
299 Graphics::Surface *getSurface() override { return &_userPixelData; }
300 const Graphics::Surface *getSurface() const override { return &_userPixelData; }
301
302 void updateGLTexture() override;
303 const Texture &getGLTexture() const override;
304
305 static bool isSupportedByContext() {
306 return OpenGLContext.shadersSupported
307 && OpenGLContext.multitextureSupported
308 && OpenGLContext.framebufferObjectSupported
309 // With 2^-8 precision this is too prone to approximation errors
310 && OpenGLContext.textureLookupPrecision > 8;
311 }
312private:
313 void lookUpColors();
314
315 Texture _clut8Texture;
316 Texture _paletteTexture;
317
318 TextureTarget *_target;
319 CLUT8LookUpPipeline *_clut8Pipeline;
320
321 GLfloat _clut8Vertices[4*2];
322
323 Graphics::Surface _clut8Data;
324 Graphics::Surface _userPixelData;
325
326 byte _palette[4 * 256];
327 bool _paletteDirty;
328};
329#endif // !USE_FORCED_GLES
330
331} // End of namespace OpenGL
332
333#endif
Definition: clut8.h:30
Definition: texture.h:211
void updateGLTexture() override
void setMask(const byte *mask) override
void setColorKey(uint colorKey) override
Graphics::PixelFormat getFormat() const override
Definition: texture.h:219
void allocate(uint width, uint height) override
bool hasPalette() const override
Definition: texture.h:221
Definition: texture.h:43
virtual void destroy()=0
virtual void enableLinearFiltering(bool enable)=0
virtual bool hasPalette() const
Definition: texture.h:127
void copyRectToTexture(uint x, uint y, uint w, uint h, const void *src, uint srcPitch)
void fill(uint32 color)
virtual void setMask(const byte *mask)
Definition: texture.h:85
virtual void setColorKey(uint colorKey)
Definition: texture.h:136
virtual void recreate()=0
virtual Graphics::PixelFormat getFormat() const =0
virtual void updateGLTexture()=0
virtual const Texture & getGLTexture() const =0
virtual void setRotation(Common::RotationMode rotation)=0
virtual void allocate(uint width, uint height)=0
Definition: texture.h:48
Definition: texture.h:273
const Texture & getGLTexture() const override
void allocate(uint width, uint height) override
void setColorKey(uint colorKey) override
Graphics::PixelFormat getFormat() const override
void setRotation(Common::RotationMode rotation) override
void enableLinearFiltering(bool enable) override
bool hasPalette() const override
Definition: texture.h:294
Definition: texture.h:164
void enableLinearFiltering(bool enable) override
Graphics::PixelFormat getFormat() const override
Definition: texture.h:192
void allocate(uint width, uint height) override
void updateGLTexture() override
void setRotation(Common::RotationMode rotation) override
void destroy() override
void recreate() override
const Texture & getGLTexture() const override
Definition: texture.h:198
TextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format)
Definition: framebuffer.h:203
Definition: scalerplugin.h:28
RotationMode
Definition: rotationmode.h:44
bool isEmpty() const
Definition: rect.h:385
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67
int16 h
Definition: surface.h:76
int16 w
Definition: surface.h:71