Sign in to follow this  
mrMatrix

DSA binding the same tex over diff shaders

Recommended Posts

I have TWO different objects with TWO different shaders and each frag shader has texture units like this
 
layout(binding = 0) uniform sampler2D tex1;
layout(binding = 1) uniform sampler2D tex2;
 
I create two new textures with DSA like this, one after another with "someTexA" and "someTexB"
 
glCreateTextures(GL_TEXTURE_2D, 1, &sometTexH);
unsigned char *img = SOIL_load_image(string(pathTex + "sometTexA.png").c_str(), &imgW, &imgH, &chan, SOIL_LOAD_RGBA);
glTextureStorage2D(sometTexH, 1, GL_RGBA16, imgW, imgH);
glTextureSubImage2D(sometTexH, 0, 0, 0, imgW, imgH, GL_RGBA, GL_UNSIGNED_BYTE, img);
glBindTextureUnit(0, sometTexH);
SOIL_free_image_data(img);
 
They have different debug textures in slot 0; If I bind two in a row with the above code, the glBindTextureUnit function puts the same tex "sometTexA" into both shaders so when I render they both have the same texture being used.
 
I assume I have to clear something between subsequent calls to create the tex?
 
My rendering looks like this. Ive removed the old ActiveTexture / glBindTexture between each program as they should be redundant with DSA tex
 
    //1
    glUseProgram(pFBO1);
    // glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, someTexH);
// GLuint someTexBindLoc = glGetUniformLocation(pFBO, "someTexA");
// glUniform1i(someTexBindLoc, 0);


    glBindVertexArray(myVAO1);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);


    //2
    glUseProgram(pFBO2);


    glBindVertexArray(myVAO2);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
Edited by mrMatrix

Share this post


Link to post
Share on other sites
I don't see you setting the uniform for which texture unit to use with which sampler.
As far as I understand it, the layout just says "your sampler is sampler #0."
But that still doesn't tell the program "this sampler pulls data from this texture unit over here" -- samplers and textures are separate.

I could be wrong, though, I haven't done OpenGL for a very long time.

Share this post


Link to post
Share on other sites

I don't see you setting the uniform for which texture unit to use with which sampler.
As far as I understand it, the layout just says "your sampler is sampler #0."
But that still doesn't tell the program "this sampler pulls data from this texture unit over here" -- samplers and textures are separate.

I could be wrong, though, I haven't done OpenGL for a very long time.

 

I have something working by calling glBindTextureUnit(THE_UNIT, HANDLE) which I've read replaces glActiveTexture / glBindTexture and is to be used with DSA. I think what I really want is bindless (sparse?) textures to go along with DSA...right?

Share this post


Link to post
Share on other sites

Not necessarily, as long as you don't run out of texture units (meaning you would have to rebind textures a lot) it's probably even faster than bindless, resident textures.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this