2009-09-15 17:53:36 +02:00
|
|
|
/* Residual - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* Residual 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 library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-09-03 15:39:16 +02:00
|
|
|
#include "engines/myst3/node.h"
|
2009-09-15 17:53:36 +02:00
|
|
|
|
2009-09-17 13:40:15 +02:00
|
|
|
#include "common/debug.h"
|
2011-08-28 20:10:47 +02:00
|
|
|
#include "common/rect.h"
|
2009-09-17 13:40:15 +02:00
|
|
|
|
2009-09-15 17:53:36 +02:00
|
|
|
namespace Myst3 {
|
|
|
|
|
2011-12-26 21:39:26 +01:00
|
|
|
void Face::setTextureFromJPEG(Graphics::JPEG *jpeg) {
|
|
|
|
_bitmap = new Graphics::Surface();
|
|
|
|
_bitmap->create(jpeg->getComponent(1)->w, jpeg->getComponent(1)->h, Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0));
|
2009-09-15 17:53:36 +02:00
|
|
|
|
|
|
|
byte *y = (byte *)jpeg->getComponent(1)->getBasePtr(0, 0);
|
|
|
|
byte *u = (byte *)jpeg->getComponent(2)->getBasePtr(0, 0);
|
|
|
|
byte *v = (byte *)jpeg->getComponent(3)->getBasePtr(0, 0);
|
|
|
|
|
2011-12-26 21:39:26 +01:00
|
|
|
byte *ptr = (byte *)_bitmap->getBasePtr(0, 0);
|
|
|
|
for (int i = 0; i < _bitmap->w * _bitmap->h; i++) {
|
2009-09-15 17:53:36 +02:00
|
|
|
byte r, g, b;
|
|
|
|
Graphics::YUV2RGB(*y++, *u++, *v++, r, g, b);
|
|
|
|
*ptr++ = r;
|
|
|
|
*ptr++ = g;
|
|
|
|
*ptr++ = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-26 21:39:26 +01:00
|
|
|
void Face::createTexture() {
|
|
|
|
glGenTextures(1, &_textureId);
|
2009-09-15 17:53:36 +02:00
|
|
|
|
2011-12-26 21:39:26 +01:00
|
|
|
glBindTexture(GL_TEXTURE_2D, _textureId);
|
2009-09-15 17:53:36 +02:00
|
|
|
|
2011-12-26 21:39:26 +01:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, 3, Node::_cubeTextureSize, Node::_cubeTextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
2009-09-15 17:53:36 +02:00
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
}
|
|
|
|
|
2011-12-26 21:39:26 +01:00
|
|
|
void Face::uploadTexture() {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _textureId);
|
|
|
|
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _bitmap->w, _bitmap->h, GL_RGB, GL_UNSIGNED_BYTE, _bitmap->pixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Face::unload() {
|
|
|
|
_bitmap->free();
|
|
|
|
delete _bitmap;
|
|
|
|
_bitmap = 0;
|
|
|
|
|
|
|
|
glDeleteTextures(1, &_textureId);
|
|
|
|
}
|
|
|
|
|
2011-09-03 15:39:16 +02:00
|
|
|
void Node::dumpFaceMask(Archive &archive, uint16 index, int face) {
|
2009-09-17 13:40:15 +02:00
|
|
|
byte *mask = new byte[640 * 640];
|
|
|
|
memset(mask, 0, sizeof(mask));
|
|
|
|
uint32 headerOffset = 0;
|
|
|
|
uint32 dataOffset = 0;
|
|
|
|
|
2011-09-11 10:15:41 +02:00
|
|
|
const DirectorySubEntry *maskDesc = archive.getDescription(index, face, DirectorySubEntry::kFaceMask);
|
|
|
|
Common::MemoryReadStream *maskStream = archive.getData(maskDesc);
|
2009-09-17 13:40:15 +02:00
|
|
|
|
|
|
|
while (headerOffset < 400) {
|
|
|
|
int blockX = (headerOffset / sizeof(dataOffset)) % 10;
|
|
|
|
int blockY = (headerOffset / sizeof(dataOffset)) / 10;
|
|
|
|
|
|
|
|
maskStream->seek(headerOffset, SEEK_SET);
|
|
|
|
dataOffset = maskStream->readUint32LE();
|
|
|
|
headerOffset = maskStream->pos();
|
|
|
|
|
|
|
|
if (dataOffset != 0) {
|
|
|
|
maskStream->seek(dataOffset, SEEK_SET);
|
|
|
|
|
|
|
|
for(int i = 63; i >= 0; i--) {
|
|
|
|
int x = 0;
|
|
|
|
byte numValues = maskStream->readByte();
|
|
|
|
for (int j = 0; j < numValues; j++) {
|
|
|
|
byte repeat = maskStream->readByte();
|
|
|
|
byte value = maskStream->readByte();
|
|
|
|
for (int k = 0; k < repeat; k++) {
|
|
|
|
mask[((blockY * 64) + i) * 640 + blockX * 64 + x] = value;
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 10:15:41 +02:00
|
|
|
delete maskStream;
|
|
|
|
|
2009-09-17 13:40:15 +02:00
|
|
|
Common::DumpFile outFile;
|
|
|
|
outFile.open("dump/1-1.masku");
|
|
|
|
outFile.write(mask, sizeof(mask));
|
|
|
|
outFile.close();
|
|
|
|
delete[] mask;
|
|
|
|
}
|
|
|
|
|
2011-09-03 15:39:16 +02:00
|
|
|
void Node::unload() {
|
2011-08-28 20:10:47 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2011-12-26 21:39:26 +01:00
|
|
|
_faces[i].unload();
|
2011-08-28 20:10:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-15 17:53:36 +02:00
|
|
|
} // end of namespace Myst3
|