Hi!
I would like to use bindless textures in a compute shader, so I declared an UBO like this :
layout(std140, binding = 0) uniform ALL_TEXTURES {
sampler2D textures[200];
};
I pass the texture index to an SSBO and I get it in the shader like this :
color * texture2D(textures[triangle.textureIndex], pixel.texCoords)
I create the UBO and fill it with textures indexes :
std::vector<Texture*> allTextures = Texture::getAllTextures(); Samplers allSamplers{}; for (unsigned int i = 0; i < allTextures.size(); i++) { allSamplers.tex[allTextures[i]->getNativeHandle()] = allTextures[i]->getNativeHandle(); } GLuint ubo = 0; glGenBuffers(1, &ubo); glBindBuffer(GL_UNIFORM_BUFFER, ubo); glBufferData(GL_UNIFORM_BUFFER, sizeof(allSamplers),allSamplers.tex, GL_STATIC_DRAW); GLuint ubid = glGetUniformBlockIndex( rayComputeShader.getHandle(), "ALL_TEXTURES"); glUniformBlockBinding(rayComputeShader.getHandle(), ubid, 0); glBindBuffer(GL_UNIFORM_BUFFER, 0); backgroundColor = sf::Color::Transparent; std::vector<Texture*> allTextures = Texture::getAllTextures(); Samplers allSamplers{}; for (unsigned int i = 0; i < allTextures.size(); i++) { allSamplers.tex[allTextures[i]->getNativeHandle()] = allTextures[i]->getNativeHandle(); } GLuint ubo = 0; glGenBuffers(1, &ubo); glBindBuffer(GL_UNIFORM_BUFFER, ubo); glBufferData(GL_UNIFORM_BUFFER, sizeof(allSamplers),allSamplers.tex, GL_STATIC_DRAW); GLuint ubid = glGetUniformBlockIndex( rayComputeShader.getHandle(), "ALL_TEXTURES"); glUniformBlockBinding(rayComputeShader.getHandle(), ubid, 0); glBindBuffer(GL_UNIFORM_BUFFER, 0); backgroundColor = sf::Color::Transparent;
glCheck(glBindBufferBase(GL_UNIFORM_BUFFER, 0, ubo));
glCheck(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, linkedListBuffer));
glCheck(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, trianglesSSBO));
glCheck(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, lightsSSBO));
glCheck(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, linkedListBuffer));
glCheck(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, trianglesSSBO));
glCheck(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, lightsSSBO));
To make it simple the texture index is the same as the texture handle.
I declare my structure like this in c++ :
struct Samplers {
GLuint64 tex[200];
};
What’s wrong ?
Thanks.