2006-04-02 14:20:45 +00:00
|
|
|
/* Residual - Virtual machine to run LucasArts' 3D adventure games
|
|
|
|
* Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org)
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-01-26 11:47:23 +00:00
|
|
|
#include "common/sys.h"
|
2008-06-12 12:08:15 +00:00
|
|
|
#include "common/endian.h"
|
2008-01-26 11:47:23 +00:00
|
|
|
#include "common/debug.h"
|
|
|
|
|
|
|
|
#include "engine/material.h"
|
|
|
|
#include "engine/colormap.h"
|
|
|
|
#include "engine/backend/driver.h"
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-04-19 09:56:34 +00:00
|
|
|
Material::Material(const char *filename, const char *data, int len, const CMap &cmap) :
|
2005-07-10 18:57:27 +00:00
|
|
|
Resource(filename), _cmap((CMap *) &cmap) {
|
2004-02-24 21:09:53 +00:00
|
|
|
if (len < 4 || memcmp(data, "MAT ", 4) != 0)
|
|
|
|
error("invalid magic loading texture\n");
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-12-10 07:26:03 +00:00
|
|
|
_numImages = READ_LE_UINT32(data + 12);
|
|
|
|
_currImage = 0;
|
|
|
|
_width = READ_LE_UINT32(data + 76 + _numImages * 40);
|
|
|
|
_height = READ_LE_UINT32(data + 80 + _numImages * 40);
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
if ((_width == 0) || (_height == 0)) {
|
2005-07-10 18:57:27 +00:00
|
|
|
if (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
|
|
|
|
warning("skip load texture: bad texture size (%dx%d) for texture %s\n", _width, _height, filename);
|
2005-01-13 20:21:12 +00:00
|
|
|
return;
|
2004-02-24 21:09:53 +00:00
|
|
|
}
|
2003-08-23 18:39:15 +00:00
|
|
|
|
2004-12-10 07:26:03 +00:00
|
|
|
data += 100 + _numImages * 40;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-04-19 09:56:34 +00:00
|
|
|
g_driver->createMaterial(this, data, &cmap);
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Material::select() const {
|
2005-01-13 20:21:12 +00:00
|
|
|
if ((_width == 0) || (_height == 0))
|
|
|
|
return;
|
2004-04-19 09:56:34 +00:00
|
|
|
g_driver->selectMaterial(this);
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Material::~Material() {
|
2005-01-13 20:21:12 +00:00
|
|
|
if ((_width == 0) || (_height == 0))
|
|
|
|
return;
|
2004-04-19 09:56:34 +00:00
|
|
|
g_driver->destroyMaterial(this);
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|