@Override public void arrayBufferUpdate( final JCGLBufferUpdateType<JCGLArrayBufferType> u) throws JCGLException, JCGLExceptionDeleted, JCGLExceptionBufferNotBound { NullCheck.notNull(u); final JCGLArrayBufferType a = u.getBuffer(); this.checkArray(a); if (a.equals(this.bind)) { final UnsignedRangeInclusiveL r = u.getDataUpdateRange(); final ByteBuffer data = u.getData(); data.rewind(); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, r.getLower(), data); } else { throw this.notBound(a); } }
/** * 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 onDataAttributeStart( final SMFAttribute attribute) { final String name = attribute.name().value(); if (this.attributes_by_name.containsKey(name)) { final Attribute attr = this.attributes_by_name.get(name); this.packer = new SMFByteBufferPacker( this.array_update.getData(), attr.type, (int) attr.offset, this.vertex_size); } else { this.packer = null; } }
@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); } }
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(); }));
up -> this.g.evaluate((g33, unused) -> { final JCGLArrayBuffersType ga = g33.getArrayBuffers(); ga.arrayBufferBind(up.getBuffer()); ga.arrayBufferUpdate(up); ga.arrayBufferUnbind(); return up.getBuffer(); })); 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 int addInstance( final PVectorI3F<R2SpaceWorldType> position, final float scale, final float rotation) throws R2ExceptionBatchIsFull { NullCheck.notNull(position, "Position"); if (this.used >= this.max_size) { final StringBuilder sb = new StringBuilder(64); sb.append("Batch is full (capacity is "); sb.append(this.max_size); sb.append(")"); throw new R2ExceptionBatchIsFull(sb.toString()); } final FloatBuffer floats = this.update_vbo.getData().asFloatBuffer(); final int index = this.used; final int offset = Math.multiplyExact(index, 5); floats.put(offset + 0, position.getXF()); floats.put(offset + 1, position.getYF()); floats.put(offset + 2, position.getZF()); floats.put(offset + 3, scale); floats.put(offset + 4, rotation); this.used = Math.addExact(this.used, 1); return 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(); 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); final JCGLIndexBufferType ii = u.getBuffer(); this.checkIndexBuffer(ii); final JCGLArrayObjectUsableType ao = this.array_objects.arrayObjectGetCurrentlyBound(); final Optional<JCGLIndexBufferUsableType> i_opt = ao.getIndexBufferBound(); if (i_opt.isPresent()) { final JCGLIndexBufferUsableType current_ib = i_opt.get(); if (ii.equals(current_ib)) { final UnsignedRangeInclusiveL r = u.getDataUpdateRange(); final ByteBuffer data = u.getData(); data.rewind(); GL15.glBufferSubData( GL15.GL_ELEMENT_ARRAY_BUFFER, r.getLower(), data); return; } } throw LWJGL3IndexBuffers.notBound(ii, i_opt); }
@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.getData(); 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); } }
@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); } }
@Override public void arrayBufferUpdate( final JCGLBufferUpdateType<JCGLArrayBufferType> u) throws JCGLException, JCGLExceptionDeleted, JCGLExceptionBufferNotBound { NullCheck.notNull(u); final JCGLArrayBufferType a = u.getBuffer(); this.checkArray(a); if (a.equals(this.bind)) { final UnsignedRangeInclusiveL r = u.getDataUpdateRange(); final ByteBuffer data = u.getData(); 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); } }
@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)); } }
@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 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.getBuffer()); final UnsignedRangeInclusiveL u_range = u.getDataUpdateRange(); final ByteBuffer u_data = u.getData(); Assert.assertEquals(a.getRange(), u_range); Assert.assertEquals(u_range.getInterval(), (long) u_data.capacity()); }