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

The following examples show how to use com.jme3.scene.VertexBuffer#getStride() . 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: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void updateVertexArray(Mesh mesh, VertexBuffer instanceData) {
    int id = mesh.getId();
    if (id == -1) {
        IntBuffer temp = intBuf1;
        gl3.glGenVertexArrays(temp);
        id = temp.get(0);
        mesh.setId(id);
    }

    if (context.boundVertexArray != id) {
        gl3.glBindVertexArray(id);
        context.boundVertexArray = id;
    }

    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    if (instanceData != null) {
        setVertexAttrib(instanceData, null);
    }

    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);
        }
    }
}
 
Example 2
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    } else {
        indices = buffers.get(Type.Index.ordinal());
    }
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly) // ignore cpu-only buffers
        {
            continue;
        }

        if (vb.getBufferType() == Type.Index) {
            indices = vb;
        } else {
            if (vb.getStride() == 0) {
                // not interleaved
                setVertexAttrib(vb);
            } else {
                // interleaved
                setVertexAttrib(vb, interleavedData);
            }
        }
    }

    if (indices != null) {
        drawTriangleList(indices, mesh, count);
    } else {
        gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
    }
    clearVertexAttribs();
    clearTextureUnits();
}
 
Example 3
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderMeshVBO(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }
    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    } else {
        indices = buffers.get(Type.Index.ordinal());
    }
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttribVBO(vb, null);
        } else {
            // interleaved
            setVertexAttribVBO(vb, interleavedData);
        }
    }

    if (indices != null) {
        drawTriangleListVBO(indices, mesh, count);
    } else {
        gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
    }
    clearVertexAttribs();
    clearTextureUnits();
}
 
Example 4
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateVertexArray(Mesh mesh) {
    int id = mesh.getId();
    if (id == -1) {
        IntBuffer temp = intBuf1;
        ARBVertexArrayObject.glGenVertexArrays(temp);
        id = temp.get(0);
        mesh.setId(id);
    }

    if (context.boundVertexArray != id) {
        ARBVertexArrayObject.glBindVertexArray(id);
        context.boundVertexArray = id;
    }

    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        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);
        }
    }
}
 
Example 5
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void updateVertexArray(Mesh mesh) {
    logger.log(Level.INFO, "updateVertexArray({0})", mesh);
    int id = mesh.getId();
    /*
    if (id == -1){
    IntBuffer temp = intBuf1;
    //      ARBVertexArrayObject.glGenVertexArrays(temp);
    GLES20.glGenVertexArrays(temp);
    id = temp.get(0);
    mesh.setId(id);
    }
    
    if (context.boundVertexArray != id){
    //     ARBVertexArrayObject.glBindVertexArray(id);
    GLES20.glBindVertexArray(id);
    context.boundVertexArray = id;
    }
     */
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
    for (int i = 0; i < buffersList.size(); i++) {
        VertexBuffer vb = buffersList.get(i);

        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);
        }
    }
}
 
Example 6
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * renderMeshVertexArray renders a mesh using vertex arrays
     * @param mesh
     * @param lod
     * @param count
     */
    private void renderMeshVertexArray(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.info("renderMeshVertexArray");
        }

        //  IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap.Entry<VertexBuffer> table[] = buffers.getTable();
        for (IntMap.Entry<VertexBuffer> entry : table) {
            if (entry == null) {
                continue;
            }
            VertexBuffer vb = entry.getValue();

            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_Array(vb);
            } else {
                // interleaved
                VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
                setVertexAttrib_Array(vb, interleavedData);
            }
        }

        VertexBuffer indices = null;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal());
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList_Array(indices, mesh, count);
        } else {
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})",
                        new Object[]{mesh.getMode(), 0, mesh.getVertexCount()});
            }

            Gdx.gl20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 7
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.log(Level.INFO, "renderMeshDefault({0}, {1}, {2})",
                    new Object[]{mesh, lod, count});
        }
        VertexBuffer indices = null;

        VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
        if (interleavedData != null && interleavedData.isUpdateNeeded()) {
            updateBufferData(interleavedData);
        }

        //IntMap<VertexBuffer> buffers = mesh.getBuffers();     ;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);// buffers.get(Type.Index.ordinal());
        }
        SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
        for (int i = 0; i < buffersList.size(); i++) {
            VertexBuffer vb = buffersList.get(i);

            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);
            }
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
//            throw new UnsupportedOperationException("Cannot render without index buffer");
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, 0, {1})",
                        new Object[]{convertElementMode(mesh.getMode()), mesh.getVertexCount()});
            }

            Gdx.gl20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 8
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void updateVertexArray(Mesh mesh) {
    logger.log(Level.INFO, "updateVertexArray({0})", mesh);
    int id = mesh.getId();
    /*
    if (id == -1){
    IntBuffer temp = intBuf1;
    //      ARBVertexArrayObject.glGenVertexArrays(temp);
    GLES20.glGenVertexArrays(temp);
    id = temp.get(0);
    mesh.setId(id);
    }
    
    if (context.boundVertexArray != id){
    //     ARBVertexArrayObject.glBindVertexArray(id);
    GLES20.glBindVertexArray(id);
    context.boundVertexArray = id;
    }
     */
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
    for (int i = 0; i < buffersList.size(); i++) {
        VertexBuffer vb = buffersList.get(i);

        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);
        }
    }
}
 
Example 9
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * renderMeshVertexArray renders a mesh using vertex arrays
     * @param mesh
     * @param lod
     * @param count
     */
    private void renderMeshVertexArray(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.info("renderMeshVertexArray");
        }

        //  IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap.Entry<VertexBuffer> table[] = buffers.getTable();
        for (IntMap.Entry<VertexBuffer> entry : table) {
            if (entry == null) {
                continue;
            }
            VertexBuffer vb = entry.getValue();

            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_Array(vb);
            } else {
                // interleaved
                VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
                setVertexAttrib_Array(vb, interleavedData);
            }
        }

        VertexBuffer indices = null;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal());
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList_Array(indices, mesh, count);
        } else {
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})",
                        new Object[]{mesh.getMode(), 0, mesh.getVertexCount()});
            }

            GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 10
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.log(Level.INFO, "renderMeshDefault({0}, {1}, {2})",
                    new Object[]{mesh, lod, count});
        }
        VertexBuffer indices = null;

        VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
        if (interleavedData != null && interleavedData.isUpdateNeeded()) {
            updateBufferData(interleavedData);
        }

        //IntMap<VertexBuffer> buffers = mesh.getBuffers();     ;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);// buffers.get(Type.Index.ordinal());
        }
        SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
        for (int i = 0; i < buffersList.size(); i++) {
            VertexBuffer vb = buffersList.get(i);

            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);
            }
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
//            throw new UnsupportedOperationException("Cannot render without index buffer");
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, 0, {1})",
                        new Object[]{convertElementMode(mesh.getMode()), mesh.getVertexCount()});
            }

            GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 11
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void renderMeshDefault(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }
    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    }
    else {
        indices = buffers.get(Type.Index.ordinal());
    }
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        /*if (vb.getBufferType() == Type.Index) {
            indices = vb;
        }
        else {*/
        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttrib(vb);
        }
        else {
            // interleaved
            setVertexAttrib(vb, interleavedData);
        }
        /*}*/
    }

    if (indices != null) {
        drawTriangleList(indices, mesh, count);
    }
    else {
        drawArrays(mesh);
    }
    clearVertexAttribs();
    clearTextureUnits();
}
 
Example 12
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void renderMeshVBO(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }
    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    }
    else {
        indices = buffers.get(Type.Index.ordinal());
    }
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly // ignore
                                                                                         // cpu-only
                                                                                         // buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttribVBO(vb, null);
        }
        else {
            // interleaved
            setVertexAttribVBO(vb, interleavedData);
        }
    }

    if (indices != null) {
        drawTriangleListVBO(indices, mesh, count);
    }
    else {
        drawArrays(mesh);
    }
    clearVertexAttribs();
    clearTextureUnits();
}
 
Example 13
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;

    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    //IntMap<VertexBuffer> buffers = mesh.getBuffers();
    SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();

    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    } else {
        indices = mesh.getBuffer(Type.Index);
    }
    //for (Entry<VertexBuffer> entry : buffers) {
    //     VertexBuffer vb = entry.getValue();
    for (int i = 0; i < buffersList.size(); i++){
        VertexBuffer vb = buffersList.get(i);

        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 {
        drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
    }
    clearVertexAttribs();
    clearTextureUnits();
}