fix const cast, fix comment

actorid
scrawl 12 years ago
parent 651a654985
commit d71b583855

@ -252,17 +252,14 @@ namespace SFO
/// \brief creates an SDL cursor from an Ogre texture /// \brief creates an SDL cursor from an Ogre texture
void InputWrapper::_createCursorFromResource(const std::string& name, Ogre::TexturePtr tex, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y) void InputWrapper::_createCursorFromResource(const std::string& name, Ogre::TexturePtr tex, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y)
{ {
Ogre::Image::Box box;
box.right = size_x;
box.bottom = size_y;
//get the surfaces set up //get the surfaces set up
Ogre::HardwarePixelBufferSharedPtr buffer = tex.get()->getBuffer(); Ogre::HardwarePixelBufferSharedPtr buffer = tex.get()->getBuffer();
buffer.get()->lock(box, Ogre::HardwarePixelBuffer::HBL_READ_ONLY); buffer.get()->lock(Ogre::HardwarePixelBuffer::HBL_READ_ONLY);
std::string tempName = "_" + name + "_processing"; std::string tempName = "_" + name + "_processing";
//we need to copy this to a temporary texture since Ogre doesn't like us using getColourAt //we need to copy this to a temporary texture first because the cursors might be in DDS format,
//and Ogre doesn't have an interface to read DDS
Ogre::TexturePtr tempTexture = Ogre::TextureManager::getSingleton().createManual( Ogre::TexturePtr tempTexture = Ogre::TextureManager::getSingleton().createManual(
tempName, tempName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
@ -275,10 +272,9 @@ namespace SFO
tempTexture->getBuffer()->blit(buffer); tempTexture->getBuffer()->blit(buffer);
buffer->unlock(); buffer->unlock();
Ogre::HardwarePixelBufferSharedPtr new_buffer = tempTexture.get()->getBuffer(); // now blit to memory
//FIXME: Casting away constness is almost certainly the wrong thing to do here Ogre::Image destImage;
Ogre::PixelBox& pixels = const_cast<Ogre::PixelBox&>(new_buffer->lock(box, Ogre::HardwarePixelBuffer::HBL_READ_ONLY)); tempTexture->convertToImage(destImage);
SDL_Surface* surf = SDL_CreateRGBSurface(0,size_x,size_y,32,0xFF000000,0x00FF0000,0x0000FF00,0x000000FF); SDL_Surface* surf = SDL_CreateRGBSurface(0,size_x,size_y,32,0xFF000000,0x00FF0000,0x0000FF00,0x000000FF);
@ -288,7 +284,7 @@ namespace SFO
{ {
for(size_t y = 0; y < size_y; ++y) for(size_t y = 0; y < size_y; ++y)
{ {
Ogre::ColourValue clr = pixels.getColourAt(x, y, 0); Ogre::ColourValue clr = destImage.getColourAt(x, y, 0);
//set the pixel on the SDL surface to the same value as the Ogre texture's //set the pixel on the SDL surface to the same value as the Ogre texture's
_putPixel(surf, x, y, SDL_MapRGBA(surf->format, clr.r*255, clr.g*255, clr.b*255, clr.a*255)); _putPixel(surf, x, y, SDL_MapRGBA(surf->format, clr.r*255, clr.g*255, clr.b*255, clr.a*255));
@ -300,8 +296,6 @@ namespace SFO
SDL_SetCursor(curs); SDL_SetCursor(curs);
mCursorMap.insert(CursorMap::value_type(std::string(name), curs)); mCursorMap.insert(CursorMap::value_type(std::string(name), curs));
new_buffer->unlock();
//clean up //clean up
SDL_FreeSurface(surf); SDL_FreeSurface(surf);
Ogre::TextureManager::getSingleton().remove(tempName); Ogre::TextureManager::getSingleton().remove(tempName);

Loading…
Cancel
Save