Best way to store multiple textures.

I am using a program which needs a varying number of textures. Is there way to make a buffer (or vector-like object) of textures?

One possible workaround I thought of was using one contiguous block of memory and store (in a buffer) starting indices of where each individual texture was stored.

Because each buffer must be declared at the beginning of each cuda file I haven’t been able to find a cleaner way to do this. Any ideas? Your help is greatly appreciated!

Hi (Josh?)

Optix 3.0 has Bindless Textures as a new feature, which could could be useful in this case.

This allows to query an id for a texture on the host, and then use this id to access the texture on the device without having to do an explicit texture declaration. The rayDifferentials sample shows how to do this:

On the host you can fill a buffer with texture ids:

TextureSampler samplers[16];
...
Buffer tex_ids = matl->getContext()->createBuffer(RT_BUFFER_INPUT,RT_FORMAT_INT, num_levels);
m_context["tex_ids"]->set( tex_ids );
int *ids = (int*)tex_ids->map();
for(int l = 0; l < num_levels; ++l)
  ids[l] = samplers[l]->getId();
tex_ids->unmap();

The device can then access the textures using the ids stored in the buffer:

rtBuffer tex_ids;
...
int texId = ...;
float4 color = rtTex2D(tex_ids[texId], uv.x, uv.y)

I’m just noticing that the forum software seems to have problems with templated code snippets. Of course, after rtBuffer and rtText2D you need to specify the template type.