mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-07 03:18:17 +00:00
EMI: Add texture-support for OpenGL
Also disable texture-usage in EMI for TinyGL right now, as that needs additional work, adding in RGB/BGR-support.
This commit is contained in:
parent
cbca9ee5e2
commit
79637c5538
@ -429,11 +429,11 @@ void GfxOpenGL::set3DMode() {
|
||||
|
||||
void GfxOpenGL::drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face) {
|
||||
int *indices = (int*)face->_indexes;
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_TEXTURE_2D); // Right now, textures are semi-work on some models
|
||||
// while for instance the catapult will become invisible.
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (int j = 0; j < face->_faceLength * 3; j++) {
|
||||
|
||||
@ -1027,9 +1027,13 @@ void GfxOpenGL::createMaterial(Texture *material, const char *data, const CMap *
|
||||
void GfxOpenGL::selectMaterial(const Texture *material) {
|
||||
GLuint *textures = (GLuint *)material->_texture;
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
glScalef(1.0f / material->_width, 1.0f / material->_height, 1);
|
||||
|
||||
// Grim has inverted tex-coords, EMI doesn't
|
||||
if (g_grim->getGameType() != GType_MONKEY4) {
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
glScalef(1.0f / material->_width, 1.0f / material->_height, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void GfxOpenGL::destroyMaterial(Texture *material) {
|
||||
|
@ -813,6 +813,8 @@ void GfxTinyGL::destroyTextObject(TextObject *text) {
|
||||
}
|
||||
|
||||
void GfxTinyGL::createMaterial(Texture *material, const char *data, const CMap *cmap) {
|
||||
if (g_grim->getGameType() == GType_MONKEY4)
|
||||
return;
|
||||
material->_texture = new TGLuint[1];
|
||||
tglGenTextures(1, (TGLuint *)material->_texture);
|
||||
char *texdata = new char[material->_width * material->_height * 4];
|
||||
@ -844,6 +846,8 @@ void GfxTinyGL::createMaterial(Texture *material, const char *data, const CMap *
|
||||
}
|
||||
|
||||
void GfxTinyGL::selectMaterial(const Texture *material) {
|
||||
if (g_grim->getGameType() == GType_MONKEY4)
|
||||
return;
|
||||
TGLuint *textures = (TGLuint *)material->_texture;
|
||||
tglBindTexture(TGL_TEXTURE_2D, textures[0]);
|
||||
tglPushMatrix();
|
||||
|
@ -85,7 +85,8 @@ void MaterialData::initGrim(const Common::String &filename, Common::SeekableRead
|
||||
}
|
||||
|
||||
void loadTGA(Common::SeekableReadStream *data, Texture *t) {
|
||||
data->seek(2, SEEK_CUR);
|
||||
assert(data->readByte() == 0); // Verify that description-field is empty
|
||||
data->seek(1, SEEK_CUR);
|
||||
|
||||
int format = data->readByte();
|
||||
assert(format == 2); // We only support uncompressed TGA
|
||||
@ -101,14 +102,35 @@ void loadTGA(Common::SeekableReadStream *data, Texture *t) {
|
||||
t->_colorFormat = BM_RGBA;
|
||||
t->_bpp = 4;
|
||||
} else {
|
||||
t->_colorFormat = BM_RGB888;
|
||||
t->_colorFormat = BM_RGB888; // Really a lie, as it should be BGR888, but we convert.
|
||||
t->_bpp = 3;
|
||||
}
|
||||
|
||||
char desc = data->readByte();
|
||||
char flipped = !(desc & 32);
|
||||
assert(bpp == 24 || bpp == 32); // Assure we have 24/32 bpp
|
||||
data->seek(1, SEEK_CUR);
|
||||
t->_data = new char[t->_width * t->_height * (bpp/8)];
|
||||
data->read(t->_data, t->_width * t->_height * (bpp/8));
|
||||
char *writePtr = t->_data + (t->_width * (t->_height - 1) * bpp/8);
|
||||
|
||||
// Since certain TGA's are flipped (relative to the tex-coords) and others not
|
||||
// We'll have to handle that here, otherwise we could just do 1.0f - texCoords
|
||||
// When drawing/loading
|
||||
if (flipped) {
|
||||
for (int i = 0; i < t->_height; i++) {
|
||||
data->read(writePtr, t->_width * (bpp/8));
|
||||
writePtr -= (t->_width * bpp/8);
|
||||
}
|
||||
} else {
|
||||
data->read(t->_data, t->_width * t->_height * (bpp/8));
|
||||
}
|
||||
|
||||
// The TGAs are BGR, not RGB, which is supported from GL 1.2 on
|
||||
// TinyGL doesn't support either, so, for now, we convert RGB->BGR here.
|
||||
unsigned char x;
|
||||
for (int i = 0; i < t->_width * t->_height * t->_bpp; i += t->_bpp) {
|
||||
x = t->_data[i];
|
||||
t->_data[i] = t->_data[i + 2];
|
||||
t->_data[i + 2] = x;
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialData::initEMI(const Common::String &filename, Common::SeekableReadStream *data) {
|
||||
@ -140,8 +162,6 @@ void MaterialData::initEMI(const Common::String &filename, Common::SeekableReadS
|
||||
continue;
|
||||
}
|
||||
loadTGA(texData, _textures + i);
|
||||
//return;
|
||||
// TODO: Add the necessary loading here.
|
||||
}
|
||||
_numImages = texFileNames.size();
|
||||
return;
|
||||
|
@ -109,8 +109,6 @@ void EMIModel::setTex(int index) {
|
||||
void EMIMeshFace::render() {
|
||||
if(_hasTexture) {
|
||||
_parent->setTex(_texID);
|
||||
} else {
|
||||
//glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
//glDrawElements(GL_TRIANGLES, _faceLength * 3, GL_UNSIGNED_INT, _indexes);
|
||||
}
|
||||
@ -191,13 +189,12 @@ void EMIModel::prepare() {
|
||||
prepareForRender();
|
||||
}
|
||||
|
||||
// TODO, fix a better timing-solution than this.
|
||||
void EMIModel::draw() {
|
||||
prepareForRender();
|
||||
// We will need to add a call to the skeleton, to get the modified vertices, but for now,
|
||||
// I'll be happy with just static drawing
|
||||
for(uint32 i = 0; i < _numFaces; i++) {
|
||||
//_faces[i].render();
|
||||
_faces[i].render();
|
||||
g_driver->drawEMIModelFace(this, &_faces[i]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user