Java Code Examples for com.jme3.scene.VertexBuffer#getNumComponents()

The following examples show how to use com.jme3.scene.VertexBuffer#getNumComponents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeometryBatchFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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("------");
    }
}
 
Example 2
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void setVertexAttribVBO(VertexBuffer vb, VertexBuffer idb) {
    int arrayType = convertArrayType(vb.getBufferType());
    if (arrayType == -1) {
        return; // unsupported
    }
    if (vb.isUpdateNeeded() && idb == null) {
        updateBufferData(vb);
    }

    int bufId = idb != null ? idb.getId() : vb.getId();
    if (context.boundArrayVBO != bufId) {
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufId);
        context.boundArrayVBO = bufId;
    }

    gl.glEnableClientState(arrayType);
    context.boundAttribs[vb.getBufferType().ordinal()] = vb;

    if (vb.getBufferType() == Type.Normal) {
        // normalize if requested
        if (vb.isNormalized() && !context.normalizeEnabled) {
            gl.glEnable(gl.GL_NORMALIZE);
            context.normalizeEnabled = true;
        } else if (!vb.isNormalized() && context.normalizeEnabled) {
            gl.glDisable(gl.GL_NORMALIZE);
            context.normalizeEnabled = false;
        }
    }

    int comps = vb.getNumComponents();
    int type = convertVertexFormat(vb.getFormat());

    switch (vb.getBufferType()) {
        case Position:
            gl.glVertexPointer(comps, type, vb.getStride(), vb.getOffset());
            break;
        case Normal:
            gl.glNormalPointer(type, vb.getStride(), vb.getOffset());
            break;
        case Color:
            gl.glColorPointer(comps, type, vb.getStride(), vb.getOffset());
            break;
        case TexCoord:
            gl.glTexCoordPointer(comps, type, vb.getStride(), vb.getOffset());
            break;
    }
}
 
Example 3
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) {
    int arrayType = convertArrayType(vb.getBufferType());
    if (arrayType == -1) {
        return; // unsupported
    }
    gl.glEnableClientState(arrayType);
    context.boundAttribs[vb.getBufferType().ordinal()] = vb;

    if (vb.getBufferType() == Type.Normal) {
        // normalize if requested
        if (vb.isNormalized() && !context.normalizeEnabled) {
            gl.glEnable(gl.GL_NORMALIZE);
            context.normalizeEnabled = true;
        } else if (!vb.isNormalized() && context.normalizeEnabled) {
            gl.glDisable(gl.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.clear();
    data.position(vb.getOffset());

    switch (vb.getBufferType()) {
        case Position:
            gl.glVertexPointer(comps, type, vb.getStride(), data);
            break;
        case Normal:
            gl.glNormalPointer(type, vb.getStride(), data);
            break;
        case Color:
            gl.glColorPointer(comps, type, vb.getStride(), data);
            break;
        case TexCoord:
            gl.glTexCoordPointer(comps, type, vb.getStride(), data);
            break;
    }
}
 
Example 4
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected void setVertexAttribVBO(VertexBuffer vb, VertexBuffer idb) {
    GL gl = GLContext.getCurrentGL();
    int arrayType = convertArrayType(vb.getBufferType());
    if (arrayType == -1) {
        return; // unsupported
    }

    if (vb.isUpdateNeeded() && idb == null) {
        updateBufferData(vb);
    }

    int bufId = idb != null ? idb.getId() : vb.getId();
    if (context.boundArrayVBO != bufId) {
        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufId);
        context.boundArrayVBO = bufId;
    }

    gl.getGL2().glEnableClientState(arrayType);
    context.boundAttribs[vb.getBufferType().ordinal()] = vb;

    if (vb.getBufferType() == Type.Normal) {
        // normalize if requested
        if (vb.isNormalized() && !context.normalizeEnabled) {
            gl.glEnable(GLLightingFunc.GL_NORMALIZE);
            context.normalizeEnabled = true;
        }
        else if (!vb.isNormalized() && context.normalizeEnabled) {
            gl.glDisable(GLLightingFunc.GL_NORMALIZE);
            context.normalizeEnabled = false;
        }
    }

    int comps = vb.getNumComponents();
    int type = convertVertexFormat(vb.getFormat());

    switch (vb.getBufferType()) {
        case Position:
            gl.getGL2().glVertexPointer(comps, type, vb.getStride(), vb.getOffset());
            break;
        case Normal:
            gl.getGL2().glNormalPointer(type, vb.getStride(), vb.getOffset());
            break;
        case Color:
            gl.getGL2().glColorPointer(comps, type, vb.getStride(), vb.getOffset());
            break;
        case TexCoord:
            gl.getGL2().glTexCoordPointer(comps, type, vb.getStride(), vb.getOffset());
            break;
    }
}