且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从glTexStorage3D切换到glTexImage3D

更新时间:2023-11-09 22:38:58

主要问题是用于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