Java Code Examples for com.jme3.scene.VertexBuffer.Type#Index

The following examples show how to use com.jme3.scene.VertexBuffer.Type#Index . 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: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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));
    }
}
 
Example 2
Source File: ModelConverter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void optimize(Mesh mesh, boolean toFixed){
        // update any data that need updating
        mesh.updateBound();
        mesh.updateCounts();

        // set all buffers into STATIC_DRAW mode
        mesh.setStatic();

        if (mesh.getBuffer(Type.Index) != null){
            // compress index buffer from UShort to UByte (if possible)
            FloatToFixed.compressIndexBuffer(mesh);

            // generate triangle strips stitched with degenerate tris
            generateStrips(mesh, false, false, 16, 0);
        }

        IntMap<VertexBuffer> bufs = mesh.getBuffers();
        for (Entry<VertexBuffer> entry : bufs){
            VertexBuffer vb = entry.getValue();
            if (vb == null || vb.getBufferType() == Type.Index)
                continue;

             if (vb.getFormat() == Format.Float){
                if (vb.getBufferType() == Type.Color){
                    // convert the color buffer to UByte
                    vb = FloatToFixed.convertToUByte(vb);
                    vb.setNormalized(true);
                }else if (toFixed){
                    // convert normals, positions, and texcoords
                    // to fixed-point (16.16)
                    vb = FloatToFixed.convertToFixed(vb);
//                    vb = FloatToFixed.convertToFloat(vb);
                }
                mesh.clearBuffer(vb.getBufferType());
                mesh.setBuffer(vb);
            }
        }
        mesh.setInterleaved();
    }
 
Example 3
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 4
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 5
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 6
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 7
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 8
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();
}
 
Example 9
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 10
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 11
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 12
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 13
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * setVertexAttrib_Array uses Vertex Array
 * @param vb
 * @param idb
 */
public void setVertexAttrib_Array(VertexBuffer vb, VertexBuffer idb) {
    if (verboseLogging) {
        logger.log(Level.INFO, "setVertexAttrib_Array({0}, {1})", new Object[]{vb, idb});
    }

    if (vb.getBufferType() == Type.Index) {
        throw new IllegalArgumentException("Index buffers not allowed to be set to vertex attrib");
    }

    // Get shader
    int programId = context.boundShaderProgram;
    if (programId > 0) {
        VertexBuffer[] attribs = context.boundAttribs;

        Attribute attrib = boundShader.getAttribute(vb.getBufferType());
        int loc = attrib.getLocation();
        if (loc == -1) {
            //throw new IllegalArgumentException("Location is invalid for attrib: [" + vb.getBufferType().name() + "]");
            if (verboseLogging) {
                logger.log(Level.WARNING, "attribute is invalid in shader: [{0}]", vb.getBufferType().name());
            }
            return;
        } else if (loc == -2) {
            String attributeName = "in" + vb.getBufferType().name();

            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glGetAttribLocation({0}, {1})", new Object[]{programId, attributeName});
            }

            loc = Gdx.gl20.glGetAttribLocation(programId, attributeName);
            if (loc < 0) {
                attrib.setLocation(-1);
                if (verboseLogging) {
                    logger.log(Level.WARNING, "attribute is invalid in shader: [{0}]", vb.getBufferType().name());
                }
                return; // not available in shader.
            } else {
                attrib.setLocation(loc);
            }

        }  // if (loc == -2)

        if ((attribs[loc] != vb) || vb.isUpdateNeeded()) {
            System.err.println("isUpdateNeeded "+vb.isUpdateNeeded());
            vb.clearUpdateNeeded();
            // NOTE: Use data from interleaved buffer if specified
            VertexBuffer avb = idb != null ? idb : vb;
            avb.getData().clear();
            avb.getData().position(vb.getOffset());

            if (verboseLogging) {
                logger.log(Level.INFO,
                        "GLES20.glVertexAttribPointer("
                                + "location={0}, "
                                + "numComponents={1}, "
                                + "format={2}, "
                                + "isNormalized={3}, "
                                + "stride={4}, "
                                + "data.capacity={5})",
                        new Object[]{loc, vb.getNumComponents(),
                                vb.getFormat(),
                                vb.isNormalized(),
                                vb.getStride(),
                                avb.getData().capacity()});
            }


            // Upload attribute data

            Gdx.gl20.glVertexAttribPointer(loc,
                    vb.getNumComponents(),
                    convertFormat(vb.getFormat()),
                    vb.isNormalized(),
                    vb.getStride(),
                    convBuffer(avb.getData()));
            checkGLError();

            Gdx.gl20.glEnableVertexAttribArray(loc);

            attribs[loc] = vb;
        } // if (attribs[loc] != vb)
    } else {
        throw new IllegalStateException("Cannot render mesh without shader bound");
    }
}
 
Example 14
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * drawTriangleList_Array uses Vertex Array
 * @param indexBuf
 * @param mesh
 * @param count
 */
public void drawTriangleList_Array(VertexBuffer indexBuf, Mesh mesh, int count) {
    if (verboseLogging) {
        logger.log(Level.INFO, "drawTriangleList_Array(Count = {0})", count);
    }

    if (indexBuf.getBufferType() != Type.Index) {
        throw new IllegalArgumentException("Only index buffers are allowed as triangle lists.");
    }

    boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
    if (useInstancing) {
        throw new IllegalArgumentException("Caps.MeshInstancing is not supported.");
    }

    int vertCount = mesh.getVertexCount();
    Buffer indexData = indexBuf.getData();
    indexData.clear();

    if (mesh.getMode() == Mode.Hybrid) {
        int[] modeStart = mesh.getModeStart();
        int[] elementLengths = mesh.getElementLengths();

        int elMode = convertElementMode(Mode.Triangles);
        int fmt = convertFormat(indexBuf.getFormat());
        int elSize = indexBuf.getFormat().getComponentSize();
        int listStart = modeStart[0];
        int stripStart = modeStart[1];
        int fanStart = modeStart[2];
        int curOffset = 0;
        for (int i = 0; i < elementLengths.length; i++) {
            if (i == stripStart) {
                elMode = convertElementMode(Mode.TriangleStrip);
            } else if (i == fanStart) {
                elMode = convertElementMode(Mode.TriangleStrip);
            }
            int elementLength = elementLengths[i];

            indexBuf.getData().position(curOffset);
            if (verboseLogging) {
                logger.log(Level.INFO, "glDrawElements(): {0}, {1}", new Object[]{elementLength, curOffset});
            }

            Gdx.gl20.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());

            curOffset += elementLength * elSize;
        }
    } else {
        if (verboseLogging) {
            logger.log(Level.INFO, "glDrawElements(), indexBuf.capacity ({0}), vertCount ({1})", new Object[]{indexBuf.getData().capacity(), vertCount});
        }

        Gdx.gl20.glDrawElements(
                convertElementMode(mesh.getMode()),
                indexBuf.getData().capacity(),
                convertFormat(indexBuf.getFormat()),
                indexBuf.getData());
    }
}
 
Example 15
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 16
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 17
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);
        }
    }
}