从glTexStorage3D切换到glTexImage3D [英] Switching to glTexImage3D from glTexStorage3D

查看:362
本文介绍了从glTexStorage3D切换到glTexImage3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

glBindTexture(GL_TEXTURE_2D_ARRAY, texture_id);
glTexStorage3D(GL_TEXTURE_2D_ARRAY,
               1,             // No mipmaps
               GL_RGBA8,      // Internal format
               width, height, // width,height
               1              // Number of layers
               );
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
                0,                // Mipmap number
                0, 0, 0,          // xoffset, yoffset, zoffset
                width, height, 1, // width, height, depth
                GL_RGBA8,         // format
                GL_UNSIGNED_BYTE, // type
                image);           // pointer to data

为了进行测试,我仅创建一个长度为1的数组.我当前使用的是OpenGL 4.3,但我想切换回OpenGL 3.3,这意味着我不能使用glTexStorage3D.

For testing I only create an array of length 1. I am currently using OpenGL 4.3 but I want to switch back to OpenGL 3.3 which means that I can not use glTexStorage3D.

所以我试图切换到glTexImage3D

glBindTexture(GL_TEXTURE_2D_ARRAY, texture_id);
glTexImage3D(GL_TEXTURE_2D_ARRAY,
             1,                // level
             GL_RGBA8,         // Internal format
             width, height, 1, // width,height,depth
             0,                // border?
             GL_RGBA,         // format
             GL_UNSIGNED_BYTE, // type
             0);               // pointer to data
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
                0,                // Mipmap number
                0, 0, 0,          // xoffset, yoffset, zoffset
                width, height, 1, // width, height, depth
                GL_RGBA8,         // format
                GL_UNSIGNED_BYTE, // type
                image);           // pointer to data

但是它不起作用,我不确定自己做错了什么.

But it is not working and I am not sure what I am doing wrong.

我可能应该补充一点,它可以与glTexStorage3d一起使用.

I should probably add that it is working with glTexStorage3d.

推荐答案

主要问题是用于glTexImage3D()的第二个参数:

The main problem is with the second argument you are using for glTexImage3D():

glTexImage3D(GL_TEXTURE_2D_ARRAY,
             1,                // level
             GL_RGBA8,         // Internal format
             width, height, 1, // width,height,depth
             0,                // border?
             GL_RGBA,         // format
             GL_UNSIGNED_BYTE, // type
             0);               // pointer to data

对于glTexImage3D(),该参数名为 level ,它是您要为其指定数据的级别的从0开始的 index ,或者只是在最后一个参数为NULL.这与 levels (请注意复数)参数不同,它是要分配的级别的 count .

For glTexImage3D(), the argument is named level, and is the 0-based index of the level you're specifying data for, or just allocating when the last argument is NULL. This is different from the levels (note plural) argument of glTexStorage3D(), which is the count of levels to be allocated.

实际上,glTexImage3D()的第二个参数直接对应于glTexSubImage3D()的第二个参数,您已经以0的形式传递了该参数.

In fact, the second argument of glTexImage3D() directly corresponds to the second argument of glTexSubImage3D(), which you're already passing as 0.

因此正确的调用仅将0用作第二个参数:

So the correct call simply uses 0 for the second argument:

glTexImage3D(GL_TEXTURE_2D_ARRAY,
             0,                // level
             GL_RGBA8,         // Internal format
             width, height, 1, // width,height,depth
             0,                // border?
             GL_RGBA,          // format
             GL_UNSIGNED_BYTE, // type
             0);               // pointer to data

此外,您的glTexSubImage3D()呼叫正常工作令我感到惊讶. GL_RGBA8作为第9个参数无效.在这种情况下,这是 format ,而不是 internalFormat ,这意味着它是未调整大小的格式.在这种情况下,该值应为GL_RGBA:

In addition, I'm surprised that your glTexSubImage3D() calls work. GL_RGBA8 is not valid as the 9th argument. In this case, this is a format, and not an internalFormat, meaning that it is an unsized format. The value in this case should be GL_RGBA:

glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
                0,                // Mipmap number
                0, 0, 0,          // xoffset, yoffset, zoffset
                width, height, 1, // width, height, depth
                GL_RGBA,          // format
                GL_UNSIGNED_BYTE, // type
                image);           // pointer to data

这篇关于从glTexStorage3D切换到glTexImage3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆