io7m
io7m-jcanephora 0.50.0
3.5
JCGLArrayObjectsType

- 3.5.1. Description
- 3.5.2. Usage Examples
- 3.5.3. State

3.5.1
Description
1
The JCGLArrayObjectsType interface provides functions for allocating, updating, and using array objects.
3.5.2
Usage Examples
1
An array object is a container for an index buffer binding and a set of numbered vertex array attributes. Essentially, the programmer can state that numbered vertex array attributes will be supplied with data from assigned array buffers, with each attribute knowing how to extract values from the otherwise untyped buffer. An array attribute will read count values of type t from an array buffer, starting at offset o in bytes, and stepping forward stride bytes for each vertex. This more or less encodes the notion that an array buffer is an array of record [3] values, with each array attribute reading from a specific record field for each element.
3.5.2.1. Array Buffers As Arrays Of Records
2
As a simple example, consider an array containing three vertices, with each vertex containing a single three-element floating point vector:
3.5.2.2. Positions

    JCGLArrayBuffersType g_ab;
    JCGLArrayBufferType ab;

    final int vertex_size = 3 * 4;
    ab = g_ab.arrayBufferAllocate(vertex_size * 3L, JCGLUsageHint.USAGE_STATIC_DRAW);

    final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(ab);
    final FloatBuffer d = u.getData().asFloatBuffer();

    d.put(0, -0.5f);
    d.put(1, 0.5f);
    d.put(2, -0.5f);

    d.put(3, -0.5f);
    d.put(4, -0.5f);
    d.put(5, -0.5f);

    d.put(6, 0.5f);
    d.put(7, -0.5f);
    d.put(8, -0.5f);

    g_ab.arrayBufferUpdate(u);
    g_ab.arrayBufferUnbind();

3
Then, assuming that vertex positions should be supplied to a shading language program via vertex attribute 0:
3.5.2.3. Attribute

    JCGLArrayObjectsType aob;

    final JCGLArrayObjectBuilderType aob = g_ao.arrayObjectNewBuilder();
    aob.setAttributeFloatingPoint(
      0,
      ab,
      3,
      JCGLScalarType.TYPE_FLOAT,
      vertex_size,
      0L,
      false);

    JCGLArrayObjectType ao = g_ao.arrayObjectAllocate(aob);

3.5.3
State
1
OpenGL specifies that exactly one array object will be bound on a context at any given time. OpenGL provides a default array object that is bound when no user-created array object exists. Many API functions operate on the currently bound array object and the jcanephora API avoids changing the current binding behind the programmer's back.

[3]
Or struct, in C terminology.