简体   繁体   中英

glCopyImageSubData gives me GL_INVALID_VALUE

I have made a minimal code example that reproduces a bug in my game.

I'm trying to copy a region of a TEXTURE_1D_ARRAY to another one.

u32 tex0;
glGenTextures(1, &tex0);
glBindTexture(GL_TEXTURE_1D_ARRAY, tex0);
glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA8, 64, 2, 0, GL_RGBA, GL_FLOAT, initTexData);
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

u32 tex1;
glGenTextures(1, &tex1);
glBindTexture(GL_TEXTURE_1D_ARRAY, tex1);
glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA8, 64, 3, 0, GL_RGBA, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glCopyImageSubData(
    tex0, GL_TEXTURE_1D_ARRAY,
    0, 0, 0, 0,
    tex1, GL_TEXTURE_1D_ARRAY,
    0, 0, 0, 0,
    64, 2, 1
);

The texture tex0 is initialized with some pixel data and has dimensions 64x2.

Then I create tex1 with dimensions 64x3 and empty data.

And finally I copy the contents from tex0 to tex1 , but it fails in the operation.

It gives error GL_INVALID_VALUE . According to the documentation there are a few different causes for that error. But I have debugged it with ApiTrace and it gave some useful info:

major api error 1281: GL_INVALID_VALUE error generated. The y values exceeds the boundaries of the corresponding image object.
glGetError(glCopyImageSubData) = GL_INVALID_VALUE

The error message suggests that I'm getting out of bounds but I just don't see how. I'm copying a region of 64x2, which should fit on both textures. There must be some silly mistake I can't see myself.

If you want to see the full code: https://gist.github.com/tuket/2198c17107c513c667d7381bbb34386d

You get the INVALID_VALUE error, because the srcHeight argument of glCopyImageSubData exceeds the boundaries of the corresponding image object.

The height of an one dimensional texture is always 1. However the depth of an on dimensional texture array can be grater than 1:

glCopyImageSubData(
    tex0, GL_TEXTURE_1D_ARRAY,
    0, 0, 0, 0,
    tex1, GL_TEXTURE_1D_ARRAY,
    0, 0, 0, 0,
    64, 1, 2                  // height = 1, but depth = 2
);

Don't let glTexImage2D confuse you where to specify the layers of the one-dimensional texture array using the height argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM