/** * 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(); }
/** * 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; }
for (Geometry geom : geoms) { for (VertexBuffer buffer : geom.getMesh().getBufferList()) { if (types.get(buffer.getBufferType()) == null) { types.put(buffer.getBufferType(), buffer); logger.log(Level.FINE, buffer.getBufferType().toString()); Integer count = typesCount.get(buffer.getBufferType()); if (count == null) { count = 0; typesCount.put(buffer.getBufferType(), count); Integer count = typesCount.get(buffer.getBufferType()); if (count != null && count < geoms.size()) { geom.getMesh().clearBuffer(buffer.getBufferType()); logger.log(Level.FINE, "removing {0} from {1}", new Object[]{buffer.getBufferType(), geom.getName()});
public static void printMesh(Mesh mesh) { for (int bufType = 0; bufType < Type.values().length; bufType++) { VertexBuffer outBuf = mesh.getBuffer(Type.values()[bufType]); if (outBuf == null) { continue; } System.out.println(outBuf.getBufferType() + ": "); for (int vert = 0; vert < outBuf.getNumElements(); vert++) { String str = "["; for (int comp = 0; comp < outBuf.getNumComponents(); comp++) { Object val = outBuf.getElementComponent(vert, comp); outBuf.setElementComponent(vert, comp, val); val = outBuf.getElementComponent(vert, comp); str += val; if (comp != outBuf.getNumComponents() - 1) { str += ", "; } } str += "]"; System.out.println(str); } System.out.println("------"); } }
public static void dumpMesh(Mesh m) { for (VertexBuffer vertexBuffer : m.getBufferList().getArray()) { System.err.println(vertexBuffer.getBufferType()); System.err.println(vertexBuffer.getFormat()); if (vertexBuffer.getData() instanceof FloatBuffer) {
for (VertexBuffer vb : buffersList.getArray()){ VertexBuffer bufClone = vb.clone(); clone.buffers.put(vb.getBufferType().ordinal(), bufClone); clone.buffersList.add(bufClone);
if (vb.getBufferType() == Type.InterleavedData || vb.getBufferType() == Type.Index) { continue;
if (vb.getBufferType() == Type.InterleavedData || vb.getBufferType() == Type.Index) { continue;
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() + " has different number of components than the rest of the meshes " + "(this: " + vb.getNumComponents() + ", expected: " + currentCompsForBuf + ")"); compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized(); throw new IllegalArgumentException("Geometry " + geom.getName() + " has no " + outBuf.getBufferType() + " buffer whereas other geoms have. all geometries should have the same types of buffers.\n Try to use GeometryBatchFactory.alignBuffer() on the BatchNode before batching"); } else if (outBuf == null) { throw new IllegalArgumentException("Geometry " + geom.getName() + " has a " + outBuf.getBufferType() + " buffer whereas other geoms don't. all geometries should have the same types of buffers.\n Try to use GeometryBatchFactory.alignBuffer() on the BatchNode before batching"); } else { inBuf.copyElements(0, outBuf, globalVertIndex, geomVertCount);
buffers.put(hwBoneIndex.getBufferType().ordinal(), hwBoneIndex); buffers.put(hwBoneWeight.getBufferType().ordinal(), hwBoneWeight);
if (oldVb.getBufferType() == VertexBuffer.Type.Index) { VertexBuffer newVb = new VertexBuffer(oldVb.getBufferType()); newVb.setNormalized(oldVb.isNormalized()); clearBuffer(newVb.getBufferType()); setBuffer(newVb);
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() + " has different number of components than the rest of the meshes " + "(this: " + vb.getNumComponents() + ", expected: " + currentCompsForBuf + ")"); compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized();
public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) { if (vb.getBufferType() == VertexBuffer.Type.Index) { throw new IllegalArgumentException("Index buffers not allowed to be set to vertex attrib"); Attribute attrib = context.boundShader.getAttribute(vb.getBufferType()); int loc = attrib.getLocation(); if (loc == -1) { loc = gl.glGetAttribLocation(context.boundShaderProgram, "in" + vb.getBufferType().name());
if (vb.getBufferType() == VertexBuffer.Type.Index) { target = GL.GL_ELEMENT_ARRAY_BUFFER; if (context.boundElementArrayVBO != bufId) {
public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) { if (indexBuf.getBufferType() != VertexBuffer.Type.Index) { throw new IllegalArgumentException("Only index buffers are allowed as triangle lists.");
/** * 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(); }
protected VertexBuffer matchBuffer( VertexBuffer source ) { if( source == null ) return null; VertexBuffer target = getBuffer(source.getBufferType()); if( target == null || target.getData().capacity() < source.getData().limit() ) { target = source.clone(); setBuffer(target); } else { target.getData().limit(source.getData().limit()); } return target; }
public static VertexBuffer convertToUByte(VertexBuffer vb){ FloatBuffer fb = (FloatBuffer) vb.getData(); ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity()); convertToUByte(fb, bb); VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); newVb.setupData(vb.getUsage(), vb.getNumComponents(), Format.UnsignedByte, bb); newVb.setNormalized(true); return newVb; }
public static VertexBuffer convertToFixed(VertexBuffer vb){ if (vb.getFormat() == Format.Int) return vb; FloatBuffer fb = (FloatBuffer) vb.getData(); IntBuffer ib = BufferUtils.createIntBuffer(fb.capacity()); convertToFixed(fb, ib); VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); newVb.setupData(vb.getUsage(), vb.getNumComponents(), Format.Int, ib); return newVb; }
public static VertexBuffer convertToFloat(VertexBuffer vb){ if (vb.getFormat() == Format.Float) return vb; IntBuffer ib = (IntBuffer) vb.getData(); FloatBuffer fb = BufferUtils.createFloatBuffer(ib.capacity()); convertToFloat(ib, fb); VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); newVb.setupData(vb.getUsage(), vb.getNumComponents(), Format.Float, fb); return newVb; }