aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/gfx/opengl
diff options
context:
space:
mode:
authorEugene Sandulenko2010-09-03 23:02:00 +0000
committerEugene Sandulenko2010-10-12 23:34:25 +0000
commit7032c209a7e8bbd77bc7638f1a173a992bdb5e81 (patch)
tree7657c701d1edd8e218f233546f8ed4cac950e079 /engines/sword25/gfx/opengl
parent5f83fd19540c3072f50edff0acddf1cb6a072b78 (diff)
downloadscummvm-rg350-7032c209a7e8bbd77bc7638f1a173a992bdb5e81.tar.gz
scummvm-rg350-7032c209a7e8bbd77bc7638f1a173a992bdb5e81.tar.bz2
scummvm-rg350-7032c209a7e8bbd77bc7638f1a173a992bdb5e81.zip
SWORD25: Initial code for vector image rendering. Crashes badly.
svn-id: r53314
Diffstat (limited to 'engines/sword25/gfx/opengl')
-rw-r--r--engines/sword25/gfx/opengl/glimage.cpp21
-rw-r--r--engines/sword25/gfx/opengl/glimage.h4
-rw-r--r--engines/sword25/gfx/opengl/glvectorimageblit.cpp146
3 files changed, 23 insertions, 148 deletions
diff --git a/engines/sword25/gfx/opengl/glimage.cpp b/engines/sword25/gfx/opengl/glimage.cpp
index bccd18660d..cf8b294ea7 100644
--- a/engines/sword25/gfx/opengl/glimage.cpp
+++ b/engines/sword25/gfx/opengl/glimage.cpp
@@ -87,6 +87,8 @@ GLImage::GLImage(const Common::String &filename, bool &result) :
// Dateidaten freigeben
delete[] pFileData;
+ _doCleanup = true;
+
result = true;
return;
}
@@ -96,20 +98,30 @@ GLImage::GLImage(const Common::String &filename, bool &result) :
GLImage::GLImage(uint width, uint height, bool &result) :
_width(width),
_height(height) {
- result = false;
_data = new byte[width * height * 4];
_backSurface = (static_cast<GraphicEngine *>(Kernel::GetInstance()->GetService("gfx")))->getSurface();
+ _doCleanup = true;
+
result = true;
return;
}
+GLImage::GLImage() : _width(0), _height(0), _data(0) {
+ _backSurface = (static_cast<GraphicEngine *>(Kernel::GetInstance()->GetService("gfx")))->getSurface();
+
+ _doCleanup = false;
+
+ return;
+}
+
// -----------------------------------------------------------------------------
GLImage::~GLImage() {
- delete[] _data;
+ if (_doCleanup)
+ delete[] _data;
}
// -----------------------------------------------------------------------------
@@ -140,6 +152,11 @@ bool GLImage::setContent(const byte *pixeldata, uint size, uint offset, uint str
return true;
}
+void GLImage::replaceContent(byte *pixeldata, int width, int height) {
+ _width = width;
+ _height = height;
+ _data = pixeldata;
+}
// -----------------------------------------------------------------------------
uint GLImage::getPixel(int x, int y) {
diff --git a/engines/sword25/gfx/opengl/glimage.h b/engines/sword25/gfx/opengl/glimage.h
index 5f019d2bc0..bcc6bf8e20 100644
--- a/engines/sword25/gfx/opengl/glimage.h
+++ b/engines/sword25/gfx/opengl/glimage.h
@@ -68,6 +68,8 @@ public:
dürfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerstören.
*/
GLImage(uint width, uint height, bool &result);
+ GLImage();
+
virtual ~GLImage();
virtual int getWidth() const {
@@ -87,6 +89,7 @@ public:
int width = -1, int height = -1);
virtual bool fill(const Common::Rect *pFillRect, uint color);
virtual bool setContent(const byte *pixeldata, uint size, uint offset = 0, uint stride = 0);
+ void replaceContent(byte *pixeldata, int width, int height);
virtual uint getPixel(int x, int y);
virtual bool isBlitSource() const {
@@ -114,6 +117,7 @@ private:
byte *_data;
int _width;
int _height;
+ bool _doCleanup;
Graphics::Surface *_backSurface;
};
diff --git a/engines/sword25/gfx/opengl/glvectorimageblit.cpp b/engines/sword25/gfx/opengl/glvectorimageblit.cpp
deleted file mode 100644
index 664d9c16b0..0000000000
--- a/engines/sword25/gfx/opengl/glvectorimageblit.cpp
+++ /dev/null
@@ -1,146 +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
- *
- */
-
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
-
-#include "sword25/gfx/image/vectorimage.h"
-#include "sword25/gfx/image/vectorimagerenderer.h"
-
-namespace Sword25 {
-
-#define BS_LOG_PREFIX "GLVECTORIMAGEBLIT"
-
-// -----------------------------------------------------------------------------
-
-namespace {
-const float LINE_SCALE_FACTOR = 1.0f;
-}
-
-// -----------------------------------------------------------------------------
-
-bool VectorImage::blit(int PosX, int PosY,
- int Flipping,
- Common::Rect *pPartRect,
- uint Color,
- int Width, int Height) {
-#if 0
- static BS_VectorImageRenderer VectorImageRenderer;
- static byte *PixelData;
- static GLS_Sprite Sprite = 0;
- static BS_VectorImage *OldThis = 0;
- static int OldWidth;
- static int OldHeight;
- static GLS_Rect OldSubImage;
-
- // Falls Breite oder Höhe 0 sind, muss nichts dargestellt werden.
- if (Width == 0 || Height == 0) return true;
-
- // Sprite erstellen, falls es noch nicht erstellt wurde
- if (Sprite == 0) {
- GLS_Result Result = GLS_NewSprite(512, 512, GLS_True, 0, &Sprite);
- if (Result != GLS_OK) {
- BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(Result));
- return false;
- }
- }
-
- // Feststellen, ob das alte Bild im Cache nicht wiederbenutzt werden kann und neu Berechnet werden muss
- if (!(OldThis == this && OldWidth == Width && OldHeight == Height && Sprite != 0)) {
- float ScaleFactorX = (Width == - 1) ? 1 : static_cast<float>(Width) / static_cast<float>(GetWidth());
- float ScaleFactorY = (Height == - 1) ? 1 : static_cast<float>(Height) / static_cast<float>(GetHeight());
-
- uint RenderedWidth;
- uint RenderedHeight;
- if (!VectorImageRenderer.Render(*this, ScaleFactorX, ScaleFactorY, RenderedWidth, RenderedHeight, PixelData, LINE_SCALE_FACTOR)) {
- BS_LOG_ERRORLN("Call to BS_VectorImageRenderer::Render() failed.");
- return false;
- }
-
- if (RenderedWidth > 512 || RenderedHeight > 512) {
- BS_LOG_WARNINGLN("Currently the maximum size for scaled vector images is 512x512.");
- return true;
- }
-
- GLS_Result Result = GLS_SetSpriteData(Sprite, RenderedWidth, RenderedHeight, PixelData, 0);
- if (Result != GLS_OK) {
- BS_LOG_ERRORLN("Call to GLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(Result));
- return false;
- }
-
- OldThis = this;
- OldHeight = Height;
- OldWidth = Width;
-
- OldSubImage.x1 = 0;
- OldSubImage.y1 = 0;
- OldSubImage.x2 = RenderedWidth;
- OldSubImage.y2 = RenderedHeight;
- }
-
- // Rendern
- // -------
-
- // pDest wird ignoriert. Es wird einfach angenommen, dass der Backbuffer gemeint ist, da nur auf den Backbuffer gerendert werden kann.
- // Ebenso werden pPartRect ignoriert. Es wird immer das gesamte Sprite gerendert.
-
- // 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;
-
- // 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(Sprite,
- PosX, PosY,
- &OldSubImage, &GLSColor,
- (Flipping & BS_Image::FLIP_V) ? GLS_True : GLS_False,
- (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 true;
-#endif
-
- return true;
-}
-
-} // End of namespace Sword25