aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/openglsdl
diff options
context:
space:
mode:
Diffstat (limited to 'backends/graphics/openglsdl')
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp188
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.h71
2 files changed, 259 insertions, 0 deletions
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
new file mode 100644
index 0000000000..b12c3af5cd
--- /dev/null
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -0,0 +1,188 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "backends/graphics/openglsdl/openglsdl-graphics.h"
+
+OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager()
+ :
+ _hwscreen(0) {
+
+}
+
+OpenGLSdlGraphicsManager::~OpenGLSdlGraphicsManager() {
+
+}
+
+void OpenGLSdlGraphicsManager::init() {
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
+ error("Could not initialize SDL: %s", SDL_GetError());
+ }
+
+ SDL_ShowCursor(SDL_DISABLE);
+
+ OpenGLGraphicsManager::init();
+}
+
+#ifdef USE_RGB_COLOR
+
+const Graphics::PixelFormat RGBList[] = {
+#if defined(ENABLE_32BIT)
+ Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), // RGBA8888
+ Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0), // RGB888
+#endif
+ Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), // RGB565
+ Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555
+ Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0), // RGBA4444
+};
+
+Common::List<Graphics::PixelFormat> OpenGLSdlGraphicsManager::getSupportedFormats() const {
+ static Common::List<Graphics::PixelFormat> list;
+ static bool inited = false;
+
+ if (inited)
+ return list;
+
+ int listLength = ARRAYSIZE(RGBList);
+
+ Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8();
+ if (_hwscreen) {
+ // Get our currently set hardware format
+ format = Graphics::PixelFormat(_hwscreen->format->BytesPerPixel,
+ 8 - _hwscreen->format->Rloss, 8 - _hwscreen->format->Gloss,
+ 8 - _hwscreen->format->Bloss, 8 - _hwscreen->format->Aloss,
+ _hwscreen->format->Rshift, _hwscreen->format->Gshift,
+ _hwscreen->format->Bshift, _hwscreen->format->Ashift);
+
+ // Workaround to MacOSX SDL not providing an accurate Aloss value.
+ if (_hwscreen->format->Amask == 0)
+ format.aLoss = 8;
+
+ // Push it first, as the prefered format.
+ for (int i = 0; i < listLength; i++) {
+ if (RGBList[i] == format) {
+ list.push_back(format);
+ break;
+ }
+ }
+
+ // Mark that we don't need to do this any more.
+ inited = true;
+ }
+
+ for (int i = 0; i < listLength; i++) {
+ if (inited && (RGBList[i].bytesPerPixel > format.bytesPerPixel))
+ continue;
+ if (RGBList[i] != format)
+ list.push_back(RGBList[i]);
+ }
+ //list.push_back(Graphics::PixelFormat::createFormatCLUT8());
+ return list;
+}
+
+#endif
+
+void OpenGLSdlGraphicsManager::warpMouse(int x, int y) {
+ if (_mouseCurState.x != x || _mouseCurState.y != y) {
+ int y1 = y;
+
+ /*if (_videoMode.aspectRatioCorrection && !_overlayVisible)
+ y1 = real2Aspect(y);*/
+
+ if (!_overlayVisible)
+ SDL_WarpMouse(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
+ else
+ SDL_WarpMouse(x, y1);
+
+ setMousePos(x, y);
+ }
+}
+
+
+void OpenGLSdlGraphicsManager::forceFullRedraw() {
+
+}
+
+bool OpenGLSdlGraphicsManager::handleScalerHotkeys(const SDL_KeyboardEvent &key) {
+ return false;
+}
+
+bool OpenGLSdlGraphicsManager::isScalerHotkey(const Common::Event &event) {
+ return false;
+}
+
+void OpenGLSdlGraphicsManager::adjustMouseEvent(Common::Event &event) {
+
+}
+
+void OpenGLSdlGraphicsManager::toggleFullScreen() {
+
+}
+
+bool OpenGLSdlGraphicsManager::saveScreenshot(const char *filename) {
+ return false;
+}
+
+//
+// Intern
+//
+
+bool OpenGLSdlGraphicsManager::loadGFXMode() {
+ _videoMode.overlayWidth = _videoMode.screenWidth * _videoMode.scaleFactor;
+ _videoMode.overlayHeight = _videoMode.screenHeight * _videoMode.scaleFactor;
+ _videoMode.hardwareWidth = _videoMode.screenWidth * _videoMode.scaleFactor;
+ _videoMode.hardwareHeight = _videoMode.screenHeight * _videoMode.scaleFactor;
+
+ _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32,
+ _videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_OPENGL) : SDL_OPENGL
+ );
+ if (_hwscreen == NULL) {
+ // DON'T use error(), as this tries to bring up the debug
+ // console, which WON'T WORK now that _hwscreen is hosed.
+
+ if (!_oldVideoMode.setup) {
+ warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError());
+ g_system->quit();
+ } else {
+ return false;
+ }
+ }
+
+ return OpenGLGraphicsManager::loadGFXMode();
+}
+
+void OpenGLSdlGraphicsManager::unloadGFXMode() {
+ if (_hwscreen) {
+ SDL_FreeSurface(_hwscreen);
+ _hwscreen = NULL;
+ }
+}
+
+bool OpenGLSdlGraphicsManager::hotswapGFXMode() {
+ return false;
+}
+
+void OpenGLSdlGraphicsManager::internUpdateScreen() {
+
+}
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h
new file mode 100644
index 0000000000..56aae27ab7
--- /dev/null
+++ b/backends/graphics/openglsdl/openglsdl-graphics.h
@@ -0,0 +1,71 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef BACKENDS_GRAPHICS_OPENGLSDL_H
+#define BACKENDS_GRAPHICS_OPENGLSDL_H
+
+#include <SDL.h>
+#if defined(ARRAYSIZE) && !defined(_WINDOWS_)
+#undef ARRAYSIZE
+#endif
+#include <SDL_opengl.h>
+
+#include "backends/graphics/opengl/opengl-graphics.h"
+
+/**
+ * SDL OpenGL graphics manager
+ */
+class OpenGLSdlGraphicsManager : public OpenGLGraphicsManager {
+public:
+ OpenGLSdlGraphicsManager();
+ virtual ~OpenGLSdlGraphicsManager();
+
+ virtual void init();
+
+#ifdef USE_RGB_COLOR
+ virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
+#endif
+
+ virtual void warpMouse(int x, int y);
+
+ virtual void forceFullRedraw();
+ virtual bool handleScalerHotkeys(const SDL_KeyboardEvent &key);
+ virtual bool isScalerHotkey(const Common::Event &event);
+ virtual void adjustMouseEvent(Common::Event &event);
+ virtual void toggleFullScreen();
+ virtual bool saveScreenshot(const char *filename);
+
+protected:
+ virtual void internUpdateScreen();
+
+ virtual bool loadGFXMode();
+ virtual void unloadGFXMode();
+ virtual bool hotswapGFXMode();
+
+ // Hardware screen
+ SDL_Surface *_hwscreen;
+};
+
+#endif