Game Development Reference
In-Depth Information
pname : This parameter specifies the symbolic name of a single-valued
texture parameter and can be one of the following: GL_DEPTH_STENCIL_
TEXTURE_MODE , GL_TEXTURE_BASE_LEVEL , GL_TEXTURE_COMPARE_FUNC , GL_
TEXTURE_COMPARE_MODE , GL_TEXTURE_LOD_BIAS , GL_TEXTURE_MIN_FILTER ,
GL_TEXTURE_MAG_FILTER , GL_TEXTURE_MIN_LOD , GL_TEXTURE_MAX_LOD ,
GL_TEXTURE_MAX_LEVEL , GL_TEXTURE_SWIZZLE_R , GL_TEXTURE_SWIZZLE_G ,
GL_TEXTURE_SWIZZLE_B , GL_TEXTURE_SWIZZLE_A , GL_TEXTURE_WRAP_S ,
GL_TEXTURE_WRAP_T , or GL_TEXTURE_WRAP_R
param : This parameter specifies the value of pname
The gl.texParameteri function sets the texture filtering mode for each texture
used in our application. It operates on the currently bound texture and sets the filter
mode for the texture. This also means that for every texture we load, we will have to
specify the filter mode for it.
We will learn all filter modes as we move but for now, we will be using the nearest-
neighbor interpolation method. Take a look at the following code:
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER,
gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
gl.NEAREST);
Nearest-neighbor interpolation is the fastest and crudest filtering method. It simply
uses the color of the texel closest to the pixel center for the pixel color. However,
the rendering of textures is not as good as expected. It results in a large number
of artifacts such as blockiness in case of magnification and aliasing/shimmering
in minification.
The preceding two lines of code set the nearest-neighbor interpolation filter for both
magnification and minification.
We will introduce a new data type in the ESSL code, sampler2D , to reference the
texture data in the shader and texture lookup functions.
A new data type - sampler
A sampler data type can be sampler1D , sampler2D , and sampler3D . A variable of
the sampler can only be defined in one of two ways. It can be defined as a function
parameter or as a uniform variable, shown as follows:
uniform sampler2D texture1;
void Function(in sampler2D myTexture);
 
Search WWH ::




Custom Search