From fd40021a722956a3c37119c72b1350acb313574e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 13 Aug 2010 15:24:23 +0000 Subject: [PATCH] SWORD25: Started rewriting gfx subsystem svn-id: r53227 --- engines/sword25/gfx/image/b25sloader.cpp | 2 +- engines/sword25/gfx/image/b25sloader.h | 2 +- engines/sword25/gfx/image/imageloader.cpp | 2 +- engines/sword25/gfx/image/imageloader.h | 4 +- engines/sword25/gfx/image/pngloader.cpp | 6 +- engines/sword25/gfx/image/pngloader.h | 4 +- engines/sword25/gfx/opengl/glimage.cpp | 29 +--------- engines/sword25/gfx/opengl/glimage.h | 2 +- engines/sword25/gfx/opengl/openglgfx.cpp | 69 +++++------------------ 9 files changed, 28 insertions(+), 92 deletions(-) diff --git a/engines/sword25/gfx/image/b25sloader.cpp b/engines/sword25/gfx/image/b25sloader.cpp index e45a4cddcbf..9288e2c4612 100644 --- a/engines/sword25/gfx/image/b25sloader.cpp +++ b/engines/sword25/gfx/image/b25sloader.cpp @@ -85,7 +85,7 @@ bool BS_B25SLoader::IsCorrectImageFormat(const char *FileDataPtr, unsigned int F // ----------------------------------------------------------------------------- -bool BS_B25SLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr, +bool BS_B25SLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, byte *&UncompressedDataPtr, int &Width, int &Height, int &Pitch) { // PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen. unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize); diff --git a/engines/sword25/gfx/image/b25sloader.h b/engines/sword25/gfx/image/b25sloader.h index 4a2cf3b8415..8d8a68e6e8e 100644 --- a/engines/sword25/gfx/image/b25sloader.h +++ b/engines/sword25/gfx/image/b25sloader.h @@ -58,7 +58,7 @@ public: protected: virtual bool IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize); - virtual bool DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr, + virtual bool DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, byte *&UncompressedDataPtr, int &Width, int &Height, int &Pitch); virtual bool ImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height); diff --git a/engines/sword25/gfx/image/imageloader.cpp b/engines/sword25/gfx/image/imageloader.cpp index 02eea59f56f..f350dba3f8f 100644 --- a/engines/sword25/gfx/image/imageloader.cpp +++ b/engines/sword25/gfx/image/imageloader.cpp @@ -48,7 +48,7 @@ bool BS_ImageLoader::_ImageLoaderListInitialized = false; bool BS_ImageLoader::LoadImage(const char *pFileData, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, - char*& pUncompressedData, + byte *&pUncompressedData, int &Width, int &Height, int &Pitch) { // Falls die Liste der BS_ImageLoader noch nicht initialisiert wurde, wird dies getan. diff --git a/engines/sword25/gfx/image/imageloader.h b/engines/sword25/gfx/image/imageloader.h index 204a56b144b..968ea35af8b 100644 --- a/engines/sword25/gfx/image/imageloader.h +++ b/engines/sword25/gfx/image/imageloader.h @@ -106,7 +106,7 @@ public: */ static bool LoadImage(const char *pFileData, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, - char*& pUncompressedData, + byte *&pUncompressedData, int &Width, int &Height, int &Pitch); @@ -175,7 +175,7 @@ protected: */ virtual bool DecodeImage(const char *pFileData, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, - char*& pUncompressedData, + byte *&pUncompressedData, int &Width, int &Height, int &Pitch) = 0; diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp index 3f892c7af1a..605dca8635c 100644 --- a/engines/sword25/gfx/image/pngloader.cpp +++ b/engines/sword25/gfx/image/pngloader.cpp @@ -62,7 +62,7 @@ static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t l // ----------------------------------------------------------------------------- -bool BS_PNGLoader::DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr, +bool BS_PNGLoader::DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, byte *&UncompressedDataPtr, int &Width, int &Height, int &Pitch) { png_structp png_ptr = NULL; png_infop info_ptr = NULL; @@ -115,7 +115,7 @@ bool BS_PNGLoader::DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, // Speicher für die endgültigen Bilddaten reservieren // Dieses geschieht vor dem reservieren von Speicher für temporäre Bilddaten um die Fragmentierung des Speichers gering zu halten - UncompressedDataPtr = new char[Pitch * Height]; + UncompressedDataPtr = new byte[Pitch * Height]; if (!UncompressedDataPtr) { error("Could not allocate memory for output image."); } @@ -256,7 +256,7 @@ bool BS_PNGLoader::DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, // ----------------------------------------------------------------------------- -bool BS_PNGLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr, +bool BS_PNGLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, byte *&UncompressedDataPtr, int &Width, int &Height, int &Pitch) { return DoDecodeImage(FileDataPtr, FileSize, ColorFormat, UncompressedDataPtr, Width, Height, Pitch); } diff --git a/engines/sword25/gfx/image/pngloader.h b/engines/sword25/gfx/image/pngloader.h index 85d12a7a946..17655c6fdc2 100644 --- a/engines/sword25/gfx/image/pngloader.h +++ b/engines/sword25/gfx/image/pngloader.h @@ -61,7 +61,7 @@ public: // Alle virtuellen Methoden von BS_ImageLoader sind hier als static-Methode implementiert, damit sie von BS_B25SLoader aufgerufen werden können. // Die virtuellen Methoden rufen diese Methoden auf. static bool DoIsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize); - static bool DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr, + static bool DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, byte *&UncompressedDataPtr, int &Width, int &Height, int &Pitch); static bool DoImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height); @@ -69,7 +69,7 @@ protected: BS_PNGLoader(); bool DecodeImage(const char *pFileData, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, - char * & pUncompressedData, + byte *&pUncompressedData, int &Width, int &Height, int &Pitch); bool IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize); diff --git a/engines/sword25/gfx/opengl/glimage.cpp b/engines/sword25/gfx/opengl/glimage.cpp index d5e13762999..3ab20016dec 100644 --- a/engines/sword25/gfx/opengl/glimage.cpp +++ b/engines/sword25/gfx/opengl/glimage.cpp @@ -75,8 +75,7 @@ BS_GLImage::BS_GLImage(const Common::String &Filename, bool &Result) : } // Das Bild dekomprimieren - char *pUncompressedData; - if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch)) { + if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, _data, m_Width, m_Height, Pitch)) { BS_LOG_ERRORLN("Could not decode image."); return; } @@ -84,19 +83,6 @@ BS_GLImage::BS_GLImage(const Common::String &Filename, bool &Result) : // Dateidaten freigeben delete[] pFileData; - // GLS-Sprite mit den Bilddaten erstellen - GLS_Result GLSResult = GLS_NewSprite(m_Width, m_Height, - (ColorFormat == BS_GraphicEngine::CF_ARGB32) ? GLS_True : GLS_False, - pUncompressedData, - &m_Sprite); - if (Result != GLS_OK) { - BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult)); - return; - } - - // Bilddaten freigeben - delete[] pUncompressedData; - Result = true; return; } @@ -104,20 +90,11 @@ BS_GLImage::BS_GLImage(const Common::String &Filename, bool &Result) : // ----------------------------------------------------------------------------- BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool &Result) : - m_Sprite(0), m_Width(Width), m_Height(Height) { Result = false; - // GLS-Sprite mit den Bilddaten erstellen - GLS_Result GLSResult = GLS_NewSprite(m_Width, m_Height, - GLS_True, - 0, - &m_Sprite); - if (GLSResult != GLS_OK) { - BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult)); - return; - } + _data = new byte[Width * Height * 4]; Result = true; return; @@ -126,7 +103,7 @@ BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool &Result) : // ----------------------------------------------------------------------------- BS_GLImage::~BS_GLImage() { - if (m_Sprite) GLS_DeleteSprite(m_Sprite); + delete[] _data; } // ----------------------------------------------------------------------------- diff --git a/engines/sword25/gfx/opengl/glimage.h b/engines/sword25/gfx/opengl/glimage.h index 9679089cee9..c1dfbdc0b90 100644 --- a/engines/sword25/gfx/opengl/glimage.h +++ b/engines/sword25/gfx/opengl/glimage.h @@ -113,7 +113,7 @@ public: return true; } private: - GLS_Sprite m_Sprite; + byte *_data; int m_Width; int m_Height; }; diff --git a/engines/sword25/gfx/opengl/openglgfx.cpp b/engines/sword25/gfx/opengl/openglgfx.cpp index 6937efb8135..7e6ad4d3923 100644 --- a/engines/sword25/gfx/opengl/openglgfx.cpp +++ b/engines/sword25/gfx/opengl/openglgfx.cpp @@ -32,15 +32,6 @@ * */ -// ----------------------------------------------------------------------------- -// INCLUDES -// ----------------------------------------------------------------------------- - -#define WIN32_LEAN_AND_MEAN -#include -#include - -#include "sword25/util/glsprites/glsprites.h" #include "sword25/gfx/bitmapresource.h" #include "sword25/gfx/animationresource.h" #include "sword25/gfx/fontresource.h" @@ -125,13 +116,7 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount m_ScreenRect.right = m_Width; m_ScreenRect.bottom = m_Height; - // GLsprites initialisieren - HWND hwnd = reinterpret_cast(BS_Kernel::GetInstance()->GetWindow()->GetWindowHandle()); - GLS_Result Result = GLS_InitExternalWindow(Width, Height, Windowed ? GLS_False : GLS_True, hwnd); - if (Result != GLS_OK) { - BS_LOG_ERRORLN("Could not initialize GLsprites. Reason: %s", GLS_ResultString(Result)); - return false; - } + // We already iniitalized gfx after the engine creation m_GLspritesInitialized = true; // Standardmäßig ist Vsync an. @@ -158,13 +143,6 @@ bool BS_OpenGLGfx::StartFrame(bool UpdateAll) { // Den Layer-Manager auf den nächsten Frame vorbereiten m_RenderObjectManagerPtr->StartFrame(); - // GLsprites bescheidgeben - GLS_Result Result = GLS_StartFrame(); - if (Result != GLS_OK) { - BS_LOG_ERRORLN("Call to GLS_StartFrame() failed. Reason: %s", GLS_ResultString(Result)); - return false; - } - return true; } @@ -174,8 +152,11 @@ bool BS_OpenGLGfx::EndFrame() { // Scene zeichnen m_RenderObjectManagerPtr->Render(); + g_system->updateScreen(); + // Debug-Lines zeichnen if (!m_DebugLines.empty()) { +#if 0 glEnable(GL_LINE_SMOOTH); glBegin(GL_LINES); @@ -192,17 +173,13 @@ bool BS_OpenGLGfx::EndFrame() { glEnd(); glDisable(GL_LINE_SMOOTH); +#endif + + warning("STUB: Drawing debug lines"); m_DebugLines.clear(); } - // Flippen - GLS_Result Result = GLS_EndFrame(); - if (Result != GLS_OK) { - BS_LOG_ERRORLN("Call to GLS_EndFrame() failed. Reason: %s", GLS_ResultString(Result)); - return false; - } - // Framecounter aktualisieren m_FPSCounter.Update(); @@ -218,21 +195,15 @@ BS_RenderObjectPtr BS_OpenGLGfx::GetMainPanel() { // ----------------------------------------------------------------------------- void BS_OpenGLGfx::SetVsync(bool Vsync) { - GLS_Result Result = GLS_SetVSync(Vsync ? GLS_True : GLS_False); - if (Result != GLS_OK) BS_LOG_WARNINGLN("Could not set vsync status. Reason: %s", GLS_ResultString(Result)); + warning("STUB: SetVsync(%d)", Vsync); } // ----------------------------------------------------------------------------- bool BS_OpenGLGfx::GetVsync() const { - GLS_Bool Status; - GLS_Result Result = GLS_IsVsync(&Status); - if (Result != GLS_OK) { - BS_LOG_WARNINGLN("Could not get vsync status. Returning false. Reason: %s", GLS_ResultString(Result)); - return false; - } + warning("STUB: GetVsync()"); - return Status == GLS_True ? true : false; + return true; } // ----------------------------------------------------------------------------- @@ -248,16 +219,9 @@ bool BS_OpenGLGfx::Fill(const BS_Rect *FillRectPtr, unsigned int Color) { FillRectPtr = &Rect; } - glBegin(GL_QUADS); - glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24); + warning("STUB: Fill()"); - glVertex2i(FillRectPtr->left, FillRectPtr->top); - glVertex2i(FillRectPtr->right, FillRectPtr->top); - glVertex2i(FillRectPtr->right, FillRectPtr->bottom); - glVertex2i(FillRectPtr->left, FillRectPtr->bottom); - glEnd(); - - return glGetError() == 0; + return true; } // ----------------------------------------------------------------------------- @@ -281,13 +245,8 @@ bool BS_OpenGLGfx::GetScreenshot(unsigned int &Width, unsigned int &Height, byte bool BS_OpenGLGfx::ReadFramebufferContents(unsigned int Width, unsigned int Height, byte **Data) { *Data = (byte *)malloc(Width * Height * 4); - glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, *Data); - - if (glGetError() == 0) - return true; - else { - return false; - } + + return true; } // -----------------------------------------------------------------------------