public VertexBuffer(Element e, int size) { this(new DataLayout(INTERLEAVE, e), size); }
public void copyVertex(int id, int offset, VertexBuffer vbuffer) { assert (id + offset < vcount) : "The destination vertex is not in bound of the destination buffer"; if (layout.equals(vbuffer.layout)) { ByteBuffer buf = vbuffer.buffer; int limit = offset + layout.getBytesize(); assert !(limit <= buf.capacity() || id > vcount) : "Couldn't copy Vertex"; buf.position(offset); buf.limit(limit); buffer.position(layout.getBytesize() * id); buffer.put(buf); } else { Vertex src = vbuffer.getVertex(id); Vertex dst = getVertex(id + offset); for (Element e : layout.getElements()) { if (vbuffer.layout.hasElement(e)) { dst.setAttribute(e, src.getAttribute(e)); } } } }
public DataLayout(DataLayout layout, Element... elements) { this(layout.format, collect(layout.getElements(), elements)); }
public VertexBuffer(DataLayout layout, float... data) { this(layout, data.length / (layout.getBytesize() / 4)); for (Element e : layout.getElements()) { if (e.getDataType() != DataType.FLOAT) { throw new IllegalArgumentException("The layout must consist of only float tpye data elements!"); } } if (data.length % (layout.getBytesize() / 4) != 0) { throw new IllegalArgumentException("The data size is not an excate multiple of the data layout size!"); } setVCount(size); buffer.asFloatBuffer().put(data); }
@AssistedInject @ParametersAreNonnullByDefault public StdAttributs(GraphicContext gcontext, @Assisted Shader shader, @Assisted VertexBO[] vbuffers, @Assisted @Nullable BufferObject indice) { assert shader.isInitialized() : "Shader is not initialized!"; this.indice = indice; configs = new BufferConfigs[vbuffers.length]; for (int i = 0; i < vbuffers.length; ++i) { DataLayout dl = vbuffers[i].layout; List<AttributConfig> cs = new LinkedList<>(); for (Element ele : dl.getElements()) { Optional<ShaderAttribute> sa = shader.getAttribut(ele); if (sa.isPresent()) { cs.add(new AttributConfig(sa.get(), dl.getAttribut(ele))); } } AttributConfig[] c = new AttributConfig[cs.size()]; cs.toArray(c); configs[i] = new BufferConfigs(gcontext, vbuffers[i].buffer, c); } }
public void getAttribute(Element ele, ByteBuffer values) { DataAttribut al = vb.layout.getAttribut(ele); assert al != null : "This Attribute doesn't exist in the VertexBuffer"; assert (values.remaining() >= ele.getVectorType().getByteSize()) : "not enough data in the buffer!"; int old = vb.buffer.position(); int oldl = vb.buffer.limit(); { int id = ind * al.stride + al.offset; vb.buffer.position(id * ele.getDataType().byteSize); vb.buffer.limit(vb.buffer.position() + ele.getVectorType().getByteSize()); values.put(vb.buffer); } vb.buffer.position(old); vb.buffer.limit(oldl); } }
public int getElementCount() { return getElements().size(); }
public void copyInto(int offset, VertexBuffer vbuffer) { assert (size >= vbuffer.vcount + offset) : "Destination Buffer not large enough"; assert (offset <= vcount) : "Offset:" + offset + " vcount:" + vcount + " (offset>vcount)"; setVCount(vbuffer.vcount + offset); if (!vbuffer.layout.equals(layout)) { setVCount(max(vcount, vbuffer.vcount + offset)); for (int i = 0; i < vbuffer.vcount; ++i) { copyVertex(i, offset, vbuffer); } } else { buffer.position(layout.getBytesize() * offset); ByteBuffer buf = vbuffer.buffer; buf.position(0); buffer.put(buf); } }
private void setVCount(int vc) { vcount = vc; buffer.limit(vcount * layout.getBytesize()); }
@Override public Mesh modifie(Mesh m) { VertexBuffer old = m.getVertices(); DataLayout layout = old.layout; boolean hasattr = layout.hasElement(position) && layout.hasElement(normal) && layout.hasElement(texcoord); if (m.getPrimitiv_typ() != GL.GL_TRIANGLES || !hasattr) { logger.warn("Mesh can't be transformed," + " only Triangle Meshs allowed!"); return m; } layout = new DataLayout(layout, tangent); VertexBuffer vb = new VertexBuffer(layout, old.getVcount()); vb.copyInto(0, old); int[] indice = m.getIndicies(); for (int i = 0; i < m.getIndexCount(); i += 3) { Vertex v0 = vb.getVertex(indice[i]); Vertex v1 = vb.getVertex(indice[i + 1]); Vertex v2 = vb.getVertex(indice[i + 2]); v0.setAttribute(tangent, calculateTangent(v0, v1, v2)); v1.setAttribute(tangent, calculateTangent(v1, v2, v0)); v2.setAttribute(tangent, calculateTangent(v2, v0, v1)); } return new Mesh(m.getIndicies(), vb, m.getPrimitiv_typ()); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final VertexBuffer other = (VertexBuffer) obj; if (this.buffer != other.buffer && (this.buffer == null || !equalsByteBuffers(buffer, other.buffer))) { return false; } if (this.layout != other.layout && (this.layout == null || !this.layout.equals(other.layout))) { return false; } if (this.vcount != other.vcount) { return false; } return true; }
public DataLayout(Format format, Element... elements) { if (elements.length == 1) { this.format = Format.INTERLEAVE; } else { this.format = format; } int[] offsets = new int[elements.length]; for (int i = 0; i < elements.length - 1; ++i) { offsets[i + 1] = offsets[i] + elements[i].getVectorType().getByteSize(); } int stride = offsets[offsets.length - 1] + elements[elements.length - 1].getVectorType().getByteSize(); if (elements.length > 1) { stride = calcStride(format, stride); } for (int i = 0; i < elements.length; ++i) { alignments.put(elements[i], new DataAttribut(stride, offsets[i])); } bytesize = stride; }
if (!vbuffer.layout.hasElement(POSITION)) { throw new IOException("The mesh doesn't have a float3 vertex position attribute!"); if (vbuffer.layout.hasElement(NORMAL)) { normals = new float[vc * CTM_NORMAL_ELEMENT_COUNT]; int k = 0; boolean hasUV = vbuffer.layout.hasElement(TEX_COORD); AttributeData[] texcoords = new AttributeData[hasUV ? 1 : 0]; if (hasUV) {
public void setAttribute(Element ele, ByteBuffer values) { DataAttribut al = vb.layout.getAttribut(ele); assert al != null : "This Attribute doesn't exist in the VertexBuffer"; assert (values.remaining() >= ele.getVectorType().getByteSize()) : "not enough data in the buffer!"; int old = vb.buffer.position(); { int id = ind * al.stride + al.offset; vb.buffer.position(id); int oldLim = values.limit(); { int newLim = values.position() + ele.getVectorType().getByteSize(); if (newLim > oldLim) { throw new BufferOverflowException(); } values.limit(newLim); vb.buffer.put(values); } values.limit(oldLim); } vb.buffer.position(old); }
for (Element ele : vbuffer.layout.getElements()) { builder.append("\"") .append(ele.getBezeichnung())
public VertexBuffer(DataLayout layout, int size) { this.size = size; this.layout = layout; buffer = GLBuffers.newDirectByteBuffer(size * layout.getBytesize()); buffer.limit(0); }
public VertexBuffer(Element e, float... data) { this(new DataLayout(INTERLEAVE, e), data); }
public Number[] getAttribute(Element ele) { Number[] values = new Number[ele.getVectorType().getElementCount()]; DataAttribut al = vb.layout.getAttribut(ele); int id = ind * al.stride + al.offset; ele.getDataType().get(vb.buffer, id, values); return values; }
private static AttributeData[] createAttributeData(VertexBuffer vbuffer) { List<AttributeData> attribute = new ArrayList<>(); for (Element el : vbuffer.layout.getElements()) { if (el.equals(POSITION) || el.equals(NORMAL) || el.equals(TEX_COORD)) { continue;
public int getVertexCount() { return buffer.getSize() / layout.getBytesize(); } }