vertex-array.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Context } from './context';
  7. import { Program } from './program';
  8. import { AttributeBuffers, ElementsBuffer } from './buffer';
  9. export function createVertexArray(ctx: Context, program: Program, attributeBuffers: AttributeBuffers, elementsBuffer?: ElementsBuffer) {
  10. const { oesVertexArrayObject } = ctx.extensions
  11. let vertexArray: WebGLVertexArrayObjectOES | undefined = undefined
  12. if (oesVertexArrayObject) {
  13. vertexArray = oesVertexArrayObject.createVertexArrayOES()
  14. oesVertexArrayObject.bindVertexArrayOES(vertexArray)
  15. if (elementsBuffer) elementsBuffer.bind()
  16. program.bindAttributes(attributeBuffers)
  17. ctx.vaoCount += 1
  18. oesVertexArrayObject.bindVertexArrayOES(null!)
  19. }
  20. return vertexArray
  21. }
  22. export function deleteVertexArray(ctx: Context, vertexArray?: WebGLVertexArrayObjectOES) {
  23. const { oesVertexArrayObject } = ctx.extensions
  24. if (oesVertexArrayObject && vertexArray) {
  25. oesVertexArrayObject.deleteVertexArrayOES(vertexArray)
  26. ctx.vaoCount -= 1
  27. }
  28. }