OpenGL ES 纹理参数设置方法 glTexParameter
太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)
本文遵循“署名-非商业用途-保持一致”创作公用协议
以下译自官网。
最近几天,会针对该方法的每个参数,做相应的翻译、分析理解和测试;
测试的结果会更新 OpenGL ES 纹理贴图的重复与嵌位概念理解 。
以下当前暂时只更新了上一篇中翻译过的部分。
后续,随研究,随翻,随更新,敬请关注。
函数名 Name
glTexParameter — 设置纹理参数 set texture parameters
C 规范 C Specification
void glTexParameterf( |
GLenum target, |
GLenum pname, | |
GLfloat param) ; |
void glTexParameteri( |
GLenum target, |
GLenum pname, | |
GLint param) ; |
函数参数 Parameters
-
target
-
指定活动纹理单元的目标纹理,它必须是
GL_TEXTURE_2D
或GL_TEXTURE_CUBE_MAP 中的一个。
Specifies the target texture of the active texture unit, which must be eitherGL_TEXTURE_2D
orGL_TEXTURE_CUBE_MAP
. -
pname
-
指定单值纹理参数的标记名。pname 可以是以下值之一:
GL_TEXTURE_MIN_FILTER
,GL_TEXTURE_MAG_FILTER
,GL_TEXTURE_WRAP_S
GL_TEXTURE_WRAP_T。
Specifies the symbolic name of a single-valued texture parameter.pname
can be one of the following:GL_TEXTURE_MIN_FILTER
,GL_TEXTURE_MAG_FILTER
,GL_TEXTURE_WRAP_S
, orGL_TEXTURE_WRAP_T
. -
param
-
指定 pname 的值。
Specifies the value ofpname
.
C 规范 C Specification
void glTexParameterfv( |
GLenum target, |
GLenum pname, | |
const GLfloat * params) ; |
void glTexParameteriv( |
GLenum target, |
GLenum pname, | |
const GLint * params) ; |
函数参数 Parameters
-
target
-
指定活动纹理单元的目标纹理,它必须是
GL_TEXTURE_2D
或GL_TEXTURE_CUBE_MAP 中的一个。
Specifies the target texture of the active texture unit, which must be eitherGL_TEXTURE_2D
orGL_TEXTURE_CUBE_MAP
. -
pname
-
指定单值纹理参数的标记名。pname 可以是以下值之一:
GL_TEXTURE_MIN_FILTER
,GL_TEXTURE_MAG_FILTER
,GL_TEXTURE_WRAP_S
或GL_TEXTURE_WRAP_T。
Specifies the symbolic name of a texture parameter.pname
can be one of the following:GL_TEXTURE_MIN_FILTER
,GL_TEXTURE_MAG_FILTER
,GL_TEXTURE_WRAP_S
, orGL_TEXTURE_WRAP_T
. -
params
-
指定一个数组指针,其中存储着 pname 的值。
Specifies a pointer to an array where the value ofpname
is stored.
函数描述 Description
纹理映射是这样一个技术,它把一张图片应用到一个对象的表面,就好像这张图片是一个贴纸或玻璃纸收缩。图片在纹理空间使用一个(s,t)坐标系统创建。纹理是一个二维空间或立方体映射的图片以及一组参数用于确定如何从图片中导出采样。
Texture mapping is a technique that applies an image onto an object's surface as if the image were a decal or cellophane shrink-wrap. The image is created in texture space, with an (s, t) coordinate system. A texture is a two-dimensional or cube-mapped image and a set of parameters that determine how samples are derived from the image.
glTexParameter 把 params 中的一个或多个值赋给 pname 指定的纹理参数。target 定义活动纹理单元的目标纹理,值为
assigns the value or values in GL_TEXTURE_2D
或 GL_TEXTURE_CUBE_MAP 中的一个。pname 可接受如下标记:
glTexParameterparams
to the texture parameter specified as pname
. target
defines the target texture of the active texture unit, either GL_TEXTURE_2D
orGL_TEXTURE_CUBE_MAP
. The following symbols are accepted in pname
:
-
GL_TEXTURE_MIN_FILTER
-
纹理缩小函数用于每当被纹理映射到一个区域的像素大于一个纹理元素时。有六个预定义的缩小函数。它们中的两个使用最近的一个或最近的四个纹理元素来计算纹理值。其它四个使用 mipmaps 。
The texture minifying function is used whenever the pixel being textured maps to an area greater than one texture element. There are six defined minifying functions. Two of them use the nearest one or nearest four texture elements to compute the texture value. The other four use mipmaps.mipmap 是一组有序的以渐低分辩率呈现同一图片的数组。如果纹理有 w × h 这样的尺寸,那么就有 “ floor log 2 max w h + 1” 级 mipmap 。第一级 mipmap 是原始的纹理,拥有w × h 的尺寸 。接下来的每一级 mipmap 拥有 “max 1 floor w 2 i × max 1 floor h 2 i” 这样的尺寸,这里 i 是 mipmap 层级,直到达到最后的 mipmap 分级,该级拥用 1 × 1 的尺寸。
A mipmap is an ordered set of arrays representing the same image at progressively lower resolutions. If the texture has dimensions w × h , there are floor log 2 max w h + 1 mipmap levels. The first mipmap level is the original texture, with dimensions w × h . Each subsequent mipmap level has dimensions max 1 floor w 2 i × max 1 floor h 2 i , where i is the mipmap level, until the final mipmap is reached, which has dimension 1 × 1 .要定义 mipmap 分级,调用 glTexImage2D, glCompressedTexImage2D, 或 glCopyTexImage2D,带着指定 mipmap 顺序的参数 level 。0 级是原始纹理;“floor log 2 max w h” 是最后一级 1 × 1 的 mipmap 。
To define the mipmap levels, call glTexImage2D, glCompressedTexImage2D, or glCopyTexImage2D with the level argument indicating the order of the mipmaps. Level 0 is the original texture; levelfloor log 2 max w h is the final 1 × 1 mipmap.params 指定一个函数用于按下面中的一种方式来缩小纹理:
supplies a function for minifying the texture as one of the following:
params-
GL_NEAREST
-
返回最贴近被填充像素中心的纹理元素值。
Returns the value of the texture element that is nearest (in Manhattan distance) to the center of the pixel being textured. -
GL_LINEAR
-
Returns the weighted average of the four texture elements that are closest to the center of the pixel being textured. -
GL_NEAREST_MIPMAP_NEAREST
-
Chooses the mipmap that most closely matches the size of the pixel being textured and uses the
GL_NEAREST
criterion (the texture element nearest to the center of the pixel) to produce a texture value. -
GL_LINEAR_MIPMAP_NEAREST
-
Chooses the mipmap that most closely matches the size of the pixel being textured and uses the
GL_LINEAR
criterion (a weighted average of the four texture elements that are closest to the center of the pixel) to produce a texture value. -
GL_NEAREST_MIPMAP_LINEAR
-
Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the
GL_NEAREST
criterion (the texture element nearest to the center of the pixel) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values. -
GL_LINEAR_MIPMAP_LINEAR
-
Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the
GL_LINEAR
criterion (a weighted average of the four texture elements that are closest to the center of the pixel) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.
As more texture elements are sampled in the minification process, fewer aliasing artifacts will be apparent. While the
GL_NEAREST
andGL_LINEAR
minification functions can be faster than the other four, they sample only one or four texture elements to determine the texture value of the pixel being rendered and can produce moire patterns or ragged transitions. The initial value ofGL_TEXTURE_MIN_FILTER
isGL_NEAREST_MIPMAP_LINEAR
. -
-
GL_TEXTURE_MAG_FILTER
-
The texture magnification function is used when the pixel being textured maps to an area less than or equal to one texture element. It sets the texture magnification function to either
GL_NEAREST
orGL_LINEAR
(see below).GL_NEAREST
is generally faster thanGL_LINEAR
, but it can produce textured images with sharper edges because the transition between texture elements is not as smooth. The initial value ofGL_TEXTURE_MAG_FILTER
isGL_LINEAR
.-
GL_NEAREST
-
Returns the value of the texture element that is nearest (in Manhattan distance) to the center of the pixel being textured.
-
GL_LINEAR
-
Returns the weighted average of the four texture elements that are closest to the center of the pixel being textured.
-
-
GL_TEXTURE_WRAP_S
-
设置纹理坐标的包装参数为
GL_CLAMP_TO_EDGE
,GL_MIRRORED_REPEAT 或
GL_REPEAT。
-
GL _CLAMP_TO_EDGE 使坐标夹紧在 这样的范围内 1 2N 1 - 12N (官方就这么写的,我也不知道是什么东西),这里 N 纹理在夹紧方向上的大小。
-
GL_REPEAT 使 s 坐标的整数部分被忽略; GL 只使用小数部分,从而创建一个重复构形。
GL_MIRRORED_REPEAT 在纹理坐标的整数部分是奇数时,使 s 坐标设置为纹理坐标的小数部分;如果整数部分是偶数,那么 s 坐标被设置成 1 - 小数部分,这里 s 的小数部分代表 s 的去掉整数部分后的小数部分。初始,GL_TEXTURE_WRAP_S 设为 GL_REPEAT。
Sets the wrap parameter for texture coordinate s to eitherGL_CLAMP_TO_EDGE
,GL_MIRRORED_REPEAT
, orGL_REPEAT
.GL_CLAMP_TO_EDGE
causes s coordinates to be clamped to the range 1 2N 1 - 12N , where N is the size of the texture in the direction of clamping.GL_REPEAT
causes the integer part of the s coordinate to be ignored; the GL uses only the fractional part, thereby creating a repeating pattern.GL_MIRRORED_REPEAT
causes the s coordinate to be set to the fractional part of the texture coordinate if the integer part of s is even; if the integer part of s is odd, then the s texture coordinate is set to 1 - frac s , where frac s represents the fractional part of s. Initially,GL_TEXTURE_WRAP_S
is set toGL_REPEAT
.
-
GL_TEXTURE_WRAP_T
-
t 坐标同 s 坐标。
Sets the wrap parameter for texture coordinate t to eitherGL_CLAMP_TO_EDGE
,GL_MIRRORED_REPEAT
, orGL_REPEAT
. See the discussion underGL_TEXTURE_WRAP_S
. Initially,GL_TEXTURE_WRAP_T
is set toGL_REPEAT
.
Notes
Suppose that a texture is accessed from a fragment shader or vertex shader and has set GL_TEXTURE_MIN_FILTER
to one of the functions that requires mipmaps. If either the dimensions of the texture images currently defined (with previous calls to glTexImage2D, glCompressedTexImage2D, or glCopyTexImage2D) do not follow the proper sequence for mipmaps (described above), or there are fewer texture images defined than are needed, or the set of texture images were defined with different formats or types, then the texture image unit will return (R, G, B, A) = (0, 0, 0, 1).
Similarly, if the width or height of a texture image are not powers of two and either the GL_TEXTURE_MIN_FILTER
is set to one of the functions that requires mipmaps or the GL_TEXTURE_WRAP_S
orGL_TEXTURE_WRAP_T
is not set to GL_CLAMP_TO_EDGE
, then the texture image unit will return (R, G, B, A) = (0, 0, 0, 1).
glTexParameter
specifies the texture parameters for the texture bound to the active texture unit, specified by calling glActiveTexture.
Errors
GL_INVALID_ENUM
is generated if target
or pname
is not one of the accepted defined values.
GL_INVALID_ENUM
is generated if params
should have a defined symbolic constant value (based on the value of pname
) and does not.
See Also
glActiveTexture, glBindTexture, glCopyTexImage2D, glCopyTexSubImage2D, glPixelStorei, glTexImage2D, glTexSubImage2D
Copyright
Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.