OpenGL, disabling texture block, glActiveTexture and glBindTexture

How do I disable a texture block, or at least prevent it from changing state when linking a texture? I use shaders, so there is no gldisable for this, I don’t think. The problem is that the event chain might look something like this:

Create texture 1 (implies binding it) Use texture 1 with texture unit 1 Create texture 2 (implies binding it) Use texture 2 with texture unit 2 

but, given the semantics of glActiveTexture, this seems impossible, because creating texture 2 will become associated with the state of texture block 1, since that was the last element that I called glActiveTexture on. those. you need to write:

 Create texture 1 Create texture 2 Use texture 1 with texture unit 1 Use texture 2 with texture unit 2 

Of course, I simplified the example, but the fact that creating and snapping a texture can accidentally affect the active texture structure, even when you only bind the texture as part of the creation process, is something that makes me somewhat uncomfortable, Of course, I have not made a mistake here and there, what can I do to disable state changes in the current glActiveTexture?

Thanks for any help you can give me here.

+4
source share
1 answer

This is pretty much what you need to learn how to live in OpenGL. GL functions only affect the current state. Therefore, to change an object, you must bind it to the current state and change it.

In general, however, you should not have a problem. There is no reason to create textures in the same place where you snap them for use. Code that actually moves your scene and binds textures for rendering should never create textures. The rendering code should set all the necessary state for each rendering (unless it knows that all the necessary state has been set in this render call earlier). Thus, this should be mandatory for all textures that every object needs. Thus, previously created textures will be evicted.

And anyway, I suggest unwrapping the textures after creation (i.e. glBindTexture(..., 0) ). This prevents them from sticking.

And remember: when you bind a texture, you also untie any texture that is currently bound. Thus, texture functions will only affect the new object.

However, if you want to rely on the EXT extension, there is EXT_direct_state_access. It is supported by NVIDIA and AMD, so it is quite widely available. It allows you to modify objects without snapping them, so you can create a texture without snapping to it.

+4
source

All Articles