1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GRIM_MATERIAL_H
24 #define GRIM_MATERIAL_H
25 
26 #include "engines/grim/object.h"
27 
28 namespace Grim {
29 
30 class CMap;
31 
32 class Texture {
33 public:
Texture()34 	Texture() :
35 		_width(0), _height(0), _colorFormat(0), _bpp(0), _hasAlpha(false), _texture(nullptr), _data(nullptr), _isShared(false) {};
36 	int _width;
37 	int _height;
38 	int _colorFormat;
39 	int _bpp;
40 	bool _hasAlpha;
41 	void *_texture;
42 	uint8 *_data;
43 	bool _isShared;
44 };
45 
46 class MaterialData {
47 public:
48 	MaterialData(const Common::String &filename, Common::SeekableReadStream *data, CMap *cmap);
49 	~MaterialData();
50 
51 	static MaterialData *getMaterialData(const Common::String &filename, Common::SeekableReadStream *data, CMap *cmap);
52 	static Common::List<MaterialData *> *_materials;
53 
54 	Common::String _fname;
55 	const ObjectPtr<CMap> _cmap;
56 	int _numImages;
57 	Texture **_textures;
58 	int _refCount;
59 
60 private:
61 	void initGrim(Common::SeekableReadStream *data);
62 	void initEMI(Common::SeekableReadStream *data);
63 };
64 
65 class Material : public Object {
66 public:
67 	// Load a texture from the given data.
68 	Material(const Common::String &filename, Common::SeekableReadStream *data, CMap *cmap, bool clamp);
69 
70 	void reload(CMap *cmap);
71 	// Load this texture into the GL context
72 	virtual void select() const;
73 
74 	// Set which image in an animated texture to use
75 	void setActiveTexture(int n);
76 
77 	int getNumTextures() const;
78 	int getActiveTexture() const;
79 
80 	const Common::String &getFilename() const;
81 	MaterialData *getData() const;
82 
83 	virtual ~Material();
84 
85 protected:
86 	Material();
87 
88 private:
89 	MaterialData *_data;
90 	int _currImage;
91 	bool _clampTexture;
92 };
93 
94 } // end of namespace Grim
95 
96 #endif
97