Login  Register

Re: GL_RGBA32F with glTexImage2D

Posted by Moa on Feb 06, 2017; 9:12am
URL: https://forum.jogamp.org/GL-RGBA32F-with-glTexImage2D-tp4035766p4037623.html

I'd ignored updating JOGL, but decided to take the plunge (I really like the single Fat Jar deployment for Jogamp, thanks for putting that together) and found a work-around for this problem.

Initially I tried fixing up the TextureData and associated classes. This was fairly complicated, and somewhat unnecessary for my purposes.  Instead I found that the JOGL Texture class could be used to wrap an OpenGL texture if you create the texture yourself and provide the OpenGL handle.  It is a good design of JOGL that such 'fallback' methods are available in the public interface. It really 'saved my bacon'.

So, for the RGBA32F image I was using (used to store the Rayleigh and Mie atmospheric scattering integrals for various combinations of altitude and angular distance from the Sun) I changed from using the following:

TextureData textureData = new TextureData(gl.getGLProfile(), internalFormat, width, height, numBorderPixels, pixelFormat, pixelType, mipmap, dataIsCompressed, flipVertically, buffer, null);

to a utility function that creates the texture I want (I've stripped out my custom error handling so show the essentials) and bypasses the use of TextureData which doesn't work for RGBA32F (as in, HDR) images:

  public Texture createRgbaFloatTexture(GL4 gl, FloatBuffer buffer, int width, int height) {
    boolean flipVertically = false;

    int numTextures = 1;
    int[] textureHandles = new int[numTextures];
    gl.glGenTextures(numTextures, textureHandles, 0);

    final int glTextureHandle = textureHandles[0];

    gl.glBindTexture(GL.GL_TEXTURE_2D, glTextureHandle);

    int mipmapLevel = 0;
    int internalFormat = GL4.GL_RGBA32F;
    int numBorderPixels = 0;
    int pixelFormat = GL4.GL_RGBA;
    int pixelType = GL4.GL_FLOAT;
    boolean mipmap = false;
    boolean dataIsCompressed = false;
    gl.glTexImage2D(GL.GL_TEXTURE_2D, mipmapLevel, internalFormat, width, height, numBorderPixels, pixelFormat, pixelType, buffer);

    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR);
    gl.glGenerateMipmap(gl.GL_TEXTURE_2D); // Don't really need mipmaps, but we'll create anyway for now.
    Texture texture = new Texture(glTextureHandle, GL4.GL_TEXTURE_2D, width, height, width, height, flipVertically);

    return texture;
  }


I hope this is of some use to other JOGL users, as I've seen a couple of people ask about  using floating-point pixel images.

Thanks so much to the JOGL team and all the contributors.

Here's a screenshot of the real-time atmospheric scattering in action in the background of this image. I'm looking forward to getting PBR going on the aircraft as part of the next step, and I'm about to drop in 30-m global terrain from NASA's SRTM survey. The coloured lines on the aircraft are the forces acting in the flight model (adapted from NASA's high-fidelity F-16 model)

Atmospheric scattering using precomputed 32-bit float transmission textures