What happens if you bind (different textures) to both GL_TEXTURE_2D
and GL_TEXTURE_CUBE_MAP
in the same texture image unit?
For example, suppose I bind one texture to GL_TEXTURE0
's GL_TEXTURE_2D
target and another texture to the same texture unit's GL_TEXTURE_CUBE_MAP
target. Can I then have two uniform variables, one a sampler2D
and the other a samplerCube
and set both to 0 (to refer to GL_TEXTURE0
)?
I suspect the answer is "no" (or that the result is undefined) but I haven't found anything in the spec that specifically prohibits using multiple texture targets in the same texture image unit.
The texture is an OpenGL object that contains one or more images that all have the same image format. To draw texture in a square shape, we need to tell each vertex of the square which part of the texture it corresponds to. So each vertex of the shape has a texture coordinate associated with them.
Load the file from your system and convert it into a format OpenGL ES can understand. Generate a texture object and activate the desired texture unit. Load the texture data into the texture unit using glTexImage2D. Set the sampling methods with glTexParameteri.
glteximage2d is the function that actually moves the texture data across to the gpu. you will need to create the texture object first using glGenTextures() and then bind it using glBindTexture(). you can then use this texture with a VBO.
OpenGL 3. x defines the minimum number for the per-stage limit to be 16, so hardware cannot have fewer than 16 textures-per-stage. It can have a higher limit, but you know you get at least 16.
I haven't found anything that describes if you can bind a 2D texture and a cube map texture in the same texture unit, but (or so) I guess this is perfectly possible. It makes sense to allow it, since all texture modification functions require you to specify the texture target to operate on, anyway.
But the OpenGL ES 2 spec explicitly disallows to use both at the same time in a shader, as chapter 2.10 says:
It is not allowed to have variables of different sampler types pointing to the same texture image unit within a program object. This situation can only be detected at the next rendering command issued, and an INVALID_OPERATION error will then be generated.
So you cannot use both a sampler2D
and a samplerCube
referring to the same texture unit to bend your implementation's texture unit limits.
For Chrome, I'm getting an error trying to perform such an operation.
var gl = document.getElementById("canv00").getContext("webgl");
const texture = gl.createTexture()
gl.bindTexture(gl.TEXTURE_2D, texture)
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture)
gl.getParameter(gl.TEXTURE_BINDING_2D) // texture
gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP) // null
gl.getError() // returns 1282 error
var gl = document.getElementById("canv00").getContext("webgl");
const texture = gl.createTexture()
gl.bindTexture(gl.TEXTURE_2D, texture)
// gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture)
gl.getParameter(gl.TEXTURE_BINDING_2D) // texture
gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP) // null
gl.getError() // no error
var gl = document.getElementById("canv00").getContext("webgl");
const texture = gl.createTexture()
// gl.bindTexture(gl.TEXTURE_2D, texture)
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture)
gl.getParameter(gl.TEXTURE_BINDING_2D) // null
gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP) // texture
gl.getError() // no error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With