de.ikosa.mars.viewer.glviewer.engine.GLSubMesh.java Source code

Java tutorial

Introduction

Here is the source code for de.ikosa.mars.viewer.glviewer.engine.GLSubMesh.java

Source

/*
 * Copyright (C) 2013 Clemens-Alexander Brust IT-Dienstleistungen
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.ikosa.mars.viewer.glviewer.engine;

import de.ikosa.mars.util.ML;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;

public class GLSubMesh {
    private int indexVboId;
    private int indexCount;
    private GLMaterial material;
    private GLMesh parent;

    public GLSubMesh(int indexVboId, int indexCount, GLMaterial material, GLMesh parent) {
        this.indexVboId = indexVboId;
        this.material = material;
        this.indexCount = indexCount;
        this.parent = parent;

        if (!material.isCompatible(parent.hasNormals(), parent.hasTexCoords())) {
            ML.f(String.format("Material \"%s\" incompatible with mesh \"%s\"", material.getName(),
                    parent.getName()));
        }
    }

    public int getIndexVboId() {
        return indexVboId;
    }

    public GLMaterial getMaterial() {
        return material;
    }

    public int getIndexCount() {
        return indexCount;
    }

    public void use() {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexVboId);
    }

    public void draw() {
        GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
    }
}