Load a texture array from a single file? Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
Hrenli
Halfling
Posts: 73
Joined: Tue Jun 14, 2016 12:26 pm
x 15

Load a texture array from a single file?

Post by Hrenli » Tue Oct 30, 2018 5:26 pm

Ogre Version: 2.1

Hi,

What I am trying to achieve is to have a texture array in a .dds file which I could just read and have it ready to be used. But atm I have a bit hard time doing that. I've created a simple array with 5 slices. Depending on the compression used I either can't load it (with error message saying something about unsupported format) or I can but it reads only the first slice (I am pretty sure there are 5 in the file):
Loading 1 faces(PF_A8R8G8B8,512x512x1) with 9 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,512x512x1.
That's using TextureManager::load() with texture type set to TEX_TYPE_2D_ARRAY...

So, first of all I want to check if I am doing something stupid or there is another/better way of reading predefined texture array images into the application?
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4138
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 268
Contact:

Re: Load a texture array from a single file?

Post by dark_sylinc » Tue Oct 30, 2018 7:09 pm

Our DDS codec was originally written to support the DX9 DDS format, which did not have texture arrays. We extended support for reading DX10 DDS format, but it just ignores the array slice flag.

On top of that, loading texture arrays from file in 2.1 is... complicated due to technical reasons, which is why Ogre 2.2 was started.

The best I can think of is to write a small tool to load these textures manually separately, merged them, and save it as an OITD format (our raw internal format). OITD in 2.1 cannot save mipmaps for texture arrays though due to these technical reasons I mentioned (it can on 2.2).
Also note that the OITD format from 2.1 is not compatible with 2.2's OITD.

Another solution: We added the notion of pools very recently. The following code can load independent files into the same array using the HlmsTextureManager path:

Code: Select all

//Load the first slice manually to know its parameters for reservePoolId
Ogre::Image image;
image.load( first_slice_filename, group );

//The important call so all the slices go to the same myPoolId, up to num_slices
hlmsTextureManager->reservePoolId(
                   myPoolId, Ogre::HlmsTextureManager::TEXTURE_TYPE_DIFFUSE,
                   image.getWidth(), image.getHeight(), num_slices,
                   image.getNumMipmaps(), image.getFormat(),
                   false, true );

//Create the texture now, from the Image in memory
hlmsTextureManager->createOrRetrieveTexture(
            first_slice_filename, first_slice_filename,
            Ogre::HlmsTextureManager::TEXTURE_TYPE_DIFFUSE, myPoolId, &image );

//Load the next slice directly from file
hlmsTextureManager->createOrRetrieveTexture(
            second_slice_filename, second_slice_filename, Ogre::HlmsTextureManager::TEXTURE_TYPE_DIFFUSE, myPoolId );
reservePoolId was meant for explicitly controlling which textures go into which array (by manipulating myPoolId, which is an arbitrary number, must be non-zero). Watch out for Ogre.log warnings if something goes wrong (for example, if two textures do not have the same pixel format we cannot put them in the same array despite having the same myPoolId)
0 x

Post Reply