private boolean initBuffer(GL4 gl4) {

    boolean validated = true;

    gl4.glGenBuffers(Buffer.MAX, bufferName);

    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
    gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
    BufferUtils.destroyDirectBuffer(elementBuffer);
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
    FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
    gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
    BufferUtils.destroyDirectBuffer(vertexBuffer);
    gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

    int[] uniformBufferOffset = {0};
    gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);
    int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]);

    gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
    gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW);
    gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

    return validated;
  }
Пример #2
0
 public GLBuffer(GLBufferTarget theTarget) {
   GL4 gl = GLGraphics.currentGL();
   gl.glGenBuffers(1, GLBufferUtil.intBuffer());
   _myID = GLBufferUtil.intBuffer().get(0);
   _myTarget = theTarget;
   bind();
   unbind();
 }
Пример #3
0
  private boolean initVertexBuffer(GL4 gl4) {

    gl4.glGenBuffers(Buffer.MAX.ordinal(), bufferName, 0);

    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.ELEMENT.ordinal()]);
    ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
    gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName[Buffer.F64.ordinal()]);
    DoubleBuffer positionBuffer = GLBuffers.newDirectDoubleBuffer(positionData);
    gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);
    gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

    return checkError(gl4, "initArrayBuffer");
  }