Skip to content

VertexArrayObject support #9

@axel22

Description

@axel22

VAOs are used as a shorthand for setting the state of the vertex processor, and, once the vertex attributes and pointers are set while a VAO is bound, subsequently binding the VAO does not require setting the vertex attribute buffers and pointers.

Right now, in the single triangle example, we access VAOs using the low-level OpenGL API:

https://github.com/storm-enroute/macrogl/blob/master/src/test/scala/org/macrogl/examples/SingleTriangle.scala#L14

We need a better support for VAOs.
We must do the following:

  • introduce VertexArrayObject.scala, which extends Handle, and its acquire generates a name, just like Program, Texture, RenderBuffer and others
  • introduce object VertexArrayObjectObject { def foreach = ... } in using: https://github.com/storm-enroute/macrogl/blob/master/src/main/scala/org/macrogl/package.scala#L115
  • have a foreach and a macro associated, just like with other kinds of using objects - it sets and unsets the VAO
  • add a def vertexArrayObject(vao: VertexArrayObject) = VertexArrayObjectObject

This should allow the following syntax:

val vao = new VertexArrayObject
vao.acquire()

// loop

for {
  _ <- using.vertexArrayObject(vao)
  ... all the rest ...
} {
  // rendering
}

// later
vao.release()

Then, I would create a lazy default VAO lying somewhere in package.scala:

Default.VAO

So that the developers can fetch it immediately without creating it:

for {
  _ <- using.vertexArrayObject(Default.VAO)
} {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions