00001
00007 #include "SO3Texture.h"
00008 #include "../SO3SceneGraph/SO3Scene.h"
00009
00010 namespace SO3
00011 {
00012
00013 STexture::STexture(SScene* scene, std::string groupName, std::string textureName, std::string path, int w, int h) : SData(textureName)
00014 {
00015 mScene = scene;
00016 mGroupName = groupName;
00017 O3TexturePtr.setNull();
00018 mWidth = w;
00019 mHeight = h;
00020
00021 O3TexturePtr = mScene->O3TextureManager->getByName(textureName, mGroupName);
00022
00023 if (O3TexturePtr.isNull())
00024 {
00025 if(path.empty())
00026 {
00027
00028 try
00029 {
00030 O3TexturePtr = mScene->O3TextureManager->createManual(textureName, mGroupName, Ogre::TEX_TYPE_2D, w, h, Ogre::MIP_DEFAULT, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC_WRITE_ONLY, this, false, 0);
00031 }
00032 catch (Ogre::Exception &e)
00033 {
00034 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00035 O3TexturePtr.setNull();
00036 }
00037 }
00038 else
00039 {
00040 try
00041 {
00042 Ogre::Image im;
00043 im.load(path, mGroupName);
00044 O3TexturePtr = mScene->O3TextureManager->loadImage(textureName, mGroupName, im);
00045 }
00046 catch( Ogre::Exception &e )
00047 {
00048 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: "+ e.getDescription());
00049 O3TexturePtr.setNull();
00050 }
00051 }
00052 }
00053 }
00054
00055 STexture::STexture() : SData("")
00056 {
00057
00058 O3TexturePtr.setNull();
00059 }
00060
00061 STexture::~STexture()
00062 {
00063
00064
00065
00066
00067
00068
00069
00070
00071 }
00072
00073 SScene* STexture::GetScene()
00074 {
00075 return mScene;
00076 }
00077
00078 std::string STexture::GetGroupName()
00079 {
00080 return mGroupName;
00081 }
00082
00083 Ogre::TexturePtr STexture::getOgreTexturePointer()
00084 {
00085 return O3TexturePtr;
00086 }
00087
00088 void STexture::loadResource(Ogre::Resource* resource)
00089 {
00090 Ogre::Texture* tex = static_cast<Ogre::Texture*>(resource);
00091
00092 tex->setTextureType(Ogre::TEX_TYPE_2D);
00093 tex->setWidth(mWidth);
00094 tex->setHeight(mHeight);
00095 tex->setFormat(Ogre::PF_R8G8B8A8);
00096 tex->setUsage(Ogre::TU_STATIC_WRITE_ONLY);
00097 tex->createInternalResources();
00098 }
00099
00100 }