createVAOAndSetAttributes static method

dynamic createVAOAndSetAttributes(
  1. OpenGLContextES gl,
  2. dynamic setters,
  3. dynamic attribs,
  4. dynamic indices,
)

Creates VAO, sets the program attributes, and binds the indices.

  • gl
  • setters: the programInfo.attribSetters
  • attribs: the bufferInfo.attribs
  • indices: the bufferInfo.indices

Implementation

static createVAOAndSetAttributes(OpenGLContextES gl, setters, attribs, indices) {
  int vao = gl.createVertexArray();
  gl.bindVertexArray(vao);

  Programs.setAttributes(setters, attribs);

  if (indices != null) {
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indices);
  }

  // We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER
  // like when creating buffers for other stuff will mess up this VAO's binding
  // gl.bindVertexArray(null); // maybe I get an issue here.
  // https://gamedev.stackexchange.com/questions/107793/binding-and-unbinding-what-would-you-do
  // gl.bindVertexArray(null); // error fails, I can't pass null value.

  /// https://community.khronos.org/t/do-i-need-to-bind-and-unbind-my-vertex-buffer-every-draw-call/104150
  gl.bindVertexArray(0); // and this line fixed alot of problems.

  return vao;
}