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"
36 tile.{h,cpp}: Texture handling stuff.
40 Find out the full path of an image by trying different filename
45 TODO: Should probably be moved out from here, because things needing
46 this function do not need anything else from this header
48 std::string getImagePath(std::string path);
51 Gets the path to a texture by first checking if the texture exists
52 in texture_path and if not, using the data path.
54 Checks all supported extensions by replacing the original extension.
56 If not found, returns "".
58 Utilizes a thread-safe cache.
60 std::string getTexturePath(const std::string &filename);
62 void clearTextureNameCache();
65 ITextureSource::generateTextureFromMesh parameters
67 namespace irr {namespace scene {class IMesh;}}
68 struct TextureFromMeshParams
71 core::dimension2d<u32> dim;
72 std::string rtt_texture_name;
73 bool delete_texture_on_shutdown;
76 core::CMatrix4<f32> camera_projection_matrix;
77 video::SColorf ambient_light;
79 video::SColorf light_color;
84 TextureSource creates and caches textures.
87 class ISimpleTextureSource
90 ISimpleTextureSource(){}
91 virtual ~ISimpleTextureSource(){}
92 virtual video::ITexture* getTexture(
93 const std::string &name, u32 *id = NULL) = 0;
96 class ITextureSource : public ISimpleTextureSource
100 virtual ~ITextureSource(){}
101 virtual u32 getTextureId(const std::string &name)=0;
102 virtual std::string getTextureName(u32 id)=0;
103 virtual video::ITexture* getTexture(u32 id)=0;
104 virtual video::ITexture* getTexture(
105 const std::string &name, u32 *id = NULL)=0;
106 virtual video::ITexture* getTextureForMesh(
107 const std::string &name, u32 *id = NULL) = 0;
108 virtual IrrlichtDevice* getDevice()=0;
109 virtual bool isKnownSourceImage(const std::string &name)=0;
110 virtual video::ITexture* generateTextureFromMesh(
111 const TextureFromMeshParams ¶ms)=0;
112 virtual video::ITexture* getNormalTexture(const std::string &name)=0;
115 class IWritableTextureSource : public ITextureSource
118 IWritableTextureSource(){}
119 virtual ~IWritableTextureSource(){}
120 virtual u32 getTextureId(const std::string &name)=0;
121 virtual std::string getTextureName(u32 id)=0;
122 virtual video::ITexture* getTexture(u32 id)=0;
123 virtual video::ITexture* getTexture(
124 const std::string &name, u32 *id = NULL)=0;
125 virtual IrrlichtDevice* getDevice()=0;
126 virtual bool isKnownSourceImage(const std::string &name)=0;
127 virtual video::ITexture* generateTextureFromMesh(
128 const TextureFromMeshParams ¶ms)=0;
130 virtual void processQueue()=0;
131 virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
132 virtual void rebuildImagesAndTextures()=0;
133 virtual video::ITexture* getNormalTexture(const std::string &name)=0;
136 IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
139 video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver);
145 TILE_MATERIAL_LIQUID_TRANSPARENT,
146 TILE_MATERIAL_LIQUID_OPAQUE,
147 TILE_MATERIAL_WAVING_LEAVES,
148 TILE_MATERIAL_WAVING_PLANTS
152 // Should backface culling be enabled?
153 #define MATERIAL_FLAG_BACKFACE_CULLING 0x01
154 // Should a crack be drawn?
155 #define MATERIAL_FLAG_CRACK 0x02
156 // Should the crack be drawn on transparent pixels (unset) or not (set)?
157 // Ignored if MATERIAL_FLAG_CRACK is not set.
158 #define MATERIAL_FLAG_CRACK_OVERLAY 0x04
159 // Animation made up by splitting the texture to vertical frames, as
160 // defined by extra parameters
161 #define MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES 0x08
162 #define MATERIAL_FLAG_HIGHLIGHTED 0x10
165 This fully defines the looks of a tile.
166 The SMaterial of a tile is constructed according to this.
177 video::ITexture *texture;
178 video::ITexture *normal_texture;
186 normal_texture(NULL),
188 material_type(TILE_MATERIAL_BASIC),
190 //0 // <- DEBUG, Use the one below
191 MATERIAL_FLAG_BACKFACE_CULLING
194 animation_frame_count(1),
195 animation_frame_length_ms(0),
200 bool operator==(const TileSpec &other) const
203 texture_id == other.texture_id &&
204 /* texture == other.texture && */
205 alpha == other.alpha &&
206 material_type == other.material_type &&
207 material_flags == other.material_flags &&
208 rotation == other.rotation
212 bool operator!=(const TileSpec &other) const
214 return !(*this == other);
217 // Sets everything else except the texture in the material
218 void applyMaterialOptions(video::SMaterial &material) const
220 switch (material_type) {
221 case TILE_MATERIAL_BASIC:
222 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
224 case TILE_MATERIAL_ALPHA:
225 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
227 case TILE_MATERIAL_LIQUID_TRANSPARENT:
228 material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
230 case TILE_MATERIAL_LIQUID_OPAQUE:
231 material.MaterialType = video::EMT_SOLID;
233 case TILE_MATERIAL_WAVING_LEAVES:
234 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
236 case TILE_MATERIAL_WAVING_PLANTS:
237 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
240 material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
244 void applyMaterialOptionsWithShaders(video::SMaterial &material) const
246 material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
251 video::ITexture *texture;
252 video::ITexture *normal_texture;
254 // Vertex alpha (when MATERIAL_ALPHA_VERTEX is used)
256 // Material parameters
260 // Animation parameters
261 u8 animation_frame_count;
262 u16 animation_frame_length_ms;
263 std::vector<FrameSpec> frames;