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

driver.cpp

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 AUTHORS
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 #include "engines/stark/gfx/driver.h"
00024 #include "engines/stark/gfx/opengls.h"
00025 
00026 #include "common/config-manager.h"
00027 
00028 #include "graphics/surface.h"
00029 #ifdef USE_OPENGL
00030 #include "graphics/opengl/context.h"
00031 #endif
00032 
00033 namespace Stark {
00034 namespace Gfx {
00035 
00036 Driver *Driver::create() {
00037 #if defined(USE_GLES2) || defined(USE_OPENGL_SHADERS)
00038     bool fullscreen = ConfMan.getBool("fullscreen");
00039     g_system->setupScreen(kOriginalWidth, kOriginalHeight, fullscreen, true);
00040 
00041     if (OpenGLContext.shadersSupported) {
00042         return new OpenGLSDriver();
00043     } else {
00044         error("Your system does not have the required OpenGL capabilities");
00045     }
00046 #endif // defined(USE_GLES2) || defined(USE_OPENGL_SHADERS)
00047 
00048     error("No renderers have been found for this game");
00049 }
00050 
00051 const Graphics::PixelFormat Driver::getRGBAPixelFormat() {
00052 #ifdef SCUMM_BIG_ENDIAN
00053     return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
00054 #else
00055     return Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
00056 #endif
00057 }
00058 
00059 void Driver::toggleFullscreen() const {
00060     if (!g_system->hasFeature(OSystem::kFeatureFullscreenToggleKeepsContext)) {
00061         warning("Unable to toggle the fullscreen state because the current backend would destroy the graphics context");
00062         return;
00063     }
00064 
00065     bool oldFullscreen = g_system->getFeatureState(OSystem::kFeatureFullscreenMode);
00066     g_system->setFeatureState(OSystem::kFeatureFullscreenMode, !oldFullscreen);
00067 }
00068 
00069 bool Driver::computeScreenViewport() {
00070     int32 screenWidth = g_system->getWidth();
00071     int32 screenHeight = g_system->getHeight();
00072 
00073     Common::Rect viewport;
00074     if (g_system->getFeatureState(OSystem::kFeatureAspectRatioCorrection)) {
00075         // Aspect ratio correction
00076         int32 viewportWidth = MIN<int32>(screenWidth, screenHeight * kOriginalWidth / kOriginalHeight);
00077         int32 viewportHeight = MIN<int32>(screenHeight, screenWidth * kOriginalHeight / kOriginalWidth);
00078         viewport = Common::Rect(viewportWidth, viewportHeight);
00079 
00080         // Pillarboxing
00081         viewport.translate((screenWidth - viewportWidth) / 2,
00082             (screenHeight - viewportHeight) / 2);
00083     } else {
00084         // Aspect ratio correction disabled, just stretch
00085         viewport = Common::Rect(screenWidth, screenHeight);
00086     }
00087 
00088     if (viewport == _screenViewport) {
00089         return false;
00090     }
00091 
00092     _screenViewport = viewport;
00093     return true;
00094 }
00095 
00096 Common::Rect Driver::gameViewport() const {
00097     Common::Rect game = Common::Rect(_screenViewport.width(), _screenViewport.height() * kGameViewportHeight / kOriginalHeight);
00098     game.translate(_screenViewport.left, _screenViewport.top + _screenViewport.height() * kTopBorderHeight / kOriginalHeight);
00099 
00100     return game;
00101 }
00102 
00103 Common::Point Driver::convertCoordinateCurrentToOriginal(const Common::Point &point) const {
00104     // Most of the engine expects 640x480 coordinates
00105     Common::Point scaledPosition = point;
00106     scaledPosition.x -= _screenViewport.left;
00107     scaledPosition.y -= _screenViewport.top;
00108     scaledPosition.x = CLIP<int16>(scaledPosition.x, 0, _screenViewport.width());
00109     scaledPosition.y = CLIP<int16>(scaledPosition.y, 0, _screenViewport.height());
00110     scaledPosition.x *= kOriginalWidth / (float)_screenViewport.width();
00111     scaledPosition.y *= kOriginalHeight / (float)_screenViewport.height();
00112 
00113     return scaledPosition;
00114 }
00115 
00116 uint Driver::scaleWidthOriginalToCurrent(uint width) const {
00117     return _screenViewport.width() * width / kOriginalWidth;
00118 }
00119 
00120 uint Driver::scaleHeightOriginalToCurrent(uint height) const {
00121     return _screenViewport.height() * height / kOriginalHeight;
00122 }
00123 
00124 uint Driver::scaleWidthCurrentToOriginal(uint width) const {
00125     return kOriginalWidth * width / _screenViewport.width();
00126 }
00127 
00128 uint Driver::scaleHeightCurrentToOriginal(uint height) const {
00129     return kOriginalHeight * height / _screenViewport.height();
00130 }
00131 
00132 void Driver::flipVertical(Graphics::Surface *s) {
00133     for (int y = 0; y < s->h / 2; ++y) {
00134         // Flip the lines
00135         byte *line1P = (byte *)s->getBasePtr(0, y);
00136         byte *line2P = (byte *)s->getBasePtr(0, s->h - y - 1);
00137 
00138         for (int x = 0; x < s->pitch; ++x)
00139             SWAP(line1P[x], line2P[x]);
00140     }
00141 }
00142 
00143 bool Driver::isPosInScreenBounds(const Common::Point &point) const {
00144     return _screenViewport.contains(point);
00145 }
00146 
00147 } // End of namespace Gfx
00148 } // End of namespace Stark


Generated on Sat Feb 23 2019 05:01:01 for ResidualVM by doxygen 1.7.1
curved edge   curved edge