OpenGL 纹理内部格式 Texture Internal Formats

简介: 转自:http://www.berkelium.com/OpenGL/GDC99/internalformat.html Texture Internal Formats Sometimes the first line of code you write is the most important.

转自:http://www.berkelium.com/OpenGL/GDC99/internalformat.html

Texture Internal Formats

Sometimes the first line of code you write is the most important. 
                                    -- Stephen Johnson, NVIDIA Corporation

While a tremendous amount of effort is generally put into creating artwork and optimizing the rendering code, often one of the most important steps of texture mapping is overlooked: texture downloads.

Getting the most out of:

glTexImage2D(target, lod, internalformat, width, height, border, format, type, data);
means understanding the ramifications of each parameter. While most are straightforward, there seems to be considerable confusion surrounding the internalformat parameter.

In OpenGL 1.0, the third parameter was called components and referred to the desired number of components in the internal texture. Legal values were 1,2,3,4. This doesn't have to match the raw data you supply; for example if you have RGBA data but don't care about alpha, you could specify (components = 3) and the GL would strip off the alpha channel and store just RGB.

In OpenGL 1.1, the components parameter was given an expanded roll and renamed internalformat to reflect its new functionality. While it still accepts the original values, it now accepts named formats:GL_RGB, GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY and GL_ALPHA. Note that there are now three different single-component texture formats, each with different behavior. Further, you can specify sized representations of these internalformats, e.g. GL_RGB5, GL_RGB8, GL_RGBA4, GL_RGBA5_A1, GL_RGBA8 (please see the reference for a complete list). This is a hint to the implementation, and indicates the desired color resolution of the texture.

The importance of using sized internalformats cannot be understated. Many architectures support multiple internal texture formats, and the implementor must choose a default for the unsized internalformats. For maximum control over performance and quality, these hints must be employed. For example if you want to minimize texture storage and bandwidth requirements at the expense of visual quality, you should use GL_RGB5 or GL_RGBA4 internalformats. If you only need a single bit of alpha you can use GL_RGB5_A1 for increased color resolution. If you are willing to sacrifice some performance for improved visual quality, be sure to request GL_RGB8 or GL_RGBA8 internalformats. Otherwise you leave this decision in the hands of the person writing the driver, whose priorities may not match your own.

There is no downside to using sized hints. If your requested size is unsupported, the implementation will use the closest supported size. If you are worried that you might not make the correct trade-off for all users and/or all architectures, give the user a control to make this choice.

Please note that your choice of setting for internalformat is independent of your choice of type and format; even if you choose to store a texture at low resolution, you must still present the data using standard types and formats (e.g. four bytes per texel if the type/format is GL_UNSIGNED_BYTE, GL_RGBA).



Copyright (c) 1999, Michael I. Gold



目录
相关文章
|
数据安全/隐私保护 索引
Opengl ES之纹理数组
Opengl ES连载系列
235 0
|
缓存 API Android开发
Android OpenGL添加纹理
Android OpenGL添加纹理
Android OpenGL添加纹理
|
Android开发 异构计算
Android OpenGL ES(八)----纹理编程框架(二)
Android OpenGL ES(八)----纹理编程框架(二)
177 0
Android OpenGL ES(八)----纹理编程框架(二)
|
存储 Java API
Android OpenGL ES(八)----纹理编程框架(一)
Android OpenGL ES(八)----纹理编程框架(一)
309 0
Android OpenGL ES(八)----纹理编程框架(一)
|
缓存 算法 机器人
Android OpenGL ES(七)----理解纹理与纹理过滤
Android OpenGL ES(七)----理解纹理与纹理过滤
238 0
Android OpenGL ES(七)----理解纹理与纹理过滤
|
图形学
学习OpenGL ES之基本纹理
学习OpenGL ES之基本纹理
学习OpenGL ES之基本纹理
|
缓存 索引
OpenGL学习笔记(十三):将纹理贴图应用到四边形上,对VAO/VBO/EBO/纹理/着色器的使用方式进行总结
OpenGL学习笔记(十三):将纹理贴图应用到四边形上,对VAO/VBO/EBO/纹理/着色器的使用方式进行总结
OpenGL学习笔记(十三):将纹理贴图应用到四边形上,对VAO/VBO/EBO/纹理/着色器的使用方式进行总结
|
存储 缓存 C++
OpenGL学习笔记(十二):纹理的使用
OpenGL学习笔记(十二):纹理的使用
OpenGL学习笔记(十二):纹理的使用
|
索引
OpenGL ES 案例08:GLKit使用索引绘图 + 纹理颜色混合
OpenGL ES 案例08:GLKit使用索引绘图 + 纹理颜色混合
92 0
OpenGL ES 案例08:GLKit使用索引绘图 + 纹理颜色混合