Code: Select all
Ogre::Image image;
image.loadDynamicImage( alphaBlendMaskBuffer, 64, 64, 1, Ogre::PF_L8, true );
auto alphaTexLoc = hlmsTextureManager->createOrRetrieveTexture(
alphaName, alphaName, TEXTURE_TYPE_NON_COLOR_DATA, &image );
datablock->setTexture( textureSlot, alphaTexLoc.xIdx, alphaTexLoc.texture, &alphaSampler );
datablock->setTextureUvSource( textureSlot, alphaUvSource );
Now porting this to 2.2, I have come up with the following code:
Code: Select all
// Continue to load the texture data into an image
Ogre::Image image;
image.loadDynamicImage( alphaBlendMaskBuffer, 64, 64, 1, Ogre::PF_L8, true );
// Create the texture, which at this point is just a descriptor
auto alphaTex = textureGpuManager->createOrRetrieveTexture(
alphaName, GpuPageOutStrategy::AlwaysKeepSystemRamCopy, TextureFlags::ManualTexture,
TextureTypes::Type2D, "Terrain", 0u );
alphaTex->setPixelFormat( PixelFormatGpu::PFG_A8_UNORM );
alphaTex->setTextureType( TextureTypes::Type2D );
alphaTex->setResolution( 64, 64, 1 );
alphaTex->setNumMipmaps( 1u );
// Schedule texture to become resident
alphaTex->_transitionTo( GpuResidency::Resident, image.getData() );
alphaTex->_setNextResidencyStatus( GpuResidency::Resident );
// Setup staging texture
auto alphaStage = textureGpuManager->getStagingTexture( 64, 64, 1, 1, PixelFormatGpu::PFG_A8_UNORM );
// Map region and upload data specified by region
alphaStage->startMapRegion();
auto mapTexBox = alphaStage->mapRegion( 64, 64, 1, 1, PixelFormatGpu::PFG_A8_UNORM );
mapTexBox.copyFrom( image.getData(), 64, 64, 64 );
alphaStage->stopMapRegion();
alphaStage->upload( mapTexBox, alphaTex, 0, 0, true );
// Destroy staging texture
textureGpuManager->removeStagingTexture( alphaStage );
alphaStage = 0;
// Notify callbacks the data has been loaded
alphaTex->notifyDataIsReady();
datablock->setTexture( textureSlot, alphaTex, &alphaSampler );
datablock->setTextureUvSource( textureSlot, alphaUvSource );
Ideas?