In a straightforward procedure of using textures in WebGL (and I believe OpenGL), it makes sense to do something like the following:
- Activate the texture unit w/
gl.activeTexture()
- Bind the texture w/
gl.bindTexture()
- Setup the parameters w/
gl.texParameteri()
and friends - Upload the data w/
gl.texImage2D()
- Assign the correct unit to the sampler w/
gl.uniform1i()
- Draw
This is also the approach taken by various books and tutorials for learning the technique.
However - in more advanced usage where a texture may be re-used for different shaders or it's desirable to have a split between loading and rendering, it seems like step 1 (assigning the texture unit) might be unnecessary until render time.
Does the texture unit really affect the setup of the texture itself?
In other words - is the following approach ok?
PREP (for each texture, before any render calls)
- Do not activate the texture unit (will always be default 0 here)
- Bind the texture w/
gl.bindTexture()
- Setup the parameters w/
gl.texParameteri()
and friends - Upload the data w/
gl.texImage2D()
RENDER (on each tick)
- Activate the desired texture unit w/
gl.activeTexture()
- Bind the texture w/
gl.bindTexture()
- Assign the correct unit to the sampler w/
gl.uniform1i()
- Draw