Glide's Vertex Layout & vertex_array_object (long)

No changes in hardware would be required.
It is just Yet Another patch for obsolete vertex arrays.
There are potential performance benefits also possible.

Inspired by:

  • Glide 3 (vertex layout)
  • DirectX 8 (vertex streams, vertex buffer locking, index buffers)
  • GL_NV_vertex_array_range (read/write frequency)
  • GL_EXT_vertex_array_set (array object)

BTW, I know nothing about GL_ATI_vertex_streams.

Thanks in advance for your comments.

============================
Part I: vertex layout object

// standard name/object managment, taken from GL_texture_object
void glGenVertexLayouts(…)
void glDeleteVertexLayouts(…)
GLboolean glIsVertexLayout(…)

// defining vertex layout
void glBeginVertexLayout(GLuint layout, GLuint stride);
void glEndVertexLayout(void);
void glVertexLayout(GLenum vertex_attrib, GLenum type, GLuint size, GLuint offset);
// <vertex_attrib> - this could be one of following:
// 1. any array token that we can (now or with future extensions) pass
// to gl[Enable/Disable]ClientState()
// 2. or any GL_TEXTUREn_ARB token (when multitexture_ARB is also
// supported) since there is only one GL_TEXTURE_COORD_ARRAY
//

<example>

struct Vertex
{
GLfloat x, y, z;
GLfloat nx, ny, nz;
GLfloat s0, t0;
GLfloat s1, t1;
unsigned color;
};

GLuint layout;
glGenVertexLayouts(1, &layout);

glBeginVertexLayout(layout, sizeof(Vertex));
glVertexLayout(GL_VERTEX_ARRAY , GL_FLOAT , 3, offsetof(Vertex, x));
glVertexLayout(GL_NORMAL_ARRAY , GL_FLOAT , 3, offsetof(Vertex, nx));
glVertexLayout(GL_TEXTURE0_ARB , GL_FLOAT , 2, offsetof(Vertex, s0));
glVertexLayout(GL_TEXTURE1_ARB , GL_FLOAT , 2, offsetof(Vertex, s1));
glVertexLayout(GL_COLOR_ARRAY , GL_UNSIGNED_BYTE , 4, offsetof(Vertex, color));
glEndVertexLayout();

</example>

// Some options to consider:

void glIncludeVertexLayout(GLuint source_layout, GLuint at_offset)
// Called between glBeginVertexLayout & glEndVertexLayout.
// Ignores stride of source_layout.

// index arrays? (like DX8 index buffer)
<example>
glBeginVertexLayout(layout, sizeof(GLuint));
glVertexLayout(GL_INDEX_ARRAY, GL_UNSIGNED_INT, 1, 0);
glEndVertexLayout();
</example>

============================
Part II: vertex array object

// standard name/object managment, taken from GL_texture_object
void glGenVertexArrays(…)
void glDeleteVertexArrays(…)
void glPrioritizeVertexArrays(…)
GLboolean glIsVertexArray(…)
GLboolean glAreVertexArraysResident(…)

// Binds vertex-layout-object to vertex-array-object.
// It could be VERY useful to change layout without changing
// contents of array (multiple passes)
void glVertexArrayLayout(GLuint array, GLuint layout)

void glVertexArrayParameter[fi](GLuint array, GLenum pname, <type> value)
<GLfloat> GL_READ_FREQUENCY - inspired by GL_NV_vertex_array_range. 0 means ‘never’
<GLfloat> GL_WRITE_FREQUENCY - inspired by GL_NV_vertex_array_range. 0 means ‘once’
<GLuint> GL_SIZE - (in bytes, NOT vertices) allocate, free, expand, truncate
<GLuint> GL_START - (in bytes, NOT vertices) additional offset, refered ONLY by
rendering commands

// Hint, useful before resizing, locking, loading.
// It doesnt set size to 0.
void glDiscardVertexArray(GLuint array);

// Inspired by DX8 vertex streams.
// We need to retain capablity of enabling more than 1 array-object
// at once. Of course layouts should not collide in such case.
void glBindVertexArray(GLuint index, GLuint array)
// <index> must be in range 0…glGetInteger(GL_MAX_ACTIVE_VERTEX_ARRAYS)-1
void glActiveVertexArrays(GLuint count)
// <count> must be in range 0…glGetInteger(GL_MAX_ACTIVE_VERTEX_ARRAYS)
// After calling ANY of those 2 functions, the following is true:
// All array-objects bound at indices in range
// 0…glGetInteger(GL_ACTIVE_VERTEX_ARRAYS)-1
// are enabled, and all other array-objects are disabled.

void glBindIndexArray(GLuint array) // optionally…?
// New rendering command would be required.
// Or just specify NULL in glDrawRangeElements

// High-level loading vertices (like TexSubImage)
void glLoadVertexArray(GLuint array, GLsizei offset, GLsizei size, const GLvoid* vertices)

// Low-level loading vertices (DirectX style)
// Could be emulated in software with performance comparable
// (or better) to compiled_vertex_arrays, I suppose.
// Some people dont like it, so maybe put it into separate ext.
void* glLockVertexArray(GLuint array, GLsizei offset, GLsizei size)
void glUnlockVertexArray(void); // unlock ALL locked arrays (if we allow Locking
// more than 1 at the time?)

I wonder why it didn’t get any comments:

  • It is because you think it SUCKS ? (ugly, and/or useless, and/or …)

  • Or because it is NOT CLEAR ? (my english is not perfect, and I tried
    to write it in possibly short form)