[Opengl]Bindless texturing, texture are not drawn

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.

Did you mean to use the old texture2D function instead of just texture? I’m kind of unsure how using deprecated functions will work with bindless textures.

What is this doing? I don’t know what a “native handle” is, but I’m pretty sure it’s impossible for it to both be the index of a texture and the handle extracted from glGetTextureHandleARB. Yet that’s what you’re doing. You’re using the same “native handle” as both index and value.

It seems more likely that you meant:

allSamplers.tex[i] = allTextures[i]->getNativeHandle();

Also, why is the code there twice?

The native handle returns the number generated by the glGenTextures function so it’s one here because I use the first texture.

I changed the code like this :

allSamplers.tex[i] = allTextures[i]->getNativeHandle();

So for texture one the texture index is 1-1 so, 0 :

pixel.color = (triangle.textureIndex > 0) ? color * texture(textures[triangle.textureIndex-1], pixel.texCoords) : color;

0 is no texture.

But that doesn’t work too, I also added this :

for (unsigned int i = 0; i < allTextures.size(); i++) {
                    GLuint64 handle_texture = glGetTextureHandleARB(allTextures[i]->getNativeHandle());
                    std::cout<<"handle texture : "<<handle_texture<<std::endl;
                    glMakeTextureHandleResidentARB(handle_texture);
                    allSamplers.tex[i] = allTextures[i]->getNativeHandle();
                }

But, the handle_texture is a great number.

But that doesn’t works too.

Ok I solved the problem, this is the handle to the texture I’ve to pass to the UBO and not the texture ID so I changed this line to this :

for (unsigned int i = 0; i < allTextures.size(); i++) {
                GLuint64 handle_texture = glGetTextureHandleARB(allTextures[i]->getNativeHandle());
                std::cout<<"handle texture : "<<handle_texture<<std::endl;
                glMakeTextureHandleResidentARB(handle_texture);
                allSamplers.tex[i] = handle_texture;
            }

Now it’s working!