@Test public final void testIndexUpdateNotBound() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); gi.indexBufferUnbind(); this.expected.expect(JCGLExceptionBufferNotBound.class); gi.indexBufferUpdate(u); }
@Test public final void testIndexUpdateDeleted() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); gi.indexBufferDelete(i); this.expected.expect(JCGLExceptionDeleted.class); gi.indexBufferUpdate(u); }
@Test public final void testIndexReadDeleted() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); gi.indexBufferDelete(i); this.expected.expect(JCGLExceptionDeleted.class); gi.indexBufferRead(i, size -> ByteBuffer.allocateDirect((int) size)); }
@Test public final void testIndexReallocateNotBound() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); gi.indexBufferUnbind(); this.expected.expect(JCGLExceptionBufferNotBound.class); gi.indexBufferReallocate(i); }
@Test public final void testIndexReadNotBound() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); gi.indexBufferUnbind(); this.expected.expect(JCGLExceptionBufferNotBound.class); gi.indexBufferRead(i, size -> ByteBuffer.allocateDirect((int) size)); }
final long sz = size.longValue(); final JCGLIndexBuffersType gi = g33.getIndexBuffers(); gi.indexBufferUnbind(); return gi.indexBufferAllocate(sz, index_type, index_usage); })); up -> this.g.evaluate((g33, unused) -> { final JCGLIndexBuffersType gi = g33.getIndexBuffers(); gi.indexBufferBind(up.getBuffer()); gi.indexBufferUpdate(up); gi.indexBufferUnbind(); return up.getBuffer(); }));
@Override public void delete(final JCGLInterfaceGL33Type g) throws R2Exception { if (!this.isDeleted()) { try { LOG.debug("delete"); final JCGLArrayBuffersType g_ab = g.getArrayBuffers(); final JCGLIndexBuffersType g_ib = g.getIndexBuffers(); final JCGLArrayObjectsType g_ao = g.getArrayObjects(); g_ao.arrayObjectDelete(this.array_object); g_ab.arrayBufferDelete(this.array); g_ib.indexBufferDelete(this.index); } finally { this.deleted = true; } } }
@Test public final void testDrawElementsOK() { final Interfaces i = this.getInterfaces("main"); final JCGLArrayObjectsType go = i.getArrayObjects(); final JCGLIndexBuffersType gi = i.getIndexBuffers(); final JCGLDrawType gd = i.getDraw(); final JCGLIndexBufferType ib = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); gi.indexBufferUnbind(); final JCGLArrayObjectBuilderType b = go.arrayObjectNewBuilder(); b.setIndexBuffer(ib); final JCGLArrayObjectType ao = go.arrayObjectAllocate(b); gd.drawElements(JCGLPrimitives.PRIMITIVE_POINTS); }
@Test public final void testIndexUpdateShared() { final JCGLSharedContextPair<JCGLIndexBuffersType> p = this.getIndexBuffersSharedWith("main", "alt"); final JCGLContextType ca = p.getMasterContext(); final JCGLContextType cb = p.getSlaveContext(); final JCGLIndexBuffersType gi = p.getMasterValue(); final JCGLIndexBuffersType gb = p.getSlaveValue(); Assert.assertTrue(ca.contextIsCurrent()); Assert.assertFalse(cb.contextIsCurrent()); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); ca.contextReleaseCurrent(); cb.contextMakeCurrent(); gb.indexBufferBind(i); gb.indexBufferUpdate(u); }
@Test public final void testIndexRead() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); final ByteBuffer b = u.getData(); for (int index = 0; index < 100; ++index) { b.put(index, (byte) 0x50); } gi.indexBufferUpdate(u); final ByteBuffer e = gi.indexBufferRead(i, size -> ByteBuffer.allocateDirect((int) size)); for (int index = 0; index < 100; ++index) { Assert.assertEquals((long) b.get(index), (long) e.get(index)); } }
@Test public final void testArrayBindIndexRebindDisallowed0() { final Interfaces i = this.getInterfaces("main"); final JCGLArrayBuffersType ga = i.getArrayBuffers(); final JCGLArrayObjectsType go = i.getArrayObjects(); final JCGLIndexBuffersType gi = i.getIndexBuffers(); final JCGLIndexBufferType ib0 = gi.indexBufferAllocate( 10L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLIndexBufferType ib1 = gi.indexBufferAllocate( 10L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); gi.indexBufferUnbind(); final JCGLArrayBufferType ab = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLArrayObjectBuilderType b = go.arrayObjectNewBuilder(); Assert.assertTrue(b.getMaximumVertexAttributes() >= 16); b.setIndexBuffer(ib0); b.setAttributeFloatingPoint( 0, ab, 4, JCGLScalarType.TYPE_FLOAT, 16, 0L, false); final JCGLArrayObjectType ao0 = go.arrayObjectAllocate(b); Assert.assertEquals(ao0, go.arrayObjectGetCurrentlyBound()); this.expected.expect(JCGLExceptionIndexBufferAlreadyConfigured.class); gi.indexBufferBind(ib1); }
final JCGLIndexBuffersType gi = i.getIndexBuffers(); final JCGLIndexBufferType ib = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, Assert.assertEquals(Optional.of(ib), ai_1.indexBufferBound()); Assert.assertEquals(Optional.of(ib), ai_2.indexBufferBound()); Assert.assertEquals(Optional.of(ib), gi.indexBufferGetCurrentlyBound()); Assert.assertTrue(ai2_refs.contains(ib)); gi.indexBufferDelete(ib);
@Test public final void testIndexBufferBindIdentity() { final Interfaces i = this.getIndexBuffers("name"); final JCGLIndexBuffersType gi = i.getIndexBuffers(); final JCGLArrayObjectsType ga = i.getArrayObjects(); final JCGLArrayObjectUsableType a0 = ga.arrayObjectGetDefault(); final Set<JCGLReferableType> a0_refs = a0.references(); final JCGLIndexBufferType i0 = gi.indexBufferAllocate( 1000L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final Set<JCGLReferenceContainerType> i0_refs = i0.referringContainers(); Assert.assertEquals(Optional.of(i0), gi.indexBufferGetCurrentlyBound()); Assert.assertEquals(Optional.of(i0), a0.indexBufferBound()); Assert.assertEquals(1L, (long) a0_refs.size()); Assert.assertTrue(a0_refs.contains(i0)); Assert.assertEquals(1L, (long) i0_refs.size()); Assert.assertTrue(i0_refs.contains(a0)); gi.indexBufferUnbind(); Assert.assertEquals(a0, ga.arrayObjectGetCurrentlyBound()); Assert.assertEquals(Optional.empty(), gi.indexBufferGetCurrentlyBound()); Assert.assertEquals(Optional.empty(), a0.indexBufferBound()); Assert.assertEquals(0L, (long) a0_refs.size()); Assert.assertEquals(0L, (long) a0_refs.size()); Assert.assertEquals(0L, (long) i0_refs.size()); }
@Test public final void testArrayAllocateIndexDeleted() { final Interfaces is = this.getInterfaces("main"); final JCGLArrayBuffersType ga = is.getArrayBuffers(); final JCGLIndexBuffersType gi = is.getIndexBuffers(); final JCGLArrayObjectsType go = is.getArrayObjects(); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLArrayObjectBuilderType b = go.arrayObjectNewBuilder(); b.setIndexBuffer(i); gi.indexBufferDelete(i); this.expected.expect(JCGLExceptionDeleted.class); go.arrayObjectAllocate(b); Assert.fail(); }
@Test public final void testIndexUpdateWrongContext() { final JCGLUnsharedContextPair<JCGLIndexBuffersType> p = this.getIndexBuffersUnshared("main", "alt"); final JCGLContextType ca = p.getContextA(); final JCGLContextType cb = p.getContextB(); final JCGLIndexBuffersType gi = p.getValueA(); final JCGLIndexBuffersType gb = p.getValueB(); Assert.assertFalse(ca.contextIsCurrent()); Assert.assertTrue(cb.contextIsCurrent()); cb.contextReleaseCurrent(); ca.contextMakeCurrent(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); ca.contextReleaseCurrent(); cb.contextMakeCurrent(); this.expected.expect(JCGLExceptionWrongContext.class); gb.indexBufferUpdate(u); }
@Override public void onFinish() { final JCGLArrayBuffersType g_ab = this.g.getArrayBuffers(); final JCGLIndexBuffersType g_ib = this.g.getIndexBuffers(); if (!this.errors.isEmpty()) { if (this.array_buffer != null) { g_ab.arrayBufferDelete(this.array_buffer); this.array_buffer = null; } if (this.index_buffer != null) { g_ib.indexBufferDelete(this.index_buffer); this.index_buffer = null; } } g_ab.arrayBufferUpdate(this.array_update); g_ib.indexBufferUpdate(this.index_update); this.array_object = this.g.getArrayObjects().arrayObjectAllocate(this.array_object_builder); }
@Test public final void testIndexBufferBadSize() { final Interfaces i = this.getIndexBuffers("name"); final JCGLIndexBuffersType gi = i.getIndexBuffers(); this.expected.expect(RangeCheckException.class); gi.indexBufferAllocate( -1L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); }
@Test public final void testIndexBufferReallocateIdentity() { final Interfaces i = this.getIndexBuffers("name"); final JCGLIndexBuffersType gi = i.getIndexBuffers(); final JCGLIndexBufferType i0 = gi.indexBufferAllocate( 1000L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); Assert.assertEquals(1000L, i0.indices()); Assert.assertEquals(JCGLUnsignedType.TYPE_UNSIGNED_BYTE, i0.type()); Assert.assertEquals(JCGLUsageHint.USAGE_STATIC_DRAW, i0.usageHint()); Assert.assertFalse(i0.isDeleted()); gi.indexBufferReallocate(i0); Assert.assertEquals(1000L, i0.indices()); Assert.assertEquals(JCGLUnsignedType.TYPE_UNSIGNED_BYTE, i0.type()); Assert.assertEquals(JCGLUsageHint.USAGE_STATIC_DRAW, i0.usageHint()); Assert.assertFalse(i0.isDeleted()); }
final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, Assert.assertEquals(Optional.of(i), gi.indexBufferGetCurrentlyBound()); Assert.assertEquals(Optional.of(i), ai.getIndexBufferBound());
g_ao.arrayObjectBind(adapter.arrayObject()); final ByteBuffer data = g_ib.indexBufferRead( ib, size -> { final ByteBuffer b = ByteBuffer.allocateDirect((int) size);