buffers.put(Type.InterleavedData.ordinal(), allData); buffersList.add(allData);
mesh.getBuffers().remove(bufferType.ordinal());
for (VertexBuffer vb : buffersList.getArray()){ VertexBuffer bufClone = vb.clone(); clone.buffers.put(vb.getBufferType().ordinal(), bufClone); clone.buffersList.add(bufClone);
/** * Unsets the {@link VertexBuffer} set on this mesh * with the given type. Does nothing if the vertex buffer type is not set * initially. * * @param type The buffer type to remove */ public void clearBuffer(VertexBuffer.Type type){ VertexBuffer vb = buffers.remove(type.ordinal()); if (vb != null){ buffersList.remove(vb); updateCounts(); } }
/** * Sets the {@link VertexBuffer} on the mesh. * This will update the vertex/triangle counts if needed. * * @param vb The buffer to set * @throws IllegalArgumentException If the buffer type is already set */ public void setBuffer(VertexBuffer vb){ if (buffers.containsKey(vb.getBufferType().ordinal())) throw new IllegalArgumentException("Buffer type already set: "+vb.getBufferType()); buffers.put(vb.getBufferType().ordinal(), vb); buffersList.add(vb); updateCounts(); }
/** * Unsets the {@link VertexBuffer} set on this mesh * with the given type. Does nothing if the vertex buffer type is not set * initially. * * @param type The buffer type to remove */ public void clearBuffer(VertexBuffer.Type type){ VertexBuffer vb = buffers.remove(type.ordinal()); if (vb != null){ buffersList.remove(vb); updateCounts(); } }
public Attribute getAttribute(VertexBuffer.Type attribType){ int ordinal = attribType.ordinal(); Attribute attrib = attribs.get(ordinal); if (attrib == null){ attrib = new Attribute(); attrib.name = attribType.name(); attribs.put(ordinal, attrib); } return attrib; }
public Attribute getAttribute(VertexBuffer.Type attribType){ int ordinal = attribType.ordinal(); Attribute attrib = attribs.get(ordinal); if (attrib == null){ attrib = new Attribute(); attrib.name = attribType.name(); attribs.put(ordinal, attrib); } return attrib; }
/** * Get the {@link VertexBuffer} stored on this mesh with the given * type. * * @param type The type of VertexBuffer * @return the VertexBuffer data, or null if not set */ public VertexBuffer getBuffer(Type type){ return buffers.get(type.ordinal()); }
/** * Get the {@link VertexBuffer} stored on this mesh with the given * type. * * @param type The type of VertexBuffer * @return the VertexBuffer data, or null if not set */ public VertexBuffer getBuffer(Type type){ return buffers.get(type.ordinal()); }
int currentCompsForBuf = compsForBuf[vb.getBufferType().ordinal()]; if (vb.getBufferType() != VertexBuffer.Type.Index && currentCompsForBuf != 0 && currentCompsForBuf != vb.getNumComponents()) { throw new UnsupportedOperationException("The geometry " + geom + " buffer " + vb.getBufferType() compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized(); compsForBuf[VertexBuffer.Type.Index.ordinal()] = components; formatForBuf[VertexBuffer.Type.Index.ordinal()] = VertexBuffer.Format.UnsignedInt; } else { formatForBuf[VertexBuffer.Type.Index.ordinal()] = VertexBuffer.Format.UnsignedShort; if (i == VertexBuffer.Type.Index.ordinal()) { data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalTris); } else { if (VertexBuffer.Type.Index.ordinal() == bufType) { int components = compsForBuf[bufType]; } else if (VertexBuffer.Type.Position.ordinal() == bufType) { FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); doCopyBuffer(inPos, globalVertIndex, outPos, 3); } else if (VertexBuffer.Type.Normal.ordinal() == bufType || VertexBuffer.Type.Tangent.ordinal() == bufType) { FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); doCopyBuffer(inPos, globalVertIndex, outPos, compsForBuf[bufType]);
int currentCompsForBuf = compsForBuf[vb.getBufferType().ordinal()]; if (vb.getBufferType() != Type.Index && currentCompsForBuf != 0 && currentCompsForBuf != vb.getNumComponents()) { throw new UnsupportedOperationException("The geometry " + geom + " buffer " + vb.getBufferType() compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized(); compsForBuf[Type.Index.ordinal()] = components; formatForBuf[Type.Index.ordinal()] = Format.UnsignedInt; } else { formatForBuf[Type.Index.ordinal()] = Format.UnsignedShort; if (i == Type.Index.ordinal()) { data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalTris); } else { if (Type.Index.ordinal() == bufType) { int components = compsForBuf[bufType]; } else if (Type.Position.ordinal() == bufType) { FloatBuffer inPos = (FloatBuffer) inBuf.getDataReadOnly(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); doTransformVerts(inPos, globalVertIndex, outPos, worldMatrix); } else if (Type.Normal.ordinal() == bufType) { FloatBuffer inPos = (FloatBuffer) inBuf.getDataReadOnly(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); doTransformNorms(inPos, globalVertIndex, outPos, worldMatrix);
/** * Creates a {@link VertexBuffer} for the mesh or modifies * the existing one per the parameters given. * * @param type The type of the buffer * @param components Number of components * @param format Data format * @param buf The buffer data * * @throws UnsupportedOperationException If the buffer already set is * incompatible with the parameters given. */ public void setBuffer(Type type, int components, Format format, Buffer buf){ VertexBuffer vb = buffers.get(type.ordinal()); if (vb == null){ vb = new VertexBuffer(type); vb.setupData(Usage.Dynamic, components, format, buf); setBuffer(vb); }else{ if (vb.getNumComponents() != components || vb.getFormat() != format){ throw new UnsupportedOperationException("The buffer already set " + "is incompatible with the given parameters"); } vb.updateData(buf); updateCounts(); } }
/** * Computes the number of remaining buffers on this mesh. * This is supposed to give a hint on how many attributes will be used in the material and computes the remaining available slots for the morph attributes. * However, the shader can declare attributes that are not used and not bound to a real buffer. * That's why we attempt to compile the shader later on to avoid any compilation crash. * This method is here to avoid too much render test iteration. * * @param mesh * @param renderer * @return */ private int getRemainingBuffers(Mesh mesh, Renderer renderer) { int nbUsedBuffers = 0; for (VertexBuffer vb : mesh.getBufferList().getArray()) { boolean isMorphBuffer = vb.getBufferType().ordinal() >= VertexBuffer.Type.MorphTarget0.ordinal() && vb.getBufferType().ordinal() <= VertexBuffer.Type.MorphTarget9.ordinal(); if (vb.getBufferType() == VertexBuffer.Type.Index || isMorphBuffer) continue; if (vb.getUsage() != VertexBuffer.Usage.CpuOnly) { nbUsedBuffers++; } } return renderer.getLimits().get(Limits.VertexAttributes) - nbUsedBuffers; }
private int bindMorphtargetBuffer(Mesh mesh, int targetNumBuffers, int boundBufferIdx, MorphTarget t) { int start = VertexBuffer.Type.MorphTarget0.ordinal(); if (targetNumBuffers >= 1) { activateBuffer(mesh, boundBufferIdx, start, t.getBuffer(VertexBuffer.Type.Position)); boundBufferIdx++; } if (targetNumBuffers >= 2) { activateBuffer(mesh, boundBufferIdx, start, t.getBuffer(VertexBuffer.Type.Normal)); boundBufferIdx++; } if (!approximateTangents && targetNumBuffers == 3) { activateBuffer(mesh, boundBufferIdx, start, t.getBuffer(VertexBuffer.Type.Tangent)); boundBufferIdx++; } return boundBufferIdx; }
/** * Sets the {@link VertexBuffer} on the mesh. * This will update the vertex/triangle counts if needed. * * @param vb The buffer to set * @throws IllegalArgumentException If the buffer type is already set */ public void setBuffer(VertexBuffer vb){ if (buffers.containsKey(vb.getBufferType().ordinal())) { throw new IllegalArgumentException("Buffer type already set: " + vb.getBufferType()); } buffers.put(vb.getBufferType().ordinal(), vb); buffersList.add(vb); updateCounts(); }
/** * Unsets the {@link VertexBuffer} set on this mesh * with the given type. Does nothing if the vertex buffer type is not set * initially. * * @param type The buffer type to remove */ public void clearBuffer(VertexBuffer.Type type){ VertexBuffer vb = buffers.remove(type.ordinal()); if (vb != null){ buffersList.remove(vb); updateCounts(); } }
/** * Get the {@link VertexBuffer} stored on this mesh with the given * type. * * @param type The type of VertexBuffer * @return the VertexBuffer data, or null if not set */ public VertexBuffer getBuffer(Type type){ return buffers.get(type.ordinal()); }
public Attribute getAttribute(VertexBuffer.Type attribType){ int ordinal = attribType.ordinal(); Attribute attrib = attribs.get(ordinal); if (attrib == null){ attrib = new Attribute(); attrib.name = attribType.name(); attribs.put(ordinal, attrib); } return attrib; }