/** * 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; }
b = BufferUtils.createFloatBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents()); vb.setupData(types.get(type).getUsage(), types.get(type).getNumComponents(), types.get(type).getFormat(), b); geom.getMesh().setBuffer(vb); logger.log(Level.FINE, "geom {0} misses buffer {1}. Creating", new Object[]{geom.getName(), type});
&& mesh.getTriangleCount() != 0) { for (VertexBuffer vb : mesh.getBufferList().getArray()) { if (vb.getData() != null && vb.getUsage() != VertexBuffer.Usage.CpuOnly) { renderer.updateBufferData(vb);
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue;
int usage = convertUsage(vb.getUsage()); vb.getData().rewind();
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue;
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 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; }
b = BufferUtils.createFloatBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents()); vb.setupData(types.get(type).getUsage(), types.get(type).getNumComponents(), types.get(type).getFormat(), b); geom.getMesh().setBuffer(vb); logger.log(Level.FINE, "geom {0} misses buffer {1}. Creating", new Object[]{geom.getName(), type});
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; }
&& mesh.getTriangleCount() != 0) { for (VertexBuffer vb : mesh.getBufferList().getArray()) { if (vb.getData() != null && vb.getUsage() != VertexBuffer.Usage.CpuOnly) { renderer.updateBufferData(vb);
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue;
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue;
int usage = convertUsage(vb.getUsage()); vb.getData().rewind();
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue;
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue;
public static void compressIndexBuffer(Mesh mesh){ int vertCount = mesh.getVertexCount(); VertexBuffer vb = mesh.getBuffer(Type.Index); Format targetFmt; if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){ if (vertCount <= 256) targetFmt = Format.UnsignedByte; else targetFmt = Format.UnsignedShort; }else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){ targetFmt = Format.UnsignedByte; }else{ return; } IndexBuffer src = mesh.getIndexBuffer(); Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size()); VertexBuffer newVb = new VertexBuffer(Type.Index); newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf); mesh.clearBuffer(Type.Index); mesh.setBuffer(newVb); IndexBuffer dst = mesh.getIndexBuffer(); for (int i = 0; i < src.size(); i++){ dst.put(i, src.get(i)); } }
int usage = convertUsage(vb.getUsage()); vb.getData().rewind();