00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "renderers/IrrlichtRenderer/irrlichttexture.h"
00025
00026 namespace CEGUI
00027 {
00028
00029 int IrrlichtTexture::iTextureNumber=0;
00030
00031 irr::core::stringc IrrlichtTexture::getUniqueName(void)
00032 {
00033 char buffer[32];
00034 sprintf(buffer,"irr_tex_%d",iTextureNumber);
00035 irr::core::stringc str(buffer);
00036 ++iTextureNumber;
00037 return str;
00038 }
00039
00040 IrrlichtTexture::IrrlichtTexture(Renderer* r, irr::IrrlichtDevice* dr)
00041 :Texture(r), device(dr),tex(0)
00042 {
00043 driver=device->getVideoDriver();
00044 }
00045
00046 IrrlichtTexture::~IrrlichtTexture(){
00047 freeTexture();
00048 }
00049
00050 irr::video::ITexture* IrrlichtTexture::getTexture()
00051 {
00052 return tex;
00053 }
00054
00055 void IrrlichtTexture::setTexture(irr::video::ITexture* texture)
00056 {
00057 this->tex=texture;
00058 }
00059
00060 void IrrlichtTexture::freeTexture()
00061 {
00062 if(tex!=0)
00063 {
00064 tex->drop();
00065 driver->removeTexture(tex);
00066 }
00067
00068 tex=0;
00069 }
00070
00071 ushort IrrlichtTexture::getWidth(void) const
00072 {
00073 if(tex) return tex->getSize().Width;
00074 return 0;
00075 }
00076
00077 ushort IrrlichtTexture::getHeight(void) const
00078 {
00079 if(tex) return tex->getSize().Height;
00080 return 0;
00081 }
00082
00083 void IrrlichtTexture::loadFromFile(const String& filename, const String& resourceGroup)
00084 {
00085 freeTexture();
00086 driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS,true);
00087 tex=driver->getTexture(filename.c_str());
00088
00089 tex->grab();
00090 }
00091
00092 void IrrlichtTexture::loadFromMemory(const void* buffPtr,
00093 uint buffWidth, uint buffHeight)
00094 {
00095 freeTexture();
00096
00097 irr::core::dimension2d<irr::s32> dim(buffWidth,buffHeight);
00098 irr::core::stringc name=getUniqueName();
00099
00100 driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS,true);
00101 tex=driver->addTexture(dim,name.c_str(),irr::video::ECF_A8R8G8B8);
00102
00103 if(irr::video::ECF_A8R8G8B8==tex->getColorFormat())
00104 {
00105 irr::u32* tt=(irr::u32*)tex->lock();
00106 irr::core::dimension2d<irr::s32> d=tex->getSize();
00107 memcpy(tt,buffPtr,d.Width*d.Height*sizeof(CEGUI::ulong));
00108 tex->unlock();
00109 }
00110 tex->grab();
00111 }
00112
00113
00114 }