private int findPositionOffset( VertexFormat format ) { List<VertexFormatElement> elements = format.getElements(); for( int i = 0; i < elements.size(); i++ ) { VertexFormatElement e = elements.get( i ); if( e.isPositionElement() ) { if( e.getType() != VertexFormatElement.EnumType.FLOAT ) { throw new IllegalArgumentException( "Only floating point positions are supported" ); } return i; } } throw new IllegalArgumentException( "Vertex format " + format + " has no position attribute!" ); } }
if( element.getUsage() == VertexFormatElement.EnumUsage.NORMAL ) normalType = element.getType();
@Override public BufferBuilder pos(double x, double y, double z) { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, (float) (x + this.xOffset)); this.byteBuffer.putFloat(i + 4, (float) (y + this.yOffset)); this.byteBuffer.putFloat(i + 8, (float) (z + this.zOffset)); break; case UINT: case INT: this.byteBuffer.putInt(i, Float.floatToRawIntBits((float) (x + this.xOffset))); this.byteBuffer.putInt(i + 4, Float.floatToRawIntBits((float) (y + this.yOffset))); this.byteBuffer.putInt(i + 8, Float.floatToRawIntBits((float) (z + this.zOffset))); break; case USHORT: case SHORT: this.byteBuffer.putShort(i, (short) ((int) (x + this.xOffset))); this.byteBuffer.putShort(i + 2, (short) ((int) (y + this.yOffset))); this.byteBuffer.putShort(i + 4, (short) ((int) (z + this.zOffset))); break; case UBYTE: case BYTE: this.byteBuffer.put(i, (byte) ((int) (x + this.xOffset))); this.byteBuffer.put(i + 1, (byte) ((int) (y + this.yOffset))); this.byteBuffer.put(i + 2, (byte) ((int) (z + this.zOffset))); } this.nextVertexFormatIndex(); return this; }
@Override public BufferBuilder lightmap(int p_187314_1_, int p_187314_2_) { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, p_187314_1_); this.byteBuffer.putFloat(i + 4, p_187314_2_); break; case UINT: case INT: this.byteBuffer.putInt(i, p_187314_1_); this.byteBuffer.putInt(i + 4, p_187314_2_); break; case USHORT: case SHORT: this.byteBuffer.putShort(i, (short) p_187314_2_); this.byteBuffer.putShort(i + 2, (short) p_187314_1_); break; case UBYTE: case BYTE: this.byteBuffer.put(i, (byte) p_187314_2_); this.byteBuffer.put(i + 1, (byte) p_187314_1_); } this.nextVertexFormatIndex(); return this; }
@Override public BufferBuilder normal(float x, float y, float z) { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, x); this.byteBuffer.putFloat(i + 4, y); this.byteBuffer.putFloat(i + 8, z); break; case UINT: case INT: this.byteBuffer.putInt(i, (int) x); this.byteBuffer.putInt(i + 4, (int) y); this.byteBuffer.putInt(i + 8, (int) z); break; case USHORT: case SHORT: this.byteBuffer.putShort(i, (short) ((int) (x * 32767) & 65535)); this.byteBuffer.putShort(i + 2, (short) ((int) (y * 32767) & 65535)); this.byteBuffer.putShort(i + 4, (short) ((int) (z * 32767) & 65535)); break; case UBYTE: case BYTE: this.byteBuffer.put(i, (byte) ((int) (x * 127) & 255)); this.byteBuffer.put(i + 1, (byte) ((int) (y * 127) & 255)); this.byteBuffer.put(i + 2, (byte) ((int) (z * 127) & 255)); } this.nextVertexFormatIndex(); return this; }
@Override public BufferBuilder tex(double u, double v) { int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex); switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, (float) u); this.byteBuffer.putFloat(i + 4, (float) v); break; case UINT: case INT: this.byteBuffer.putInt(i, (int) u); this.byteBuffer.putInt(i + 4, (int) v); break; case USHORT: case SHORT: this.byteBuffer.putShort(i, (short) ((int) v)); this.byteBuffer.putShort(i + 2, (short) ((int) u)); break; case UBYTE: case BYTE: this.byteBuffer.put(i, (byte) ((int) v)); this.byteBuffer.put(i + 1, (byte) ((int) u)); } this.nextVertexFormatIndex(); return this; }
switch (this.vertexFormatElement.getType()) { case FLOAT: this.byteBuffer.putFloat(i, red / 255.0F);
@Override public void put( final int element, final float... data ) { final VertexFormatElement e = getVertexFormat().getElement( element ); if ( e.getUsage() == EnumUsage.UV && e.getIndex() == 1 && e.getType() == EnumType.SHORT && data.length >= 2 && hasLightMap ) { final int lvFromData_sky = (int) ( data[0] / maxLightmap ) & 0xf; final int lvFromData_block = (int) ( data[1] / maxLightmap ) & 0xf; lv = Math.max( lvFromData_sky, lv ); lv = Math.max( lvFromData_block, lv ); } }
public void setVertexFormat( VertexFormat format ) { hasLightMap = false; int eCount = format.getElementCount(); for ( int x = 0; x < eCount; x++ ) { VertexFormatElement e = format.getElement( x ); if ( e.getUsage() == EnumUsage.UV && e.getIndex() == 1 && e.getType() == EnumType.SHORT ) { hasLightMap = true; } } this.format = format; }
final int offset = vf.getOffset(i); final int count = attr.getElementCount(); final int constant = attr.getType().getGlConstant(); final int index = attr.getIndex(); final EnumUsage usage = attr.getUsage();