Skip to main content
Version: Phaser v4.0.0

WebGLVAOWrapper

Wrapper for a WebGL Vertex Array Object (VAO).

A VAO stores the complete vertex attribute configuration for a draw call, including attribute pointer definitions, enabled attribute arrays, and the bound element array buffer. Binding a VAO before drawing restores all of this state in a single call, reducing the number of WebGL API calls needed per frame.

A raw WebGLVertexArrayObject should never be exposed outside the WebGLRenderer, so the WebGLRenderer can handle context loss and other events without other systems having to be aware of it. Always use WebGLVAOWrapper instead.

Constructor

new WebGLVAOWrapper(renderer, program, indexBuffer, attributeBufferLayouts)

Parameters

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe WebGLRenderer instance that owns this wrapper.
programPhaser.Renderer.WebGL.Wrappers.WebGLProgramWrapperNoThe shader program that this VAO is associated with.
indexBufferPhaser.Renderer.WebGL.Wrappers.WebGLBufferWrapperNoThe index buffer used in this VAO, if any.
attributeBufferLayoutsArray.<Phaser.Renderer.WebGL.Wrappers.WebGLVertexBufferLayoutWrapper>NoThe vertex buffers containing attribute data for this VAO, alongside the relevant attribute layout.

Scope: static

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L9
Since: 4.0.0

Public Members

attributeBufferLayouts

attributeBufferLayouts: Array.<Phaser.Renderer.WebGL.Wrappers.WebGLVertexBufferLayoutWrapper>

Description:

The vertex buffers containing attribute data for this VAO, alongside the relevant attribute layout.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L78
Since: 4.0.0


glState

glState: object

Description:

The state object used to bind this VAO.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L88
Since: 4.0.0


indexBuffer

indexBuffer: Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper

Description:

The element array buffer used in this VAO, if any.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L68
Since: 4.0.0


program

program: Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper

Description:

The shader program that this VAO is associated with.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L45
Since: 4.0.0


renderer

renderer: Phaser.Renderer.WebGL.WebGLRenderer

Description:

The WebGLRenderer instance that owns this wrapper.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L36
Since: 4.0.0


vertexArrayObject

vertexArrayObject: WebGLVertexArrayObject

Description:

The WebGLVertexArrayObject being wrapped by this class.

This property could change at any time. Therefore, you should never store a reference to this value. It should only be passed directly to the WebGL API for drawing.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L54
Since: 4.0.0


Public Methods

bind

<instance> bind()

Description:

Binds this WebGLVAOWrapper to the current WebGLRenderingContext.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L207
Since: 4.0.0


createResource

<instance> createResource()

Description:

Creates a new WebGLVertexArrayObject and records the full vertex attribute configuration into it. This includes binding the optional index buffer, enabling each vertex attribute array, setting up the attribute pointers (including per-column pointers for matrix attributes), and applying instance divisors for instanced rendering. Once the VAO is fully configured it is unbound, along with any array and element-array buffers, to leave the WebGL state clean.

This method is called automatically by the constructor. It is also called by the WebGLRenderer when the WebGL context is restored after a context loss event.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L102
Since: 4.0.0


destroy

<instance> destroy()

Description:

Destroys this WebGLVAOWrapper and removes all associated resources.

Source: src/renderer/webgl/wrappers/WebGLVAOWrapper.js#L218
Since: 4.0.0