OpenGL 的glDisable(GL_TEXTURE_2D)函数和glBindTexture(GL_TEXTURE_2D,0)有什么区别?


OpenGL glDisable(GL_TEXTURE_2D) vs glBindTexture(GL_TEXTURE_2D,0)

These are two fundamentally different things.


glDisable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,0)

glDisable (GL_TEXTURE_2D)

  • Disables 2D textures for the active Texture Unit in the fixed-function OpenGL pipeline.
  • In programmable OpenGL (GLSL or the older ARB VP/FP assembly languages), enabling or disabling GL_TEXTURE_2D is meaningless.

glBindTexture (GL_TEXTURE_2D,0)

  • Binds the "default" texture to the active Texture Image Unit.
  • For all intents and purposes, there is always a texture bound to a Texture Image Unit; 0 is just a special-case with an initially incomplete set of states, thus complicating validation (see below).

There is a little bit of validation overhead associated with binding any OpenGL resource (GLSL programs and FBOs tend to have the most complicated validation). In general,

Therefore,

If your intention by binding 0 was simply to "disable" a texture, you would be better off setting a uniform value to communicate this intent to a shader. Uniforms are extremely cheap to set (assuming you do not do something stupid like query their location everytime you set them). Changing a uniform is orders of magnitude quicker than binding a different texture or even worse a different GLSL program.


If you are using fixed-function OpenGL: OpenGL1.0

  • Disabling GL_TEXTURE_2D is a better way of approaching this problem.
  • Changing bound objects should be done as little as possible.

If you are using programmable OpenGL: OpenGL2.0

  • Neither of these things make much sense.
  • Work your desired behavior into your shaders.

https://gamedev.stackexchange.com/questions/74583/opengl-gldisablegl-texture-2d-vs-glbindtexturegl-texture-2d-0/74584