2010-07-05 03:21:48 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BACKENDS_GRAPHICS_OPENGL_H
|
|
|
|
#define BACKENDS_GRAPHICS_OPENGL_H
|
|
|
|
|
2010-07-10 22:47:29 +00:00
|
|
|
#include "backends/graphics/opengl/gltexture.h"
|
2010-07-05 03:21:48 +00:00
|
|
|
#include "backends/graphics/graphics.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/array.h"
|
2011-08-08 21:56:54 +00:00
|
|
|
#include "common/rect.h"
|
2011-08-07 11:33:32 +00:00
|
|
|
#include "graphics/font.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "graphics/pixelformat.h"
|
2010-07-05 03:21:48 +00:00
|
|
|
|
2010-07-26 06:03:55 +00:00
|
|
|
// Uncomment this to enable the 'on screen display' code.
|
|
|
|
#define USE_OSD 1
|
|
|
|
|
2010-07-13 05:38:10 +00:00
|
|
|
namespace OpenGL {
|
2010-07-31 22:54:10 +00:00
|
|
|
// The OpenGL GFX modes. They have to be inside the OpenGL namespace so they
|
|
|
|
// do not clash with the SDL GFX modes.
|
2010-07-05 03:21:48 +00:00
|
|
|
enum {
|
2010-07-13 05:38:10 +00:00
|
|
|
GFX_NORMAL = 0,
|
2010-09-03 03:23:46 +00:00
|
|
|
GFX_CONSERVE = 1,
|
2011-03-20 16:29:08 +00:00
|
|
|
GFX_ORIGINAL = 2
|
2010-07-05 03:21:48 +00:00
|
|
|
};
|
|
|
|
|
2010-07-13 05:38:10 +00:00
|
|
|
}
|
|
|
|
|
2010-07-05 03:21:48 +00:00
|
|
|
/**
|
2010-12-03 19:16:23 +00:00
|
|
|
* OpenGL graphics manager. This is an abstract class, it does not do the
|
2010-07-31 22:54:10 +00:00
|
|
|
* window and OpenGL context initialization.
|
|
|
|
* Derived classes should at least override internUpdateScreen for doing
|
|
|
|
* the buffers swap, and implement loadGFXMode for handling the window/context if
|
|
|
|
* needed. If USE_RGB_COLOR is enabled, getSupportedFormats must be implemented.
|
2010-07-05 03:21:48 +00:00
|
|
|
*/
|
2011-08-08 21:56:54 +00:00
|
|
|
class OpenGLGraphicsManager : public GraphicsManager {
|
2010-07-05 03:21:48 +00:00
|
|
|
public:
|
|
|
|
OpenGLGraphicsManager();
|
|
|
|
virtual ~OpenGLGraphicsManager();
|
|
|
|
|
|
|
|
virtual bool hasFeature(OSystem::Feature f);
|
|
|
|
virtual void setFeatureState(OSystem::Feature f, bool enable);
|
|
|
|
virtual bool getFeatureState(OSystem::Feature f);
|
|
|
|
|
2010-07-30 03:31:05 +00:00
|
|
|
static const OSystem::GraphicsMode *supportedGraphicsModes();
|
2010-07-05 03:21:48 +00:00
|
|
|
virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
|
|
|
|
virtual int getDefaultGraphicsMode() const;
|
|
|
|
virtual bool setGraphicsMode(int mode);
|
|
|
|
virtual int getGraphicsMode() const;
|
2010-07-30 03:06:57 +00:00
|
|
|
virtual void resetGraphicsScale();
|
2010-07-05 03:21:48 +00:00
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
virtual Graphics::PixelFormat getScreenFormat() const;
|
2010-07-13 04:31:15 +00:00
|
|
|
virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const = 0;
|
2010-07-05 03:21:48 +00:00
|
|
|
#endif
|
|
|
|
virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL);
|
|
|
|
virtual int getScreenChangeID() const;
|
|
|
|
|
|
|
|
virtual void beginGFXTransaction();
|
|
|
|
virtual OSystem::TransactionError endGFXTransaction();
|
|
|
|
|
|
|
|
virtual int16 getHeight();
|
|
|
|
virtual int16 getWidth();
|
2011-02-07 17:52:38 +00:00
|
|
|
protected:
|
|
|
|
// PaletteManager API
|
2010-07-05 03:21:48 +00:00
|
|
|
virtual void setPalette(const byte *colors, uint start, uint num);
|
|
|
|
virtual void grabPalette(byte *colors, uint start, uint num);
|
2011-02-07 17:52:38 +00:00
|
|
|
|
|
|
|
public:
|
2012-06-16 00:18:01 +00:00
|
|
|
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
|
2010-07-05 03:21:48 +00:00
|
|
|
virtual Graphics::Surface *lockScreen();
|
|
|
|
virtual void unlockScreen();
|
|
|
|
virtual void fillScreen(uint32 col);
|
|
|
|
virtual void updateScreen();
|
|
|
|
virtual void setShakePos(int shakeOffset);
|
2010-12-03 19:16:23 +00:00
|
|
|
virtual void setFocusRectangle(const Common::Rect &rect);
|
2010-07-05 03:21:48 +00:00
|
|
|
virtual void clearFocusRectangle();
|
|
|
|
|
|
|
|
virtual void showOverlay();
|
|
|
|
virtual void hideOverlay();
|
|
|
|
virtual Graphics::PixelFormat getOverlayFormat() const;
|
|
|
|
virtual void clearOverlay();
|
2012-06-16 02:17:14 +00:00
|
|
|
virtual void grabOverlay(void *buf, int pitch);
|
|
|
|
virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
|
2010-07-05 03:21:48 +00:00
|
|
|
virtual int16 getOverlayHeight();
|
|
|
|
virtual int16 getOverlayWidth();
|
|
|
|
|
|
|
|
virtual bool showMouse(bool visible);
|
|
|
|
virtual void warpMouse(int x, int y);
|
2012-06-16 01:10:43 +00:00
|
|
|
virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL);
|
2010-07-05 03:21:48 +00:00
|
|
|
virtual void setCursorPalette(const byte *colors, uint start, uint num);
|
|
|
|
|
|
|
|
virtual void displayMessageOnOSD(const char *msg);
|
|
|
|
protected:
|
2010-07-31 22:54:10 +00:00
|
|
|
/**
|
|
|
|
* Setup OpenGL settings
|
|
|
|
*/
|
2010-07-19 05:36:10 +00:00
|
|
|
virtual void initGL();
|
2010-07-31 22:54:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and refreshs OpenGL textures.
|
|
|
|
*/
|
2010-07-22 15:36:50 +00:00
|
|
|
virtual void loadTextures();
|
2010-07-19 05:36:10 +00:00
|
|
|
|
2010-07-18 03:25:58 +00:00
|
|
|
//
|
|
|
|
// GFX and video
|
|
|
|
//
|
2010-07-11 04:32:24 +00:00
|
|
|
enum {
|
|
|
|
kTransactionNone = 0,
|
|
|
|
kTransactionActive = 1,
|
|
|
|
kTransactionRollback = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TransactionDetails {
|
|
|
|
bool sizeChanged;
|
2010-08-13 04:48:58 +00:00
|
|
|
bool needRefresh;
|
2010-07-11 04:32:24 +00:00
|
|
|
bool needUpdatescreen;
|
2010-07-22 15:36:50 +00:00
|
|
|
bool filterChanged;
|
2010-07-11 04:32:24 +00:00
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
bool formatChanged;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
TransactionDetails _transactionDetails;
|
|
|
|
int _transactionMode;
|
|
|
|
|
|
|
|
struct VideoState {
|
|
|
|
bool setup;
|
|
|
|
|
|
|
|
bool fullscreen;
|
|
|
|
|
|
|
|
int mode;
|
|
|
|
int scaleFactor;
|
2010-07-22 15:36:50 +00:00
|
|
|
bool antialiasing;
|
2011-03-20 16:29:08 +00:00
|
|
|
bool aspectRatioCorrection;
|
2010-07-11 04:32:24 +00:00
|
|
|
|
|
|
|
int screenWidth, screenHeight;
|
|
|
|
int overlayWidth, overlayHeight;
|
|
|
|
int hardwareWidth, hardwareHeight;
|
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
Graphics::PixelFormat format;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
VideoState _videoMode, _oldVideoMode;
|
2010-07-12 06:00:19 +00:00
|
|
|
|
2010-07-31 22:54:10 +00:00
|
|
|
/**
|
|
|
|
* Sets the OpenGL texture format for the given pixel format. If format is not support will raise an error.
|
|
|
|
*/
|
|
|
|
virtual void getGLPixelFormat(Graphics::PixelFormat pixelFormat, byte &bpp, GLenum &intFormat, GLenum &glFormat, GLenum &type);
|
2010-07-18 03:25:58 +00:00
|
|
|
|
|
|
|
virtual void internUpdateScreen();
|
|
|
|
virtual bool loadGFXMode();
|
|
|
|
virtual void unloadGFXMode();
|
|
|
|
|
2011-03-17 19:27:00 +00:00
|
|
|
/**
|
|
|
|
* Setup the fullscreen mode state.
|
|
|
|
*/
|
|
|
|
void setFullscreenMode(bool enable);
|
|
|
|
|
2011-03-17 19:29:48 +00:00
|
|
|
/**
|
|
|
|
* Query the fullscreen state.
|
|
|
|
*/
|
|
|
|
inline bool getFullscreenMode() const { return _videoMode.fullscreen; }
|
|
|
|
|
2011-03-17 18:58:47 +00:00
|
|
|
/**
|
|
|
|
* Set the scale factor.
|
2011-06-19 22:59:48 +00:00
|
|
|
*
|
2011-03-17 18:58:47 +00:00
|
|
|
* This can only be used in a GFX transaction.
|
|
|
|
*
|
|
|
|
* @param newScale New scale factor.
|
|
|
|
*/
|
|
|
|
void setScale(int newScale);
|
2010-07-27 07:30:56 +00:00
|
|
|
|
2011-03-17 18:47:18 +00:00
|
|
|
/**
|
|
|
|
* Query the scale factor.
|
|
|
|
*/
|
|
|
|
inline int getScale() const { return _videoMode.scaleFactor; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the antialiasing state of the current video mode.
|
|
|
|
*
|
|
|
|
* This can only be used in a GFX transaction.
|
|
|
|
*/
|
|
|
|
void toggleAntialiasing();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query the antialiasing state.
|
|
|
|
*/
|
|
|
|
inline bool getAntialiasingState() const { return _videoMode.antialiasing; }
|
|
|
|
|
2010-09-03 03:23:46 +00:00
|
|
|
// Drawing coordinates for the current display mode and scale
|
|
|
|
int _displayX;
|
|
|
|
int _displayY;
|
|
|
|
int _displayWidth;
|
|
|
|
int _displayHeight;
|
2010-07-27 07:30:56 +00:00
|
|
|
|
2010-09-03 03:23:46 +00:00
|
|
|
virtual const char *getCurrentModeName();
|
2010-07-31 22:54:10 +00:00
|
|
|
|
2010-09-03 03:23:46 +00:00
|
|
|
virtual void calculateDisplaySize(int &width, int &height);
|
|
|
|
virtual void refreshDisplaySize();
|
2010-08-01 02:26:20 +00:00
|
|
|
|
2011-08-12 02:06:54 +00:00
|
|
|
uint getAspectRatio() const;
|
2010-07-19 05:36:10 +00:00
|
|
|
|
2012-02-15 01:09:46 +00:00
|
|
|
void setFormatIsBGR(bool isBGR) { _formatBGR = isBGR; }
|
2010-07-26 06:52:58 +00:00
|
|
|
bool _formatBGR;
|
|
|
|
|
2010-07-18 03:25:58 +00:00
|
|
|
//
|
|
|
|
// Game screen
|
|
|
|
//
|
2010-12-03 19:16:23 +00:00
|
|
|
GLTexture *_gameTexture;
|
2010-07-24 05:54:51 +00:00
|
|
|
Graphics::Surface _screenData;
|
2010-07-18 03:25:58 +00:00
|
|
|
int _screenChangeCount;
|
2010-07-24 05:54:51 +00:00
|
|
|
bool _screenNeedsRedraw;
|
|
|
|
Common::Rect _screenDirtyRect;
|
2010-07-18 03:25:58 +00:00
|
|
|
|
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
Graphics::PixelFormat _screenFormat;
|
|
|
|
#endif
|
|
|
|
byte *_gamePalette;
|
|
|
|
|
2010-07-24 05:54:51 +00:00
|
|
|
virtual void refreshGameScreen();
|
|
|
|
|
2010-07-18 03:25:58 +00:00
|
|
|
// Shake mode
|
2010-07-27 03:16:10 +00:00
|
|
|
int _shakePos;
|
2010-07-18 03:25:58 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Overlay
|
|
|
|
//
|
2010-12-03 19:16:23 +00:00
|
|
|
GLTexture *_overlayTexture;
|
2010-07-24 05:54:51 +00:00
|
|
|
Graphics::Surface _overlayData;
|
2010-07-18 03:25:58 +00:00
|
|
|
Graphics::PixelFormat _overlayFormat;
|
2010-07-24 05:54:51 +00:00
|
|
|
bool _overlayVisible;
|
|
|
|
bool _overlayNeedsRedraw;
|
|
|
|
Common::Rect _overlayDirtyRect;
|
2011-03-17 18:47:18 +00:00
|
|
|
|
2010-07-24 05:54:51 +00:00
|
|
|
virtual void refreshOverlay();
|
2010-07-12 06:00:19 +00:00
|
|
|
|
2010-07-18 03:25:58 +00:00
|
|
|
//
|
|
|
|
// Mouse
|
|
|
|
//
|
2010-07-12 06:00:19 +00:00
|
|
|
struct MousePos {
|
2011-02-19 19:24:54 +00:00
|
|
|
// The mouse position in hardware screen coordinates.
|
2010-07-12 06:00:19 +00:00
|
|
|
int16 x, y;
|
|
|
|
|
|
|
|
// The size and hotspot of the original cursor image.
|
|
|
|
int16 w, h;
|
|
|
|
int16 hotX, hotY;
|
|
|
|
|
2010-07-31 22:54:10 +00:00
|
|
|
// The size and hotspot of the scaled cursor, in real coordinates.
|
2010-07-26 04:17:37 +00:00
|
|
|
int16 rW, rH;
|
|
|
|
int16 rHotX, rHotY;
|
2010-07-12 06:00:19 +00:00
|
|
|
|
2010-07-31 22:54:10 +00:00
|
|
|
// The size and hotspot of the scaled cursor, in game coordinates.
|
2010-07-26 04:17:37 +00:00
|
|
|
int16 vW, vH;
|
|
|
|
int16 vHotX, vHotY;
|
2010-07-12 06:00:19 +00:00
|
|
|
|
2010-07-26 04:17:37 +00:00
|
|
|
MousePos() : x(0), y(0), w(0), h(0), hotX(0), hotY(0),
|
2010-07-26 06:58:33 +00:00
|
|
|
rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0),
|
|
|
|
vHotX(0), vHotY(0) {}
|
2010-07-12 06:00:19 +00:00
|
|
|
};
|
|
|
|
|
2010-12-03 19:16:23 +00:00
|
|
|
GLTexture *_cursorTexture;
|
2010-07-24 05:54:51 +00:00
|
|
|
Graphics::Surface _cursorData;
|
2010-07-18 03:25:58 +00:00
|
|
|
Graphics::PixelFormat _cursorFormat;
|
|
|
|
byte *_cursorPalette;
|
2010-07-16 23:50:46 +00:00
|
|
|
bool _cursorPaletteDisabled;
|
2010-07-18 03:25:58 +00:00
|
|
|
MousePos _cursorState;
|
|
|
|
bool _cursorVisible;
|
|
|
|
uint32 _cursorKeyColor;
|
2012-06-03 00:02:57 +00:00
|
|
|
bool _cursorDontScale;
|
2010-07-18 03:25:58 +00:00
|
|
|
bool _cursorNeedsRedraw;
|
|
|
|
|
2012-02-15 01:09:46 +00:00
|
|
|
/**
|
|
|
|
* Set up the mouse position for graphics output.
|
|
|
|
*
|
|
|
|
* @param x X coordinate in native coordinates.
|
|
|
|
* @param y Y coordinate in native coordinates.
|
|
|
|
*/
|
|
|
|
void setMousePosition(int x, int y) { _cursorState.x = x; _cursorState.y = y; }
|
|
|
|
|
2010-07-18 03:25:58 +00:00
|
|
|
virtual void refreshCursor();
|
2010-07-26 04:17:37 +00:00
|
|
|
virtual void refreshCursorScale();
|
2011-03-17 16:37:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up the mouse position for the (event) system.
|
|
|
|
*
|
|
|
|
* @param x X coordinate in native coordinates.
|
|
|
|
* @param y Y coordinate in native coordinates.
|
|
|
|
*/
|
|
|
|
virtual void setInternalMousePosition(int x, int y) = 0;
|
|
|
|
|
2011-02-19 19:40:45 +00:00
|
|
|
/**
|
|
|
|
* Adjusts hardware screen coordinates to either overlay or game screen
|
|
|
|
* coordinates depending on whether the overlay is visible or not.
|
|
|
|
*
|
|
|
|
* @param x X coordinate of the mouse position.
|
|
|
|
* @param y Y coordinate of the mouse position.
|
|
|
|
*/
|
|
|
|
virtual void adjustMousePosition(int16 &x, int16 &y);
|
2010-07-19 05:36:10 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Misc
|
|
|
|
//
|
|
|
|
virtual bool saveScreenshot(const char *filename);
|
2010-07-26 06:03:55 +00:00
|
|
|
|
|
|
|
#ifdef USE_OSD
|
2012-02-15 00:56:59 +00:00
|
|
|
/**
|
|
|
|
* Returns the font used for on screen display
|
|
|
|
*/
|
|
|
|
virtual const Graphics::Font *getFontOSD();
|
2011-08-07 11:33:32 +00:00
|
|
|
|
2011-03-17 17:31:35 +00:00
|
|
|
/**
|
|
|
|
* Update the OSD texture / surface.
|
|
|
|
*/
|
|
|
|
void updateOSD();
|
|
|
|
|
2012-02-15 01:09:46 +00:00
|
|
|
/**
|
|
|
|
* The OSD contents.
|
|
|
|
*/
|
|
|
|
Common::Array<Common::String> _osdLines;
|
|
|
|
|
2010-07-26 06:03:55 +00:00
|
|
|
GLTexture *_osdTexture;
|
|
|
|
Graphics::Surface _osdSurface;
|
|
|
|
uint8 _osdAlpha;
|
2011-06-19 22:59:48 +00:00
|
|
|
uint32 _osdFadeStartTime;
|
2010-12-08 01:53:20 +00:00
|
|
|
bool _requireOSDUpdate;
|
2010-07-26 06:03:55 +00:00
|
|
|
enum {
|
|
|
|
kOSDFadeOutDelay = 2 * 1000,
|
|
|
|
kOSDFadeOutDuration = 500,
|
|
|
|
kOSDInitialAlpha = 80
|
|
|
|
};
|
|
|
|
#endif
|
2010-07-05 03:21:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|