/** * Fill a builder with attribute values from the provided {@code JCGLBufferUpdateType} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder<T> from(JCGLBufferUpdateType<T> instance) { Objects.requireNonNull(instance, "instance"); setBuffer(instance.buffer()); setData(instance.data()); setDataUpdateRange(instance.dataUpdateRange()); return this; }
@Test public final void testArrayRead() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); final ByteBuffer b = u.data(); for (int index = 0; index < 100; ++index) { b.put(index, (byte) 0x50); } ga.arrayBufferUpdate(u); final ByteBuffer e = ga.arrayBufferRead(a, size -> ByteBuffer.allocateDirect((int) size)); for (int index = 0; index < 100; ++index) { final long bv = (long) b.get(index); final long ev = (long) e.get(index); Assert.assertEquals("index " + index, bv, ev); } }
@Override public void arrayBufferUpdate( final JCGLBufferUpdateType<JCGLArrayBufferType> u) throws JCGLException, JCGLExceptionDeleted, JCGLExceptionBufferNotBound { NullCheck.notNull(u, "Update"); final JCGLArrayBufferType a = u.buffer(); this.checkArray(a); if (Objects.equals(a, this.bind)) { final UnsignedRangeInclusiveL r = u.dataUpdateRange(); final ByteBuffer data = u.data(); data.rewind(); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, r.getLower(), data); } else { throw this.notBound(a); } }
@Override public void indexBufferUpdate( final JCGLBufferUpdateType<JCGLIndexBufferType> u) throws JCGLException, JCGLExceptionDeleted, JCGLExceptionBufferNotBound { NullCheck.notNull(u, "Update"); final JCGLIndexBufferType ii = u.buffer(); this.checkIndexBuffer(ii); final JCGLArrayObjectUsableType ao = this.array_objects.arrayObjectGetCurrentlyBound(); final Optional<JCGLIndexBufferUsableType> i_opt = ao.indexBufferBound(); if (i_opt.isPresent()) { final JCGLIndexBufferUsableType current_ib = i_opt.get(); if (Objects.equals(ii, current_ib)) { final UnsignedRangeInclusiveL r = u.dataUpdateRange(); final ByteBuffer data = u.data(); data.rewind(); GL15.glBufferSubData( GL15.GL_ELEMENT_ARRAY_BUFFER, r.getLower(), data); return; } } throw notBound(ii, i_opt); }
@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.data(); 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)); } }
@Override public void arrayBufferUpdate( final JCGLBufferUpdateType<JCGLArrayBufferType> u) throws JCGLException, JCGLExceptionDeleted, JCGLExceptionBufferNotBound { NullCheck.notNull(u, "Update"); final JCGLArrayBufferType a = u.buffer(); this.checkArray(a); if (Objects.equals(a, this.bind)) { final UnsignedRangeInclusiveL r = u.dataUpdateRange(); final ByteBuffer data = u.data(); data.rewind(); final FakeArrayBuffer fa = (FakeArrayBuffer) a; final ByteBuffer fa_data = fa.getData(); /* * XXX: Clearly overflowing integers. */ final long lo = r.getLower(); final long hi = r.getUpper(); for (long index = lo; Long.compareUnsigned(index, hi) <= 0; ++index) { final int ii = (int) index; fa_data.put(ii, data.get(ii)); } } else { throw this.notBound(a); } }
if (Objects.equals(ii, current_ib)) { final UnsignedRangeInclusiveL r = u.dataUpdateRange(); final ByteBuffer data = u.data(); data.rewind(); final FakeIndexBuffer fa = (FakeIndexBuffer) ii;
@Test public final void testBufferUpdateAllIdentities() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); Assert.assertSame(a, u.buffer()); final UnsignedRangeInclusiveL u_range = u.dataUpdateRange(); final ByteBuffer u_data = u.data(); Assert.assertEquals(a.byteRange(), u_range); Assert.assertEquals(u_range.getInterval(), (long) u_data.capacity()); }