3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "irrlichttypes.h"
27 #include <IrrlichtDevice.h>
34 tile.{h,cpp}: Texture handling stuff.
38 Find out the full path of an image by trying different filename
43 TODO: Should probably be moved out from here, because things needing
44 this function do not need anything else from this header
46 std::string getImagePath(std::string path);
49 Gets the path to a texture by first checking if the texture exists
50 in texture_path and if not, using the data path.
52 Checks all supported extensions by replacing the original extension.
54 If not found, returns "".
56 Utilizes a thread-safe cache.
58 std::string getTexturePath(const std::string &filename);
60 void clearTextureNameCache();
63 ITextureSource::generateTextureFromMesh parameters
65 namespace irr {namespace scene {class IMesh;}}
66 struct TextureFromMeshParams
69 core::dimension2d<u32> dim;
70 std::string rtt_texture_name;
71 bool delete_texture_on_shutdown;
74 core::CMatrix4<f32> camera_projection_matrix;
75 video::SColorf ambient_light;
77 video::SColorf light_color;
82 TextureSource creates and caches textures.
85 class ISimpleTextureSource
88 ISimpleTextureSource(){}
89 virtual ~ISimpleTextureSource(){}
90 virtual video::ITexture* getTexture(
91 const std::string &name, u32 *id = NULL) = 0;
94 class ITextureSource : public ISimpleTextureSource
98 virtual ~ITextureSource(){}
99 virtual u32 getTextureId(const std::string &name)=0;
100 virtual u32 getTextureIdDirect(const std::string &name)=0;
101 virtual std::string getTextureName(u32 id)=0;
102 virtual video::ITexture* getTexture(u32 id)=0;
103 virtual video::ITexture* getTexture(
104 const std::string &name, u32 *id = NULL)=0;
105 virtual IrrlichtDevice* getDevice()=0;
106 virtual bool isKnownSourceImage(const std::string &name)=0;
107 virtual video::ITexture* generateTextureFromMesh(
108 const TextureFromMeshParams ¶ms)=0;
111 class IWritableTextureSource : public ITextureSource
114 IWritableTextureSource(){}
115 virtual ~IWritableTextureSource(){}
116 virtual u32 getTextureId(const std::string &name)=0;
117 virtual u32 getTextureIdDirect(const std::string &name)=0;
118 virtual std::string getTextureName(u32 id)=0;
119 virtual video::ITexture* getTexture(u32 id)=0;
120 virtual video::ITexture* getTexture(
121 const std::string &name, u32 *id = NULL)=0;
122 virtual IrrlichtDevice* getDevice()=0;
123 virtual bool isKnownSourceImage(const std::string &name)=0;
124 virtual video::ITexture* generateTextureFromMesh(
125 const TextureFromMeshParams ¶ms)=0;
127 virtual void processQueue()=0;
128 virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
129 virtual void rebuildImagesAndTextures()=0;
132 IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
137 TILE_MATERIAL_LIQUID_TRANSPARENT,
138 TILE_MATERIAL_LIQUID_OPAQUE,
142 // Should backface culling be enabled?
143 #define MATERIAL_FLAG_BACKFACE_CULLING 0x01
144 // Should a crack be drawn?
145 #define MATERIAL_FLAG_CRACK 0x02
146 // Should the crack be drawn on transparent pixels (unset) or not (set)?
147 // Ignored if MATERIAL_FLAG_CRACK is not set.
148 #define MATERIAL_FLAG_CRACK_OVERLAY 0x04
149 // Animation made up by splitting the texture to vertical frames, as
150 // defined by extra parameters
151 #define MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES 0x08
154 This fully defines the looks of a tile.
155 The SMaterial of a tile is constructed according to this.
163 material_type(TILE_MATERIAL_BASIC),
165 //0 // <- DEBUG, Use the one below
166 MATERIAL_FLAG_BACKFACE_CULLING
168 animation_frame_count(1),
169 animation_frame_length_ms(0),
174 bool operator==(const TileSpec &other) const
177 texture_id == other.texture_id &&
178 /* texture == other.texture && */
179 alpha == other.alpha &&
180 material_type == other.material_type &&
181 material_flags == other.material_flags &&
182 rotation == other.rotation
186 bool operator!=(const TileSpec &other) const
188 return !(*this == other);
191 // Sets everything else except the texture in the material
192 void applyMaterialOptions(video::SMaterial &material) const
194 switch(material_type){
195 case TILE_MATERIAL_BASIC:
196 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
198 case TILE_MATERIAL_ALPHA:
199 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
201 case TILE_MATERIAL_LIQUID_TRANSPARENT:
202 material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
204 case TILE_MATERIAL_LIQUID_OPAQUE:
205 material.MaterialType = video::EMT_SOLID;
208 material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) ? true : false;
210 void applyMaterialOptionsWithShaders(video::SMaterial &material,
211 const video::E_MATERIAL_TYPE &basic,
212 const video::E_MATERIAL_TYPE &liquid,
213 const video::E_MATERIAL_TYPE &alpha) const
215 switch(material_type){
216 case TILE_MATERIAL_BASIC:
217 material.MaterialType = basic;
219 case TILE_MATERIAL_ALPHA:
220 material.MaterialType = alpha;
222 case TILE_MATERIAL_LIQUID_TRANSPARENT:
223 material.MaterialType = liquid;
225 case TILE_MATERIAL_LIQUID_OPAQUE:
226 material.MaterialType = liquid;
229 material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) ? true : false;
233 video::ITexture *texture;
234 // Vertex alpha (when MATERIAL_ALPHA_VERTEX is used)
236 // Material parameters
239 // Animation parameters
240 u8 animation_frame_count;
241 u16 animation_frame_length_ms;