Example usage for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER

List of usage examples for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER.

Prototype

int GL_ARRAY_BUFFER

To view the source code for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER.

Click Source Link

Document

Accepted by the target parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, GetBufferParameteriv, and GetBufferPointerv.

Usage

From source file:com.rvantwisk.cnctools.opengl.VBOHelper.java

License:Open Source License

/**
 * Cretae a VBO array with/*from   w  w  w . j  av  a 2  s  .  c o  m*/
 *
 * @param data Array of float
 * @param i    Number of rows
 * @param b    set if it has it's own color
 * @return
 */
public static VBOHelper createLines(final float[] data, int i, boolean b) {
    VBOHelper vbo = new GLLines();
    vbo.vbRows = i;
    vbo.hasOwnColor = b;
    vbo.data = data;

    IntBuffer buffer = BufferUtils.createIntBuffer(1);
    GL15.glGenBuffers(buffer);
    vbo.vbID = buffer.get(0);

    FloatBuffer vertex_buffer_data = BufferUtils.createFloatBuffer(vbo.data.length);
    vertex_buffer_data.put(vbo.data);
    vertex_buffer_data.rewind();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo.vbID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertex_buffer_data, GL15.GL_STATIC_DRAW);
    vbo.data = null;

    return vbo;
}

From source file:com.rvantwisk.cnctools.opengl.VBOHelper.java

License:Open Source License

public static VBOHelper createTriangles(final float[] data, int i, boolean b) {
    VBOHelper vbo = new GLTriangles();
    vbo.vbRows = i;//  w  w w. ja v a  2  s.co m
    vbo.hasOwnColor = b;
    vbo.data = data;

    IntBuffer buffer = BufferUtils.createIntBuffer(1);
    GL15.glGenBuffers(buffer);
    vbo.vbID = buffer.get(0);

    FloatBuffer vertex_buffer_data = BufferUtils.createFloatBuffer(vbo.data.length);
    vertex_buffer_data.put(vbo.data);
    vertex_buffer_data.rewind();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo.vbID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertex_buffer_data, GL15.GL_STATIC_DRAW);
    vbo.data = null;

    return vbo;
}

From source file:com.samrj.devil.gl.VAO.java

private VAO(Pair<VertexData, ShaderProgram> pair) {
    DGL.checkState();//from w  w  w  .j  a va2s  .co m
    if (!DGL.getCapabilities().OpenGL30)
        throw new UnsupportedOperationException("Vertex arrays unsupported in OpenGL < 3.0");
    id = GL30.glGenVertexArrays();
    this.pair = pair;

    bind();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, pair.a.vbo());
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, pair.a.ibo());

    for (ShaderProgram.Attribute satt : pair.b.getAttributes()) {
        VertexData.Attribute att = pair.a.getAttribute(satt.name);

        if (att != null) {
            AttributeType type = att.getType();
            for (int layer = 0; layer < type.layers; layer++) {
                int location = satt.location + layer;
                GL20.glEnableVertexAttribArray(location);
                vertexAttribPointer(location, type, att.getStride(), att.getOffset() + layer * type.size);
            }
        }
    }
}

From source file:com.samrj.devil.gl.VertexBuffer.java

License:Open Source License

/**
 * Completes this vertex buffer, uploading its vertex data to the GPU and
 * freeing local resources./* www  .  ja v a 2s .  c om*/
 */
public void end() {
    ensureState(State.READY);
    if (numVertices <= 0)
        throw new IllegalStateException("No vertices emitted.");

    vbo = GL15.glGenBuffers();
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.nglBufferData(GL15.GL_ARRAY_BUFFER, numVertices * vertexSize(), vertexBlock.address,
            GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    vramUsage += vertexBlock.size * 8L;
    vertexBlock.free();
    vertexBlock = null;
    vertexBuffer = null;

    if (maxIndices > 0) {
        if (numIndices > 0) {
            ibo = GL15.glGenBuffers();
            prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
            GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
            GL15.nglBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, numIndices * 4, indexBlock.address,
                    GL15.GL_STATIC_DRAW);
            GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);
        }

        vramUsage += indexBlock.size * 8L;
        indexBlock.free();
        indexBlock = null;
        indexBuffer = null;
    }

    state = State.COMPLETE;

    Profiler.addUsedVRAM(vramUsage);
}

From source file:com.samrj.devil.gl.VertexStream.java

License:Open Source License

@Override
void onBegin() {/*  ww  w .j ava 2 s .  c  o  m*/
    vboSize = maxVertices * vertexSize();
    vertexBlock = new Memory(vboSize);
    vertexBuffer = vertexBlock.buffer;
    vbo = GL15.glGenBuffers();
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vboSize, GL15.GL_STREAM_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    if (maxIndices > 0) {
        eboSize = maxIndices * 4;
        indexBlock = new Memory(eboSize);
        indexBuffer = indexBlock.buffer;
        ibo = GL15.glGenBuffers();
        prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, eboSize, GL15.GL_STREAM_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);
    }

    state = State.READY;

    Profiler.addUsedVRAM(vboSize * 8L);
    Profiler.addUsedVRAM(eboSize * 8L);
}

From source file:com.samrj.devil.gl.VertexStream.java

License:Open Source License

/**
 * Uploads this vertex data to the GPU and clears the stream, allowing new
 * data to be emitted.//from ww w  .  j  a  v  a2  s  .  com
 */
public void upload() {
    ensureState(State.READY);

    //Allocate new stores, orphaning the old ones to allow for asynchronous drawing.
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vboSize, GL15.GL_STREAM_DRAW);
    GL15.nglBufferSubData(GL15.GL_ARRAY_BUFFER, 0, bufferedVerts * vertexSize(), vertexBlock.address);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    if (maxIndices > 0) {
        prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, eboSize, GL15.GL_STREAM_DRAW);
        GL15.nglBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, bufferedInds * 4, indexBlock.address);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);
    }

    uploadedVerts = bufferedVerts;
    uploadedInds = bufferedInds;

    clear();
}

From source file:com.samrj.devil.graphics.MeshDrawer.java

License:Open Source License

public MeshDrawer(Mesh mesh) {
    this.mesh = mesh;

    //Set up attributes.
    position = new Attribute(VEC3, mesh.positionOffset, true);
    normal = new Attribute(VEC3, mesh.normalOffset, mesh.hasNormals);
    uvs = new HashMap<>();
    for (int i = 0; i < mesh.uvLayers.length; i++) {
        Attribute color = new Attribute(VEC2, mesh.uvOffsets[i], true);
        uvs.put(mesh.uvLayers[i], color);
    }/*  w  w  w.  jav  a 2 s  .c  om*/
    tangent = new Attribute(VEC3, mesh.tangentOffset, mesh.hasTangents);
    colors = new HashMap<>();
    for (int i = 0; i < mesh.colorLayers.length; i++) {
        Attribute color = new Attribute(VEC3, mesh.colorOffsets[i], true);
        colors.put(mesh.colorLayers[i], color);
    }

    AttributeType groupsType, weightType;
    switch (mesh.numGroups) {
    case 0:
        groupsType = NONE;
        weightType = NONE;
        break;
    case 1:
        groupsType = INT;
        weightType = FLOAT;
        break;
    case 2:
        groupsType = VEC2I;
        weightType = VEC2;
        break;
    case 3:
        groupsType = VEC3I;
        weightType = VEC3;
        break;
    case 4:
        groupsType = VEC4I;
        weightType = VEC4;
        break;
    default:
        throw new IllegalArgumentException("Vertex group count over four.");
    }

    groups = new Attribute(groupsType, mesh.groupIndexOffset, mesh.numGroups > 0);
    weights = new Attribute(weightType, mesh.groupWeightOffset, mesh.numGroups > 0);
    material = new Attribute(INT, mesh.materialOffset, mesh.hasMaterials);

    vbo = GL15.glGenBuffers();
    int prevBinding = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.nglBufferData(GL15.GL_ARRAY_BUFFER, mesh.vertexBlock.size, mesh.vertexBlock.address,
            GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevBinding);

    ibo = GL15.glGenBuffers();
    prevBinding = GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
    GL15.nglBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.indexBlock.size, mesh.indexBlock.address,
            GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, prevBinding);

    attributes = new HashMap<>();

    Profiler.addUsedVRAM(mesh.vertexBlock.size * 8L);
    Profiler.addUsedVRAM(mesh.indexBlock.size * 8L);
}

From source file:com.timvisee.voxeltex.module.mesh.Mesh.java

License:Open Source License

/**
 * Render or draw the mesh using OpenGL.
 *///from w w  w  .  ja  va 2 s. co m
public void draw(Material material) {
    // Bind the vertex buffer
    glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
    GL11.glVertexPointer(this.raw.getVertexAxisCount(), GL11.GL_FLOAT, 0, 0L);

    // Bind the normal coordinate buffer if available
    if (hasNormalData()) {
        glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
        GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0L);
    }

    // Bind the texture coordinate buffer if available
    if (hasTextureData()) {
        glBindBuffer(GL_ARRAY_BUFFER, vboTextureHandle);
        GL11.glTexCoordPointer(this.raw.getTextureAxisCount(), GL11.GL_FLOAT, 0, 0L);
    }

    // Enable the client states for the buffers that were bound
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    if (hasNormalData())
        GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
    if (hasTextureData())
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    // Draw the mesh
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.vertexCount);

    // Disable the client used states
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    if (hasNormalData())
        GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
    if (hasTextureData())
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    // Unbind all buffers
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java

License:Open Source License

public void create(int vaoId) {
    build();/*from  w  ww . ja  v  a  2s .  c  o  m*/

    GL30.glBindVertexArray(vaoId);

    // Create a new Vertex Buffer Object in memory and select it (bind)
    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STREAM_DRAW);

    // Put the position coordinates in attribute list 0
    GL20.glVertexAttribPointer(0, RenderingConstants.POSITION_ELEMENT_COUNT, GL11.GL_FLOAT, false,
            RenderingConstants.STRIDE, RenderingConstants.POSITION_BYTE_OFFSET);
    // Put the color components in attribute list 1
    GL20.glVertexAttribPointer(1, RenderingConstants.COLOUR_ELEMENT_COUNT, GL11.GL_FLOAT, false,
            RenderingConstants.STRIDE, RenderingConstants.COLOUR_BYTE_OFFSET);
    // Put the texture coordinates in attribute list 2
    GL20.glVertexAttribPointer(2, RenderingConstants.TEXTURE_ELEMENT_COUNT, GL11.GL_FLOAT, false,
            RenderingConstants.STRIDE, RenderingConstants.TEXTURE_BYTE_OFFSET);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    // Deselect (bind to 0) the VAO
    GL30.glBindVertexArray(0);

    // Create a new VBO for the indices and select it (bind) - INDICES
    vboiId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}

From source file:com.voxelplugineering.voxelsniper.render.buffer.BufferSection.java

License:Open Source License

public void destroy() {
    // Delete the vertex VBO
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboId);/*from w  w w.  j  ava 2 s  .  co m*/

    // Delete the index VBO
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboiId);

}