I have the following code:
BindTextureUnit(&editor->devTexture, 0);
BindTextureUnit(&editor->renderBuffer, 1);
BindTextureUnit(&editor->lightBuffer, 2);
BindTextureUnit(&editor->uiSprites, 3);
GLenum err = glGetError();
Which consists of:
_INTERNAL void
BindTextureUnit(Texture* texture, u32 unit)
{
glActiveTexture(GL_TEXTURE0 + unit);
glBindTexture(GL_TEXTURE_2D, texture->handle);
texture->unit = unit;
}
This section before the game loop is the only place where I bind textures to texture units. Rest of the time I set the sampler in shaders. Also note that the GL Error is set to 0 through all of this.
The first three textures work as expected, no problems. I recently added the fourth texture "uiSprites". When I render anything with that texture, it comes out white. Now supposedly my GPU can handle 192 texture units, so I'm not running out...but for some reason the texture units above 2 don't work properly.
Here is what I've found in my investigations
- I know for sure that the textures are being loaded correctly. If I put uiSprites into the first texture unit, it renders correctly. Similarly, if I put devTexture into the 3rd unit, it renders white.
- If I comment out the first line, where devTexture is being bound, then I bind uiSprites to unit 0 AFTER binding the renderBuffer and lightBuffer...the texture is rendered as white. This means that the only time binding to texture unit 0 works is if I do it before the other two.
renderBuffer and lightBuffer are both Framebuffers and work correctly the whole time while testing this. I'm wracking my brain trying to figure out why a) the 3rd texture unit is white b) why is this order dependent?