SWORD25: Started rewriting gfx subsystem

svn-id: r53227
This commit is contained in:
Eugene Sandulenko 2010-08-13 15:24:23 +00:00
parent d50dcb80ad
commit fd40021a72
9 changed files with 28 additions and 92 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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.

View File

@ -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;

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}
// -----------------------------------------------------------------------------

View File

@ -113,7 +113,7 @@ public:
return true;
}
private:
GLS_Sprite m_Sprite;
byte *_data;
int m_Width;
int m_Height;
};

View File

@ -32,15 +32,6 @@
*
*/
// -----------------------------------------------------------------------------
// INCLUDES
// -----------------------------------------------------------------------------
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <GL/GL.h>
#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<HWND>(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_Panel> 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;
}
// -----------------------------------------------------------------------------