Example usage for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER_BINDING

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

Introduction

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

Prototype

int GL_ARRAY_BUFFER_BINDING

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

Click Source Link

Document

Accepted by the pname parameter of GetBooleanv, GetIntegerv, GetFloatv, and GetDoublev.

Usage

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  .  j av  a 2 s.  co  m
 */
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() {/*from ww  w .ja va  2s.  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.// w  w w. j a v a2 s . c  o  m
 */
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);
    }/*from   w w w .  j  a v a2  s.  c o m*/
    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:itdelatrisu.opsu.render.CurveRenderState.java

License:Open Source License

/**
 * Backup the current state of the relevant OpenGL state and change it to
 * what's needed to draw the curve./*  w  w  w.  j  a  va2s  . c om*/
 */
private RenderState startRender() {
    RenderState state = new RenderState();
    state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
    state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND);
    state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
    state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK);
    state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D);
    state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
    state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
    state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
    GL11.glEnable(GL11.GL_BLEND);
    GL14.glBlendEquation(GL14.GL_FUNC_ADD);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthMask(true);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_TEXTURE_1D);
    GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);

    GL20.glUseProgram(0);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();

    return state;
}