/** * 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; }
@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); }
@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); } }
final JCGLIndexBufferType ii = u.buffer(); this.checkIndexBuffer(ii);
up -> this.g.evaluate((g33, unused) -> { final JCGLArrayBuffersType ga = g33.arrayBuffers(); ga.arrayBufferBind(up.buffer()); ga.arrayBufferUpdate(up); ga.arrayBufferUnbind(); return up.buffer(); })); up -> this.g.evaluate((g33, unused) -> { final JCGLIndexBuffersType gi = g33.indexBuffers(); gi.indexBufferBind(up.buffer()); gi.indexBufferUpdate(up); gi.indexBufferUnbind(); return up.buffer(); }));
@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()); }