GPUs support the capability to apply two or more textures simultaneously during
a single pass rendering.
Example: Grass texture and checkerboard texture
it is a good idea to determine how many texture units are supported by the
graphics hardware. This can be done
GLint MaxUnits; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &MaxUnits);
my computer, there are 32 texture units!
texture binding operations affect the currently active texture unit. By
default, the 0th
texture unit is the active texture unit.
can be changed using: glActiveTexture(Glenum
where textureUnit is GL_TEXTURE0,
active, a texture can be bound
in the template, this can be done by calling the Bind(int unit)
of a CTexture object, unit is the texture unit to use.
that any type of texture (1D, 2D, 3D, cube maps) can be loaded into any texture
GLSL, we’ll use sampler2Ds to access texels in the different units. On the client side, we must indicate which
texture unit to use for each sampler2D.
example, suppose in your fragment shader you have four textures that you are
applying simultaneously. pTerrainProgram->SetUniform("sampler0", 0); pTerrainProgram->SetUniform("sampler1", 1); pTerrainProgram->SetUniform("sampler2", 2); pTerrainProgram->SetUniform("sampler3", 3);
multi-textured with four different textures, interpolated by height.