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. 
                                    -- 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

时间: 2024-10-10 03:13:16

OpenGL 纹理内部格式 Texture Internal Formats的相关文章

高级 OpenGL 纹理贴图 Advanced OpenGL Texture Mapping

转自:http://www.flipcode.com/archives/Advanced_OpenGL_Texture_Mapping.shtml Advanced OpenGL Texture Mappingby Nate Miller (03 April 2000)  Return to The Archives Introduction  As we all know texture mapping is a crucial element in today's games and gra

opengl纹理问题,纹理数组如何使用

问题描述 opengl纹理问题,纹理数组如何使用 作业是六面体做六个不同的纹理,想着用纹理数组做,看了网上的uv,有的是图片最左上是(0,0)有的是最左下 然后自己用纹理数组做六面体的时候只能上下两个面有图案,中间的都是过度的,如果是用画一个面贴一个图形是没问题的,用数组就是不行,以下是源码 #define GLUT_DISABLE_ATEXIT_HACK #include #include #include #include #define BMP_Header_Length 54 float

opengl 纹理 球-用opengl纹理实现地球仪 问题

问题描述 用opengl纹理实现地球仪 问题 纹理已经正确加载,但是在没用纹理矩阵时纹理根本动不了.如果用glMatrixMode(GL_TEXTURE) 转动很奇怪,而且感觉纹理没很好的铺满球体.求正确方法我的显示代码: glMatrixMode(GL_MODELVIEW); glPushMatrix(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D,texture1); glEna

opengl纹理混合-opengl纹理贴图的插值

问题描述 opengl纹理贴图的插值 大家好.我在编写opengl的时候,想做出纹理贴图的插值. 好比,一张纹理是f1(x),一张为f2(x).能够得到g(x)= t * f1(x)+ (1-t)* f2(x) t:0~1 这样的效果. 谢谢~ 解决方案 你用GLSL写个shader,把目标纹理绑定到FBO上面,然后shader里面读入两张纹理按照你的函数输出即可 解决方案二: 你用GLSL写个shader,把目标纹理绑定到FBO上面,然后shader里面读入两张纹理按照你的函数输出即可

opengl 纹理 球-opengl在mfc中载入一副BMP文件作为纹理,编译链接都通过了但运行时就提示停止工作

问题描述 opengl在mfc中载入一副BMP文件作为纹理,编译链接都通过了但运行时就提示停止工作 HBITMAP hBMP;//定义BMP头BITMAP BMP;//BMP结构体//byte Texture[]={IDB_BITMAP3};byte Texture[]={IDB_BITMAP4};glGenTextures(sizeof(Texture) &texture[0]);// Generate 6 Textures (sizeof(Texture)=6 ID's)for(int lo

手机游戏开发中如何选择适合的纹理格式

为毛要写这个 本来觉得像这样的问题,是无法归类的,因为不同的项目有不同的需求,但今天因为quick论坛中的一个技术疑问贴,钩起了我整理这篇文章的兴趣 http://www.cocoachina.com/bbs/read.php?tid=214811 于是,我决定尽力描述一下纹理格式选择方面的问题,一是起到一个科普的作用,因为目前没有发现十分完整的讲这方面的文章.二是整理一下自己的思路. 当然,这些东西肯定不是我自己凭空YY出来的,我也是参考了不少文章,也从项目中总结了一些问题.在此先列出一些链接

最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)

本文记录OpenGL播放视频的技术.上一篇文章中,介绍了一种简单的使用OpenGL显示视频的方式.但是那还不是OpenGL显示视频技术的精髓.和Direct3D一样,OpenGL更好的显示视频的方式也是通过纹理(Texture).本文介绍OpenGL通过纹理的方式显示视频的技术. OpenGL中坐标和Direct3D坐标的不同 OpenGL中的纹理的坐标和Direct3D中的坐标是不一样的. 在Direct3D中.纹理坐标如下图所示.取值是0到1.坐标系原点在左上角. 物体表面坐标如下图所示.取

OpenGL ES 纹理参数设置方法 glTexParameter

OpenGL ES 纹理参数设置方法 glTexParameter 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 以下译自官网. 最近几天,会针对该方法的每个参数,做相应的翻译.分析理解和测试

OpenGL ES 在 iOS 平台纹理贴图倒置的问题研究

OpenGL ES 在 iOS 平台纹理贴图倒置的问题研究 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. (一大疑惑,为什么android上关于OpenGL ES 开发的资料很多,确涉及该主题