Пример #1
0
  private boolean initBuffer(GL3 gl3) {

    ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
    FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
    IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);

    gl3.glGenBuffers(Buffer.MAX, bufferName);

    gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
    gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
    gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
    gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

    gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset);
    int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0));

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

    BufferUtils.destroyDirectBuffer(elementBuffer);
    BufferUtils.destroyDirectBuffer(vertexBuffer);
    BufferUtils.destroyDirectBuffer(uniformBufferOffset);

    return checkError(gl3, "initBuffer");
  }
  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;
  }