Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

irrlichttexture.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       irrlichttexture.cpp
00003         created:        20/7/2004
00004         author:         Thomas Suter
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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()) // paranoid!
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 }

Generated on Wed Feb 16 12:41:08 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1