Login  Register

Why glReadPixels' buffer is too small?

Posted by Artur on Apr 17, 2012; 11:00am
URL: https://forum.jogamp.org/Why-glReadPixels-buffer-is-too-small-tp3916912.html

Hello, what's wrong with the following code?

        gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport);
        int capacity = viewport.get(2)*viewport.get(3);
        if(depth == null || depth.capacity() != capacity)
            depth = GLBuffers.newDirectByteBuffer(capacity);
        gl.glReadPixels(viewport.get(0), viewport.get(1),
                viewport.get(2), viewport.get(3),
                GL2.GL_DEPTH_COMPONENT, GL2.GL_UNSIGNED_BYTE,
                depth);

It is supposed to read the entire depth buffer, but throws an exception:

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Required 274750 remaining bytes in buffer, only had 273888
        at com.jogamp.common.nio.Buffers.rangeCheckBytes(Buffers.java:780)
        at jogamp.opengl.gl4.GL4bcImpl.glReadPixels(GL4bcImpl.java:21024)

content of the buffer "viewport": 0 0 634 432

634*432=273888, so should not it be enough?