aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-26 17:04:03 +0100
committerSven Gothel <[email protected]>2014-02-26 17:04:03 +0100
commit80a0ddd084e674fbfff007e6a83eec6162aaa32d (patch)
tree10ae3efcd51e174997943f40a5ea8c9bd39a8b75 /src/test
parentd84812b6fb398c73cb3f339ab13d74b7e6822181 (diff)
parent72d44215a266ccb569efbd5af3142385c4442fe9 (diff)
Merge branch 'master' into 2.2-train
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java82
1 files changed, 59 insertions, 23 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java
index ac82c74ea..23778ecf6 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java
@@ -36,6 +36,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES3;
import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLBufferStorage;
import javax.media.opengl.GLCapabilities;
@@ -57,44 +58,65 @@ public class TestMapBufferRead01NEWT extends UITestCase {
static final boolean DEBUG = false;
@Test
- public void testWriteRead01a() throws InterruptedException {
+ public void testWriteRead01aMap() throws InterruptedException {
if(!GLProfile.isAvailable(GLProfile.GL2GL3)) {
System.err.println("Test requires GL2/GL3 profile.");
return;
}
ByteBuffer verticiesBB = ByteBuffer.allocate(4*9);
verticiesBB.order(ByteOrder.nativeOrder());
- testWriteRead01(verticiesBB);
+ testWriteRead01(verticiesBB, false /* useRange */);
}
@Test
- public void testWriteRead01b() throws InterruptedException {
+ public void testWriteRead01bMap() throws InterruptedException {
if(!GLProfile.isAvailable(GLProfile.GL2GL3)) {
System.err.println("Test requires GL2/GL3 profile.");
return;
}
ByteBuffer verticiesBB = Buffers.newDirectByteBuffer(4*9);
- testWriteRead01(verticiesBB);
+ testWriteRead01(verticiesBB, false /* useRange */);
}
- private void testWriteRead01(ByteBuffer verticiesBB) throws InterruptedException {
+ @Test
+ public void testWriteRead02aMapRange() throws InterruptedException {
+ if(!GLProfile.isAvailable(GLProfile.GL3) && !!GLProfile.isAvailable(GLProfile.GLES3)) {
+ System.err.println("Test requires GL3 or GLES3 profile.");
+ return;
+ }
+ ByteBuffer verticiesBB = ByteBuffer.allocate(4*9);
+ verticiesBB.order(ByteOrder.nativeOrder());
+ testWriteRead01(verticiesBB, true/* useRange */);
+ }
+ @Test
+ public void testWriteRead02bMapRange() throws InterruptedException {
+ if(!GLProfile.isAvailable(GLProfile.GL3) && !!GLProfile.isAvailable(GLProfile.GLES3)) {
+ System.err.println("Test requires GL3 or GLES3 profile.");
+ return;
+ }
+ ByteBuffer verticiesBB = Buffers.newDirectByteBuffer(4*9);
+ testWriteRead01(verticiesBB, true /* useRange */);
+ }
+
+ private void testWriteRead01(ByteBuffer verticiesBB, boolean useRange) throws InterruptedException {
+ final GLProfile glp = GLProfile.getMaxProgrammable(true);
final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOffscreenWindow(
- new GLCapabilities(GLProfile.getGL2GL3()), 800, 600, true);
+ new GLCapabilities(glp), 800, 600, true);
try {
final GL gl = winctx.context.getGL();
int[] vertexBuffer = new int[1];
- verticiesBB.putFloat(0);
- verticiesBB.putFloat(0.5f);
- verticiesBB.putFloat(0);
+ verticiesBB.putFloat(-0.3f);
+ verticiesBB.putFloat(-0.2f);
+ verticiesBB.putFloat(-0.1f);
- verticiesBB.putFloat(0.5f);
- verticiesBB.putFloat(-0.5f);
- verticiesBB.putFloat(0);
+ verticiesBB.putFloat(0.1f);
+ verticiesBB.putFloat(0.2f);
+ verticiesBB.putFloat(0.3f);
- verticiesBB.putFloat(-0.5f);
- verticiesBB.putFloat(-0.5f);
- verticiesBB.putFloat(0);
+ verticiesBB.putFloat(0.4f);
+ verticiesBB.putFloat(0.5f);
+ verticiesBB.putFloat(0.6f);
verticiesBB.rewind();
if(DEBUG) {
for(int i=0; i < verticiesBB.capacity(); i+=4) {
@@ -106,28 +128,42 @@ public class TestMapBufferRead01NEWT extends UITestCase {
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexBuffer[0]);
- // gl.glBufferData(GL.GL_ARRAY_BUFFER, verticiesBB.capacity(), verticiesBB, GL.GL_STATIC_READ);
- gl.glBufferData(GL.GL_ARRAY_BUFFER, verticiesBB.capacity(), verticiesBB, GL.GL_STATIC_DRAW);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, verticiesBB.capacity(), verticiesBB, GL2ES3.GL_STATIC_READ);
+ // gl.glBufferData(GL.GL_ARRAY_BUFFER, verticiesBB.capacity(), verticiesBB, GL.GL_STATIC_DRAW);
final int bufferName = gl.getBoundBuffer(GL.GL_ARRAY_BUFFER);
final GLBufferStorage bufferStorage = gl.getBufferStorage(bufferName);
System.err.println("gpu-01 GL_ARRAY_BUFFER -> bufferName "+bufferName+" -> "+bufferStorage);
Assert.assertEquals("Buffer storage's bytes-buffer not null before map", null, bufferStorage.getMappedBuffer());
- final ByteBuffer bb = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL2GL3.GL_READ_ONLY);
- Assert.assertNotNull(bb);
- System.err.println("gpu-02 mapped GL_ARRAY_BUFFER -> "+bb);
+ final int floatOffset, byteOffset, mapByteLength;
+ final ByteBuffer bb;
+ if( useRange ) {
+ floatOffset = 3;
+ byteOffset = Buffers.SIZEOF_FLOAT*floatOffset;
+ mapByteLength = verticiesBB.capacity()-byteOffset;
+ bb = gl.glMapBufferRange(GL.GL_ARRAY_BUFFER, byteOffset, mapByteLength, GL.GL_MAP_READ_BIT);
+ } else {
+ floatOffset = 0;
+ byteOffset = 0;
+ mapByteLength = verticiesBB.capacity();
+ bb = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL2GL3.GL_READ_ONLY);
+ }
+ System.err.println("gpu-02 mapped GL_ARRAY_BUFFER, floatOffset "+floatOffset+", byteOffset "+byteOffset+", mapByteLength "+mapByteLength+" -> "+bb);
System.err.println("gpu-03 GL_ARRAY_BUFFER -> bufferName "+bufferName+" -> "+bufferStorage);
- Assert.assertEquals("Buffer storage size not equals buffer storage size", bufferStorage.getSize(), bb.capacity());
- Assert.assertEquals("Buffer storage's bytes-buffer not equal with mapped bytes-buffer", bufferStorage.getMappedBuffer(), bb);
+ Assert.assertNotNull(bb);
+ Assert.assertEquals("BufferStorage size less byteOffset not equals buffer storage size", bufferStorage.getSize()-byteOffset, bb.capacity());
+ Assert.assertEquals("BufferStorage's bytes-buffer not equal with mapped bytes-buffer", bufferStorage.getMappedBuffer(), bb);
+ Assert.assertEquals("Buffer storage size not equals mapByteLength", mapByteLength, bb.capacity());
if(DEBUG) {
+ System.err.println("floatOffset "+floatOffset+", byteOffset "+byteOffset);
for(int i=0; i < bb.capacity(); i+=4) {
System.err.println("gpu "+i+": "+bb.getFloat(i));
}
}
for(int i=0; i < bb.capacity(); i+=4) {
- Assert.assertEquals(verticiesBB.getFloat(i), bb.getFloat(i), 0.0);
+ Assert.assertEquals(verticiesBB.getFloat(byteOffset+i), bb.getFloat(i), 0.0001f);
}
gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER);
Assert.assertEquals("Buffer storage's bytes-buffer not null after unmap", null, bufferStorage.getMappedBuffer());