package com.io7m.bugs; import java.nio.IntBuffer; import javax.media.opengl.GL; import javax.media.opengl.GL2GL3; import javax.media.opengl.GL3; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLContext; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import com.jogamp.common.nio.Buffers; import com.jogamp.newt.opengl.GLWindow; /** * The 3.1 context on Mesa 9.0.1 seems to be broken. */ public final class TestBuggyMesa901 { /** * The glPolygonMode() call raises GL_INVALID_ENUM on buggy Mesa 9.0.1 3.1 * contexts. */ @SuppressWarnings("static-method") @Test public void testPolygonModeFailure() { final GLProfile pro = GLProfile.get(GLProfile.GL3); final GLCapabilities caps = new GLCapabilities(pro); final GLWindow window = GLWindow.create(caps); window.setSize(640, 480); window.addGLEventListener(new GLEventListener() { public void reshape( final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { // Nothing. } public void init( final GLAutoDrawable drawable) { final GLContext context = drawable.getContext(); Assume.assumeTrue(context.getGLVersionMajor() >= 3); Assume.assumeTrue(context.getGLVersionMinor() >= 1); final GL3 gl = drawable.getGL().getGL3(); gl.glPolygonMode(GL.GL_FRONT, GL2GL3.GL_FILL); final int e = gl.glGetError(); Assert.assertTrue(e == GL.GL_INVALID_ENUM); } public void dispose( final GLAutoDrawable drawable) { // Nothing. } public void display( final GLAutoDrawable drawable) { // Nothing. } }); window.setVisible(true); window.destroy(); } /** * Binding a VBO attribute fails. It raises GL_INVALID_OPERATION despite * being entirely valid according to the documentation. The same call works * correctly in the 3.0 context. */ @SuppressWarnings("static-method") @Test public void testBindArrayAttributeFails() { final GLProfile pro = GLProfile.get(GLProfile.GL3); final GLCapabilities caps = new GLCapabilities(pro); final GLWindow window = GLWindow.create(caps); window.setSize(640, 480); window.addGLEventListener(new GLEventListener() { public void reshape( final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { // Nothing. } public void init( final GLAutoDrawable drawable) { final GLContext context = drawable.getContext(); Assume.assumeTrue(context.getGLVersionMajor() >= 3); Assume.assumeTrue(context.getGLVersionMinor() >= 1); final GL3 gl = drawable.getGL().getGL3(); final IntBuffer buffers = Buffers.newDirectIntBuffer(1); gl.glGenBuffers(1, buffers); Assert.assertTrue(gl.glGetError() == 0); final int name = buffers.get(0); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, name); Assert.assertTrue(gl.glGetError() == 0); gl.glBufferData(GL.GL_ARRAY_BUFFER, 4 * 32, null, GL.GL_STATIC_DRAW); Assert.assertTrue(gl.glGetError() == 0); Assert.assertTrue(gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER) == name); gl.glEnableVertexAttribArray(1); Assert.assertTrue(gl.glGetError() == 0); gl.glVertexAttribPointer(1, 4, GL.GL_FLOAT, false, 0, 0L); Assert.assertTrue(gl.glGetError() == GL.GL_INVALID_OPERATION); } public void dispose( final GLAutoDrawable drawable) { // Nothing. } public void display( final GLAutoDrawable drawable) { // Nothing. } }); window.setVisible(true); window.destroy(); } }