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>
31 #include "util/numeric.h"
38 tile.{h,cpp}: Texture handling stuff.
42 Find out the full path of an image by trying different filename
47 TODO: Should probably be moved out from here, because things needing
48 this function do not need anything else from this header
50 std::string getImagePath(std::string path);
53 Gets the path to a texture by first checking if the texture exists
54 in texture_path and if not, using the data path.
56 Checks all supported extensions by replacing the original extension.
58 If not found, returns "".
60 Utilizes a thread-safe cache.
62 std::string getTexturePath(const std::string &filename);
64 void clearTextureNameCache();
67 ITextureSource::generateTextureFromMesh parameters
69 namespace irr {namespace scene {class IMesh;}}
70 struct TextureFromMeshParams
73 core::dimension2d<u32> dim;
74 std::string rtt_texture_name;
75 bool delete_texture_on_shutdown;
78 core::CMatrix4<f32> camera_projection_matrix;
79 video::SColorf ambient_light;
81 video::SColorf light_color;
86 TextureSource creates and caches textures.
89 class ISimpleTextureSource
92 ISimpleTextureSource(){}
93 virtual ~ISimpleTextureSource(){}
94 virtual video::ITexture* getTexture(
95 const std::string &name, u32 *id = NULL) = 0;
98 class ITextureSource : public ISimpleTextureSource
102 virtual ~ITextureSource(){}
103 virtual u32 getTextureId(const std::string &name)=0;
104 virtual std::string getTextureName(u32 id)=0;
105 virtual video::ITexture* getTexture(u32 id)=0;
106 virtual video::ITexture* getTexture(
107 const std::string &name, u32 *id = NULL)=0;
108 virtual video::ITexture* getTextureForMesh(
109 const std::string &name, u32 *id = NULL) = 0;
110 virtual IrrlichtDevice* getDevice()=0;
111 virtual bool isKnownSourceImage(const std::string &name)=0;
112 virtual video::ITexture* generateTextureFromMesh(
113 const TextureFromMeshParams ¶ms)=0;
114 virtual video::ITexture* getNormalTexture(const std::string &name)=0;
115 virtual video::SColor getTextureAverageColor(const std::string &name)=0;
116 virtual video::ITexture *getShaderFlagsTexture(bool normamap_present,
117 bool tileable_vertical, bool tileable_horizontal)=0;
120 class IWritableTextureSource : public ITextureSource
123 IWritableTextureSource(){}
124 virtual ~IWritableTextureSource(){}
125 virtual u32 getTextureId(const std::string &name)=0;
126 virtual std::string getTextureName(u32 id)=0;
127 virtual video::ITexture* getTexture(u32 id)=0;
128 virtual video::ITexture* getTexture(
129 const std::string &name, u32 *id = NULL)=0;
130 virtual IrrlichtDevice* getDevice()=0;
131 virtual bool isKnownSourceImage(const std::string &name)=0;
132 virtual video::ITexture* generateTextureFromMesh(
133 const TextureFromMeshParams ¶ms)=0;
135 virtual void processQueue()=0;
136 virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
137 virtual void rebuildImagesAndTextures()=0;
138 virtual video::ITexture* getNormalTexture(const std::string &name)=0;
139 virtual video::SColor getTextureAverageColor(const std::string &name)=0;
140 virtual video::ITexture *getShaderFlagsTexture(bool normamap_present,
141 bool tileable_vertical, bool tileable_horizontal)=0;
144 IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
147 video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver);
153 TILE_MATERIAL_LIQUID_TRANSPARENT,
154 TILE_MATERIAL_LIQUID_OPAQUE,
155 TILE_MATERIAL_WAVING_LEAVES,
156 TILE_MATERIAL_WAVING_PLANTS
160 // Should backface culling be enabled?
161 #define MATERIAL_FLAG_BACKFACE_CULLING 0x01
162 // Should a crack be drawn?
163 #define MATERIAL_FLAG_CRACK 0x02
164 // Should the crack be drawn on transparent pixels (unset) or not (set)?
165 // Ignored if MATERIAL_FLAG_CRACK is not set.
166 #define MATERIAL_FLAG_CRACK_OVERLAY 0x04
167 // Animation made up by splitting the texture to vertical frames, as
168 // defined by extra parameters
169 #define MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES 0x08
170 #define MATERIAL_FLAG_HIGHLIGHTED 0x10
173 This fully defines the looks of a tile.
174 The SMaterial of a tile is constructed according to this.
181 normal_texture(NULL),
186 video::ITexture *texture;
187 video::ITexture *normal_texture;
188 video::ITexture *flags_texture;
196 normal_texture(NULL),
199 material_type(TILE_MATERIAL_BASIC),
201 //0 // <- DEBUG, Use the one below
202 MATERIAL_FLAG_BACKFACE_CULLING
205 animation_frame_count(1),
206 animation_frame_length_ms(0),
211 bool operator==(const TileSpec &other) const
214 texture_id == other.texture_id &&
215 /* texture == other.texture && */
216 alpha == other.alpha &&
217 material_type == other.material_type &&
218 material_flags == other.material_flags &&
219 rotation == other.rotation
223 bool operator!=(const TileSpec &other) const
225 return !(*this == other);
228 // Sets everything else except the texture in the material
229 void applyMaterialOptions(video::SMaterial &material) const
231 switch (material_type) {
232 case TILE_MATERIAL_BASIC:
233 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
235 case TILE_MATERIAL_ALPHA:
236 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
238 case TILE_MATERIAL_LIQUID_TRANSPARENT:
239 material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
241 case TILE_MATERIAL_LIQUID_OPAQUE:
242 material.MaterialType = video::EMT_SOLID;
244 case TILE_MATERIAL_WAVING_LEAVES:
245 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
247 case TILE_MATERIAL_WAVING_PLANTS:
248 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
251 material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
255 void applyMaterialOptionsWithShaders(video::SMaterial &material) const
257 material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
262 video::ITexture *texture;
263 video::ITexture *normal_texture;
264 video::ITexture *flags_texture;
266 // Vertex alpha (when MATERIAL_ALPHA_VERTEX is used)
268 // Material parameters
272 // Animation parameters
273 u8 animation_frame_count;
274 u16 animation_frame_length_ms;
275 std::vector<FrameSpec> frames;