Search code examples
openglbindingtexturestarget

OpenGL: What happens to a texture if I bind a new one to another target?


I'm currently learning some OpenGL theory. Now I got some questions of which I cant find an answer.

Here is one of my question: Lets assume, that I bind a GL_TEXTURE_2D to unit GL_TEXTURE0 like this:

GL.glBindTexture(GL.GL_TEXTURE_2D, myTexture1_ID);

Now I'm going to bind another one, but this time it's a GL_TEXTURE_1D.

GL.glBindTexture(GL.GL_TEXTURE_1D, myTexture2_ID);

What happens to the first binding call? Does it unbind, because of the same texture unit or does it stay, because of the different texture target?

Thanks!


Solution

  • The texture binding to the target GL_TEXTURE_2D is left untouched as long as you are not rebinding another texture to the same target.

    You can even bind multiple textures, each to a different "texture unit" by calling

    glActiveTexture(GL_TEXTURE0 + i)
    

    before binding a new texture.