【OpenGL/ES】 第04讲 glTexImage2D用法的区别

来源:互联网 发布:java ftp下载文件状态 编辑:程序博客网 时间:2024/05/22 10:40

    GL和GLES标准的一些细微的区别常常令人抓狂,原本在PC上好好的,一移植就乱七八糟的,纹理作为标准里的重要部分非常值得探讨一下,glTexImage2D作为一个热门接口函数几乎会陪伴你一生,下面来分析一下。

    作者在用GLES2.0绘制纹理时遇到如下的异常情况:

         

    修正之后正确效果如下:

        

    错误追踪后发现是glTexImage2D抛出GL_INVALIA_OPERATION的错误,随后作者紧急查阅了一下gles2.0/gl4.5的Spec,找到了问题发生的原因。

    gles2.0的Spec    

          void glTexImage2D(GLenum target,GLint level,GLint internalformat,GLsizei width,GLsizei height,GLint border,GLenum format,GLenum type,const GLvoid* data);

        对于上面的若干参数,可能唯一理解有点障碍的就是internalformat和format,Spec给出的说明分别是

             internalformat - 这个格式指的是内部GPU上的纹理数据格式

               Specifies the internal format of the texture. 

               Must be one of the following symbolic constants: 

             GL_ALPHAGL_LUMINANCEGL_LUMINANCE_ALPHA,GL_RGBGL_RGBA

                  format - 这个格式指的是传进来的data数据的格式,必须和internalformat匹                                 配,经测试发现必须和internalformat一样

               Specifies the format of the texel data. Must match internalformat

               The following symbolic values are accepted: GL_ALPHAGL_RGBGL_RGBA,

             GL_LUMINANCE,and GL_LUMINANCE_ALPHA

         同时给出了更清晰的说明 - 

             两种format必须一致,在纹理处理过程中不支持不同格式的转换

     Notes

                 internalformat must match format

               No conversion between formats is supported during texture image processing. 

                 type may be used as a hint to specify how much precision is desired, 

               but a GL implementation may choose to store the texture array at any internal resolution it chooses.

      
   gl4.5的Spec:

      internalformat和format和gles2.0含义一样,只是各种格式非常的多,还有compressed压缩格式

       支持纹理处理过程中的不同格式转换,具体每种格式用法的细节读者自行查阅Spec

0 0