ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
openglsdl-graphics3d.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_GRAPHICS3D_OPENGLSDL_GRAPHICS3D_H
23 #define BACKENDS_GRAPHICS3D_OPENGLSDL_GRAPHICS3D_H
24 
25 #include "backends/graphics/sdl/sdl-graphics.h"
26 
27 #include "math/rect2d.h"
28 
29 #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
30 
31 #include "graphics/opengl/context.h"
32 
33 namespace OpenGL {
34  class FrameBuffer;
35  class SurfaceRenderer;
36  class TiledSurface;
37 }
38 
44 class OpenGLSdlGraphics3dManager : public SdlGraphicsManager {
45 public:
46  OpenGLSdlGraphics3dManager(SdlEventSource *eventSource, SdlWindow *window, bool supportsFrameBuffer);
47  virtual ~OpenGLSdlGraphics3dManager();
48 
49  // GraphicsManager API - Features
50  bool hasFeature(OSystem::Feature f) const override;
51  bool getFeatureState(OSystem::Feature f) const override;
52  void setFeatureState(OSystem::Feature f, bool enable) override;
53 
54  const OSystem::GraphicsMode *getSupportedGraphicsModes() const override;
55  int getDefaultGraphicsMode() const override;
56  bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override;
57  int getGraphicsMode() const override;
58 
59  const OSystem::GraphicsMode *getSupportedStretchModes() const override;
60  int getDefaultStretchMode() const override;
61  bool setStretchMode(int mode) override;
62  int getStretchMode() const override;
63 
64  void beginGFXTransaction() override;
65  OSystem::TransactionError endGFXTransaction() override;
66 
67  // GraphicsManager API - Graphics mode
68 #ifdef USE_RGB_COLOR
69  Graphics::PixelFormat getScreenFormat() const override { return _overlayFormat; }
70  Common::List<Graphics::PixelFormat> getSupportedFormats() const override {
71  Common::List<Graphics::PixelFormat> supportedFormats;
72  return supportedFormats;
73  }
74 #endif
75  int getScreenChangeID() const override { return _screenChangeCount; }
76  void initSize(uint w, uint h, const Graphics::PixelFormat *format) override;
77  int16 getHeight() const override;
78  int16 getWidth() const override;
79 
80  // GraphicsManager API - Draw methods
81  void updateScreen() override;
82  // Following methods are not used by 3D graphics managers
83  void setPalette(const byte *colors, uint start, uint num) override {}
84  void grabPalette(byte *colors, uint start, uint num) const override {}
85  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override {}
86  Graphics::Surface *lockScreen() override { return nullptr; }
87  void unlockScreen() override {}
88  void fillScreen(uint32 col) override {}
89  void fillScreen(const Common::Rect &r, uint32 col) override {}
90  void setShakePos(int shakeXOffset, int shakeYOffset) override {};
91  void setFocusRectangle(const Common::Rect& rect) override {}
92  void clearFocusRectangle() override {}
93 
94  // GraphicsManager API - Overlay
95  void showOverlay(bool inGUI) override;
96  void hideOverlay() override;
97  Graphics::PixelFormat getOverlayFormat() const override { return _overlayFormat; }
98  void clearOverlay() override;
99  void grabOverlay(Graphics::Surface &surface) const override;
100  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
101  int16 getOverlayWidth() const override;
102  int16 getOverlayHeight() const override;
103 
104  // GraphicsManager API - Mouse
105  bool showMouse(bool visible) override;
106  void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL, const byte *mask = NULL) override {}
107  void setCursorPalette(const byte *colors, uint start, uint num) override {}
108 
109  // SdlGraphicsManager API
110  void notifyVideoExpose() override {};
111  void notifyResize(const int width, const int height) override;
112 
113  bool gameNeedsAspectRatioCorrection() const override;
114 
115  void showSystemMouseCursor(bool visible) override;
116 
117 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
118  void *getImGuiTexture(const Graphics::Surface &image, const byte *palette, int palCount) override;
119  void freeImGuiTexture(void *texture) override;
120 #endif
121 
122 protected:
123 #if SDL_VERSION_ATLEAST(2, 0, 0)
124  int _glContextProfileMask, _glContextMajor, _glContextMinor;
125  SDL_GLContext _glContext;
126  void deinitializeRenderer();
127 #endif
128 
129  OpenGL::ContextType _glContextType;
130 
131  bool _supportsFrameBuffer;
132 
133  struct OpenGLPixelFormat {
134  uint bytesPerPixel;
135  uint redSize;
136  uint blueSize;
137  uint greenSize;
138  uint alphaSize;
139  int multisampleSamples;
140 
141  OpenGLPixelFormat(uint screenBytesPerPixel, uint red, uint blue, uint green, uint alpha, int samples);
142  };
143 
150  bool createOrUpdateGLContext(uint gameWidth, uint gameHeight, uint effectiveWidth, uint effectiveHeight,
151  bool renderToFramebuffer, bool engineSupportsArbitraryResolutions);
152 
153  void createOrUpdateScreen();
154  void setupScreen();
155 
156  void handleResizeImpl(const int width, const int height) override;
157 
158 #ifdef EMSCRIPTEN
159 
168  bool _queuedScreenshot = false;
169  void saveScreenshot() override;
170 #endif
171 
172  bool saveScreenshot(const Common::Path &filename) const override;
173 
174  uint _engineRequestedWidth, _engineRequestedHeight;
175 
176  int _screenChangeCount;
177  int _antialiasing;
178  int _stretchMode;
179  bool _vsync;
180  bool _fullscreen;
181  bool _lockAspectRatio;
182 
183  OpenGL::TiledSurface *_overlayScreen;
184  OpenGL::TiledSurface *_overlayBackground;
185  OpenGL::SurfaceRenderer *_surfaceRenderer;
186 
187  Graphics::PixelFormat _overlayFormat;
188 
189  void initializeOpenGLContext() const;
190  void drawOverlay();
191  void closeOverlay();
192 
193  OpenGL::FrameBuffer *_frameBuffer;
194  OpenGL::FrameBuffer *createFramebuffer(uint width, uint height);
195  bool shouldRenderToFramebuffer() const;
196 
197 protected:
198 
199  enum TransactionMode {
200  kTransactionNone = 0,
201  kTransactionActive = 1,
202  kTransactionRollback = 2
203  };
204 
208  TransactionMode _transactionMode;
209 };
210 
211 #endif // defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
212 
213 #endif
Definition: surface.h:67
Definition: system.h:779
Definition: sdl-events.h:40
Definition: sdl-graphics.h:38
Definition: pixelformat.h:138
Definition: system.h:730
Feature
Definition: system.h:403
Definition: list.h:44
Definition: rect.h:144
Definition: path.h:52
TransactionError
Definition: system.h:1155
Definition: renderbuffer.h:27
Definition: surfacerenderer.h:37
Definition: tiledsurface.h:40
Definition: sdl-window.h:30