ScummVM API documentation
opengl-graphics.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_OPENGL_GRAPHICS_H
23#define BACKENDS_GRAPHICS_OPENGL_OPENGL_GRAPHICS_H
24
25#include "backends/graphics/opengl/framebuffer.h"
26#include "backends/graphics/windowed.h"
27
28#include "base/plugins.h"
29
30#include "common/frac.h"
31#include "common/mutex.h"
32#include "common/ustr.h"
33
34#include "graphics/surface.h"
35
36namespace Graphics {
37class Font;
38} // End of namespace Graphics
39
40namespace OpenGL {
41
42// HACK: We use glColor in the OSD code. This might not be working on GL ES but
43// we still enable it because Tizen already shipped with it. Also, the
44// SurfaceSDL backend enables it and disabling it can cause issues in sdl.cpp.
45#define USE_OSD 1
46
47class Surface;
48class Pipeline;
49#if !USE_FORCED_GLES
50class LibRetroPipeline;
51#endif
52#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
53class Renderer3D;
54#endif
55
56enum {
57 GFX_OPENGL = 0
58};
59
61public:
63 virtual ~OpenGLGraphicsManager();
64
65 // GraphicsManager API
66 bool hasFeature(OSystem::Feature f) const override;
67 void setFeatureState(OSystem::Feature f, bool enable) override;
68 bool getFeatureState(OSystem::Feature f) const override;
69
70 const OSystem::GraphicsMode *getSupportedGraphicsModes() const override;
71 int getDefaultGraphicsMode() const override;
72 bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override;
73 int getGraphicsMode() const override;
74
75#ifdef USE_RGB_COLOR
76 Graphics::PixelFormat getScreenFormat() const override;
77 Common::List<Graphics::PixelFormat> getSupportedFormats() const override;
78#endif
79
80 const OSystem::GraphicsMode *getSupportedStretchModes() const override;
81 int getDefaultStretchMode() const override;
82 bool setStretchMode(int mode) override;
83 int getStretchMode() const override;
84
85#ifdef USE_SCALERS
86 uint getDefaultScaler() const override;
87 uint getDefaultScaleFactor() const override;
88 bool setScaler(uint mode, int factor) override;
89 uint getScaler() const override;
90 uint getScaleFactor() const override;
91#endif
92
93#if !USE_FORCED_GLES
94 bool setShader(const Common::Path &fileNode) override;
95#endif
96
97 void beginGFXTransaction() override;
98 OSystem::TransactionError endGFXTransaction() override;
99
100 int getScreenChangeID() const override;
101
102 void initSize(uint width, uint height, const Graphics::PixelFormat *format) override;
103
104 int16 getWidth() const override;
105 int16 getHeight() const override;
106
107 void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
108 void fillScreen(uint32 col) override;
109 void fillScreen(const Common::Rect &r, uint32 col) override;
110
111 void updateScreen() override;
112 void presentBuffer() override;
113
114 Graphics::Surface *lockScreen() override;
115 void unlockScreen() override;
116
117 void setFocusRectangle(const Common::Rect& rect) override;
118 void clearFocusRectangle() override;
119
120 int16 getOverlayWidth() const override;
121 int16 getOverlayHeight() const override;
122 void showOverlay(bool inGUI) override;
123 void hideOverlay() override;
124
125 Graphics::PixelFormat getOverlayFormat() const override;
126
127 void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
128 void clearOverlay() override;
129 void grabOverlay(Graphics::Surface &surface) const override;
130
131 void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, const Graphics::PixelFormat *format, const byte *mask, frac_t scaleX, frac_t scaleY) override;
132 void setCursorPalette(const byte *colors, uint start, uint num) override;
133
134 void displayMessageOnOSD(const Common::U32String &msg) override;
135 void displayActivityIconOnOSD(const Graphics::Surface *icon) override;
136
137 // PaletteManager interface
138 void setPalette(const byte *colors, uint start, uint num) override;
139 void grabPalette(byte *colors, uint start, uint num) const override;
140
141protected:
142 void renderCursor();
143
147 bool isGLESContext() const { return OpenGLContext.type == kContextGLES || OpenGLContext.type == kContextGLES2; }
148
160 ContextType type,
161 Framebuffer *target,
162 const Graphics::PixelFormat &defaultFormat,
163 const Graphics::PixelFormat &defaultFormatAlpha);
164
172
183 Surface *createSurface(const Graphics::PixelFormat &format, bool wantAlpha = false, bool wantScaler = false, bool wantMask = false);
184
185 //
186 // Transaction support
187 //
188 struct VideoState {
189 VideoState() : valid(false), gameWidth(0), gameHeight(0),
190#ifdef USE_RGB_COLOR
191 gameFormat(),
192#endif
193 aspectRatioCorrection(false), graphicsMode(GFX_OPENGL), flags(0),
194 filtering(true), scalerIndex(0), scaleFactor(1), shader() {
195 }
196
197 bool valid;
198
199 uint gameWidth, gameHeight;
200#ifdef USE_RGB_COLOR
201 Graphics::PixelFormat gameFormat;
202#endif
203 bool aspectRatioCorrection;
204 int graphicsMode;
205 uint flags;
206 bool filtering;
207
208 uint scalerIndex;
209 int scaleFactor;
210
211 Common::Path shader;
212
213 bool operator==(const VideoState &right) {
214 return gameWidth == right.gameWidth && gameHeight == right.gameHeight
215#ifdef USE_RGB_COLOR
216 && gameFormat == right.gameFormat
217#endif
218 && aspectRatioCorrection == right.aspectRatioCorrection
219 && graphicsMode == right.graphicsMode
220 && flags == right.flags
221 && filtering == right.filtering
222 && shader == right.shader;
223 }
224
225 bool operator!=(const VideoState &right) {
226 return !(*this == right);
227 }
228 };
229
234
239
240protected:
241 enum TransactionMode {
242 kTransactionNone = 0,
243 kTransactionActive = 1,
244 kTransactionRollback = 2
245 };
246
247 TransactionMode getTransactionMode() const { return _transactionMode; }
248
249private:
253 TransactionMode _transactionMode;
254
258 int _screenChangeID;
259
263 int _stretchMode;
264
268 Common::Point _shakeOffsetScaled;
269
270protected:
285 virtual bool loadVideoMode(uint requestedWidth, uint requestedHeight, bool resizable, int antialiasing) = 0;
286
287 bool loadShader(const Common::Path &fileName);
288
292 virtual void refreshScreen() = 0;
293
300 bool saveScreenshot(const Common::Path &filename) const;
301
302 // Do not hide the argument-less saveScreenshot from the base class
303 using WindowedGraphicsManager::saveScreenshot;
304
305private:
306 //
307 // OpenGL utilities
308 //
309
313 void initializeGLContext();
314
318 Pipeline *_pipeline;
319
320#if !USE_FORCED_GLES
324 LibRetroPipeline *_libretroPipeline;
325#endif
326
327protected:
333 bool getGLPixelFormat(const Graphics::PixelFormat &pixelFormat, GLenum &glIntFormat, GLenum &glFormat, GLenum &glType) const;
334
335 bool gameNeedsAspectRatioCorrection() const override;
336 int getGameRenderScale() const override;
337 void recalculateDisplayAreas() override;
338 void handleResizeImpl(const int width, const int height) override;
339
340 void updateTextureSettings();
341
342 Pipeline *getPipeline() const { return _pipeline; }
343
348
353
358
363
364#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
368 Renderer3D *_renderer3d;
369#endif
370
374 byte _gamePalette[3 * 256];
375
376 //
377 // Overlay
378 //
379
384
385 //
386 // Cursor
387 //
388
393
398
403
408
413
419
425
431
436
441
446
451
456
461
466
470 byte _cursorPalette[3 * 256];
471
472#ifdef USE_SCALERS
476 const PluginList &_scalerPlugins;
477#endif
478
479#ifdef USE_OSD
480 //
481 // OSD
482 //
483protected:
487 virtual const Graphics::Font *getFontOSD() const;
488
489private:
493 bool _osdMessageChangeRequest;
494
501 Common::U32String _osdMessageNextData;
502
506 void osdMessageUpdateSurface();
507
511 Surface *_osdMessageSurface;
512
516 uint8 _osdMessageAlpha;
517
521 uint32 _osdMessageFadeStartTime;
522
523 enum {
524 kOSDMessageFadeOutDelay = 2 * 1000,
525 kOSDMessageFadeOutDuration = 500,
526 kOSDMessageInitialAlpha = 80
527 };
528
532 Surface *_osdIconSurface;
533
534 enum {
535 kOSDIconTopMargin = 10,
536 kOSDIconRightMargin = 10
537 };
538#endif
539};
540
541} // End of namespace OpenGL
542
543#endif
Definition: list.h:44
Definition: path.h:52
Definition: ustr.h:57
Definition: font.h:83
Definition: framebuffer.h:38
Definition: libretro.h:50
Definition: opengl-graphics.h:60
virtual const Graphics::Font * getFontOSD() const
void notifyContextCreate(ContextType type, Framebuffer *target, const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha)
VideoState _oldState
Definition: opengl-graphics.h:238
bool isGLESContext() const
Definition: opengl-graphics.h:147
Surface * _gameScreen
Definition: opengl-graphics.h:362
Graphics::PixelFormat _defaultFormatAlpha
Definition: opengl-graphics.h:352
Surface * _cursor
Definition: opengl-graphics.h:397
Graphics::PixelFormat _defaultFormat
Definition: opengl-graphics.h:347
Surface * _overlay
Definition: opengl-graphics.h:383
int _cursorHotspotYScaled
Definition: opengl-graphics.h:430
int _cursorHotspotXScaled
Definition: opengl-graphics.h:424
byte _gamePalette[3 *256]
Definition: opengl-graphics.h:374
int _cursorHotspotY
Definition: opengl-graphics.h:412
float _cursorScaleX
Definition: opengl-graphics.h:455
virtual void refreshScreen()=0
Framebuffer * _targetBuffer
Definition: opengl-graphics.h:357
float _cursorHeightScaled
Definition: opengl-graphics.h:440
uint32 _cursorKeyColor
Definition: opengl-graphics.h:445
byte _cursorPalette[3 *256]
Definition: opengl-graphics.h:470
bool getGLPixelFormat(const Graphics::PixelFormat &pixelFormat, GLenum &glIntFormat, GLenum &glFormat, GLenum &glType) const
bool _cursorUseKey
Definition: opengl-graphics.h:450
bool _cursorPaletteEnabled
Definition: opengl-graphics.h:465
int getGameRenderScale() const override
Surface * createSurface(const Graphics::PixelFormat &format, bool wantAlpha=false, bool wantScaler=false, bool wantMask=false)
void setPalette(const byte *colors, uint start, uint num) override
Surface * _cursorMask
Definition: opengl-graphics.h:402
bool gameNeedsAspectRatioCorrection() const override
void grabPalette(byte *colors, uint start, uint num) const override
void recalculateDisplayAreas() override
VideoState _currentState
Definition: opengl-graphics.h:233
virtual bool loadVideoMode(uint requestedWidth, uint requestedHeight, bool resizable, int antialiasing)=0
int _cursorHotspotX
Definition: opengl-graphics.h:407
float _cursorWidthScaled
Definition: opengl-graphics.h:435
void handleResizeImpl(const int width, const int height) override
float _cursorScaleY
Definition: opengl-graphics.h:460
bool saveScreenshot(const Common::Path &filename) const
Definition: pipeline.h:40
Definition: texture.h:43
Definition: windowed.h:52
int32 frac_t
Definition: frac.h:52
Feature
Definition: system.h:415
TransactionError
Definition: system.h:1188
@ kGfxModeNoFlags
Definition: system.h:790
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: system.h:741
Definition: opengl-graphics.h:188