Jump to content
  • Advertisement
Sign in to follow this  
mrMatrix

DSA binding the same tex over diff shaders

This topic is 1497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!