1 #include "irrlichtwrapper.h"
3 IrrlichtWrapper::IrrlichtWrapper(IrrlichtDevice *device)
5 m_main_thread = get_current_thread_id();
10 void IrrlichtWrapper::Run()
15 if(m_get_texture_queue.size() > 0)
17 GetRequest<TextureSpec, video::ITexture*, u8, u8>
18 request = m_get_texture_queue.pop();
20 dstream<<"got texture request with key.name="
21 <<request.key.name<<std::endl;
23 GetResult<TextureSpec, video::ITexture*, u8, u8>
25 result.key = request.key;
26 result.callers = request.callers;
27 result.item = getTextureDirect(request.key);
29 request.dest->push_back(result);
33 video::ITexture* IrrlichtWrapper::getTexture(TextureSpec spec)
35 video::ITexture *t = m_texturecache.get(spec.name);
39 if(get_current_thread_id() == m_main_thread)
41 dstream<<"Getting texture directly: name="
42 <<spec.name<<std::endl;
44 t = getTextureDirect(spec);
48 // We're gonna ask the result to be put into here
49 ResultQueue<TextureSpec, video::ITexture*, u8, u8> result_queue;
52 m_get_texture_queue.add(spec, 0, 0, &result_queue);
54 dstream<<"Waiting for texture "<<spec.name<<std::endl;
57 GetResult<TextureSpec, video::ITexture*, u8, u8>
58 result = result_queue.pop_front(1000);
60 // Check that at least something worked OK
61 assert(result.key.name == spec.name);
66 // Add to cache and return
67 m_texturecache.set(spec.name, t);
71 video::ITexture* IrrlichtWrapper::getTexture(const std::string &path)
73 return getTexture(TextureSpec(path, path, NULL));
77 Non-thread-safe functions
80 video::ITexture* IrrlichtWrapper::getTextureDirect(TextureSpec spec)
82 video::IVideoDriver* driver = m_device->getVideoDriver();
86 dstream<<"IrrlichtWrapper::getTextureDirect: Loading texture "
87 <<spec.path<<std::endl;
88 return driver->getTexture(spec.path.c_str());
91 dstream<<"IrrlichtWrapper::getTextureDirect: Loading and modifying "
92 "texture "<<spec.path<<" to make "<<spec.name<<std::endl;
94 video::ITexture *base = driver->getTexture(spec.path.c_str());
95 video::ITexture *result = spec.mod->make(base, spec.name.c_str(), driver);
102 video::ITexture * CrackTextureMod::make(video::ITexture *original,
103 const char *newname, video::IVideoDriver* driver)
105 core::dimension2d<u32> dim(16, 16);
106 core::position2d<s32> pos_base(0, 0);
107 core::position2d<s32> pos_other(0, 16 * progression);
109 video::IImage *baseimage = driver->createImage(original, pos_base, dim);
112 video::ITexture *other = driver->getTexture("../data/crack.png");
113 // We have to get the whole texture because getting a smaller area
114 // messes the whole thing. It is probably a bug in Irrlicht.
115 video::IImage *otherimage = driver->createImage(
116 other, core::position2d<s32>(0,0), other->getSize());
120 /*core::rect<s32> clip_rect(v2s32(0,0), dim);
121 otherimage->copyToWithAlpha(baseimage, v2s32(0,0),
122 core::rect<s32>(pos_other, dim),
123 video::SColor(255,255,255,255),
126 otherimage->copyToWithAlpha(baseimage, v2s32(0,0),
127 core::rect<s32>(pos_other, dim),
128 video::SColor(255,255,255,255),
133 video::ITexture *newtexture = driver->addTexture(newname, baseimage);
141 video::ITexture * createAlphaBlitTexture(const char *name, video::ITexture *base,
142 video::ITexture *other, v2u32 size, v2s32 pos_base, v2s32 pos_other)
146 video::IVideoDriver* driver = g_device->getVideoDriver();
148 core::dimension2d<u32> dim(size.X, size.Y);
150 video::IImage *baseimage = driver->createImage(
152 core::position2d<s32>(pos_base.X, pos_base.Y),
156 video::IImage *otherimage = driver->createImage(
158 core::position2d<s32>(pos_other.X, pos_other.Y),
162 otherimage->copyToWithAlpha(baseimage, v2s32(0,0),
163 core::rect<s32>(v2s32(0,0), dim),
164 video::SColor(255,255,255,255),
165 core::rect<s32>(v2s32(0,0), dim));
168 video::ITexture *newtexture = driver->addTexture(name, baseimage);