From 0c5ec6e60151073b559dd00df078d765cdb7fed3 Mon Sep 17 00:00:00 2001
From: Sean Wild <[hidden email]> Date: Wed, 25 Aug 2010 02:17:13 +1000 Subject: [PATCH] TestVbo01NEWT Signed-off-by: Sean Wild <[hidden email]> --- .../com/jogamp/test/junit/newt/TestVbo01NEWT.java | 220 ++++++++++++++++++++ 1 files changed, 220 insertions(+), 0 deletions(-) create mode 100644 src/junit/com/jogamp/test/junit/newt/TestVbo01NEWT.java diff --git a/src/junit/com/jogamp/test/junit/newt/TestVbo01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestVbo01NEWT.java new file mode 100644 index 0000000..8915b4c --- /dev/null +++ b/src/junit/com/jogamp/test/junit/newt/TestVbo01NEWT.java @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Adapted for VBO test + * August 2010 + * Sean Wild + * + * Issue: glVertexPointer (and TextureCoord, Normal pointers) + * throws + * GLException: javax.media.opengl.GLException: + * Required extensions not available to call this function. + * + * on Ubuntu Linux machine. + * Open GL version string: 1.4 Mesa 7.7.1 + * Supported extensions include GL_ARB_vertex_buffer_object + * + * Issue does not occur on Windows XP machine with later Open GL + * version string and discrete graphics card. + * + * + */ + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +public class TestVbo01NEWT { + + int[] vbo_pointer = new int[1]; + FloatBuffer vbo_data; + GL2 gl = null; + + public void drawVBO(GL2 gl) throws InterruptedException { + ByteBuffer b = ByteBuffer.allocateDirect(16 * 8); + b.order(ByteOrder.nativeOrder()); + vbo_data = b.asFloatBuffer(); + for (int i = 0; i < 16; i++) { + vbo_data.put(0.0f); + } + vbo_data.flip(); + + gl.glGenBuffers(1, vbo_pointer, 0); + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vbo_pointer[0]); + gl.glBufferData(GL2.GL_ARRAY_BUFFER, 16 * 4, vbo_data, GL2.GL_STATIC_DRAW); + + gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); + gl.glVertexPointer(3, GL2.GL_FLOAT, 8 * 4, 0); + + gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + gl.glTexCoordPointer(2, GL2.GL_FLOAT, 8 * 4, 3 * 4); + + gl.glEnableClientState(GL2.GL_NORMAL_ARRAY); + gl.glNormalPointer(GL2.GL_FLOAT, 8 * 4, 5 * 4); + + gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 16); + + gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); + gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(GL2.GL_NORMAL_ARRAY); + } + + static { + GLProfile.initSingleton(); + } + + static GLProfile glp; + static GLDrawableFactory factory; + static int width, height; + GLCapabilities caps; + Window window; + GLDrawable drawable; + GLContext context; + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + factory = GLDrawableFactory.getFactory(glp); + Assert.assertNotNull(factory); + width = 640; + height = 480; + } + + @AfterClass + public static void releaseClass() { + Assert.assertNotNull(factory); + factory=null; + } + + @Before + public void initTest() { + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + void createWindow(boolean onscreen, boolean pbuffer, boolean undecorated) throws InterruptedException { + caps.setOnscreen(onscreen); + caps.setPBuffer(!onscreen && pbuffer); + caps.setDoubleBuffered(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + window = NewtFactory.createWindow(screen, caps, onscreen && undecorated); + Assert.assertNotNull(window); + window.setSize(width, height); + window.setVisible(true); + // System.out.println("Created: "+window); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(glCaps); + Assert.assertTrue(glCaps.getGreenBits()>5); + Assert.assertTrue(glCaps.getBlueBits()>5); + Assert.assertTrue(glCaps.getRedBits()>5); + Assert.assertEquals(glCaps.isOnscreen(),onscreen); + Assert.assertTrue(onscreen || !pbuffer || glCaps.isPBuffer()); // pass if onscreen, or !pbuffer req. or have pbuffer + Assert.assertEquals(glCaps.getDoubleBuffered(),onscreen); + Assert.assertTrue(glCaps.getDepthBits()>4); + + drawable = factory.createGLDrawable(window); + Assert.assertNotNull(drawable); + // System.out.println("Pre: "+drawable); + // + drawable.setRealized(true); + // Assert.assertEquals(width,drawable.getWidth()); + // Assert.assertEquals(height,drawable.getHeight()); + // Assert.assertEquals(glCaps,drawable.getChosenGLCapabilities()); + Assert.assertEquals(window,drawable.getNativeWindow()); + // System.out.println("Post: "+drawable); + + context = drawable.createContext(null); + Assert.assertNotNull(context); + // System.out.println(context); + + int res = context.makeCurrent(); + Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res); + + GL2 gl = context.getGL().getGL2(); + drawVBO(gl); + + drawable.swapBuffers(); + context.release(); + + // System.out.println("Final: "+window); + } + + void destroyWindow() { + // GLWindow.dispose(..) sequence + Assert.assertNotNull(context); + context.destroy(); + + Assert.assertNotNull(drawable); + drawable.setRealized(false); + + // GLWindow.destroy(..) sequence cont.. + Assert.assertNotNull(window); + window.destroy(true); // incl screen + display + + drawable = null; + context = null; + window = null; + } + + @Test + public void testVBO() throws InterruptedException { + createWindow(true, true, true); + Thread.sleep(500); + destroyWindow(); + } +} -- 1.7.0.4 |
Free forum by Nabble | Edit this page |