EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

texParameteri method

Sets texture parameters for the current texture unit.

IE11

 

Syntax

WebGLRenderingContext.texParameteri(target, pname, param);

Parameters

target [in]

Type: Number

The target texture for the current texture unit. Must be one of the following:

ValueMeaning
gl.TEXTURE_2D

Represents a 2D image.

gl.TEXTURE_CUBE_MAP

The texture is composed of six 2D images, one for each face of a cube.

 

pname [in]

Type: Number

The name of the texture parameter. Use one of the following:

ValueMeaning
gl.TEXTURE_MIN_FILTER

A texture filter constant to use when a surface is rendered smaller than the corresponding texture bitmap (such as for distant objects). Initial value is gl.NEAREST_MIPMAP_LINEAR.

gl.TEXTURE_MAG_FILTER

A texture filter constant to use when a surface is rendered larger than the corresponding texture bitmap (such as for close-up objects). Initial value is gl.LINEAR.

gl.TEXTURE_WRAP_S

Sets the wrap parameter for texture coordinate s to either gl.CLAMP or gl.REPEAT. gl.CLAMP causes s coordinates to be clamped to the range [0,1] and is useful for preventing wrapping artifacts when mapping a single image onto an object. gl.REPEAT causes the integer part of the s coordinate to be ignored; WebGL uses only the fractional part, thereby creating a repeating pattern. Border texture elements are accessed only if wrapping is set to gl.CLAMP. Initial value is gl.REPEAT.

gl.TEXTURE_WRAP_T

Sets the wrap parameter for texture coordinate t to either gl.CLAMP or gl.REPEAT. Initial value is gl.REPEAT.

gl.TEXTURE_MAX_ANISOTROPY_EXT

Use anisotropic filtering. You must call getExtension("gl.TEXTURE_MAX_ANISOTROPY_EXT") first to enable. For more info, see Anisotropic filtering.

 

param [in]

Type: Number

The value of pname.

Return value

This method does not return a value.

Remarks

WebGL errorDescription
gl.INVALID_OPERATIONIf no texture is bound.
gl.INVALID_ENUMIf target, pname, or param values are invalid.

 

The value of param depends on the value of pname. When using floating-point textures, only gl.NEAREST is supported. The following shows possible calling values :

  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
  • texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT)

Examples

The following example uses texParameteri to set the parameters on an image to be rendered. For more info on this example, see Get started with WebGL.


// Create a texture object that will contain the image.
var texture = gl.createTexture();

// Bind the texture the target (TEXTURE_2D) of the active texture unit.
gl.bindTexture(gl.TEXTURE_2D, texture);

// Flip the image's Y axis to match the WebGL texture coordinate space.
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
    
// Set the parameters so we can render any size image.        
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);

  // Upload the resized canvas image into the texture.
//    Note: a canvas is used here but can be replaced by an image object. 
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);


See also

WebGLRenderingContext

 

 

Mostrar:
© 2014 Microsoft