Posted by
mike on
Jan 11, 2012; 11:14am
URL: https://forum.jogamp.org/IndexOutOfBoundsException-in-glTexImage3D-and-glTexImage2D-tp3650300.html
hi,
this looks like a bug...
*** jogl.all.jar MANIFEST ***
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_29-b11 (Sun Microsystems Inc.)
Specification-Title: Java Bindings for OpenGL API Specification
Specification-Version: 2.0
Specification-Vendor: JogAmp Community
Implementation-Title: Java Bindings for OpenGL Runtime Environment
Implementation-Version: 2.0-b45-20111219
Implementation-Branch: rc
Implementation-Commit: 2f2b071d60f5b630989140b1ade49d648ad78c20
Implementation-Vendor: JogAmp Community
Implementation-URL:
http://jogamp.org/Extension-Name: javax.media.opengl
Implementation-Vendor-Id: com.jogamp
Trusted-Library: true
*** SOURCECODE ***
import java.awt.Dimension;
import java.nio.ByteBuffer;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLJPanel;
import javax.swing.JFrame;
public class Main extends JFrame implements GLEventListener {
public static void main(String[] args) {
new Main();
}
public Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
GLProfile profile = GLProfile.getDefault();
System.out.println("GLProfile " + profile);
GLCapabilities caps = new GLCapabilities(profile);
GLJPanel canvas = new GLJPanel(caps);
canvas.addGLEventListener(this);
canvas.setPreferredSize(new Dimension(512, 512));
getContentPane().add(canvas);
pack();
setVisible(true);
}
public void init(GLAutoDrawable g) {
GL2 gl = g.getGL().getGL2();
System.out.println("GL " + gl);
System.out.println("GLCaps.glVersion " + gl.glGetString(GL2.GL_VERSION));
System.out.println("GLCaps.glslVersion " + gl.glGetString(GL2.GL_SHADING_LANGUAGE_VERSION));
System.out.println("\nGLCaps.supportsNonPower2Textures " + gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two") + "\n");
createTex(gl, 64, 64, 64); // OK
createTex(gl, 60, 64, 64); // OK
createTex(gl, 63, 64, 64); // FAIL
createTex(gl, 64, 64); // OK
createTex(gl, 60, 64); // OK
createTex(gl, 63, 64); // FAIL
}
private void createTex(GL2 gl, int w, int h, int d) {
System.out.print("creating tex3D " + w + " x " + h + " x " + d + " (" + (w * h * d) + " bytes) ... ");
int format = GL2.GL_ALPHA;
int internalFormat = GL2.GL_ALPHA8;
int dataType = GL2.GL_UNSIGNED_BYTE;
int[] texs = new int[1];
gl.glGenTextures(1, texs, 0);
int tex = texs[0];
try {
byte[] buf = new byte[w * h * d];
ByteBuffer buffer = ByteBuffer.wrap(buf);
gl.glBindTexture(GL2.GL_TEXTURE_3D, tex);
gl.glTexImage3D(GL2.GL_TEXTURE_3D, 0, internalFormat, w, h, d, 0, format, dataType, buffer);
System.out.println("OK");
} catch (Exception e) {
System.out.println("FAILED");
e.printStackTrace();
}
gl.glDeleteTextures(1, new int[] { tex }, 0);
}
private void createTex(GL2 gl, int w, int h) {
System.out.print("creating tex2D " + w + " x " + h + " (" + (w * h) + " bytes) ... ");
int format = GL2.GL_ALPHA;
int internalFormat = GL2.GL_ALPHA8;
int dataType = GL2.GL_UNSIGNED_BYTE;
int[] texs = new int[1];
gl.glGenTextures(1, texs, 0);
int tex = texs[0];
try {
byte[] buf = new byte[w * h];
ByteBuffer buffer = ByteBuffer.wrap(buf);
gl.glBindTexture(GL2.GL_TEXTURE_2D, tex);
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, internalFormat, w, h, 0, format, dataType, buffer);
System.out.println("OK");
} catch (Exception e) {
System.out.println("FAILED");
e.printStackTrace();
}
gl.glDeleteTextures(1, new int[] { tex }, 0);
}
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
}
public void dispose(GLAutoDrawable arg0) {
}
public void display(GLAutoDrawable arg0) {
}
}
*** OUTPUT ***
GLProfile GLProfile[GL3bc/GL3bc]
GL jogamp.opengl.gl4.GL4bcImpl@1ded0fd
GLCaps.glVersion 3.3.0
GLCaps.glslVersion 3.30 NVIDIA via Cg compiler
GLCaps.supportsNonPower2Textures true
creating tex3D 64 x 64 x 64 (262144 bytes) ... OK
creating tex3D 60 x 64 x 64 (245760 bytes) ... OK
creating tex3D 63 x 64 x 64 (258048 bytes) ... FAILED
java.lang.IndexOutOfBoundsException: Required 262143 remaining bytes in buffer, only had 258048
at com.jogamp.common.nio.Buffers.rangeCheckBytes(Buffers.java:787)
at jogamp.opengl.gl4.GL4bcImpl.glTexImage3D(GL4bcImpl.java:23742)
at Main.createTex(Main.java:60)
at Main.init(Main.java:40)
creating tex2D 64 x 64 (4096 bytes) ... OK
creating tex2D 60 x 64 (3840 bytes) ... OK
creating tex2D 63 x 64 (4032 bytes) ... FAILED
java.lang.IndexOutOfBoundsException: Required 4095 remaining bytes in buffer, only had 4032
at com.jogamp.common.nio.Buffers.rangeCheckBytes(Buffers.java:787)
at jogamp.opengl.gl4.GL4bcImpl.glTexImage2D(GL4bcImpl.java:23699)
at Main.createTex(Main.java:83)
at Main.init(Main.java:44)