@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; } }
@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); } }
@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 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); } }
@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)); } }
if (ii.equals(current_ib)) { final UnsignedRangeInclusiveL r = u.getDataUpdateRange(); final ByteBuffer data = u.getData(); data.rewind(); final FakeIndexBuffer fa = (FakeIndexBuffer) ii;
@Override public void update( final JCGLInterfaceGL33Type g, final R2TransformContextType context) { NullCheck.notNull(context); NullCheck.notNull(g); final JCGLArrayBuffersType g_ab = g.getArrayBuffers(); final JCGLArrayObjectsType g_ao = g.getArrayObjects(); final FloatBuffer floats = this.update_vbo.getData().asFloatBuffer(); for (int index = this.used; index < this.max_size; ++index) { final int offset = Math.multiplyExact(index, 5); floats.put(offset + 0, 0.0f); floats.put(offset + 1, 0.0f); floats.put(offset + 2, 0.0f); floats.put(offset + 3, 0.0f); floats.put(offset + 4, 0.0f); } g_ao.arrayObjectBind(this.data_vao); g_ab.arrayBufferBind(this.data_vbo); g_ab.arrayBufferReallocate(this.data_vbo); g_ab.arrayBufferUpdate(this.update_vbo); g_ao.arrayObjectUnbind(); }
@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()); }
@Override public void onDataTriangle( final long v0, final long v1, final long v2) { final ByteBuffer buffer = this.index_update.getData(); switch (this.index_type) { case TYPE_UNSIGNED_BYTE: { Unsigned8.packToBuffer((int) v0, buffer, this.index_position); Unsigned8.packToBuffer((int) v1, buffer, this.index_position + 1); Unsigned8.packToBuffer((int) v2, buffer, this.index_position + 2); break; } case TYPE_UNSIGNED_INT: { Unsigned32.packToBuffer(v0, buffer, this.index_position); Unsigned32.packToBuffer(v1, buffer, this.index_position + 4); Unsigned32.packToBuffer(v2, buffer, this.index_position + 8); break; } case TYPE_UNSIGNED_SHORT: { Unsigned16.packToBuffer((int) v0, buffer, this.index_position); Unsigned16.packToBuffer((int) v1, buffer, this.index_position + 2); Unsigned16.packToBuffer((int) v2, buffer, this.index_position + 4); break; } } this.index_position = Math.addExact(this.index_position, this.index_stride); }
this.matrix_pointer = PMatrixByteBufferedM4x4F.newMatrixFromByteBuffer( this.update_vbo.getData(), 0L);
final ByteBuffer d = u.getData();