Integer Texture Support


Currently Jme3 does not support textures with integer formats, such as GL_RGBA32UI.

What are your thoughts on providing integer texture support.

It requires OpenGL 2.0 and GL_EXT_texture_integer.

As I am aware:
It would require modification of com.jme3.renderer.opengl.GLImageFormats and com.jme3.texture.Image.Format classes

What I know about this:
In 2007 I used integer textures on both ATI and NVIDIA cards via C++ and GLSL.
It required a different GLSL syntax on those two different hardwares.
But it worked (even on my mid- to low- range computer at home).
Should be possible with current technology too.

So I have tried to used Integer Textures with jme3, and currently it is possible with just the following hack:

public static Image.Format RGBA_16I = Image.Format.Reserved1;
     static void initFormat(Renderer r) {
        GLRenderer gl = (GLRenderer)r;
        Object textureUtil = read(gl, "texUtil");
        GLImageFormat[][] formats = (GLImageFormat[][]) read(textureUtil, "formats");
        formats[0][RGBA_16I.ordinal()] = new GLImageFormat(GL30.GL_RGBA16I, GL30.GL_RGBA_INTEGER, GL.GL_SHORT);//GL.GL_UNSIGNED_SHORT);
     static Object read(Object o, String name) {
        try {
            java.lang.reflect.Field f = o.getClass().getDeclaredField(name);
            return f.get(o);
        } catch (Exception e) {
        return null;

Once you call method initFormat, you can use the new format in your texture

matTex = new Texture2D(w, h, RGBA_16I);

In case you are writing to your integer texture:
In fragment shader:

layout(location = 0) out ivec4 FragMat;

layout requires GLSL330
Alternatively, GLSL130:

out ivec4 FragMat;

should work. If not BindFragDataLocationEXT is probably needed.

So basically, I am asking a core dev if we can expand the Image.Format enum with other texture types. I can make the patch if we agree on this.

There is a table of texture types here. Shall we include all of them or just a subset?


What happened to this? Additional formats would be useful for me too.

Well, pretty much I am waiting for someone from core team to discuss which formats, if any, or all, to add. In the meantime, you can use the ‘hack’ that I provided. :chimpanzee_amused:

Missed that post completely sorry.
The one to ping for this usually is @Momoko_Fan.
IMO I don’t see any issue as long as the user is aware of what he’s doing, and properly checks for the extension.
Could you make a PR for this?


Okay, thanks I’ll prepare a PR and we’ll take things from there.

Edit: link to PR: