Whenever I try to use textures, I have to at least specify the sample filtering parameters (GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER) for textures to work at all. If I don't, sampling the textures in a shader will usually just return a value of 0 for all texels in the texture, even though glReadPixels return the correct values, and rendering to the textures actually works. Debugging tools like Nsight and gDebugger confirm this.
I tested this on two NVIDIA GPUs (GTX 970, GT 555m) with the latest driver versions (347.09), and the behavior is the same.
However, I can't find any reference to this in docs like this or this
I assumed that not specifying these parameters just made them take on their default values. So is this actually intended standard behavior (probably meaning "undefined behavior") or can I assume this is a driver bug?
Answer
By default, OpenGL assumes that your textures will have mipmaps attached. If you haven't attached any mipmaps to a texture, then OpenGL assumes that you didn't finish setting it up. OpenGL will therefore deem the texture to be "incomplete" and will refuse to render from it.
In order to make your texture "complete" in OpenGL's eyes (and therefore usable for rendering), you need to do one of the following:
- Set
GL_TEXTURE_MIN_FILTER
to something which won't try to use mipmap data. (GL_NEAREST
orGL_LINEAR
) - or set
GL_TEXTURE_MAX_LEVEL
to 0, thus explicitly declaring that your texture has no mipmaps, so that OpenGL won't be bothered by their nonexistence. - or create mipmaps for your texture.
- or tell OpenGL to automatically create the mipmaps for you, using
glGenerateMipmap()
or theGL_GENERATE_MIPMAP
texture parameter.
You can read more discussion of this issue in opengl.org's Common Mistakes document. This issue is number six in their list; "Creating a complete texture".
No comments:
Post a Comment