aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sword25/gfx/graphicengine.h4
-rw-r--r--engines/sword25/gfx/opengl/glimage.cpp105
-rw-r--r--engines/sword25/gfx/opengl/glimage.h4
-rw-r--r--engines/sword25/gfx/opengl/glvectorimageblit.cpp8
-rw-r--r--engines/sword25/gfx/opengl/openglgfx.cpp10
-rw-r--r--engines/sword25/gfx/opengl/openglgfx.h8
-rw-r--r--engines/sword25/gfx/opengl/swimage.cpp2
7 files changed, 94 insertions, 47 deletions
diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h
index 45603efb6e..225abcadf4 100644
--- a/engines/sword25/gfx/graphicengine.h
+++ b/engines/sword25/gfx/graphicengine.h
@@ -46,6 +46,7 @@
// Includes
#include "common/array.h"
#include "common/str.h"
+#include "graphics/surface.h"
#include "sword25/kernel/common.h"
#include "sword25/kernel/bs_stdint.h"
#include "sword25/kernel/resservice.h"
@@ -300,6 +301,9 @@ public:
return m_RepaintedPixels;
}
+ Graphics::Surface _backSurface;
+ Graphics::Surface *getSurface() { return &_backSurface; }
+
// Access methods
/**
diff --git a/engines/sword25/gfx/opengl/glimage.cpp b/engines/sword25/gfx/opengl/glimage.cpp
index 3ab20016de..0b0c2c1f7c 100644
--- a/engines/sword25/gfx/opengl/glimage.cpp
+++ b/engines/sword25/gfx/opengl/glimage.cpp
@@ -50,7 +50,7 @@ namespace Sword25 {
// -----------------------------------------------------------------------------
BS_GLImage::BS_GLImage(const Common::String &Filename, bool &Result) :
- m_Sprite(0),
+ _data(0),
m_Width(0),
m_Height(0) {
Result = false;
@@ -58,6 +58,8 @@ BS_GLImage::BS_GLImage(const Common::String &Filename, bool &Result) :
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"));
BS_ASSERT(pPackage);
+ _backSurface = (static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx")))->getSurface();
+
// Datei laden
char *pFileData;
unsigned int FileSize;
@@ -122,11 +124,13 @@ bool BS_GLImage::SetContent(const byte *Pixeldata, uint size, unsigned int Offse
return false;
}
- // GLS-Sprite mit den Bilddaten füllen
- GLS_Result GLSResult = GLS_SetSpriteData(m_Sprite, m_Width, m_Height, &Pixeldata[Offset], Stride / 4);
- if (GLSResult != GLS_OK) {
- BS_LOG_ERRORLN("CGLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(GLSResult));
- return false;
+ const byte *in = &Pixeldata[Offset];
+ byte *out = _data;
+
+ for (int i = 0; i < m_Height; i++) {
+ memcpy(out, in, m_Width * 4);
+ out += m_Width * 4;
+ in += Stride;
}
return true;
@@ -146,43 +150,78 @@ bool BS_GLImage::Blit(int PosX, int PosY,
BS_Rect *pPartRect,
unsigned int Color,
int Width, int Height) {
- // BS_Rect nach GLS_Rect konvertieren
- GLS_Rect SubImage;
+ int x1 = 0, y1 = 0;
+ int w = m_Width, h = m_Height;
if (pPartRect) {
- SubImage.x1 = pPartRect->left;
- SubImage.y1 = pPartRect->top;
- SubImage.x2 = pPartRect->right;
- SubImage.y2 = pPartRect->bottom;
+ x1 = pPartRect->left;
+ y1 = pPartRect->top;
+ w = pPartRect->right - pPartRect->left;
+ h = pPartRect->bottom - pPartRect->top;
}
- // Farbe nach GLS_Color konvertieren
- GLS_Color GLSColor;
- GLSColor.a = Color >> 24;
- GLSColor.r = (Color >> 16) & 0xff;
- GLSColor.g = (Color >> 8) & 0xff;
- GLSColor.b = Color & 0xff;
-
// Skalierungen berechnen
- GLS_Float ScaleX, ScaleY;
- if (Width == -1) Width = m_Width;
- ScaleX = (GLS_Float) Width / (GLS_Float) m_Width;
+ float ScaleX, ScaleY;
+ if (Width == -1)
+ Width = m_Width;
+ ScaleX = (float) Width / (float) m_Width;
+
+ if (Height == -1)
+ Height = m_Height;
+ ScaleY = (float) Height / (float) m_Height;
+
+ if (Color != 0xffffffff) {
+ warning("STUB: Image bg color: %x", Color);
+ }
+
+ if (ScaleX != 1.0 || ScaleY != 1.0) {
+ warning("STUB: Sprite scaling (%f x %f)", ScaleX, ScaleY);
+ }
+
+ if (Flipping & (BS_Image::FLIP_V | BS_Image::FLIP_H)) {
+ warning("STUB: Sprite flipping");
+ }
- if (Height == -1) Height = m_Height;
- ScaleY = (GLS_Float) Height / (GLS_Float) m_Height;
+ w = CLIP(x1 + w, 0, (int)_backSurface->w);
+ h = CLIP(y1 + h, 0, (int)_backSurface->h);
// Rendern
// TODO:
// Die Bedeutung von FLIP_V und FLIP_H ist vertauscht. Allerdings glaubt der Rest der Engine auch daran, daher war es einfacher diesen Fehler
// weiterzuführen. Bei Gelegenheit ist dieses aber zu ändern.
- GLS_Result Result = GLS_Blit(m_Sprite,
- PosX, PosY,
- pPartRect ? &SubImage : 0, &GLSColor,
- (Flipping & BS_Image::FLIP_V) ? GLS_True : GLS_False,
- (Flipping & BS_Image::FLIP_H) ? GLS_True : GLS_False,
- ScaleX, ScaleY);
- if (Result != GLS_OK) BS_LOG_ERRORLN("GLS_Blit() failed. Reason: %s", GLS_ResultString(Result));
-
- return Result == GLS_OK;
+
+ // TODO: scaling
+ // TODO: Flipping
+ byte *ino = &_data[y1 * m_Width * 4 + x1 * 4];
+ byte *outo = (byte *)_backSurface->getBasePtr(PosX, PosY);
+ byte *in, *out;
+ bool alphawarn = false;
+
+ for (int i = 0; i < h; i++) {
+ out = outo;
+ in = ino;
+ for (int j = 0; j < w; j++) {
+ if (*in == 0) {
+ in += 4;
+ out += 4;
+ continue;
+ }
+
+ if (*in != 255)
+ alphawarn = true;
+
+ *in++ = *out++; // TODO: alpha blending
+ *in++ = *out++;
+ *in++ = *out++;
+ *in++ = *out++;
+ }
+ outo += _backSurface->pitch;
+ ino += m_Width * 4;
+ }
+
+ if (alphawarn)
+ warning("STUB: alpha image");
+
+ return true;
}
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/opengl/glimage.h b/engines/sword25/gfx/opengl/glimage.h
index c1dfbdc0b9..678a40aff4 100644
--- a/engines/sword25/gfx/opengl/glimage.h
+++ b/engines/sword25/gfx/opengl/glimage.h
@@ -43,8 +43,6 @@
#include "sword25/gfx/image/image.h"
#include "sword25/gfx/graphicengine.h"
-#include <vector>
-
namespace Sword25 {
// -----------------------------------------------------------------------------
@@ -116,6 +114,8 @@ private:
byte *_data;
int m_Width;
int m_Height;
+
+ Graphics::Surface *_backSurface;
};
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/opengl/glvectorimageblit.cpp b/engines/sword25/gfx/opengl/glvectorimageblit.cpp
index 5689fdfcba..35b6c2ba5f 100644
--- a/engines/sword25/gfx/opengl/glvectorimageblit.cpp
+++ b/engines/sword25/gfx/opengl/glvectorimageblit.cpp
@@ -61,6 +61,7 @@ bool BS_VectorImage::Blit(int PosX, int PosY,
BS_Rect *pPartRect,
unsigned int Color,
int Width, int Height) {
+#if 0
static BS_VectorImageRenderer VectorImageRenderer;
static byte *PixelData;
static GLS_Sprite Sprite = 0;
@@ -138,8 +139,13 @@ bool BS_VectorImage::Blit(int PosX, int PosY,
(Flipping & BS_Image::FLIP_H) ? GLS_True : GLS_False,
1.0f, 1.0f);
if (Result != GLS_OK) BS_LOG_ERRORLN("GLS_Blit() failed. Reason: %s", GLS_ResultString(Result));
+#else
+ warning("STUB: BS_VectorImage::Blit()");
- return Result == GLS_OK;
+ return true;
+#endif
+
+ return true;
}
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/opengl/openglgfx.cpp b/engines/sword25/gfx/opengl/openglgfx.cpp
index 7e6ad4d392..30263d7b1d 100644
--- a/engines/sword25/gfx/opengl/openglgfx.cpp
+++ b/engines/sword25/gfx/opengl/openglgfx.cpp
@@ -32,6 +32,8 @@
*
*/
+#include "common/system.h"
+
#include "sword25/gfx/bitmapresource.h"
#include "sword25/gfx/animationresource.h"
#include "sword25/gfx/fontresource.h"
@@ -56,8 +58,8 @@ namespace Sword25 {
// -----------------------------------------------------------------------------
namespace {
-const unsigned int BIT_DEPTH = 32;
-const unsigned int BACKBUFFER_COUNT = 1;
+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");
@@ -79,7 +81,7 @@ BS_OpenGLGfx::BS_OpenGLGfx(BS_Kernel *pKernel) :
// -----------------------------------------------------------------------------
BS_OpenGLGfx::~BS_OpenGLGfx() {
- if (m_GLspritesInitialized) GLS_Quit();
+ _backSurface.free();
}
// -----------------------------------------------------------------------------
@@ -116,6 +118,8 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount
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;
diff --git a/engines/sword25/gfx/opengl/openglgfx.h b/engines/sword25/gfx/opengl/openglgfx.h
index ae56ff7fe3..b62ecf960d 100644
--- a/engines/sword25/gfx/opengl/openglgfx.h
+++ b/engines/sword25/gfx/opengl/openglgfx.h
@@ -39,15 +39,9 @@
// INCLUDES
// -----------------------------------------------------------------------------
-#include "sword25/kernel/memlog_off.h"
-#include <memory>
-#include <vector>
-#include "sword25/kernel/memlog_on.h"
-
#include "sword25/kernel/common.h"
#include "sword25/gfx/graphicengine.h"
#include "sword25/gfx/renderobjectptr.h"
-#include "sword25/util/glsprites/glsprites.h"
namespace Sword25 {
@@ -94,7 +88,6 @@ public:
// Debugging Methoden
// ------------------
virtual void DrawDebugLine(const BS_Vertex &Start, const BS_Vertex &End, unsigned int Color);
- static const char *GetGLSResultString(GLS_Result Result);
// Persistenz Methoden
// -------------------
@@ -103,6 +96,7 @@ public:
private:
bool m_GLspritesInitialized;
+ byte *_backBuffer;
BS_RenderObjectPtr<BS_Panel> m_MainPanelPtr;
diff --git a/engines/sword25/gfx/opengl/swimage.cpp b/engines/sword25/gfx/opengl/swimage.cpp
index f3aa9c1533..6fff44a75c 100644
--- a/engines/sword25/gfx/opengl/swimage.cpp
+++ b/engines/sword25/gfx/opengl/swimage.cpp
@@ -76,7 +76,7 @@ BS_SWImage::BS_SWImage(const Common::String &Filename, bool &Result) :
}
// Das Bild dekomprimieren
- char *pUncompressedData;
+ byte *pUncompressedData;
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch)) {
BS_LOG_ERRORLN("Could not decode image.");
return;