private void renderMeshDefault(Mesh mesh, int lod, int count) { VertexBuffer indices; VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); if (interleavedData != null && interleavedData.isUpdateNeeded()) { updateBufferData(interleavedData); } if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = mesh.getBuffer(Type.Index); } for (VertexBuffer vb : mesh.getBufferList().getArray()) { if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue; } if (vb.getStride() == 0) { // not interleaved setVertexAttrib(vb); } else { // interleaved setVertexAttrib(vb, interleavedData); } } if (indices != null) { drawTriangleList(indices, mesh, count); } else { GL gl = GLContext.getCurrentGL(); gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); } // TODO: Fix these to use IDList?? clearVertexAttribs(); clearTextureUnits(); resetFixedFuncBindings(); }
public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) { if (vb.getBufferType() == VertexBuffer.Type.Color && !context.useVertexColor) { // Ignore vertex color buffer if vertex color is disabled. return; } int arrayType = convertArrayType(vb.getBufferType()); if (arrayType == -1) { return; // unsupported } glEnableClientState(arrayType); context.boundAttribs[vb.getBufferType().ordinal()] = vb; if (vb.getBufferType() == Type.Normal) { // normalize if requested if (vb.isNormalized() && !context.normalizeEnabled) { glEnable(GL_NORMALIZE); context.normalizeEnabled = true; } else if (!vb.isNormalized() && context.normalizeEnabled) { glDisable(GL_NORMALIZE); context.normalizeEnabled = false; } } // NOTE: Use data from interleaved buffer if specified Buffer data = idb != null ? idb.getData() : vb.getData(); int comps = vb.getNumComponents(); int type = convertVertexFormat(vb.getFormat()); data.rewind(); switch (vb.getBufferType()) { case Position: if (!(data instanceof FloatBuffer)) { throw new UnsupportedOperationException(); } glVertexPointer(comps, vb.getStride(), (FloatBuffer) data); break; case Normal: if (!(data instanceof FloatBuffer)) { throw new UnsupportedOperationException(); } glNormalPointer(vb.getStride(), (FloatBuffer) data); break; case Color: if (data instanceof FloatBuffer) { glColorPointer(comps, vb.getStride(), (FloatBuffer) data); } else if (data instanceof ByteBuffer) { glColorPointer(comps, true, vb.getStride(), (ByteBuffer) data); } else { throw new UnsupportedOperationException(); } break; case TexCoord: if (!(data instanceof FloatBuffer)) { throw new UnsupportedOperationException(); } glTexCoordPointer(comps, vb.getStride(), (FloatBuffer) data); break; default: // Ignore, this is an unsupported attribute for OpenGL1. break; } }