samedi 4 mars 2017

Why is glTexSubImage2D giving me GL_INVALID_OPERATION here?

I've been banging at this for more than a few hours now. I can't figure out why glTexSubImage2D is an invalid operation in this code.

    GLuint texture = 0;
    int textureWidth = 512;
    int textureHeight = 512;

    // Create and bind
    glCreateTextures(GL_TEXTURE_2D, 1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    // Set wrapping and filtering.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    // Set storage type and allocate memory.
    glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, textureWidth, textureHeight);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, GL_RED, GL_UNSIGNED_INT, NULL);

I've queried a bunch of parameters (most against mipmap level 0) on my texture before calling glTexSubImage2D, and all the results seem to indicate that the texture is well-formed:

GL_TEXTURE_IMMUTABLE_FORMAT: 1
GL_TEXTURE_WIDTH: 512
GL_TEXTURE_HEIGHT: 512
GL_TEXTURE_DEPTH: 1
GL_TEXTURE_INTERNAL_FORMAT: 33334
GL_TEXTURE_RED_SIZE: 32
GL_TEXTURE_GREEN_SIZE: 0
GL_TEXTURE_BLUE_SIZE: 0
GL_TEXTURE_ALPHA_SIZE: 0
GL_TEXTURE_DEPTH_SIZE: 0
GL_TEXTURE_COMPRESSED: 0
GL_TEXTURE_BUFFER_OFFSET: 0

I've also tried setting actual data instead of NULL via a single-dimension vector array:

std::vector<GLuint> textureData(textureWidth * textureHeight, 0);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, GL_RED, GL_UNSIGNED_INT, textureData.data());

And through memcpy:

GLuint *zeros = new GLuint[textureWidth * textureHeight];
memset(zeros, 0, textureWidth * textureHeight * 4);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, GL_RED, GL_UNSIGNED_INT, zeros);
delete[] zeros;

None of this changes the error. In my fragment shader I (obviously) find a black texture.

Aucun commentaire:

Enregistrer un commentaire