11#include <OgreBitwise.h> 
   16STexture::STexture(
SScene* scene, 
const std::string& groupName, 
const std::string& textureName, 
const std::string& path, 
const int& 
w, 
const int& h) : 
SData(textureName)
 
   29  catch (Ogre::Exception &)
 
   39      if (caps && (!caps->hasCapability(Ogre::RSC_NON_POWER_OF_2_TEXTURES) || caps->getNonPOW2TexturesLimited()))
 
   41        mWidth = Ogre::Bitwise::firstPO2From(
static_cast <unsigned short>(mWidth / 2));
 
   42        mHeight = Ogre::Bitwise::firstPO2From(
static_cast <unsigned short>(mHeight / 2));
 
   47        Ogre::PixelFormat format = Ogre::PF_A8R8G8B8;
 
   49        Ogre::TexturePtr texptr = 
mScene->
O3TextureManager->createManual(textureName, 
mGroupName, Ogre::TEX_TYPE_2D, mWidth, mHeight, Ogre::MIP_DEFAULT, format, Ogre::TU_STATIC_WRITE_ONLY, 
this, 
false, 0);
 
   53      catch (Ogre::Exception &e)
 
   55              Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"An exception has occurred: "+ e.getDescription());
 
   75      catch( Ogre::Exception &e )
 
   77        Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"An exception has occurred: " + e.getDescription());
 
 
   84STexture::STexture(
SScene* scene, 
const std::string& groupName, 
const std::string& textureName, Ogre::Image image) : 
SData(textureName)
 
   89  mWidth = image.getWidth();
 
   90  mHeight = image.getHeight();
 
   97  catch (Ogre::Exception &)
 
  107    catch (Ogre::Exception &e)
 
  109      Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"An exception has occurred: " + e.getDescription());
 
 
  115STexture::STexture() : 
SData(
"")
 
  132        Ogre::TextureManager::getSingletonPtr()->remove(
O3TexturePtr->getHandle());
 
  134      catch(Ogre::Exception&)
 
  144    SAFE_FREE(mBuffer.data);
 
 
  165    SAFE_FREE(mBuffer.data);
 
  167  std::size_t textureNumMipmap = 0;
 
  169  if (
O3TexturePtr->getNumMipmaps() != Ogre::MIP_UNLIMITED)
 
  173  Ogre::HardwarePixelBufferSharedPtr pixelBuffer = 
O3TexturePtr->getBuffer(0, 0);
 
  176  pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
 
  179  const Ogre::PixelBox& largePixelBox = pixelBuffer->getCurrentLock();
 
  181  mBuffer = Ogre::PixelBox(largePixelBox.getWidth(), largePixelBox.getHeight(), largePixelBox.getDepth(), largePixelBox.format);
 
  182  mBuffer.data = (uchar*)malloc(mBuffer.getConsecutiveSize());
 
  183  Ogre::Image::scale(largePixelBox, mBuffer);
 
  186  for (
size_t iMipmap = 1; iMipmap < textureNumMipmap; iMipmap++)
 
  189    Ogre::HardwarePixelBufferSharedPtr pixelBufferMipmap = 
O3TexturePtr->getBuffer(0, iMipmap);
 
  192    pixelBufferMipmap->lock(Ogre::HardwareBuffer::HBL_DISCARD);
 
  193    const Ogre::PixelBox& smallPixelBox = pixelBufferMipmap->getCurrentLock();
 
  198    pixelBufferMipmap->unlock();
 
  202  pixelBuffer->unlock();
 
 
  208    SAFE_FREE(mBuffer.data);
 
  210  std::size_t textureNumMipmap = 0;
 
  212  if (
O3TexturePtr->getNumMipmaps() != Ogre::MIP_UNLIMITED)
 
  216  Ogre::HardwarePixelBufferSharedPtr pixelBuffer = 
O3TexturePtr->getBuffer(0, 0);
 
  219  pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
 
  221  const Ogre::PixelBox& largePixelBox = pixelBuffer->getCurrentLock();
 
  223  mBuffer = Ogre::PixelBox(largePixelBox.getWidth(), largePixelBox.getHeight(), largePixelBox.getDepth(), largePixelBox.format);
 
  224  mBuffer.data = (uchar*)malloc(mBuffer.getConsecutiveSize());
 
  225  Ogre::Image::scale(largePixelBox, mBuffer);
 
  228  for (
size_t iMipmap = 1; iMipmap < textureNumMipmap; iMipmap++)
 
  231    Ogre::HardwarePixelBufferSharedPtr pixelBufferMipmap = 
O3TexturePtr->getBuffer(0, iMipmap);
 
  234    pixelBufferMipmap->lock(Ogre::HardwareBuffer::HBL_DISCARD);
 
  235    const Ogre::PixelBox& smallPixelBox = pixelBufferMipmap->getCurrentLock();
 
  239    pixelBufferMipmap->unlock();
 
  243  pixelBuffer->unlock();
 
 
  246void STexture::loadResource(Ogre::Resource* resource)
 
  250    std::size_t textureNumMipmap = 
O3TexturePtr->getNumMipmaps();
 
  253    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = 
O3TexturePtr->getBuffer(0, 0);
 
  256    pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
 
  258    const Ogre::PixelBox& largePixelBox = pixelBuffer->getCurrentLock();
 
  259    Ogre::Image::scale(mBuffer, largePixelBox);
 
  262    for (
size_t iMipmap = 1; iMipmap < textureNumMipmap; iMipmap++)
 
  265      Ogre::HardwarePixelBufferSharedPtr pixelBufferMipmap = 
O3TexturePtr->getBuffer(0, iMipmap);
 
  268      pixelBufferMipmap->lock(Ogre::HardwareBuffer::HBL_DISCARD);
 
  269      const Ogre::PixelBox& smallPixelBox = pixelBufferMipmap->getCurrentLock();
 
  270      Ogre::Image::scale(mBuffer, smallPixelBox);
 
  273      pixelBufferMipmap->unlock();
 
  277    pixelBuffer->unlock();
 
SCOL_EXPORT int cbmachine w
bool GetRttPixelFormat(Ogre::PixelFormat &format, bool alpha=false, bool floattex=false)
Ogre::RenderSystem * GetOgreRenderSystem()
static SRoot & getSingleton()
Ogre::TextureManager * O3TextureManager
std::string GetGroupName()
void BlitTexture(PtrObjBitmap B)
void BlitAlphaTexture(PtrObjBitmap Bcolor, PtrObjBitmap Balpha)
Ogre::TexturePtr getOgreTexturePointer()
Ogre::TexturePtr O3TexturePtr