ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

openglsdl-graphics.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef BACKENDS_GRAPHICS_OPENGLSDL_GRAPHICS_H
00024 #define BACKENDS_GRAPHICS_OPENGLSDL_GRAPHICS_H
00025 
00026 #include "backends/graphics/sdl/resvm-sdl-graphics.h"
00027 
00028 namespace OpenGL {
00029     class FrameBuffer;
00030     class SurfaceRenderer;
00031     class Texture;
00032     class TiledSurface;
00033 }
00034 
00040 class OpenGLSdlGraphicsManager : public ResVmSdlGraphicsManager {
00041 public:
00045     struct Capabilities {
00049         bool openGLFrameBuffer;
00050 
00052         Common::Array<uint> openGLAntiAliasLevels;
00053 
00054         Capabilities() : openGLFrameBuffer(false) {}
00055     };
00056 
00057     OpenGLSdlGraphicsManager(SdlEventSource *eventSource, SdlWindow *window, const Capabilities &capabilities);
00058     virtual ~OpenGLSdlGraphicsManager();
00059 
00060     // GraphicsManager API - Features
00061     virtual bool hasFeature(OSystem::Feature f) const override;
00062     virtual bool getFeatureState(OSystem::Feature f) const override;
00063     virtual void setFeatureState(OSystem::Feature f, bool enable) override;
00064 
00065     // GraphicsManager API - Graphics mode
00066 #ifdef USE_RGB_COLOR
00067     virtual Graphics::PixelFormat getScreenFormat() const override { return _screenFormat; }
00068 #endif
00069     virtual int getScreenChangeID() const override { return _screenChangeCount; }
00070     virtual void setupScreen(uint gameWidth, uint gameHeight, bool fullscreen, bool accel3d) override;
00071     virtual Graphics::PixelBuffer getScreenPixelBuffer() override;
00072     virtual int16 getHeight() const override;
00073     virtual int16 getWidth() const override;
00074 
00075     // GraphicsManager API - Draw methods
00076     virtual void updateScreen();
00077 
00078     // GraphicsManager API - Overlay
00079     virtual void showOverlay() override;
00080     virtual void hideOverlay() override;
00081     virtual Graphics::PixelFormat getOverlayFormat() const override { return _overlayFormat; }
00082     virtual void clearOverlay() override;
00083     virtual void grabOverlay(void *buf, int pitch) const override;
00084     virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
00085     int16 getOverlayWidth() const override;
00086     int16 getOverlayHeight() const override;
00087 
00088     /* Render the passed Surfaces besides the game texture.
00089      * This is used for widescreen support in the Grim engine.
00090      * Note: we must copy the Surfaces, as they are free()d after this call.
00091      */
00092     virtual void suggestSideTextures(Graphics::Surface *left, Graphics::Surface *right) override;
00093 
00094     // GraphicsManager API - Mouse
00095     virtual void warpMouse(int x, int y) override;
00096 
00097     // SdlGraphicsManager API
00098     virtual void transformMouseCoordinates(Common::Point &point) override;
00099 
00100     void notifyResize(const int width, const int height) override;
00101 
00102 protected:
00103 #if SDL_VERSION_ATLEAST(2, 0, 0)
00104     SDL_GLContext _glContext;
00105     void deinitializeRenderer();
00106 #endif
00107 
00108     const Capabilities &_capabilities;
00109 
00110     Math::Rect2d _gameRect;
00111 
00112     struct OpenGLPixelFormat {
00113         uint bytesPerPixel;
00114         uint redSize;
00115         uint blueSize;
00116         uint greenSize;
00117         uint alphaSize;
00118         int multisampleSamples;
00119 
00120         OpenGLPixelFormat(uint screenBytesPerPixel, uint red, uint blue, uint green, uint alpha, int samples);
00121     };
00122 
00129     bool createOrUpdateGLContext(uint gameWidth, uint gameHeight, uint effectiveWidth, uint effectiveHeight,
00130                                  bool renderToFramebuffer, bool engineSupportsArbitraryResolutions);
00131 
00132     void createOrUpdateScreen();
00133 
00135     Math::Rect2d computeGameRect(bool renderToFrameBuffer, uint gameWidth, uint gameHeight,
00136                                  uint screenWidth, uint screenHeight);
00137 
00138     // ResVmSdlGraphicsManager API
00139     virtual bool saveScreenshot(const Common::String &filename) const override;
00140 
00141     virtual int getGraphicsModeScale(int mode) const override { return 1; }
00142 
00143     uint _engineRequestedWidth, _engineRequestedHeight;
00144 
00145     int _screenChangeCount;
00146     int _antialiasing;
00147     bool _vsync;
00148     bool _fullscreen;
00149     bool _lockAspectRatio;
00150     bool _overlayVisible;
00151 
00152     OpenGL::TiledSurface *_overlayScreen;
00153     OpenGL::TiledSurface *_overlayBackground;
00154     OpenGL::Texture *_sideTextures[2];
00155     OpenGL::SurfaceRenderer *_surfaceRenderer;
00156 
00157     Graphics::PixelFormat _overlayFormat;
00158 #ifdef USE_RGB_COLOR
00159     Graphics::PixelFormat _screenFormat;
00160 #endif
00161 
00162     void initializeOpenGLContext() const;
00163     void drawOverlay();
00164     void drawSideTextures();
00165     void closeOverlay();
00166 
00167     OpenGL::FrameBuffer *_frameBuffer;
00168     OpenGL::FrameBuffer *createFramebuffer(uint width, uint height);
00169     bool shouldRenderToFramebuffer() const;
00170 
00171     bool isVSyncEnabled() const;
00172 };
00173 
00174 #endif


Generated on Sat May 23 2020 05:00:28 for ResidualVM by doxygen 1.7.1
curved edge   curved edge