0
\$\begingroup\$

I'm trying to use arrax textures with opengl 3.3 since this the target version for my application. So I have to use the glTexImage3D() method instead of glTexStorage3D(). The problem is, if I use glTexImage3D() instead of glTexStorage3D() the screen is always black. The other way round, everything works. Here is how I create the array texture:

public ArrayTexture(int width, int height) {
    this.width = width;
    this.height = height;
    this.arrayTextureHandle = GL11.glGenTextures();
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, arrayTextureHandle);

        //Works perfect
        GL42.glTexStorage3D(GL30.GL_TEXTURE_2D_ARRAY, 1, GL11.GL_RGBA8, width, height, 10);
        //Doesn't work with these parameters
        //GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA8, width, height, 10, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null);

    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);
}

public void addTexture(ScrollingSprite... sprites) {
    if(zLayerCounter + sprites.length <= MAX_LAYERS) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, arrayTextureHandle);

        Arrays.asList(sprites).forEach(sprite -> {
            sprite.getTexture().getTextureData().prepare();
            GL12.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY,
                0,                      //Mipmap number
                0, 0, zLayerCounter++, //xoffset, yoffset, zoffset
                width, height, 1,          //width, height, depth
                GL11.GL_RGBA,                 //format
                GL11.GL_UNSIGNED_BYTE,       //type
                sprite.getTexture().getTextureData().consumePixmap().getPixels()); //pointer to data

            GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, sprite.getTextureWrapS());
            GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, sprite.getTextureWrapT());
        });

        GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);
    } else {
        throw new IllegalArgumentException("Maximum number of textures reached!");
    }
}
\$\endgroup\$
  • \$\begingroup\$ Try using glGetError \$\endgroup\$ – Bálint Aug 16 '17 at 15:58
  • \$\begingroup\$ I get an error 1280, which means GL_INVALID_ENUM. But that error appears with both methods. \$\endgroup\$ – mrdlink Aug 16 '17 at 16:08
  • \$\begingroup\$ In the version that works you're only creating 10 aray slices. In the version that doesn't work you're creating 100. Have you checked your hardware maximums? \$\endgroup\$ – Maximus Minimus Aug 16 '17 at 16:15
1
\$\begingroup\$

Looking at http://docs.gl/gl3/glTexImage3D, the 8th parameter (format) has to be one of GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA, you use GL_RGBA8 which is not allowed. Use GL_RGBA instead.

\$\endgroup\$
  • \$\begingroup\$ Still not working. I tried all different parameters listed in the docs. \$\endgroup\$ – mrdlink Aug 16 '17 at 16:20
  • \$\begingroup\$ Do you still get an GL_INVALID_ENUM error? Check for errors after each gl*-Call to find out which one throws the error. \$\endgroup\$ – tkausl Aug 16 '17 at 16:22
  • \$\begingroup\$ no that error has nothing to do with the array texture. I get no error at all calling glTexImage3D() or glTexStorage3D(). \$\endgroup\$ – mrdlink Aug 16 '17 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.