io7m
io7m-jcanephora 0.45.2
3.4
JCGLArrayBuffersType

- 3.4.1. Description
- 3.4.2. Usage examples
- 3.4.3. State

3.4.1
Description
1
The JCGLArrayBuffersType interface provides functions for allocating, updating, and using array buffers. It provides a typed interface to the glGenBuffers and glBufferData functions.
2
Array buffers are the basic storage type for vertex data used during rendering. The jcanephora API uses the same model as the OpenGL 3.3 API: Buffers must be bound before use, and at most one buffer of each type can be bound at any one time. The API currently exposes the following buffer types:
3.4.1.1. Buffer Types

- Array buffers
- Index buffers

3.4.2
Usage examples
1
To allocate a 128 byte array buffer, indicating to OpenGL that the contents of the buffer will be specified once and then used repeatedly for rendering:
3.4.2.1. Allocation

    JCGLArrayBuffersType g;

    JCGLArrayBufferType a = g.arrayBufferAllocate(128, JCGLUsageHint.USAGE_STATIC_DRAW);

2
The buffer will remain bound after allocation. To update the contents of the buffer, an instance of JCGLBufferUpdateType must be created:
3.4.2.2. Updates

    JCGLArrayBuffersType g;
    JCGLArrayBufferType a;

    final JCGLBufferUpdateType<JCGLArrayBufferType> u =
      JCGLBufferUpdates.newUpdateReplacingAll(this.array_buffer);
    final ByteBuffer b = u.getData();

    for (int index = 0; index < 128; ++index) {
      b.put(index, (byte) index);
    }

    g.arrayBufferUpdate(u);
    g.arrayBufferUnbind();

3.4.3
State
1
OpenGL specifies that at most one array buffer can be bound on a context at any given time. Many API functions operate on the currently bound buffer and the jcanephora API avoids changing the current binding behind the programmer's back.