WebGLRenderingContext.texParameter[fi]()

WebGL API  的WebGLRenderingContext.texParameter[fi]()方法用于设置纹理参数.

语法

void gl.texParameterf(GLenum target, GLenum pname, GLfloat param);
void gl.texParameteri(GLenum target, GLenum pname, GLint param);

参数

target
GLenum 指定绑定点(目标)。可能的值:
  • gl.TEXTURE_2D: 二维纹理.
  • gl.TEXTURE_CUBE_MAP: 立方体纹理.
  • 当使用 WebGL 2 context 时,还可以使用以下值
    • gl.TEXTURE_3D: 三维贴图.
    • gl.TEXTURE_2D_ARRAY: 二维数组贴图.

pname 参数是 Glenum  指定要设置的纹理参数. param 参数是 GLfloat 或 GLint 已指定的 pname参数的值。

pname 描述 参数
Available in WebGL 1
gl.TEXTURE_MAG_FILTER 纹理放大滤波器 gl.LINEAR (默认值), gl.NEAREST.
gl.TEXTURE_MIN_FILTER 纹理缩小滤波器 gl.LINEAR, gl.NEAREST, gl.NEAREST_MIPMAP_NEAREST, gl.LINEAR_MIPMAP_NEAREST, gl.NEAREST_MIPMAP_LINEAR (默认值), gl.LINEAR_MIPMAP_LINEAR.
gl.TEXTURE_WRAP_S 纹理坐标水平填充 s gl.REPEAT (默认值),gl.CLAMP_TO_EDGE, gl.MIRRORED_REPEAT.
gl.TEXTURE_WRAP_T 纹理坐标垂直填充 t gl.REPEAT (默认值),gl.CLAMP_TO_EDGE, gl.MIRRORED_REPEAT.
Additionally available when using the EXT_texture_filter_anisotropic extension
ext.TEXTURE_MAX_ANISOTROPY_EXT 纹理最大向异性  GLfloat 值.
Additionally available when using a WebGL 2 context
gl.TEXTURE_BASE_LEVEL 纹理映射等级 任何整型值.
gl.TEXTURE_COMPARE_FUNC 纹理对比函数 gl.LEQUAL (默认值), gl.GEQUAL, gl.LESS, gl.GREATER, gl.EQUAL, gl.NOTEQUAL, gl.ALWAYS, gl.NEVER.
gl.TEXTURE_COMPARE_MODE 纹理对比模式 gl.NONE (默认值), gl.COMPARE_REF_TO_TEXTURE.
gl.TEXTURE_MAX_LEVEL 最大纹理映射数组等级 任何整型值.
gl.TEXTURE_MAX_LOD 纹理最大细节层次值 任何整型值.
gl.TEXTURE_MIN_LOD 纹理最小细节层次值 任何浮点型值.
gl.TEXTURE_WRAP_R 纹理坐标r包装功能 gl.REPEAT (默认值), gl.CLAMP_TO_EDGE, gl.MIRRORED_REPEAT.

返回值

INVALID_ENUM target不是合法的值。

INVALID_OPRATION 当前目标上没有绑定纹理对象。

示例

gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);

说明

Specification Status Comment
WebGL 1.0
texParameter[fi]
Recommendation WebGL初始定义.
OpenGL ES 2.0
glTexParameter
Standard OpenGL ES 2.0 API手册(类似).
WebGL 2.0
texParameter[fi]
Editor's Draft WebGL更新定义.
OpenGL ES 3.0
glTexParameter
Standard OpenGL ES 3.0 API手册(类似).

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
texParameterfChrome Full support 9Edge Full support 12Firefox Full support 4IE Full support 11Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support 25Firefox Android Full support YesOpera Android Full support 12Safari iOS Full support 8Samsung Internet Android Full support Yes
WebGL2Chrome Full support 56Edge No support NoFirefox Full support 51IE No support NoOpera Full support 43Safari No support NoWebView Android Full support 58Chrome Android Full support 58Firefox Android Full support 51Opera Android Full support 43Safari iOS No support NoSamsung Internet Android Full support 7.0

Legend

Full support  
Full support
No support  
No support

另见