What's the best way to obtain a TextureGpu* of a texture which resides inside a texture array? Do I have to use AsyncTextureTicket? Is there a use case scenario in the samples which I can study and take as a reference?
I'd like to use the cubemap of a specific probe as a Terra reflection map, but I need to extract it from the PCC cubemap array.
[2.2] Extract a slice from a texture array
-
- OGRE Contributor
- Posts: 267
- Joined: Wed Apr 23, 2014 3:49 pm
- Location: Bologna, Italy
- x 75
[2.2] Extract a slice from a texture array
Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft Esport — Racecraft Coin-Op, Victory: The Age of Racing
-
- OGRE Team Member
- Posts: 5502
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1370
Re: [2.2] Extract a slice from a texture array
Image2::convertFromTexture is an example which handles all cases even the edge ones.
This will download all slices though (and you can later access the slice you want via TextureBox).
However if you're interested in only download a particular slice, this modified excerpt from Image2 should do the trick:
If you want more examples, just Find in Files for 'createAsyncTextureTicket'. Its only purpose is to get data from GPU textures to the CPU.
Accessing more than one slice that have been downloaded requires two paths for maximum performance. See 'if( asyncTicket->canMapMoreThanOneSlice() )' part of Image2.
Note that you can just assume canMapMoreThanOneSlice is always false and write only one codepath.
This will download all slices though (and you can later access the slice you want via TextureBox).
However if you're interested in only download a particular slice, this modified excerpt from Image2 should do the trick:
Code: Select all
depthOrSlices = 1u; // Because we only need to allocate space to download just one, which is what we're interested. Note a cubemap has 6 slices
AsyncTextureTicket *asyncTicket =
textureManager->createAsyncTextureTicket( width, height, depthOrSlices,
TextureTypes::Type2DArray,
texture->getPixelFormat() );
TextureBox srcBox = texture->getEmptyBox( mip );
srcBox.sliceStart = ...; // The slice you want. Just make sure sliceStart + numSlices doesn't go out of bounds
srcBox.numSlices = depthOrSlices;
// If you can wait a few frames to access the downloaded the data, set accurateTracking to false instead of true
asyncTicket->download( resolvedTexture, mip, true, &srcBox );
// You may want to do other stuff here until the data finishes downloading
const TextureBox finalBox = asyncTicket->map( 0 );
// access finalBox
asyncTicket->unmap();
textureManager->destroyAsyncTextureTicket( asyncTicket );
Accessing more than one slice that have been downloaded requires two paths for maximum performance. See 'if( asyncTicket->canMapMoreThanOneSlice() )' part of Image2.
Note that you can just assume canMapMoreThanOneSlice is always false and write only one codepath.