diff options
author | Eugene Sandulenko | 2010-09-14 19:58:25 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-12 23:51:36 +0000 |
commit | 69cae2e7dd5f52801093a4ab069924673f6e307c (patch) | |
tree | dcbad1613e6e862388ed82525c1b8ea54ce883b1 /engines/sword25 | |
parent | 1aa907e8151013e8068b08699238b64ef474bd93 (diff) | |
download | scummvm-rg350-69cae2e7dd5f52801093a4ab069924673f6e307c.tar.gz scummvm-rg350-69cae2e7dd5f52801093a4ab069924673f6e307c.tar.bz2 scummvm-rg350-69cae2e7dd5f52801093a4ab069924673f6e307c.zip |
SWORD25: Got rid of OpenGLGfx class
svn-id: r53356
Diffstat (limited to 'engines/sword25')
-rw-r--r-- | engines/sword25/gfx/graphicengine.cpp | 358 | ||||
-rw-r--r-- | engines/sword25/gfx/graphicengine.h | 57 | ||||
-rw-r--r-- | engines/sword25/gfx/opengl/openglgfx.cpp | 431 | ||||
-rw-r--r-- | engines/sword25/gfx/opengl/openglgfx.h | 126 | ||||
-rw-r--r-- | engines/sword25/kernel/service_ids.h | 4 | ||||
-rw-r--r-- | engines/sword25/module.mk | 1 |
6 files changed, 389 insertions, 588 deletions
diff --git a/engines/sword25/gfx/graphicengine.cpp b/engines/sword25/gfx/graphicengine.cpp index f36993784d..199ca8a84c 100644 --- a/engines/sword25/gfx/graphicengine.cpp +++ b/engines/sword25/gfx/graphicengine.cpp @@ -34,10 +34,22 @@ #define BS_LOG_PREFIX "GRAPHICENGINE" -#include "sword25/gfx/image/image.h" +#include "common/system.h" + +#include "sword25/gfx/bitmapresource.h" +#include "sword25/gfx/animationresource.h" +#include "sword25/gfx/fontresource.h" +#include "sword25/gfx/panel.h" +#include "sword25/gfx/renderobjectmanager.h" #include "sword25/gfx/screenshot.h" +#include "sword25/gfx/image/vectorimage.h" +#include "sword25/gfx/opengl/glimage.h" +#include "sword25/gfx/opengl/swimage.h" +#include "sword25/package/packagemanager.h" #include "sword25/kernel/inputpersistenceblock.h" #include "sword25/kernel/outputpersistenceblock.h" + + #include "sword25/gfx/graphicengine.h" namespace Lua { @@ -46,9 +58,20 @@ extern "C" #include "sword25/util/lua/lua.h" #include "sword25/util/lua/lauxlib.h" } +} +namespace { +const int BIT_DEPTH = 32; +const int BACKBUFFER_COUNT = 1; +const Common::String PNG_EXTENSION(".png"); +const Common::String PNG_S_EXTENSION("_s.png"); +const Common::String ANI_EXTENSION("_ani.xml"); +const Common::String FNT_EXTENSION("_fnt.xml"); +const Common::String SWF_EXTENSION(".swf"); +const Common::String B25S_EXTENSION(".b25s"); } + namespace Sword25 { using namespace Lua; @@ -74,8 +97,320 @@ GraphicEngine::GraphicEngine(Kernel *pKernel) : BS_LOGLN("Script bindings registered."); } +GraphicEngine::~GraphicEngine() { + _backSurface.free(); +} + +Service *GraphicEngine_CreateObject(Kernel *pKernel) { + return new GraphicEngine(pKernel); +} + +bool GraphicEngine::Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed) { + // Warnung ausgeben, wenn eine nicht unterstützte Bittiefe gewählt wurde. + if (BitDepth != BIT_DEPTH) { + BS_LOG_WARNINGLN("Can't use a bit depth of %d (not supported). Falling back to %d.", BitDepth, BIT_DEPTH); + m_BitDepth = BIT_DEPTH; + } + + // Warnung ausgeben, wenn nicht genau ein Backbuffer gewählt wurde. + if (BackbufferCount != BACKBUFFER_COUNT) { + BS_LOG_WARNINGLN("Can't use %d backbuffers (not supported). Falling back to %d.", BackbufferCount, BACKBUFFER_COUNT); + BackbufferCount = BACKBUFFER_COUNT; + } + + // Parameter in lokale Variablen kopieren + m_Width = Width; + m_Height = Height; + m_BitDepth = BitDepth; + m_Windowed = Windowed; + m_ScreenRect.left = 0; + m_ScreenRect.top = 0; + m_ScreenRect.right = m_Width; + m_ScreenRect.bottom = m_Height; + + _backSurface.create(Width, Height, 4); + + // Standardmäßig ist Vsync an. + SetVsync(true); + + // Layer-Manager initialisieren. + _renderObjectManagerPtr.reset(new RenderObjectManager(Width, Height, BackbufferCount + 1)); + + // Hauptpanel erstellen + m_MainPanelPtr = _renderObjectManagerPtr->getTreeRoot()->addPanel(Width, Height, BS_ARGB(0, 0, 0, 0)); + if (!m_MainPanelPtr.isValid()) return false; + m_MainPanelPtr->setVisible(true); + + return true; +} + +// ----------------------------------------------------------------------------- + +bool GraphicEngine::StartFrame(bool UpdateAll) { + // Berechnen, wie viel Zeit seit dem letzten Frame vergangen ist. + // Dieser Wert kann über GetLastFrameDuration() von Modulen abgefragt werden, die zeitabhängig arbeiten. + UpdateLastFrameDuration(); + + // Den Layer-Manager auf den nächsten Frame vorbereiten + _renderObjectManagerPtr->startFrame(); + + return true; +} + +// ----------------------------------------------------------------------------- + +bool GraphicEngine::EndFrame() { + // Scene zeichnen + _renderObjectManagerPtr->render(); + + g_system->updateScreen(); + + // Debug-Lines zeichnen + if (!m_DebugLines.empty()) { +#if 0 + glEnable(GL_LINE_SMOOTH); + glBegin(GL_LINES); + + Common::Array<DebugLine>::const_iterator iter = m_DebugLines.begin(); + for (; iter != m_DebugLines.end(); ++iter) { + const uint &Color = (*iter).Color; + const BS_Vertex &Start = (*iter).Start; + const BS_Vertex &End = (*iter).End; + + glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24); + glVertex2d(Start.X, Start.Y); + glVertex2d(End.X, End.Y); + } + + glEnd(); + glDisable(GL_LINE_SMOOTH); +#endif + + warning("STUB: Drawing debug lines"); + + m_DebugLines.clear(); + } + + // Framecounter aktualisieren + m_FPSCounter.Update(); + + return true; +} + +// ----------------------------------------------------------------------------- + +RenderObjectPtr<Panel> GraphicEngine::GetMainPanel() { + return m_MainPanelPtr; +} + +// ----------------------------------------------------------------------------- + +void GraphicEngine::SetVsync(bool Vsync) { + warning("STUB: SetVsync(%d)", Vsync); +} + +// ----------------------------------------------------------------------------- + +bool GraphicEngine::GetVsync() const { + warning("STUB: GetVsync()"); + + return true; +} + +// ----------------------------------------------------------------------------- + +bool GraphicEngine::fill(const Common::Rect *fillRectPtr, uint color) { + Common::Rect rect(m_Width - 1, m_Height - 1); + + if (fillRectPtr) { + rect = *fillRectPtr; + } + + if (fillRectPtr->width() > 0 && fillRectPtr->height() > 0) { + _backSurface.fillRect(rect, color); + g_system->copyRectToScreen((byte *)_backSurface.getBasePtr(fillRectPtr->left, fillRectPtr->top), _backSurface.pitch, fillRectPtr->left, fillRectPtr->top, fillRectPtr->width(), fillRectPtr->height()); + } + + return true; +} + // ----------------------------------------------------------------------------- +bool GraphicEngine::GetScreenshot(uint &Width, uint &Height, byte **Data) { + if (!ReadFramebufferContents(m_Width, m_Height, Data)) + return false; + + // Die Größe des Framebuffers zurückgeben. + Width = m_Width; + Height = m_Height; + + // Bilddaten vom OpenGL-Format in unser eigenes Format umwandeln. + ReverseRGBAComponentOrder(*Data, Width * Height); + FlipImagedataVertical(Width, Height, *Data); + + return true; +} + +// ----------------------------------------------------------------------------- + +bool GraphicEngine::ReadFramebufferContents(uint Width, uint Height, byte **Data) { + *Data = (byte *)malloc(Width * Height * 4); + + return true; +} + +// ----------------------------------------------------------------------------- + +void GraphicEngine::ReverseRGBAComponentOrder(byte *Data, uint size) { + uint32 *ptr = (uint32 *)Data; + + for (uint i = 0; i < size; i++) { + uint Pixel = *ptr; + *ptr = (Pixel & 0xff00ff00) | ((Pixel >> 16) & 0xff) | ((Pixel & 0xff) << 16); + ++ptr; + } +} + +// ----------------------------------------------------------------------------- + +void GraphicEngine::FlipImagedataVertical(uint Width, uint Height, byte *Data) { +#if 0 // TODO + vector<uint> LineBuffer(Width); + + for (uint Y = 0; Y < Height / 2; ++Y) { + vector<uint>::iterator Line1It = Data.begin() + Y * Width; + vector<uint>::iterator Line2It = Data.begin() + (Height - 1 - Y) * Width; + copy(Line1It, Line1It + Width, LineBuffer.begin()); + copy(Line2It, Line2It + Width, Line1It); + copy(LineBuffer.begin(), LineBuffer.end(), Line2It); + } +#endif +} + +// ----------------------------------------------------------------------------- +// RESOURCE MANAGING +// ----------------------------------------------------------------------------- + +Resource *GraphicEngine::LoadResource(const Common::String &FileName) { + BS_ASSERT(CanLoadResource(FileName)); + + // Bild für den Softwarebuffer laden + if (FileName.hasSuffix(PNG_S_EXTENSION)) { + bool Result = false; + SWImage *pImage = new SWImage(FileName, Result); + if (!Result) { + delete pImage; + return 0; + } + + BitmapResource *pResource = new BitmapResource(FileName, pImage); + if (!pResource->isValid()) { + delete pResource; + return 0; + } + + return pResource; + } + + // Sprite-Bild laden + if (FileName.hasSuffix(PNG_EXTENSION) || FileName.hasSuffix(B25S_EXTENSION)) { + bool Result = false; + GLImage *pImage = new GLImage(FileName, Result); + if (!Result) { + delete pImage; + return 0; + } + + BitmapResource *pResource = new BitmapResource(FileName, pImage); + if (!pResource->isValid()) { + delete pResource; + return 0; + } + + return pResource; + } + + + // Vectorgraphik laden + if (FileName.hasSuffix(SWF_EXTENSION)) { + debug(2, "VectorImage: %s", FileName.c_str()); + + // Pointer auf Package-Manager holen + PackageManager *pPackage = Kernel::GetInstance()->GetPackage(); + BS_ASSERT(pPackage); + + // Datei laden + byte *pFileData; + uint FileSize; + if (!(pFileData = static_cast<byte *>(pPackage->GetFile(FileName, &FileSize)))) { + BS_LOG_ERRORLN("File \"%s\" could not be loaded.", FileName.c_str()); + return 0; + } + + bool Result = false; + VectorImage *pImage = new VectorImage(pFileData, FileSize, Result, FileName); + if (!Result) { + delete pImage; + delete [] pFileData; + return 0; + } + + BitmapResource *pResource = new BitmapResource(FileName, pImage); + if (!pResource->isValid()) { + delete pResource; + delete[] pFileData; + return 0; + } + + delete[] pFileData; + return pResource; + } + + // Animation laden + if (FileName.hasSuffix(ANI_EXTENSION)) { + AnimationResource *pResource = new AnimationResource(FileName); + if (pResource->isValid()) + return pResource; + else { + delete pResource; + return 0; + } + } + + // Font laden + if (FileName.hasSuffix(FNT_EXTENSION)) { + FontResource *pResource = new FontResource(Kernel::GetInstance(), FileName); + if (pResource->IsValid()) + return pResource; + else { + delete pResource; + return 0; + } + } + + BS_LOG_ERRORLN("Service cannot load \"%s\".", FileName.c_str()); + return 0; +} + +// ----------------------------------------------------------------------------- + +bool GraphicEngine::CanLoadResource(const Common::String &FileName) { + return FileName.hasSuffix(PNG_EXTENSION) || + FileName.hasSuffix(ANI_EXTENSION) || + FileName.hasSuffix(FNT_EXTENSION) || + FileName.hasSuffix(SWF_EXTENSION) || + FileName.hasSuffix(B25S_EXTENSION); +} + + +// ----------------------------------------------------------------------------- +// DEBUGGING +// ----------------------------------------------------------------------------- + +void GraphicEngine::DrawDebugLine(const Vertex &Start, const Vertex &End, uint Color) { + m_DebugLines.push_back(DebugLine(Start, End, Color)); +} + void GraphicEngine::UpdateLastFrameDuration() { // Aktuelle Zeit holen uint64_t CurrentTime = Kernel::GetInstance()->GetMicroTicks(); @@ -96,8 +431,6 @@ void GraphicEngine::UpdateLastFrameDuration() { m_LastTimeStamp = CurrentTime; } -// ----------------------------------------------------------------------------- - namespace { bool DoSaveScreenshot(GraphicEngine &GraphicEngine, const Common::String &Filename, bool Thumbnail) { uint Width; @@ -115,20 +448,14 @@ bool DoSaveScreenshot(GraphicEngine &GraphicEngine, const Common::String &Filena } } -// ----------------------------------------------------------------------------- - bool GraphicEngine::SaveScreenshot(const Common::String &Filename) { return DoSaveScreenshot(*this, Filename, false); } -// ----------------------------------------------------------------------------- - bool GraphicEngine::SaveThumbnailScreenshot(const Common::String &Filename) { return DoSaveScreenshot(*this, Filename, true); } -// ----------------------------------------------------------------------------- - void GraphicEngine::ARGBColorToLuaColor(lua_State *L, uint Color) { lua_Number Components[4] = { (Color >> 16) & 0xff, // Rot @@ -146,8 +473,6 @@ void GraphicEngine::ARGBColorToLuaColor(lua_State *L, uint Color) { } } -// ----------------------------------------------------------------------------- - uint GraphicEngine::LuaColorToARGBColor(lua_State *L, int StackIndex) { #ifdef DEBUG int __startStackDepth = lua_gettop(L); @@ -194,17 +519,18 @@ uint GraphicEngine::LuaColorToARGBColor(lua_State *L, int StackIndex) { return (Alpha << 24) | (Red << 16) | (Green << 8) | Blue; } -// ----------------------------------------------------------------------------- - bool GraphicEngine::persist(OutputPersistenceBlock &writer) { writer.write(m_TimerActive); - return true; -} -// ----------------------------------------------------------------------------- + bool result = _renderObjectManagerPtr->persist(writer); + + return result; +} bool GraphicEngine::unpersist(InputPersistenceBlock &reader) { reader.read(m_TimerActive); + _renderObjectManagerPtr->unpersist(reader); + return reader.isGood(); } diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h index 084c2f1476..8c98d349fd 100644 --- a/engines/sword25/gfx/graphicengine.h +++ b/engines/sword25/gfx/graphicengine.h @@ -62,6 +62,7 @@ class Kernel; class Image; class Panel; class Screenshot; +class RenderObjectManager; // Typen typedef uint BS_COLOR; @@ -105,6 +106,11 @@ public: CF_ABGR32 }; + // Constructor + // ----------- + GraphicEngine(Kernel *pKernel); + ~GraphicEngine(); + // Interface // --------- @@ -117,7 +123,7 @@ public: * @param BackbufferCount The number of back buffers to be created. The default value is 2 * @param Windowed Indicates whether the engine is to run in windowed mode. */ - virtual bool Init(int Width = 800, int Height = 600, int BitDepth = 16, int BackbufferCount = 2, bool Windowed = false) = 0; + bool Init(int Width = 800, int Height = 600, int BitDepth = 16, int BackbufferCount = 2, bool Windowed = false); /** * Begins rendering a new frame. @@ -126,7 +132,7 @@ public: * @param UpdateAll Specifies whether the renderer should redraw everything on the next frame. * This feature can be useful if the renderer with Dirty Rectangles works, but sometimes the client may */ - virtual bool StartFrame(bool UpdateAll = false) = 0; + bool StartFrame(bool UpdateAll = false); /** * Ends the rendering of a frame and draws it on the screen. @@ -134,7 +140,7 @@ public: * This method must be at the end of the main loop. After this call, no further Render method may be called. * This should only be called once for a given previous call to #StartFrame. */ - virtual bool EndFrame() = 0; + bool EndFrame(); // Debug methods @@ -148,7 +154,7 @@ public: * @param End The ending point of the line * @param Color The colour of the line. The default is BS_RGB (255,255,255) (White) */ - virtual void DrawDebugLine(const Vertex &Start, const Vertex &End, uint Color = BS_RGB(255, 255, 255)) = 0; + void DrawDebugLine(const Vertex &Start, const Vertex &End, uint Color = BS_RGB(255, 255, 255)); /** * Creates a screenshot of the current frame buffer and writes it to a graphic file in PNG format. @@ -175,10 +181,10 @@ public: * @param Height Returns the height of the frame buffer * @param Data Returns the raw data of the frame buffer as an array of 32-bit colour values. */ - virtual bool GetScreenshot(uint &Width, uint &Height, byte **Data) = 0; + bool GetScreenshot(uint &Width, uint &Height, byte **Data); - virtual RenderObjectPtr<Panel> GetMainPanel() = 0; + RenderObjectPtr<Panel> GetMainPanel(); /** * Specifies the time (in microseconds) since the last frame has passed @@ -241,13 +247,13 @@ public: * Notes: In windowed mode, this setting has no effect. * @param Vsync Indicates whether the frame buffer changes are to be synchronised with Vsync. */ - virtual void SetVsync(bool Vsync) = 0; + void SetVsync(bool Vsync); /** * Returns true if V-Sync is on. * Notes: In windowed mode, this setting has no effect. */ - virtual bool GetVsync() const = 0; + bool GetVsync() const; /** * Returns true if the engine is running in Windowed mode. @@ -265,7 +271,7 @@ public: * @param Color The 32-bit colour with which the area is to be filled. The default is BS_RGB(0, 0, 0) (black) @remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt. */ - virtual bool fill(const Common::Rect *FillRectPtr = 0, uint Color = BS_RGB(0, 0, 0)) = 0; + bool fill(const Common::Rect *FillRectPtr = 0, uint Color = BS_RGB(0, 0, 0)); // Debugging Methods @@ -314,6 +320,11 @@ public: return -1; } + // Resource-Managing Methods + // -------------------------- + virtual Resource *LoadResource(const Common::String &FileName); + virtual bool CanLoadResource(const Common::String &FileName); + // Persistence Methods // ------------------- virtual bool persist(OutputPersistenceBlock &Writer); @@ -323,9 +334,6 @@ public: static uint LuaColorToARGBColor(lua_State *L, int StackIndex); protected: - // Constructor - // ----------- - GraphicEngine(Kernel *pKernel); // Display Variables // ----------------- @@ -356,6 +364,31 @@ private: bool m_TimerActive; Common::Array<uint> m_FrameTimeSamples; uint m_FrameTimeSampleSlot; + +private: + byte *_backBuffer; + + RenderObjectPtr<Panel> m_MainPanelPtr; + + Common::ScopedPtr<RenderObjectManager> _renderObjectManagerPtr; + + struct DebugLine { + DebugLine(const Vertex &_Start, const Vertex &_End, uint _Color) : + Start(_Start), + End(_End), + Color(_Color) {} + DebugLine() {} + + Vertex Start; + Vertex End; + uint Color; + }; + + Common::Array<DebugLine> m_DebugLines; + + static bool ReadFramebufferContents(uint Width, uint Height, byte **Data); + static void ReverseRGBAComponentOrder(byte *Data, uint size); + static void FlipImagedataVertical(uint Width, uint Height, byte *Data); }; } // End of namespace Sword25 diff --git a/engines/sword25/gfx/opengl/openglgfx.cpp b/engines/sword25/gfx/opengl/openglgfx.cpp deleted file mode 100644 index 6ea3072b3a..0000000000 --- a/engines/sword25/gfx/opengl/openglgfx.cpp +++ /dev/null @@ -1,431 +0,0 @@ -/* 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$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#include "common/system.h" - -#include "sword25/gfx/bitmapresource.h" -#include "sword25/gfx/animationresource.h" -#include "sword25/gfx/fontresource.h" -#include "sword25/gfx/panel.h" -#include "sword25/gfx/renderobjectmanager.h" -#include "sword25/gfx/image/vectorimage.h" -#include "sword25/package/packagemanager.h" -#include "sword25/kernel/inputpersistenceblock.h" -#include "sword25/kernel/outputpersistenceblock.h" - -#include "sword25/gfx/opengl/openglgfx.h" -#include "sword25/gfx/opengl/glimage.h" -#include "sword25/gfx/opengl/swimage.h" - -namespace Sword25 { - -#define BS_LOG_PREFIX "OPENGLGFX" - - -// ----------------------------------------------------------------------------- -// CONSTANTS -// ----------------------------------------------------------------------------- - -namespace { -const int BIT_DEPTH = 32; -const int BACKBUFFER_COUNT = 1; -const Common::String PNG_EXTENSION(".png"); -const Common::String PNG_S_EXTENSION("_s.png"); -const Common::String ANI_EXTENSION("_ani.xml"); -const Common::String FNT_EXTENSION("_fnt.xml"); -const Common::String SWF_EXTENSION(".swf"); -const Common::String B25S_EXTENSION(".b25s"); -} - - -// ----------------------------------------------------------------------------- -// CONSTRUCTION / DESTRUCTION -// ----------------------------------------------------------------------------- - -OpenGLGfx::OpenGLGfx(Kernel *pKernel) : - GraphicEngine(pKernel), - m_GLspritesInitialized(false) { -} - -// ----------------------------------------------------------------------------- - -OpenGLGfx::~OpenGLGfx() { - _backSurface.free(); -} - -// ----------------------------------------------------------------------------- - -Service *OpenGLGfx_CreateObject(Kernel *pKernel) { - return new OpenGLGfx(pKernel); -} - - -// ----------------------------------------------------------------------------- -// INTERFACE -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed) { - // Warnung ausgeben, wenn eine nicht unterstützte Bittiefe gewählt wurde. - if (BitDepth != BIT_DEPTH) { - BS_LOG_WARNINGLN("Can't use a bit depth of %d (not supported). Falling back to %d.", BitDepth, BIT_DEPTH); - m_BitDepth = BIT_DEPTH; - } - - // Warnung ausgeben, wenn nicht genau ein Backbuffer gewählt wurde. - if (BackbufferCount != BACKBUFFER_COUNT) { - BS_LOG_WARNINGLN("Can't use %d backbuffers (not supported). Falling back to %d.", BackbufferCount, BACKBUFFER_COUNT); - BackbufferCount = BACKBUFFER_COUNT; - } - - // Parameter in lokale Variablen kopieren - m_Width = Width; - m_Height = Height; - m_BitDepth = BitDepth; - m_Windowed = Windowed; - m_ScreenRect.left = 0; - m_ScreenRect.top = 0; - m_ScreenRect.right = m_Width; - m_ScreenRect.bottom = m_Height; - - _backSurface.create(Width, Height, 4); - - // We already iniitalized gfx after the engine creation - m_GLspritesInitialized = true; - - // Standardmäßig ist Vsync an. - SetVsync(true); - - // Layer-Manager initialisieren. - _renderObjectManagerPtr.reset(new RenderObjectManager(Width, Height, BackbufferCount + 1)); - - // Hauptpanel erstellen - m_MainPanelPtr = _renderObjectManagerPtr->getTreeRoot()->addPanel(Width, Height, BS_ARGB(0, 0, 0, 0)); - if (!m_MainPanelPtr.isValid()) return false; - m_MainPanelPtr->setVisible(true); - - return true; -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::StartFrame(bool UpdateAll) { - // Berechnen, wie viel Zeit seit dem letzten Frame vergangen ist. - // Dieser Wert kann über GetLastFrameDuration() von Modulen abgefragt werden, die zeitabhängig arbeiten. - UpdateLastFrameDuration(); - - // Den Layer-Manager auf den nächsten Frame vorbereiten - _renderObjectManagerPtr->startFrame(); - - return true; -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::EndFrame() { - // Scene zeichnen - _renderObjectManagerPtr->render(); - - g_system->updateScreen(); - - // Debug-Lines zeichnen - if (!m_DebugLines.empty()) { -#if 0 - glEnable(GL_LINE_SMOOTH); - glBegin(GL_LINES); - - Common::Array<DebugLine>::const_iterator iter = m_DebugLines.begin(); - for (; iter != m_DebugLines.end(); ++iter) { - const uint &Color = (*iter).Color; - const BS_Vertex &Start = (*iter).Start; - const BS_Vertex &End = (*iter).End; - - glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24); - glVertex2d(Start.X, Start.Y); - glVertex2d(End.X, End.Y); - } - - glEnd(); - glDisable(GL_LINE_SMOOTH); -#endif - - warning("STUB: Drawing debug lines"); - - m_DebugLines.clear(); - } - - // Framecounter aktualisieren - m_FPSCounter.Update(); - - return true; -} - -// ----------------------------------------------------------------------------- - -RenderObjectPtr<Panel> OpenGLGfx::GetMainPanel() { - return m_MainPanelPtr; -} - -// ----------------------------------------------------------------------------- - -void OpenGLGfx::SetVsync(bool Vsync) { - warning("STUB: SetVsync(%d)", Vsync); -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::GetVsync() const { - warning("STUB: GetVsync()"); - - return true; -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::fill(const Common::Rect *fillRectPtr, uint color) { - Common::Rect rect(m_Width - 1, m_Height - 1); - - if (fillRectPtr) { - rect = *fillRectPtr; - } - - if (fillRectPtr->width() > 0 && fillRectPtr->height() > 0) { - _backSurface.fillRect(rect, color); - g_system->copyRectToScreen((byte *)_backSurface.getBasePtr(fillRectPtr->left, fillRectPtr->top), _backSurface.pitch, fillRectPtr->left, fillRectPtr->top, fillRectPtr->width(), fillRectPtr->height()); - } - - return true; -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::GetScreenshot(uint &Width, uint &Height, byte **Data) { - if (!ReadFramebufferContents(m_Width, m_Height, Data)) - return false; - - // Die Größe des Framebuffers zurückgeben. - Width = m_Width; - Height = m_Height; - - // Bilddaten vom OpenGL-Format in unser eigenes Format umwandeln. - ReverseRGBAComponentOrder(*Data, Width * Height); - FlipImagedataVertical(Width, Height, *Data); - - return true; -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::ReadFramebufferContents(uint Width, uint Height, byte **Data) { - *Data = (byte *)malloc(Width * Height * 4); - - return true; -} - -// ----------------------------------------------------------------------------- - -void OpenGLGfx::ReverseRGBAComponentOrder(byte *Data, uint size) { - uint32 *ptr = (uint32 *)Data; - - for (uint i = 0; i < size; i++) { - uint Pixel = *ptr; - *ptr = (Pixel & 0xff00ff00) | ((Pixel >> 16) & 0xff) | ((Pixel & 0xff) << 16); - ++ptr; - } -} - -// ----------------------------------------------------------------------------- - -void OpenGLGfx::FlipImagedataVertical(uint Width, uint Height, byte *Data) { -#if 0 // TODO - vector<uint> LineBuffer(Width); - - for (uint Y = 0; Y < Height / 2; ++Y) { - vector<uint>::iterator Line1It = Data.begin() + Y * Width; - vector<uint>::iterator Line2It = Data.begin() + (Height - 1 - Y) * Width; - copy(Line1It, Line1It + Width, LineBuffer.begin()); - copy(Line2It, Line2It + Width, Line1It); - copy(LineBuffer.begin(), LineBuffer.end(), Line2It); - } -#endif -} - -// ----------------------------------------------------------------------------- -// RESOURCE MANAGING -// ----------------------------------------------------------------------------- - -Resource *OpenGLGfx::LoadResource(const Common::String &FileName) { - BS_ASSERT(CanLoadResource(FileName)); - - // Bild für den Softwarebuffer laden - if (FileName.hasSuffix(PNG_S_EXTENSION)) { - bool Result = false; - SWImage *pImage = new SWImage(FileName, Result); - if (!Result) { - delete pImage; - return 0; - } - - BitmapResource *pResource = new BitmapResource(FileName, pImage); - if (!pResource->isValid()) { - delete pResource; - return 0; - } - - return pResource; - } - - // Sprite-Bild laden - if (FileName.hasSuffix(PNG_EXTENSION) || FileName.hasSuffix(B25S_EXTENSION)) { - bool Result = false; - GLImage *pImage = new GLImage(FileName, Result); - if (!Result) { - delete pImage; - return 0; - } - - BitmapResource *pResource = new BitmapResource(FileName, pImage); - if (!pResource->isValid()) { - delete pResource; - return 0; - } - - return pResource; - } - - - // Vectorgraphik laden - if (FileName.hasSuffix(SWF_EXTENSION)) { - debug(2, "VectorImage: %s", FileName.c_str()); - - // Pointer auf Package-Manager holen - PackageManager *pPackage = Kernel::GetInstance()->GetPackage(); - BS_ASSERT(pPackage); - - // Datei laden - byte *pFileData; - uint FileSize; - if (!(pFileData = static_cast<byte *>(pPackage->GetFile(FileName, &FileSize)))) { - BS_LOG_ERRORLN("File \"%s\" could not be loaded.", FileName.c_str()); - return 0; - } - - bool Result = false; - VectorImage *pImage = new VectorImage(pFileData, FileSize, Result, FileName); - if (!Result) { - delete pImage; - delete [] pFileData; - return 0; - } - - BitmapResource *pResource = new BitmapResource(FileName, pImage); - if (!pResource->isValid()) { - delete pResource; - delete[] pFileData; - return 0; - } - - delete[] pFileData; - return pResource; - } - - // Animation laden - if (FileName.hasSuffix(ANI_EXTENSION)) { - AnimationResource *pResource = new AnimationResource(FileName); - if (pResource->isValid()) - return pResource; - else { - delete pResource; - return 0; - } - } - - // Font laden - if (FileName.hasSuffix(FNT_EXTENSION)) { - FontResource *pResource = new FontResource(Kernel::GetInstance(), FileName); - if (pResource->IsValid()) - return pResource; - else { - delete pResource; - return 0; - } - } - - BS_LOG_ERRORLN("Service cannot load \"%s\".", FileName.c_str()); - return 0; -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::CanLoadResource(const Common::String &FileName) { - return FileName.hasSuffix(PNG_EXTENSION) || - FileName.hasSuffix(ANI_EXTENSION) || - FileName.hasSuffix(FNT_EXTENSION) || - FileName.hasSuffix(SWF_EXTENSION) || - FileName.hasSuffix(B25S_EXTENSION); -} - - -// ----------------------------------------------------------------------------- -// DEBUGGING -// ----------------------------------------------------------------------------- - -void OpenGLGfx::DrawDebugLine(const Vertex &Start, const Vertex &End, uint Color) { - m_DebugLines.push_back(DebugLine(Start, End, Color)); -} - -// ----------------------------------------------------------------------------- -// PERSISTENZ -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::persist(OutputPersistenceBlock &writer) { - bool result = true; - - result &= GraphicEngine::persist(writer); - result &= _renderObjectManagerPtr->persist(writer); - - return result; -} - -// ----------------------------------------------------------------------------- - -bool OpenGLGfx::unpersist(InputPersistenceBlock &reader) { - bool result = true; - - result &= GraphicEngine::unpersist(reader); - result &= _renderObjectManagerPtr->unpersist(reader); - - return result && reader.isGood(); -} - -} // End of namespace Sword25 diff --git a/engines/sword25/gfx/opengl/openglgfx.h b/engines/sword25/gfx/opengl/openglgfx.h deleted file mode 100644 index e8f312ad28..0000000000 --- a/engines/sword25/gfx/opengl/openglgfx.h +++ /dev/null @@ -1,126 +0,0 @@ -/* 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$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_OPENGLGFX_H -#define SWORD25_OPENGLGFX_H - -// ----------------------------------------------------------------------------- -// INCLUDES -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/common.h" -#include "sword25/gfx/graphicengine.h" -#include "sword25/gfx/renderobjectptr.h" - -namespace Sword25 { - -// ----------------------------------------------------------------------------- -// FORWARD DECLARATIONS -// ----------------------------------------------------------------------------- - -class Kernel; -class Service; -class Resource; -class Panel; -class BS_Image; -class RenderObjectManager; - - -// ----------------------------------------------------------------------------- -// CLASS DECLARATION -// ----------------------------------------------------------------------------- - -class OpenGLGfx : public GraphicEngine { -public: - OpenGLGfx(Kernel *pKernel); - virtual ~OpenGLGfx(); - - // Interface - // --------- - virtual bool Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed); - virtual bool StartFrame(bool UpdateAll); - virtual bool EndFrame(); - - virtual RenderObjectPtr<Panel> GetMainPanel(); - - virtual void SetVsync(bool Vsync); - virtual bool GetVsync() const; - - virtual bool fill(const Common::Rect *FillRectPtr = 0, uint Color = BS_RGB(0, 0, 0)); - virtual bool GetScreenshot(uint &Width, uint &Height, byte **Data); - - // Resource-Managing Methoden - // -------------------------- - virtual Resource *LoadResource(const Common::String &FileName); - virtual bool CanLoadResource(const Common::String &FileName); - - // Debugging Methoden - // ------------------ - virtual void DrawDebugLine(const Vertex &Start, const Vertex &End, uint Color); - - // Persistenz Methoden - // ------------------- - virtual bool persist(OutputPersistenceBlock &writer); - virtual bool unpersist(InputPersistenceBlock &reader); - -private: - bool m_GLspritesInitialized; - byte *_backBuffer; - - RenderObjectPtr<Panel> m_MainPanelPtr; - - Common::ScopedPtr<RenderObjectManager> _renderObjectManagerPtr; - - struct DebugLine { - DebugLine(const Vertex &_Start, const Vertex &_End, uint _Color) : - Start(_Start), - End(_End), - Color(_Color) {} - DebugLine() {} - - Vertex Start; - Vertex End; - uint Color; - }; - - Common::Array<DebugLine> m_DebugLines; - - static bool ReadFramebufferContents(uint Width, uint Height, byte **Data); - static void ReverseRGBAComponentOrder(byte *Data, uint size); - static void FlipImagedataVertical(uint Width, uint Height, byte *Data); -}; - -} // End of namespace Sword25 - -#endif diff --git a/engines/sword25/kernel/service_ids.h b/engines/sword25/kernel/service_ids.h index bf60279679..7c41fe459e 100644 --- a/engines/sword25/kernel/service_ids.h +++ b/engines/sword25/kernel/service_ids.h @@ -49,7 +49,7 @@ namespace Sword25 { -Service *OpenGLGfx_CreateObject(Kernel *pKernel); +Service *GraphicEngine_CreateObject(Kernel *pKernel); Service *PackageManager_CreateObject(Kernel *pKernel); Service *InputEngine_CreateObject(Kernel *pKernel); Service *FMODExSound_CreateObject(Kernel *pKernel); @@ -64,7 +64,7 @@ const BS_ServiceInfo BS_SERVICE_TABLE[] = { // of the class and returns it // Example: // BS_ServiceInfo("Superclass", "Service", CreateMethod) - BS_ServiceInfo("gfx", "opengl", OpenGLGfx_CreateObject), + BS_ServiceInfo("gfx", "opengl", GraphicEngine_CreateObject), BS_ServiceInfo("package", "archiveFS", PackageManager_CreateObject), BS_ServiceInfo("input", "winapi", InputEngine_CreateObject), BS_ServiceInfo("sfx", "fmodex", FMODExSound_CreateObject), diff --git a/engines/sword25/module.mk b/engines/sword25/module.mk index 34a6988915..80e4a1cec7 100644 --- a/engines/sword25/module.mk +++ b/engines/sword25/module.mk @@ -39,7 +39,6 @@ MODULE_OBJS := \ gfx/image/art_svp_vpath_stroke.o \ gfx/image/art_vpath_bpath.o \ gfx/opengl/glimage.o \ - gfx/opengl/openglgfx.o \ gfx/opengl/swimage.o \ input/inputengine.o \ input/inputengine_script.o \ |