c++ - OpenGL 3.2 为什么我会收到 glTexStorage3D 的 INVALID_ENUM 错误?

标签 c++ opengl rendering

stbi_uc* data = stbi_load(path, &width, &height, NULL, 4);
if (data == NULL) {
    return false;
}
gl_flush_errors();

glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D_ARRAY, id);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA, 50, 50, 1);

这是我的代码中出现 INVALID_ENUM 错误的部分,我已将其缩小到 glTexStorage3D 调用。在这段代码之后,我也遇到了一个 INVALID_VALUE 错误:

glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);

glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_CLAMP_TO_EDGE);

我的目标是使用我的工作图 block 实例设置一个纹理数组,这样我就可以在一次绘制调用中渲染我的图 block map 。我遇到了与此处相同的问题: Instanced drawing with texture atlas

但是,我不确定我目前是否正确地执行此操作,因此将不胜感激任何帮助或指导。这些也是我的着色器,以防它们是问题的原因:

片段着色器

#version 330
// From vertex shader
in vec2 uvcoord;

// Application data
uniform sampler2DArray textures;
// uniform vec3 fcolor;

// Output color
layout(location = 0) out  vec4 color;

void main()
{

    color = texture(textures, vec3(uvcoord.x, uvcoord.y, 0.0));


}

顶点着色器

#version 330 
// Input attributes
in vec2 in_position;
in vec2 in_uvcoord;
in vec2 in_centre_pos;

// Passed to fragment shader
out vec2 uvcoord;
out vec2 vpos;

// Application data
uniform mat3 transform;
uniform mat3 projection;

void main()
{
    uvcoord = in_uvcoord;
    vpos = in_position;
    vec3 pos = projection * vec3(in_position.x + in_centre_pos.x, in_position.y + in_centre_pos.y, 1.0);
    gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
}

最佳答案

OpenGL 4.6 API Core Profile Specification; 8.19. IMMUTABLE-FORMAT TEXTURE IMAGES; page 272 :

The TexStorage* commands specify properties of the texture object bound to the target parameter of each command.

.....

Errors

An INVALID_ENUM error is generated if internalformat is one of the unsized base internal formats listed in table 8.11.


这意味着不允许对 glTexStorage3D 的第三个参数使用 GL_RGBA .

改用GL_RGBA8:

glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 50, 50, 1);

关于c++ - OpenGL 3.2 为什么我会收到 glTexStorage3D 的 INVALID_ENUM 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49827961/

相关文章:

作为 Python 扩展模块的 C++ API

c++ - 数组的迭代方向

c++ - 互斥量加锁和解锁时间差

c++ - Visual Studio 2015 中的其他包含目录不起作用

opengl - 如何增加 openGL 停止绘制对象的距离(zfar/gluPerspective)?

opengl - gluLookat 在免费相机的情况下

c++ - 分层图像作为具有大量层的帧缓冲区

linux - 如何在 headless 服务器上利用我的独立显卡?

java - Android 字体很棒的方形而不是某些字符(仅限 KitKat)

java - 使用getRGB()时负数是什么意思?