glTexImage2D error

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

glTexImage2D error

elect
Trying to debug the example number 14 of the arcsyn tutorials

https://github.com/elect86/modern-jogl-examples/tree/master/modern-jogl-examples/src/tut14/materialTexture

I am stuck on creating the gaussian texture, so I decreased manually some dimension in order to analyze smaller quantity of data, in this case cosAngleResolution=1 and shininessResolution=128


    private int createGaussianTexture(GL3 gl3, int cosAngleResolution, int shininessResolution) {

        byte[] textureData = buildGaussianData(cosAngleResolution, shininessResolution);
        System.out.println("textureData.length " + textureData.length);

        int[] gaussTexture = new int[1];
        gl3.glGenTextures(1, gaussTexture, 0);

        gl3.glBindTexture(GL3.GL_TEXTURE_2D, gaussTexture[0]);
        {
            ByteBuffer byteBuffer = GLBuffers.newDirectByteBuffer(textureData);
            System.out.println("byteBuffer " + byteBuffer.toString());
            System.out.println("cosAngleResolution " + cosAngleResolution + " shininessResolution " + shininessResolution);
            gl3.glTexImage2D(GL3.GL_TEXTURE_2D, 0, GL3.GL_R8, cosAngleResolution, shininessResolution,
                    0, GL3.GL_RED, GL3.GL_UNSIGNED_BYTE, byteBuffer);
            gl3.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_BASE_LEVEL, 0);
            gl3.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_MAX_LEVEL, 0);
        }
        gl3.glBindTexture(GL3.GL_TEXTURE_2D, 0);

        return gaussTexture[0];
    }


the glTexImage2D returns

Caused by: java.lang.IndexOutOfBoundsException: Required 509 remaining bytes in buffer, only had 128

And this is the output

textureData.length 128
byteBuffer java.nio.DirectByteBuffer[pos=0 lim=128 cap=128]
cosAngleResolution 1 shininessResolution 128

I really dont get why it expects 509 bytes in the buffer since width is 1 and height is 128..
Reply | Threaded
Open this post in threaded view
|

Re: glTexImage2D error

gouessej
Administrator
Hi

Just try GL_LUMINANCE8 instead of GL_R8 in order to verify whether the range check is the culprit. Maybe it's a bug. Please post the full stack trace.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: glTexImage2D error

elect
gouessej wrote
Hi

Just try GL_LUMINANCE8 instead of GL_R8 in order to verify whether the range check is the culprit. Maybe it's a bug. Please post the full stack trace.
Wait wait, I just figured it out it can be the alignment, I am sending data with (w, h) = (1, 128) and given my alignment being 4, if I do:

127 * 4 + 1 = 509

exactly the bytes it wants..

I will continue debuggin and let you know
Reply | Threaded
Open this post in threaded view
|

Re: glTexImage2D error

gouessej
Administrator
As 128 * 4 = 512, I was wondering if there was a problem of alignment too.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: glTexImage2D error

elect
gouessej wrote
As 128 * 4 = 512, I was wondering if there was a problem of alignment too.
I dont remember where, but once I read the last alignment bytes dont need to be read, that's why 509
Reply | Threaded
Open this post in threaded view
|

Re: glTexImage2D error

elect
Solved, it was the alignment