mirror of
https://github.com/libretro/scummvm.git
synced 2025-05-13 09:36:21 +00:00
STARK: Refactor texture handling
This commit is contained in:
parent
413ee2a75d
commit
dd82239ca1
@ -24,7 +24,7 @@
|
||||
|
||||
#include "engines/stark/services/archiveloader.h"
|
||||
#include "engines/stark/skeleton.h"
|
||||
#include "engines/stark/texture.h"
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
|
||||
#include "common/stream.h"
|
||||
|
||||
@ -32,7 +32,7 @@ namespace Stark {
|
||||
|
||||
Actor::Actor() :
|
||||
_skeleton(nullptr),
|
||||
_texture(nullptr),
|
||||
_textureSet(nullptr),
|
||||
_u1(0),
|
||||
_facingDirection(0.0) {
|
||||
|
||||
@ -142,8 +142,8 @@ void Actor::setAnim(SkeletonAnim *anim)
|
||||
_skeleton->setAnim(anim);
|
||||
}
|
||||
|
||||
void Actor::setTexture(Texture *texture) {
|
||||
_texture = texture;
|
||||
void Actor::setTextureSet(Gfx::TextureSet *texture) {
|
||||
_textureSet = texture;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
|
@ -30,10 +30,14 @@
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class TextureSet;
|
||||
}
|
||||
|
||||
class ArchiveReadStream;
|
||||
class Skeleton;
|
||||
class SkeletonAnim;
|
||||
class Texture;
|
||||
|
||||
|
||||
class VertNode {
|
||||
public:
|
||||
@ -113,7 +117,7 @@ public:
|
||||
const Common::Array<MeshNode *> &getMeshes() const { return _meshes; }
|
||||
const Common::Array<MaterialNode *> &getMaterials() const { return _materials; }
|
||||
Skeleton *getSkeleton() const { return _skeleton; }
|
||||
const Texture *getTexture() const { return _texture; }
|
||||
const Gfx::TextureSet *getTextureSet() const { return _textureSet; }
|
||||
float getFacingDirection() const { return _facingDirection; }
|
||||
|
||||
/**
|
||||
@ -124,7 +128,7 @@ public:
|
||||
/**
|
||||
* Load texture data from the specified stream
|
||||
*/
|
||||
void setTexture(Texture *texture);
|
||||
void setTextureSet(Gfx::TextureSet *textureSet);
|
||||
|
||||
private:
|
||||
uint32 _u1;
|
||||
@ -133,7 +137,7 @@ private:
|
||||
Common::Array<MaterialNode *> _materials;
|
||||
Common::Array<MeshNode *> _meshes;
|
||||
Skeleton *_skeleton;
|
||||
Texture *_texture;
|
||||
Gfx::TextureSet *_textureSet;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
@ -20,28 +20,31 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/stark/texture.h"
|
||||
#include "engines/stark/formats/tm.h"
|
||||
|
||||
#include "common/stream.h"
|
||||
#include "common/str.h"
|
||||
|
||||
#include <SDL_opengl.h> // HACK: I just want to see something - ideally we get _gfx from _scene
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
|
||||
namespace Stark {
|
||||
namespace Formats {
|
||||
|
||||
Texture::Texture() : _palette(NULL) {
|
||||
|
||||
TextureSetReader::TextureSetReader(GfxDriver *driver) :
|
||||
_palette(nullptr),
|
||||
_driver(driver) {
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
if (_palette)
|
||||
delete[] _palette;
|
||||
|
||||
for (Common::HashMap<Common::String, uint32>::iterator it = _texMap.begin(); it != _texMap.end(); ++it)
|
||||
glDeleteTextures(1, &it->_value);
|
||||
TextureSetReader::~TextureSetReader() {
|
||||
delete[] _palette;
|
||||
}
|
||||
|
||||
void Texture::createFromStream(Common::ReadStream *stream) {
|
||||
Gfx::TextureSet *TextureSetReader::read(Common::ReadStream *stream) {
|
||||
Gfx::TextureSet *textureSet = new Gfx::TextureSet();
|
||||
|
||||
uint32 id = stream->readUint32LE();
|
||||
uint32 format = stream->readUint32LE();
|
||||
uint32 u1 = stream->readUint32LE();
|
||||
@ -49,11 +52,13 @@ void Texture::createFromStream(Common::ReadStream *stream) {
|
||||
|
||||
uint32 len = stream->readUint32LE();
|
||||
for (uint32 i = 0; i < len; ++i) {
|
||||
readChunk(stream, format);
|
||||
readChunk(stream, format, textureSet);
|
||||
}
|
||||
|
||||
return textureSet;
|
||||
}
|
||||
|
||||
void Texture::readChunk(Common::ReadStream *stream, uint32 format) {
|
||||
void TextureSetReader::readChunk(Common::ReadStream *stream, uint32 format, Gfx::TextureSet *textureSet) {
|
||||
uint32 marker = stream->readUint32LE();
|
||||
if (marker != 0xf0f0f0f0) {
|
||||
error("Wrong magic while reading texture");
|
||||
@ -69,17 +74,15 @@ void Texture::readChunk(Common::ReadStream *stream, uint32 format) {
|
||||
|
||||
if (type == 0x02faf082) {
|
||||
// Palette
|
||||
if (_palette)
|
||||
delete[] _palette;
|
||||
delete[] _palette;
|
||||
|
||||
int entries = stream->readUint32LE();
|
||||
_palette = new uint32[entries * 3];
|
||||
byte *ptr = (byte *)_palette;
|
||||
_palette = new byte[entries * 3];
|
||||
byte *ptr = _palette;
|
||||
for (int i = 0; i < entries; ++i) {
|
||||
*ptr++ = (byte)stream->readUint16LE();
|
||||
*ptr++ = (byte)stream->readUint16LE();
|
||||
*ptr++ = (byte)stream->readUint16LE();
|
||||
*ptr++ = 0xff;
|
||||
}
|
||||
} else if (type == 0x02faf080) {
|
||||
// Img
|
||||
@ -90,38 +93,30 @@ void Texture::readChunk(Common::ReadStream *stream, uint32 format) {
|
||||
delete[] name;
|
||||
byte u = stream->readByte();
|
||||
|
||||
uint32 texIdx;
|
||||
glGenTextures(1, &texIdx);
|
||||
_texMap.setVal(nameStr, texIdx);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texIdx);
|
||||
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
Gfx::MipMapTexture *texture = _driver->createMipMapTexture();
|
||||
|
||||
uint32 w = stream->readUint32LE();
|
||||
uint32 h = stream->readUint32LE();
|
||||
int levels = stream->readUint32LE();
|
||||
for (int i = 0; i < levels; ++i) {
|
||||
uint32 *img = new uint32[w * h];
|
||||
uint32 levels = stream->readUint32LE();
|
||||
|
||||
for (uint32 j = 0; j < w * h; ++j)
|
||||
img[j] = _palette[stream->readByte()];
|
||||
texture->setLevelCount(levels);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img);
|
||||
for (uint32 i = 0; i < levels; ++i) {
|
||||
// Read the pixel data to a surface
|
||||
Graphics::Surface level;
|
||||
level.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
|
||||
stream->read(level.getPixels(), level.w * level.h);
|
||||
|
||||
delete[] img;
|
||||
// Add the mipmap level to the texture
|
||||
texture->addLevel(i, &level, _palette);
|
||||
|
||||
level.free();
|
||||
|
||||
w /= 2;
|
||||
h /= 2;
|
||||
}
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
||||
|
||||
textureSet->addTexture(nameStr, texture);
|
||||
} else {
|
||||
byte *data = new byte[size];
|
||||
stream->read(data, size);
|
||||
@ -135,16 +130,9 @@ void Texture::readChunk(Common::ReadStream *stream, uint32 format) {
|
||||
|
||||
uint32 len = stream->readUint32LE();
|
||||
for (uint32 i = 0; i < len; ++i) {
|
||||
readChunk(stream, format);
|
||||
readChunk(stream, format, textureSet);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 Texture::getTexture(Common::String name) const {
|
||||
Common::HashMap<Common::String, uint32>::const_iterator it = _texMap.find(name);
|
||||
if (it != _texMap.end())
|
||||
return it->_value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // End of namespace Formats
|
||||
} // End of namespace Stark
|
@ -20,10 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STARK_TEXTURE_H
|
||||
#define STARK_TEXTURE_H
|
||||
#ifndef STARK_FORMATS_TM_H
|
||||
#define STARK_FORMATS_TM_H
|
||||
|
||||
#include "common/hash-str.h"
|
||||
#include "common/scummsys.h"
|
||||
|
||||
namespace Common {
|
||||
class ReadStream;
|
||||
@ -31,26 +31,37 @@ namespace Common {
|
||||
|
||||
namespace Stark {
|
||||
|
||||
class GfxDriver;
|
||||
|
||||
namespace Gfx {
|
||||
class TextureSet;
|
||||
}
|
||||
|
||||
namespace Formats {
|
||||
|
||||
/**
|
||||
* Texture manager to load and store actor textures
|
||||
* A texture set loader able to read '.tm' files
|
||||
*/
|
||||
class Texture {
|
||||
class TextureSetReader {
|
||||
public:
|
||||
Texture();
|
||||
~Texture();
|
||||
TextureSetReader(GfxDriver *driver);
|
||||
~TextureSetReader();
|
||||
|
||||
void createFromStream(Common::ReadStream *stream);
|
||||
|
||||
uint32 getTexture(Common::String name) const;
|
||||
/**
|
||||
* Load a texture set from the provided stream.
|
||||
*
|
||||
* The caller is responsible for freeing the texture set.
|
||||
*/
|
||||
Gfx::TextureSet *read(Common::ReadStream *stream);
|
||||
|
||||
private:
|
||||
void readChunk(Common::ReadStream *stream, uint32 format);
|
||||
void readChunk(Common::ReadStream *stream, uint32 format, Gfx::TextureSet *textureSet);
|
||||
|
||||
uint32 *_palette;
|
||||
|
||||
Common::HashMap<Common::String, uint32> _texMap;
|
||||
byte *_palette;
|
||||
GfxDriver *_driver;
|
||||
};
|
||||
|
||||
} // End of namespace Formats
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_TEXTURE_H
|
||||
#endif // STARK_FORMATS_TM_H
|
@ -33,6 +33,11 @@
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Texture;
|
||||
class MipMapTexture;
|
||||
}
|
||||
|
||||
class GfxDriver {
|
||||
public:
|
||||
static GfxDriver *create();
|
||||
@ -50,6 +55,13 @@ public:
|
||||
virtual void clearScreen() = 0;
|
||||
virtual void flipBuffer() = 0;
|
||||
|
||||
/**
|
||||
* Create a new mipmap texture.
|
||||
*
|
||||
* The caller is responsible for freeing it.
|
||||
*/
|
||||
virtual Gfx::MipMapTexture *createMipMapTexture() = 0;
|
||||
|
||||
virtual void drawSurface(const Graphics::Surface *surface, Common::Point dest = Common::Point(), Common::Rect rect = Common::Rect()) = 0;
|
||||
|
||||
virtual void set3DMode() = 0;
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
#include "math/matrix4.h"
|
||||
|
||||
#include "engines/stark/gfx/opengltexture.h"
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
|
||||
#ifdef SDL_BACKEND
|
||||
@ -84,6 +86,10 @@ void OpenGLGfxDriver::flipBuffer() {
|
||||
g_system->updateScreen();
|
||||
}
|
||||
|
||||
Gfx::MipMapTexture *OpenGLGfxDriver::createMipMapTexture() {
|
||||
return new Gfx::OpenGlMipMapTexture();
|
||||
}
|
||||
|
||||
void OpenGLGfxDriver::drawSurface(const Graphics::Surface *surface, Common::Point dest, Common::Rect rect) {
|
||||
// Draw the whole surface by default
|
||||
if (rect.isEmpty())
|
||||
|
@ -50,6 +50,8 @@ public:
|
||||
void clearScreen();
|
||||
void flipBuffer();
|
||||
|
||||
Gfx::MipMapTexture *createMipMapTexture() override;
|
||||
|
||||
void drawSurface(const Graphics::Surface *surface, Common::Point dest, Common::Rect rect);
|
||||
|
||||
void set3DMode();
|
||||
|
90
engines/stark/gfx/opengltexture.cpp
Normal file
90
engines/stark/gfx/opengltexture.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the AUTHORS
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/stark/gfx/opengltexture.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
namespace Stark {
|
||||
namespace Gfx {
|
||||
|
||||
OpenGlTexture::OpenGlTexture() :
|
||||
Texture(),
|
||||
_id(0) {
|
||||
glGenTextures(1, &_id);
|
||||
}
|
||||
|
||||
OpenGlTexture::~OpenGlTexture() {
|
||||
glDeleteTextures(1, &_id);
|
||||
}
|
||||
|
||||
void OpenGlTexture::bind() const {
|
||||
glBindTexture(GL_TEXTURE_2D, _id);
|
||||
}
|
||||
|
||||
OpenGlMipMapTexture::OpenGlMipMapTexture() :
|
||||
OpenGlTexture(),
|
||||
MipMapTexture(),
|
||||
_levelCount(0) {
|
||||
|
||||
bind();
|
||||
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
OpenGlMipMapTexture::~OpenGlMipMapTexture() {
|
||||
}
|
||||
|
||||
void OpenGlMipMapTexture::setLevelCount(uint32 count) {
|
||||
_levelCount = count;
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, count - 1);
|
||||
}
|
||||
|
||||
void OpenGlMipMapTexture::addLevel(uint32 level, const Graphics::Surface *surface, const byte *palette) {
|
||||
assert(level < _levelCount);
|
||||
|
||||
if (surface->format.bytesPerPixel != 4) {
|
||||
// Convert the surface to texture format
|
||||
Graphics::Surface *convertedSurface = surface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), palette);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, convertedSurface->w, convertedSurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, convertedSurface->getPixels());
|
||||
|
||||
convertedSurface->free();
|
||||
delete convertedSurface;
|
||||
} else {
|
||||
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->getPixels());
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGlMipMapTexture::bind() const {
|
||||
OpenGlTexture::bind();
|
||||
}
|
||||
|
||||
} // End of namespace Gfx
|
||||
} // End of namespace Stark
|
68
engines/stark/gfx/opengltexture.h
Normal file
68
engines/stark/gfx/opengltexture.h
Normal file
@ -0,0 +1,68 @@
|
||||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the AUTHORS
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STARK_GFX_OPENGL_TEXTURE_H
|
||||
#define STARK_GFX_OPENGL_TEXTURE_H
|
||||
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
|
||||
namespace Stark {
|
||||
namespace Gfx {
|
||||
|
||||
/**
|
||||
* An OpenGL texture wrapper
|
||||
*/
|
||||
class OpenGlTexture : public Texture {
|
||||
public:
|
||||
OpenGlTexture();
|
||||
virtual ~OpenGlTexture();
|
||||
|
||||
// Texture API
|
||||
void bind() const override;
|
||||
|
||||
protected:
|
||||
uint32 _id;
|
||||
};
|
||||
|
||||
/**
|
||||
* An OpenGL MipMap texture wrapper
|
||||
*/
|
||||
class OpenGlMipMapTexture : public MipMapTexture, public OpenGlTexture {
|
||||
public:
|
||||
OpenGlMipMapTexture();
|
||||
virtual ~OpenGlMipMapTexture();
|
||||
|
||||
// Texture API
|
||||
void bind() const override;
|
||||
|
||||
// MipMapTexture API
|
||||
void setLevelCount(uint32 count) override;
|
||||
void addLevel(uint32 level, const Graphics::Surface *surface, const byte *palette = nullptr) override;
|
||||
|
||||
protected:
|
||||
uint32 _levelCount;
|
||||
};
|
||||
|
||||
} // End of namespace Gfx
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_GFX_OPENGL_TEXTURE_H
|
62
engines/stark/gfx/texture.cpp
Normal file
62
engines/stark/gfx/texture.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the AUTHORS
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
|
||||
namespace Stark {
|
||||
namespace Gfx {
|
||||
|
||||
Texture::~Texture() {
|
||||
}
|
||||
|
||||
MipMapTexture::~MipMapTexture() {
|
||||
}
|
||||
|
||||
TextureSet::TextureSet() {
|
||||
}
|
||||
|
||||
TextureSet::~TextureSet() {
|
||||
for (TextureMap::iterator it = _texMap.begin(); it != _texMap.end(); ++it) {
|
||||
delete it->_value;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureSet::addTexture(const Common::String &name, Texture *texture) {
|
||||
if (_texMap.contains(name)) {
|
||||
error("A texture with the name '%s' already exists in the set.", name.c_str());
|
||||
}
|
||||
|
||||
_texMap.setVal(name, texture);
|
||||
}
|
||||
|
||||
const Texture *TextureSet::getTexture(const Common::String &name) const {
|
||||
TextureMap::const_iterator it = _texMap.find(name);
|
||||
if (it != _texMap.end())
|
||||
return it->_value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // End of namespace Gfx
|
||||
} // End of namespace Stark
|
93
engines/stark/gfx/texture.h
Normal file
93
engines/stark/gfx/texture.h
Normal file
@ -0,0 +1,93 @@
|
||||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the AUTHORS
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STARK_GFX_TEXTURE_H
|
||||
#define STARK_GFX_TEXTURE_H
|
||||
|
||||
#include "common/hash-str.h"
|
||||
|
||||
namespace Graphics {
|
||||
class Surface;
|
||||
}
|
||||
|
||||
namespace Stark {
|
||||
namespace Gfx {
|
||||
|
||||
/**
|
||||
* An abstract texture
|
||||
*/
|
||||
class Texture {
|
||||
public:
|
||||
virtual ~Texture();
|
||||
|
||||
/** Make the texture active */
|
||||
virtual void bind() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* An abstract texture with manual mipmap levels support
|
||||
*/
|
||||
class MipMapTexture : public Texture {
|
||||
public:
|
||||
virtual ~MipMapTexture();
|
||||
|
||||
/**
|
||||
* Define the total number of levels
|
||||
*
|
||||
* Must be called before adding any level
|
||||
*/
|
||||
virtual void setLevelCount(uint32 count) = 0;
|
||||
|
||||
/**
|
||||
* Add a detail level to the texture
|
||||
*/
|
||||
virtual void addLevel(uint32 level, const Graphics::Surface *surface, const byte *palette = nullptr) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* A collection of textures referenced by their names
|
||||
*/
|
||||
class TextureSet {
|
||||
public:
|
||||
TextureSet();
|
||||
~TextureSet();
|
||||
|
||||
/**
|
||||
* Add a texture to the set
|
||||
*/
|
||||
void addTexture(const Common::String &name, Texture *texture);
|
||||
|
||||
/**
|
||||
* Retrieve a texture from the set
|
||||
*/
|
||||
const Texture *getTexture(const Common::String &name) const;
|
||||
|
||||
private:
|
||||
typedef Common::HashMap<Common::String, Texture *> TextureMap;
|
||||
|
||||
TextureMap _texMap;
|
||||
};
|
||||
|
||||
} // End of namespace Gfx
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_GFX_TEXTURE_H
|
@ -7,8 +7,11 @@ MODULE_OBJS := \
|
||||
gfx/coordinate.o \
|
||||
gfx/driver.o \
|
||||
gfx/opengl.o \
|
||||
gfx/opengltexture.o \
|
||||
gfx/renderentry.o \
|
||||
gfx/texture.o \
|
||||
formats/iss.o \
|
||||
formats/tm.o \
|
||||
formats/xarc.o \
|
||||
formats/xmg.o \
|
||||
formats/xrc.o \
|
||||
@ -49,7 +52,6 @@ MODULE_OBJS := \
|
||||
skeleton.o \
|
||||
skeleton_anim.o \
|
||||
stark.o \
|
||||
texture.o \
|
||||
visual/actor.o \
|
||||
visual/image.o \
|
||||
visual/smacker.o
|
||||
|
@ -22,26 +22,27 @@
|
||||
|
||||
#include "engines/stark/resources/textureset.h"
|
||||
|
||||
#include "engines/stark/formats/tm.h"
|
||||
#include "engines/stark/formats/xrc.h"
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
#include "engines/stark/services/archiveloader.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
#include "engines/stark/texture.h"
|
||||
|
||||
namespace Stark {
|
||||
namespace Resources {
|
||||
|
||||
TextureSet::~TextureSet() {
|
||||
delete _texture;
|
||||
delete _textureSet;
|
||||
}
|
||||
|
||||
TextureSet::TextureSet(Object *parent, byte subType, uint16 index, const Common::String &name) :
|
||||
Object(parent, subType, index, name),
|
||||
_texture(nullptr) {
|
||||
_textureSet(nullptr) {
|
||||
_type = TYPE;
|
||||
}
|
||||
|
||||
Texture *TextureSet::getTexture() {
|
||||
return _texture;
|
||||
Gfx::TextureSet *TextureSet::getTexture() {
|
||||
return _textureSet;
|
||||
}
|
||||
|
||||
void TextureSet::readData(Formats::XRCReadStream *stream) {
|
||||
@ -50,14 +51,17 @@ void TextureSet::readData(Formats::XRCReadStream *stream) {
|
||||
}
|
||||
|
||||
void TextureSet::onPostRead() {
|
||||
// Get the archive loader service
|
||||
// Get the required services
|
||||
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader;
|
||||
GfxDriver *gfxDriver = StarkServices::instance().gfx;
|
||||
|
||||
Common::ReadStream *stream = archiveLoader->getFile(_filename, _archiveName);
|
||||
|
||||
_texture = new Texture();
|
||||
_texture->createFromStream(stream);
|
||||
Formats::TextureSetReader *reader = new Formats::TextureSetReader(gfxDriver);
|
||||
|
||||
_textureSet = reader->read(stream);
|
||||
|
||||
delete reader;
|
||||
delete stream;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,10 @@
|
||||
|
||||
namespace Stark {
|
||||
|
||||
class Texture;
|
||||
namespace Gfx {
|
||||
class TextureSet;
|
||||
}
|
||||
|
||||
namespace Formats {
|
||||
class XRCReadStream;
|
||||
}
|
||||
@ -58,7 +61,7 @@ public:
|
||||
void onPostRead() override;
|
||||
|
||||
/** Obtain the texture to be rendered */
|
||||
Texture *getTexture();
|
||||
Gfx::TextureSet *getTexture();
|
||||
|
||||
protected:
|
||||
void printData() override;
|
||||
@ -66,7 +69,7 @@ protected:
|
||||
Common::String _filename;
|
||||
Common::String _archiveName;
|
||||
|
||||
Texture *_texture;
|
||||
Gfx::TextureSet *_textureSet;
|
||||
};
|
||||
|
||||
} // End of namespace Resources
|
||||
|
@ -33,6 +33,7 @@ namespace Stark {
|
||||
|
||||
class ArchiveLoader;
|
||||
class DialogPlayer;
|
||||
class GfxDriver;
|
||||
class Global;
|
||||
class ResourceProvider;
|
||||
class Scene;
|
||||
@ -46,6 +47,7 @@ public:
|
||||
StarkServices() {
|
||||
archiveLoader = nullptr;
|
||||
dialogPlayer = nullptr;
|
||||
gfx = nullptr;
|
||||
global = nullptr;
|
||||
resourceProvider = nullptr;
|
||||
randomSource = nullptr;
|
||||
@ -55,6 +57,7 @@ public:
|
||||
|
||||
ArchiveLoader *archiveLoader;
|
||||
DialogPlayer *dialogPlayer;
|
||||
GfxDriver *gfx;
|
||||
Global *global;
|
||||
ResourceProvider *resourceProvider;
|
||||
Common::RandomSource *randomSource;
|
||||
|
@ -106,6 +106,7 @@ Common::Error StarkEngine::run() {
|
||||
StarkServices &services = StarkServices::instance();
|
||||
services.archiveLoader = _archiveLoader;
|
||||
services.dialogPlayer = _dialogPlayer;
|
||||
services.gfx = _gfx;
|
||||
services.global = _global;
|
||||
services.resourceProvider = _resourceProvider;
|
||||
services.randomSource = _randomSource;
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
#include "engines/stark/actor.h"
|
||||
#include "engines/stark/skeleton.h"
|
||||
#include "engines/stark/texture.h"
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
|
||||
#include "common/archive.h"
|
||||
#include "common/stream.h"
|
||||
@ -51,8 +51,8 @@ void VisualActor::setAnim(SkeletonAnim *anim) {
|
||||
_actor->setAnim(anim);
|
||||
}
|
||||
|
||||
void VisualActor::setTexture(Texture *texture) {
|
||||
_actor->setTexture(texture);
|
||||
void VisualActor::setTexture(Gfx::TextureSet *texture) {
|
||||
_actor->setTextureSet(texture);
|
||||
}
|
||||
|
||||
void VisualActor::setTime(uint32 time) {
|
||||
@ -70,23 +70,24 @@ void VisualActor::render(Stark::GfxDriver *gfx, const Math::Vector3d position, f
|
||||
glRotatef(90, 1.f, 0.f, 0.f);
|
||||
glRotatef(90 - (_actor->getFacingDirection() + direction), 0.f, 1.f, 0.f);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
Common::Array<BoneNode *> bones = _actor->getSkeleton()->getBones();
|
||||
Common::Array<MeshNode *> meshes = _actor->getMeshes();
|
||||
Common::Array<MaterialNode *> mats = _actor->getMaterials();
|
||||
const Texture *texture = _actor->getTexture();
|
||||
const Gfx::TextureSet *texture = _actor->getTextureSet();
|
||||
|
||||
for (Common::Array<MeshNode *>::iterator mesh = meshes.begin(); mesh != meshes.end(); ++mesh) {
|
||||
for (Common::Array<FaceNode *>::iterator face = (*mesh)->_faces.begin(); face != (*mesh)->_faces.end(); ++face) {
|
||||
// For each triangle to draw
|
||||
uint32 tex = texture->getTexture(mats[(*face)->_matIdx]->_texName);
|
||||
if (tex)
|
||||
const Gfx::Texture *tex = texture->getTexture(mats[(*face)->_matIdx]->_texName);
|
||||
if (tex) {
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
else
|
||||
glColor3f(mats[(*face)->_matIdx]->_r, mats[(*face)->_matIdx]->_g, mats[(*face)->_matIdx]->_b);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
tex->bind();
|
||||
} else {
|
||||
glColor3f(mats[(*face)->_matIdx]->_r, mats[(*face)->_matIdx]->_g, mats[(*face)->_matIdx]->_b);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (Common::Array<TriNode *>::iterator tri = (*face)->_tris.begin(); tri != (*face)->_tris.end(); ++tri) {
|
||||
|
@ -35,9 +35,13 @@ namespace Common {
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class TextureSet;
|
||||
}
|
||||
|
||||
class Actor;
|
||||
class SkeletonAnim;
|
||||
class Texture;
|
||||
|
||||
|
||||
class VisualActor : public Visual {
|
||||
public:
|
||||
@ -48,7 +52,7 @@ public:
|
||||
|
||||
void setMesh(Actor *mesh);
|
||||
void setAnim(SkeletonAnim *anim);
|
||||
void setTexture(Texture *texture);
|
||||
void setTexture(Gfx::TextureSet *texture);
|
||||
void setTime(uint32 time);
|
||||
|
||||
void render(GfxDriver *gfx, const Math::Vector3d position, float direction);
|
||||
|
Loading…
x
Reference in New Issue
Block a user