How do I load texture array in jogl?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I load texture array in jogl?

Steyrix
Hello, everyone.
I have been trying to load texture array in my jogl app using gl functions like
glTexStorage3D, glTexSubImage3D.
I use PNG texture.
The texture I loaded has wrong colors due to Java's ARGB. I tried converting images data bytes from ARGB
to RGBA manually and didn't succeed (the texture became invisible since I discard every fragment which has alpha <= 0 in my fragment shader)
However, I know that JOGL provides such class as TextureIO, which makes texture loading easy
and also takes care about right coloring.
I wonder if there's any way to load texture array as easy as I do load a single texture using TextureIO.
And if there is not, how can I load texture array by myself properly?
Reply | Threaded
Open this post in threaded view
|

Re: How do I load texture array in jogl?

gouessej
Administrator
Hello

You can use TextureIO to create a TextureData instance but Texture uses only GL.GL_TEXTURE_2D and GL2.GL_TEXTURE_RECTANGLE_ARB as texture targets. You can pass the pixels of a TextureData instance returned by getBuffer() to glTexSubImage3D.

Our PNG loader uses PNGJ under the hood, it should work except if you use an unsupported PNG format.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How do I load texture array in jogl?

Steyrix
Thank you for the advice.
I ve tried to load TextureData, but it's buffer appears empty, so I don't see any image.
Previously I loaded it using File class instance created from image file (commented overload)
Now I load it this way:
    public static TextureData loadTextureData (String filePath, GL4 gl) throws GLException, IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(ImageIO.read(new File(filePath)), "png", outputStream);
        InputStream fileInputStream = new ByteArrayInputStream(outputStream.toByteArray());

        return TextureIO.newTextureData(gl.getGLProfile(), fileInputStream, false, null);
        //return TextureIO.newTextureData(gl.getGLProfile(), imageFile, false, null);
    }

-----Loading data to texture array------
        IntBuffer texture = IntBuffer.allocate(1);
        gl.glGenTextures(1, texture);
        gl.glActiveTexture(GL4.GL_TEXTURE0);
        gl.glBindTexture(GL4.GL_TEXTURE_2D_ARRAY, texture.get(0));

        System.out.println("loadTextureArray func 0:" + gl.glGetError());

        gl.glTexStorage3D(GL4.GL_TEXTURE_2D_ARRAY, 1, GL4.GL_RGBA8, texLayerWidth, texLayerHeight, textures.size());
        System.out.println("loadTextureArray func 1:" + gl.glGetError());

        int arraySpot = 0;
        for (TextureData texData: textures) {
            gl.glTexSubImage3D(GL4.GL_TEXTURE_2D_ARRAY, 0, 0, 0, arraySpot++, texLayerWidth, texLayerHeight,
                    1, GL4.GL_RGBA, GL4.GL_BYTE, texData.getBuffer());
        }


texData.getBuffer().toString() is "java.nio.DirectByteBuffer[pos=0 lim=819200 cap=819200]"
Reply | Threaded
Open this post in threaded view
|

Re: How do I load texture array in jogl?

gouessej
Administrator
Steyrix wrote
Thank you for the advice.
I ve tried to load TextureData, but it's buffer appears empty, so I don't see any image.
Steyrix wrote
texData.getBuffer().toString() is "java.nio.DirectByteBuffer[pos=0 lim=819200 cap=819200]"
It doesn't appear to be empty according to toString(), the position of the NIO buffer is at the very beginning (zero) and the limit is set to 819200.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How do I load texture array in jogl?

Steyrix
Oh, my bad, sorry. Still, I can’t figure out what’s wrong.
I use standard png 32-bit color image. I tried to set pixel internal format
to different sized rgba formats and it made no difference.
However, I succeeded at loading jpg texture using TextureData.getBuffet();
But I still need to find out how to load png textures correctly
Reply | Threaded
Open this post in threaded view
|

Re: How do I load texture array in jogl?

gouessej
Administrator
You should test those PNG files:
https://github.com/sgothel/jogl/tree/master/src/test/com/jogamp/opengl/test/junit/jogl/util/texture

They are guaranteed to work with JOGL as we use them in our unit tests. If they don't work in your source code, it will mean that the problem will have to be searched in it and not in JOGL.
Julien Gouesse | Personal blog | Website