本章介绍内容包括:
• Texturing basics
• Loading textures and mipmapping
• Texture filtering and wrapping
• Texture level-of-detail, swizzles, and depth comparison
• Texture formats
• Using textures in the fragment shader
• Texture subimage specification
• Copying texture data from the framebuffer
• Compressed textures
• Sampler objects
• Immutable textures
• Pixel unpack buffer objects
Texturing Basics
2D textures
2D texture arrays
3D textures
cubemap textures
(1)2D textures
(2)cubemap textures
At its most basic, a cubemap is a texture made up of six individual 2D texture faces.
(3)3D textures
3D textures can be thought of as an array of multiple slices of 2D textures.
(4)2D texture arrays
The 2D texture array is very similar to a 3D texture, but is used for a different purpose. For example, 2D texture arrays are often used to store an animation of a 2D image. Each slice of the array represents one frame of the texture animation.
Texture Objects and Loading Textures
glGenTextures:
glDeleteTextures:
glBindTexture:
glTexImage2D:
glPixelStorei & glReadPixels
注意三点
1)glPixelStorei 使用 GL_UNPACK_xxxxx, glReadPixels 使用GL_PACK_xxxxx (在Fragment Operations阶段)
2)The pack and unpack options set by glPixelStoreiare global state and are not stored or associated with a texture object. 全局属性
3) In practice, it is rare to use any options other than GL_UNPACK_ALIGNMENTfor specifying textures.
Texture Filtering and Mipmapping
Minification is what happens when the size of the projected polygon on the screen is smaller than the size of the texture.
Magnification is what happens when the size of the projected polygon on screen is larger than the size of the texture.
For magnification, mipmapping is not relevant, because we will always be sampling from the largest level available.
glTexParameter*:
Seamless Cubemap Filtering
In OpenGL ES 3.0, there is nothing you need to do to enable seamless cubemap filtering; all linear filter kernels will use it automatically.
1)When calling glGenerateMipmapon a bound texture object, this function will generate the entire mipmap chain from the contents of the image in level zero.
2)OpenGL ES 3.0 does not mandate that a particular filtering algorithm be used for generating mipmaps . If you require a particular filtering method, then you will still
need to generate the mipmaps on your own.
3)Automatic mipmap generation becomes particularly important when you start to use framebuffer objects for rendering to a texture.
Texture Coordinate Wrapping
Texture wrap modes are used to specify the behavior that occurs when a texture coordinate is outside of the range [0.0, 1.0].
glTexParameter[i|f][v] : GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_TEXTURE_WRAP_R
Texture Swizzles
1)glTexParameter[i|f][v]
2)GL_TEXTURE_SWIZZLE_R,GL_TEXTURE_SWIZZLE_G,GL_TEXTURE_SWIZZLE_B,GL_TEXTURE_SWIZZLE_A
3)GL_RED,GL_GREEN,GL_BLUE,GL_ALPHA
Texture Level of Detail
1)glTexParameter[i|f][v]
2)GL_TEXTURE_BASE_LEVEL / GL_TEXTURE_MAX_LEVEL
3)GL_TEXTURE_MIN_LOD / GL_TEXTURE_MAX_LOD (其中LOD : level of detail 的意思)
Depth Texture Compare (Percentage Closest Filtering)
GL_TEXTURE_COMPARE_FUNC
GL_TEXTURE_COMPARE_MODE
Texture Formats
Using Textures in a Shader
Example of Using a Cubemap Texture
Loading 3D Textures and 2D Texture Arrays
As
Compressed Textures
Thus
Texture Subimage Specification
After
Copying Texture Data from the Color Buffer
An
Sampler Objects
Previously
Immutable Textures
Another
Pixel Unpack Buffer Objects
In