My shader need a texture2darray but I don’t know how to construct a valid object. Though texture class in panda3d provides setup2dTextureArray(), I have no thought how to fill the data.
TexturePool class has a load2dTextureArray method, but I want to create it using existing texture in memory, instead of in disk.
I have tried concatenating texture datas as following:
a_textures_array = Texture()
a_textures_array.setup2dTextureArray(750, 750, texture_amount, Texture.T_float, Texture.F_rgba) # 750, 750 is the pixel amount of the textures I intend to use
ptr = a_textures_array.modifyRamImage()
size = 786465 # bytes
for n, texture in enumerate(list_of_textures): # This list contains several textures
ptr.setSubdata(n * size, size, texture.getRamImage().getData())
However, running this code would get a error, which comes from function graphicsEngine.renderFrame, saying AssertionError: image_ptr >= orig_image_ptr && image_ptr + view_size <= orig_image_ptr + tex->get_ram_mipmap_image_size(n).
And I found texture2darray object has a strange size as 33 when texture_amount == 0 and 9000033 when texture_amount == 1, while a single texture occupy 786465 bytes.
There is another topic with the same question, but it has not been properly answered:
So I am asking again for a solution. Any help would be greatly appreciated.
Thank you for replying. I get a size of 786432 still for a single image using tex.getExpectedRamMipmapPageSize() or tex.getExpectedRamImageSize(). And UncompressedRamImage has the same size which really confuses me.
The image may be resized to 512x512, and 512x512x3(jpg file)=786432, but I can’t explain absence of float size (4).
Changing texture array size to 512x512 has no effect.
And clear() of the pointer seems be unrelated to the error: same error occurs after I comment that.
Sorry, I wrote that in a hurry and did not explain it correctly. in my example the textures list does not contain Texture objects but objects that have a method create_image() that returns a PNMImage instance. Instead you could simply have a list of PNMImage.
Sadly Panda has methods to directly load mipmap levels directly from the ram, but it’s not possible for array pages, so you have to use PNMImage or manipulate the memory as you do.