Reputation: 41
Why do I have to use SDL_LockTexture and SDL_UnlockTexture to manipulate hardware textures with SDL2? I am aware of the difference between "STATIC" texture access and "STREAMING" texture access, but I guess I am confused because I seem to remember using "SDL_SetTextureColorMod" to adjust the color of "STATIC" textures. So, why is it that sometimes we have to lock pixels and sometimes we don't?
Upvotes: 1
Views: 487
Reputation: 2558
You have to lock a texture in order to modify its pixels. SDL_SetTextureColorMod
doesn't do this, it only sets a color which is multiplied with color of a pixel when the texture is used for rendering.
Why do I have to use SDL_LockTexture and SDL_UnlockTexture to manipulate hardware textures?
"Hardware texture" means that pixels of a texture are stored in VRAM and can be directly accessed by a GPU when rendering. You can't modify VRAM memory directly. SDL_LockTexture
returns pointer to buffer accessible by CPU, while SDL_UnlockTexture
copies this (modified) buffer back to VRAM.
Upvotes: 6