APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.glutils

public Class VertexBufferObjectWithVAO

extends Object
implements VertexData
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.graphics.glutils.VertexData, com.badlogic.gdx.utils.Disposable
Imports
java.nio.Buffer, .ByteBuffer, .FloatBuffer, .IntBuffer, com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.GL20, .GL30, .VertexAttribute, .VertexAttributes, com.badlogic.gdx.utils.BufferUtils, .IntArray

A VertexData implementation that uses vertex buffer objects and vertex array objects. (This is required for OpenGL 3.0+ core profiles. In particular, the default VAO has been deprecated, as has the use of client memory for passing vertex attributes.) Use of VAOs should give a slight performance benefit since you don't have to bind the attributes on every draw anymore.

If the OpenGL ES context was lost you can call invalidate() to recreate a new OpenGL vertex buffer object.

VertexBufferObjectWithVAO objects must be disposed via the dispose() method when no longer needed

Code adapted from VertexBufferObject.
Author
mzechner, Dave Clayton , Nate Austin

Field Summary

Modifier and TypeField and Description
pack-priv final VertexAttributes
pack-priv final FloatBuffer
pack-priv int
pack-priv final ByteBuffer
pack-priv IntArray
pack-priv boolean
pack-priv boolean
pack-priv final boolean
pack-priv final boolean
pack-priv static final IntBuffer
pack-priv final int
pack-priv int

Constructor Summary

AccessConstructor and Description
public
VertexBufferObjectWithVAO(boolean
whether the vertex data is static.
isStatic
,
int
the maximum number of vertices
numVertices
,
VertexAttribute... attributes)

Constructs a new interleaved VertexBufferObjectWithVAO.

public
VertexBufferObjectWithVAO(boolean
whether the vertex data is static.
isStatic
,
int
the maximum number of vertices
numVertices
,
VertexAttributes attributes)

Constructs a new interleaved VertexBufferObjectWithVAO.

public
VertexBufferObjectWithVAO(boolean isStatic, ByteBuffer unmanagedBuffer, VertexAttributes attributes)

Method Summary

Modifier and TypeMethod and Description
public void
bind(ShaderProgram
the shader
shader
)

Implements com.badlogic.gdx.graphics.glutils.VertexData.bind.

Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements

public void
bind(ShaderProgram shader, int[] locations)

Implements com.badlogic.gdx.graphics.glutils.VertexData.bind.

Binds this VertexData for rendering via glDrawArrays or glDrawElements.

private void
bindAttributes(ShaderProgram shader, int[] locations)

private void
private void
private void
private void
public void
dispose()

Implements com.badlogic.gdx.graphics.glutils.VertexData.dispose.

Disposes of all resources this VertexBufferObject uses.

public VertexAttributes
public FloatBuffer
getBuffer()

Implements com.badlogic.gdx.graphics.glutils.VertexData.getBuffer.

Deprecated use getBuffer(boolean) instead

Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind.

public FloatBuffer
getBuffer(boolean forWriting)

Implements com.badlogic.gdx.graphics.glutils.VertexData.getBuffer.

Returns the underlying FloatBuffer for reading or writing.

public int
public int
public void
invalidate()

Implements com.badlogic.gdx.graphics.glutils.VertexData.invalidate.

Invalidates the VertexBufferObject so a new OpenGL buffer handle is created.

public void
setVertices(float[] vertices, int offset, int count)

Implements com.badlogic.gdx.graphics.glutils.VertexData.setVertices.

Sets the vertices of this VertexData, discarding the old vertex data.

public void
unbind(final ShaderProgram
the shader
shader
)

Implements com.badlogic.gdx.graphics.glutils.VertexData.unbind.

Unbinds this VertexBufferObject.

public void
unbind(final ShaderProgram shader, final int[] locations)

Implements com.badlogic.gdx.graphics.glutils.VertexData.unbind.

Unbinds this VertexData.

private void
public void
updateVertices(int targetOffset, float[] vertices, int sourceOffset, int count)

Implements com.badlogic.gdx.graphics.glutils.VertexData.updateVertices.

Update (a portion of) the vertices.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
pack-priv final VertexAttributes attributes
bufferback to summary
pack-priv final FloatBuffer buffer
bufferHandleback to summary
pack-priv int bufferHandle
byteBufferback to summary
pack-priv final ByteBuffer byteBuffer
cachedLocationsback to summary
pack-priv IntArray cachedLocations
isBoundback to summary
pack-priv boolean isBound
isDirtyback to summary
pack-priv boolean isDirty
isStaticback to summary
pack-priv final boolean isStatic
ownsBufferback to summary
pack-priv final boolean ownsBuffer
tmpHandleback to summary
pack-priv static final IntBuffer tmpHandle
usageback to summary
pack-priv final int usage
vaoHandleback to summary
pack-priv int vaoHandle

Constructor Detail

VertexBufferObjectWithVAOback to summary
public VertexBufferObjectWithVAO(boolean isStatic, int numVertices, VertexAttribute... attributes)

Constructs a new interleaved VertexBufferObjectWithVAO.

Parameters
isStatic:boolean

whether the vertex data is static.

numVertices:int

the maximum number of vertices

attributes:VertexAttribute[]

the com.badlogic.gdx.graphics.VertexAttributes.

VertexBufferObjectWithVAOback to summary
public VertexBufferObjectWithVAO(boolean isStatic, int numVertices, VertexAttributes attributes)

Constructs a new interleaved VertexBufferObjectWithVAO.

Parameters
isStatic:boolean

whether the vertex data is static.

numVertices:int

the maximum number of vertices

attributes:VertexAttributes

the VertexAttributes.

VertexBufferObjectWithVAOback to summary
public VertexBufferObjectWithVAO(boolean isStatic, ByteBuffer unmanagedBuffer, VertexAttributes attributes)

Method Detail

bindback to summary
public void bind(ShaderProgram shader)

Implements com.badlogic.gdx.graphics.glutils.VertexData.bind.

Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements

Parameters
shader:ShaderProgram

the shader

Annotations
@Override
bindback to summary
public void bind(ShaderProgram shader, int[] locations)

Implements com.badlogic.gdx.graphics.glutils.VertexData.bind.

Doc from com.badlogic.gdx.graphics.glutils.VertexData.bind.

Binds this VertexData for rendering via glDrawArrays or glDrawElements.

Annotations
@Override
bindAttributesback to summary
private void bindAttributes(ShaderProgram shader, int[] locations)
bindDataback to summary
private void bindData(GL20 gl)
bufferChangedback to summary
private void bufferChanged()
createVAOback to summary
private void createVAO()
deleteVAOback to summary
private void deleteVAO()
disposeback to summary
public void dispose()

Implements com.badlogic.gdx.graphics.glutils.VertexData.dispose.

Disposes of all resources this VertexBufferObject uses.

Annotations
@Override
getAttributesback to summary
public VertexAttributes getAttributes()

Implements com.badlogic.gdx.graphics.glutils.VertexData.getAttributes.

Annotations
@Override
getBufferback to summary
public FloatBuffer getBuffer()

Implements com.badlogic.gdx.graphics.glutils.VertexData.getBuffer.

Doc from com.badlogic.gdx.graphics.glutils.VertexData.getBuffer.

Deprecated

use getBuffer(boolean) instead

Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind. If you need immediate uploading use setVertices(float[], int, int); Any modifications made to the Buffer *after* the call to bind will not automatically be uploaded.

Annotations
@Override
@Deprecated
getBufferback to summary
public FloatBuffer getBuffer(boolean forWriting)

Implements com.badlogic.gdx.graphics.glutils.VertexData.getBuffer.

Doc from com.badlogic.gdx.graphics.glutils.VertexData.getBuffer.

Returns the underlying FloatBuffer for reading or writing.

Annotations
@Override
getNumMaxVerticesback to summary
public int getNumMaxVertices()

Implements com.badlogic.gdx.graphics.glutils.VertexData.getNumMaxVertices.

Annotations
@Override
getNumVerticesback to summary
public int getNumVertices()

Implements com.badlogic.gdx.graphics.glutils.VertexData.getNumVertices.

Annotations
@Override
invalidateback to summary
public void invalidate()

Implements com.badlogic.gdx.graphics.glutils.VertexData.invalidate.

Invalidates the VertexBufferObject so a new OpenGL buffer handle is created. Use this in case of a context loss.

Annotations
@Override
setVerticesback to summary
public void setVertices(float[] vertices, int offset, int count)

Implements com.badlogic.gdx.graphics.glutils.VertexData.setVertices.

Doc from com.badlogic.gdx.graphics.glutils.VertexData.setVertices.

Sets the vertices of this VertexData, discarding the old vertex data. The count must equal the number of floats per vertex times the number of vertices to be copied to this VertexData. The order of the vertex attributes must be the same as specified at construction time via VertexAttributes.

This can be called in between calls to bind and unbind. The vertex data will be updated instantly.

Annotations
@Override
unbindback to summary
public void unbind(final ShaderProgram shader)

Implements com.badlogic.gdx.graphics.glutils.VertexData.unbind.

Unbinds this VertexBufferObject.

Parameters
shader:ShaderProgram

the shader

Annotations
@Override
unbindback to summary
public void unbind(final ShaderProgram shader, final int[] locations)

Implements com.badlogic.gdx.graphics.glutils.VertexData.unbind.

Doc from com.badlogic.gdx.graphics.glutils.VertexData.unbind.

Unbinds this VertexData.

Annotations
@Override
unbindAttributesback to summary
private void unbindAttributes(ShaderProgram shaderProgram)
updateVerticesback to summary
public void updateVertices(int targetOffset, float[] vertices, int sourceOffset, int count)

Implements com.badlogic.gdx.graphics.glutils.VertexData.updateVertices.

Doc from com.badlogic.gdx.graphics.glutils.VertexData.updateVertices.

Update (a portion of) the vertices. Does not resize the backing buffer.

Annotations
@Override