Mercurial > fife-parpg
changeset 635:3094988564d5
* Added a simple method to query the default video card capabilities. This is still a work in progress. You can now get a list of ScreenModes the device supports. ScreenMode includes information on the screen resolution, if the mode is fullscreen/windowed and if it would use the OpenGL or SDL renderer.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 06 Oct 2010 19:19:08 +0000 |
parents | 5f381fa34769 |
children | f7863bfa92cd |
files | engine/core/controller/engine.cpp engine/core/controller/engine.h engine/core/controller/engine.i engine/core/video/devicecaps.cpp engine/core/video/devicecaps.h engine/core/video/renderbackend.cpp engine/core/video/renderbackend.h engine/core/video/video.i |
diffstat | 8 files changed, 310 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/controller/engine.cpp Wed Oct 06 15:49:53 2010 +0000 +++ b/engine/core/controller/engine.cpp Wed Oct 06 19:19:08 2010 +0000 @@ -48,6 +48,7 @@ #include "audio/soundclippool.h" #include "video/renderbackend.h" #include "video/cursor.h" +#include "video/devicecaps.h" #ifdef HAVE_OPENGL #include "video/opengl/renderbackendopengl.h" #include "gui/base/opengl/opengl_gui_graphics.h" @@ -124,6 +125,10 @@ return m_settings; } + DeviceCaps& Engine::getDeviceCaps() { + return m_devcaps; + } + void Engine::preInit() { m_logmanager = LogManager::instance(); @@ -192,6 +197,9 @@ m_renderbackend->setColorKeyEnabled(m_settings.isColorKeyEnabled()); m_renderbackend->init(); + FL_LOG(_log, "Querying device capabilities"); + m_devcaps.fillDeviceCaps(); + FL_LOG(_log, "Creating main screen"); m_renderbackend->createMainScreen( m_settings.getScreenWidth(),
--- a/engine/core/controller/engine.h Wed Oct 06 15:49:53 2010 +0000 +++ b/engine/core/controller/engine.h Wed Oct 06 19:19:08 2010 +0000 @@ -40,6 +40,7 @@ // First block: files included from the FIFE root src directory // Second block: files included from the same folder #include "enginesettings.h" +#include "video/devicecaps.h" namespace gcn { class Graphics; @@ -63,7 +64,6 @@ class SoundClipPool; class RendererBase; - /** Engine acts as a controller to the whole system * Responsibilities of the engine are: * - Construct and initialize engine internals @@ -83,7 +83,11 @@ /** Gets settings class for engine */ EngineSettings& getSettings(); - + + /** Gets device capabilities + */ + DeviceCaps& getDeviceCaps(); + /** Initializes the engine */ void init(); @@ -91,12 +95,12 @@ /** Explicit destruction of engine */ void destroy(); - + /** Initializes the continuous processing of the engine * Call this only once in your program */ void initializePumping(); - + /** Finalizes the continuous processing of the engine * Call this only once in your program, after you have called * initializePumping + (pump() * N times) @@ -110,23 +114,23 @@ /** Provides access point to the SoundManager */ SoundManager* getSoundManager() const { return m_soundmanager; } - + /** Provides access point to the EventManager */ EventManager* getEventManager() const { return m_eventmanager; } - + /** Provides access point to the TimeManager */ TimeManager* getTimeManager() const { return m_timemanager; } - + /** Provides access point to the GuiManager */ GUIManager* getGuiManager() const { return m_guimanager; } - + /** Provides access point to the ImagePool */ ImagePool* getImagePool() const { return m_imagepool; } - + /** Provides access point to the AnimationPool */ AnimationPool* getAnimationPool() const { return m_animpool; } @@ -134,34 +138,34 @@ /** Provides access point to the SoundClipPool */ SoundClipPool* getSoundClipPool() const { return m_soundclippool; } - + /** Provides access point to the RenderBackend */ RenderBackend* getRenderBackend() const { return m_renderbackend; } - + /** Provides access point to the Model */ Model* getModel() const { return m_model; } - + /** Provides access point to the LogManager */ LogManager* getLogManager() const { return m_logmanager; } - + /** Returns default font used in the engine */ GuiFont* getDefaultFont() const { return m_defaultfont; } - + /** Provides access point to the VFS */ VFS* getVFS() const { return m_vfs; } - + /** Returns cursor used in the engine */ Cursor* getCursor() const { return m_cursor; } private: void preInit(); - + RenderBackend* m_renderbackend; GUIManager* m_guimanager; EventManager* m_eventmanager; @@ -177,8 +181,9 @@ GuiFont* m_defaultfont; Cursor* m_cursor; bool m_destroyed; - + EngineSettings m_settings; + DeviceCaps m_devcaps; std::vector<RendererBase*> m_renderers;
--- a/engine/core/controller/engine.i Wed Oct 06 15:49:53 2010 +0000 +++ b/engine/core/controller/engine.i Wed Oct 06 19:19:08 2010 +0000 @@ -21,6 +21,7 @@ %module fife %{ #include "controller/engine.h" +#include "video/devicecaps.h" %} namespace FIFE { @@ -39,6 +40,7 @@ class VFS; class Cursor; class RendererBase; + class DeviceCaps; class EngineSettings { public: @@ -90,6 +92,8 @@ void pump(); EngineSettings& getSettings(); + DeviceCaps& getDeviceCaps(); + void init(); void destroy();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/engine/core/video/devicecaps.cpp Wed Oct 06 19:19:08 2010 +0000 @@ -0,0 +1,128 @@ +/*************************************************************************** + * Copyright (C) 2005-2010 by the FIFE team * + * http://www.fifengine.net * + * This file is part of FIFE. * + * * + * FIFE is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +// Standard C++ library includes +#include <iostream> + +// 3rd party library includes +#include <SDL.h> +#include <SDL_video.h> + +// FIFE includes +// These includes are split up in two parts, separated by one empty line +// First block: files included from the FIFE root src directory +// Second block: files included from the same folder +#include "devicecaps.h" + +namespace FIFE { + + ScreenMode::ScreenMode() : + m_width(0), m_height(0), m_bpp(0), m_SDLFlags(0){ + } + + ScreenMode::ScreenMode(uint16_t width, uint16_t height, uint16_t bpp, uint32_t SDLFlags) : + m_width(width), m_height(height), m_bpp(bpp), m_SDLFlags(SDLFlags){ + } + + ScreenMode::ScreenMode(const ScreenMode& rhs){ + m_width = rhs.getWidth(); + m_height = rhs.getHeight(); + m_bpp = rhs.getBPP(); + m_SDLFlags = rhs.getSDLFlags(); + } + + DeviceCaps::DeviceCaps() { + } + + + DeviceCaps::~DeviceCaps() { + } + + void DeviceCaps::fillDeviceCaps() { + int numBPP = 1; + int bpps[numBPP]; + + int numResolutions = 15; + + //FLAGS +#ifdef HAVE_OPENGL + int numFlags = 4; + Uint32 flags[numFlags]; + + //OpenGL, windowed, hw accel + flags[0] = SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL; + //OpenGL, fullscree, hw accel + flags[1] = SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL | SDL_FULLSCREEN; + //SDL, windowed + flags[2] = 0; + //SDL, fullscreen + flags[3] = SDL_FULLSCREEN; +#else + int numFlags = 2; + Uint32 flags[numFlags]; + + //SDL, windowed + flags[0] = 0; + //SDL, fullscreen + flags[1] = SDL_FULLSCREEN; +#endif + //BITS PER PIXEL + + bpps[0] = 32; + + + //RESOLUTIONS + int resolutions[15][2] = { + {640, 480}, + {800, 600}, + {1024, 768}, + {1152, 864}, + {1280, 768}, + {1280, 800}, + {1280, 960}, + {1280, 1024}, + {1366, 768}, + {1440, 900}, + {1600, 900}, + {1600, 1200}, + {1680, 1050}, + {1920, 1080}, + {1920, 1200} + }; + + int bpp; + + for (int i = 0; i < numBPP; i++){ + for (int j = 0; j < numFlags; j++) { + for (int k = 0; k < numResolutions; k++) { + bpp = SDL_VideoModeOK(resolutions[k][0], resolutions[k][1], bpps[i], flags[j]); + if (bpp > 0) { +// std::cout << resolutions[k][0] << "x" << resolutions[k][1] << ":" << bpp << std::endl; + ScreenMode mode = ScreenMode(resolutions[k][0], resolutions[k][1], bpps[i], flags[j]); + m_screenModes.push_back(mode); + } + } + } + } + + } + +} //FIFE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/engine/core/video/devicecaps.h Wed Oct 06 19:19:08 2010 +0000 @@ -0,0 +1,104 @@ +/*************************************************************************** + * Copyright (C) 2005-2010 by the FIFE team * + * http://www.fifengine.net * + * This file is part of FIFE. * + * * + * FIFE is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef FIFE_DEVICECAPS_H +#define FIFE_DEVICECAPS_H + +// Standard C++ library includes +#include <string> +#include <vector> + +// Platform specific includes + +// 3rd party library includes + +// FIFE includes +// These includes are split up in two parts, separated by one empty line +// First block: files included from the FIFE root src directory +// Second block: files included from the same folder + +namespace FIFE { + + + class ScreenMode { + public: + /** Constructors. + */ + ScreenMode(); + ScreenMode(uint16_t width, uint16_t height, uint16_t bpp, uint32_t SDLFlags); + ScreenMode(const ScreenMode& rhs); + + /** Destructor. + */ + ~ScreenMode() {}; + + /** Returns the width of the screen mode. + */ + uint16_t getWidth() const { return m_width; }; + + /** Returns the height of the screen mode. + */ + uint16_t getHeight() const { return m_height; }; + + /** Returns the number of bits per pixel this mode supports. + */ + uint16_t getBPP() const { return m_bpp; }; + + /** Returns the SDL flags used when testing this mode. + */ + uint32_t getSDLFlags() const { return m_SDLFlags; }; + + /** True if this is a fullscreen mode. Fals if it is a windowed mode. + */ + bool isFullScreen() const { return (m_SDLFlags & SDL_FULLSCREEN) ? true : false;}; + + /** True if this mode uses the OpenGL renderer. False otherwise. + */ + bool isOpenGL() const { return (m_SDLFlags & SDL_OPENGL) ? true : false; }; + + private: + uint16_t m_width; + uint16_t m_height; + uint16_t m_bpp; + uint32_t m_SDLFlags; + + }; //ScreenMode + + class DeviceCaps { + public: + /** Constructor. + */ + DeviceCaps(); + + /** Destructor. + */ + ~DeviceCaps(); + + void fillDeviceCaps(); + std::vector<ScreenMode> getSupportedScreenModes() const {return m_screenModes;} ; + + private: + std::vector<ScreenMode> m_screenModes; + + }; //DeviceCaps +} + +#endif //FIFE_DEVICECAPS_H
--- a/engine/core/video/renderbackend.cpp Wed Oct 06 15:49:53 2010 +0000 +++ b/engine/core/video/renderbackend.cpp Wed Oct 06 19:19:08 2010 +0000 @@ -28,6 +28,7 @@ // First block: files included from the FIFE root src directory // Second block: files included from the same folder #include "renderbackend.h" +#include "video/devicecaps.h" namespace FIFE { @@ -44,6 +45,12 @@ RenderBackend::~RenderBackend() { } + Image* RenderBackend::createMainScreen(const ScreenMode& mode, const std::string& title, const std::string& icon) + { + bool fs = (mode.getSDLFlags() & SDL_FULLSCREEN) ? true : false; + return createMainScreen(mode.getWidth(), mode.getHeight(), mode.getBPP(), fs, title, icon); + } + void RenderBackend::deinit() { delete m_screen; m_screen = NULL;
--- a/engine/core/video/renderbackend.h Wed Oct 06 15:49:53 2010 +0000 +++ b/engine/core/video/renderbackend.h Wed Oct 06 19:19:08 2010 +0000 @@ -45,6 +45,7 @@ namespace FIFE { class Image; + class ScreenMode; /** Abstract interface for all the renderbackends. */ class RenderBackend: public AbstractImage, public DynamicSingleton<RenderBackend> { @@ -92,6 +93,8 @@ */ virtual Image* createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fullscreen, const std::string& title, const std::string& icon) = 0; + Image* createMainScreen(const ScreenMode& mode, const std::string& title, const std::string& icon); + /** Creates an Image suitable for this renderbackend. * @param data Pointer to the imagedata (needs to be in RGBA, 8 bits per channel). * @param width Width of the image.
--- a/engine/core/video/video.i Wed Oct 06 15:49:53 2010 +0000 +++ b/engine/core/video/video.i Wed Oct 06 19:19:08 2010 +0000 @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * + * Copyright (C) 2005-2010 by the FIFE team * + * http://www.fifengine.net * * This file is part of FIFE. * * * * FIFE is free software; you can redistribute it and/or * @@ -28,6 +28,7 @@ #include "video/animationpool.h" #include "video/renderbackend.h" #include "video/image_location.h" +#include "video/devicecaps.h" #include "util/base/exception.h" %} @@ -35,6 +36,14 @@ %include "util/resource/resource.i" namespace FIFE { + class ScreenMode; +} + +namespace std { + %template(ScreenModeVector) std::vector<FIFE::ScreenMode>; +} + +namespace FIFE { class Pool; class Point; class ResourceLocation; @@ -220,4 +229,27 @@ Cursor(ImagePool* imgpool, AnimationPool* animpool); }; + class ScreenMode { + public: + ScreenMode(); + ScreenMode(uint16_t width, uint16_t height, uint16_t bpp, uint32_t SDLFlags); + ScreenMode(const ScreenMode& rhs); + ~ScreenMode(); + + uint16_t getWidth() const; + uint16_t getHeight() const; + uint16_t getBPP() const; + uint32_t getSDLFlags() const; + bool isFullScreen(); + bool isOpenGL(); + }; + + class DeviceCaps { + public: + DeviceCaps(); + ~DeviceCaps(); + + void fillDeviceCaps(); + std::vector<ScreenMode> getSupportedScreenModes() const; + }; }