public class VertexBuffer extends NativeObject implements Savable, java.lang.Cloneable
VertexBuffer
contains a particular type of geometry
data used by Mesh
es. Every VertexBuffer set on a Mesh
is sent as an attribute to the vertex shader to be processed.
Several terms are used throughout the javadoc for this class, explanation:
Modifier and Type | Class and Description |
---|---|
static class |
VertexBuffer.Format
Specifies format of the data stored in the buffer.
|
static class |
VertexBuffer.Type
Type of buffer.
|
static class |
VertexBuffer.Usage
The usage of the VertexBuffer, specifies how often the buffer
is used.
|
Modifier and Type | Field and Description |
---|---|
protected VertexBuffer.Type |
bufType |
protected int |
components |
protected int |
componentsLength
derived from components * format.getComponentSize()
|
protected java.nio.Buffer |
data |
protected boolean |
dataSizeChanged |
protected VertexBuffer.Format |
format |
protected int |
instanceSpan |
protected int |
lastLimit |
protected boolean |
normalized |
protected int |
offset |
protected int |
stride |
protected VertexBuffer.Usage |
usage |
handleRef, id, INVALID_ID, objectManager, OBJTYPE_AUDIOBUFFER, OBJTYPE_AUDIOSTREAM, OBJTYPE_BO, OBJTYPE_FILTER, OBJTYPE_FRAMEBUFFER, OBJTYPE_SHADER, OBJTYPE_SHADERSOURCE, OBJTYPE_TEXTURE, OBJTYPE_VERTEXBUFFER, updateNeeded
Modifier | Constructor and Description |
---|---|
protected |
VertexBuffer()
Serialization only.
|
protected |
VertexBuffer(int id) |
|
VertexBuffer(VertexBuffer.Type type)
Creates an empty, uninitialized buffer.
|
Modifier and Type | Method and Description |
---|---|
void |
clearUpdateNeeded()
Internal use only.
|
VertexBuffer |
clone()
Creates a deep clone of the
VertexBuffer . |
VertexBuffer |
clone(VertexBuffer.Type overrideType)
Creates a deep clone of this VertexBuffer but overrides the
VertexBuffer.Type . |
void |
compact(int numElements)
Reduces the capacity of the buffer to the given amount
of elements, any elements at the end of the buffer are truncated
as necessary.
|
void |
convertToHalf()
Converts single floating-point data to
half floating-point data. |
void |
copyElement(int inIndex,
VertexBuffer outVb,
int outIndex)
Copies a single element of data from this
VertexBuffer
to the given output VertexBuffer. |
void |
copyElements(int inIndex,
VertexBuffer outVb,
int outIndex,
int len)
Copies a sequence of elements of data from this
VertexBuffer
to the given output VertexBuffer. |
static java.nio.Buffer |
createBuffer(VertexBuffer.Format format,
int components,
int numElements)
Creates a
Buffer that satisfies the given type and size requirements
of the parameters. |
NativeObject |
createDestructableClone()
Creates a shallow clone of this GL Object.
|
protected void |
deleteNativeBuffers()
Deletes any associated native
buffers . |
void |
deleteObject(java.lang.Object rendererObject)
Deletes the GL object from the GPU when it is no longer used.
|
int |
getBaseInstanceCount()
Returns the number of 'instances' in this VertexBuffer.
|
VertexBuffer.Type |
getBufferType() |
java.nio.Buffer |
getData()
Returns the raw internal data buffer used by this VertexBuffer.
|
java.nio.Buffer |
getDataReadOnly()
Returns a safe read-only version of this VertexBuffer's data.
|
java.lang.Object |
getElementComponent(int elementIndex,
int componentIndex)
Get the component inside an element.
|
VertexBuffer.Format |
getFormat() |
int |
getInstanceSpan() |
int |
getNumComponents() |
int |
getNumElements() |
int |
getOffset() |
int |
getStride() |
long |
getUniqueId()
Returns a unique ID for this NativeObject.
|
VertexBuffer.Usage |
getUsage() |
boolean |
hasDataSizeChanged()
Returns true if the data size of the VertexBuffer has changed.
|
boolean |
invariant() |
boolean |
isInstanced()
Returns true if instanceSpan is more than 0 indicating
that this vertex buffer contains per-instance data.
|
boolean |
isNormalized() |
void |
read(JmeImporter im) |
void |
resetObject()
Called when the GL context is restarted to reset all IDs.
|
void |
setElementComponent(int elementIndex,
int componentIndex,
java.lang.Object val)
Modify a component inside an element.
|
void |
setInstanced(boolean instanced)
Sets the instanceSpan to 1 or 0 depending on
the value of instanced and the existing value of
instanceSpan.
|
void |
setInstanceSpan(int i)
Sets how this vertex buffer matches with rendered instances
where 0 means no instancing at all, ie: all elements are
per vertex.
|
void |
setNormalized(boolean normalized) |
void |
setOffset(int offset) |
void |
setStride(int stride)
Set the stride (in bytes) for the data.
|
void |
setupData(VertexBuffer.Usage usage,
int components,
VertexBuffer.Format format,
java.nio.Buffer data)
Called to initialize the data in the
VertexBuffer . |
void |
setUsage(VertexBuffer.Usage usage) |
java.lang.String |
toString() |
void |
updateData(java.nio.Buffer data)
Called to update the data in the buffer with new data.
|
void |
write(JmeExporter ex) |
dispose, getId, isUpdateNeeded, setId, setUpdateNeeded
protected int offset
protected int lastLimit
protected int stride
protected int components
protected transient int componentsLength
protected java.nio.Buffer data
protected VertexBuffer.Usage usage
protected VertexBuffer.Type bufType
protected VertexBuffer.Format format
protected boolean normalized
protected int instanceSpan
protected transient boolean dataSizeChanged
public VertexBuffer(VertexBuffer.Type type)
protected VertexBuffer()
protected VertexBuffer(int id)
public boolean invariant()
public int getOffset()
setOffset(int)
public void setOffset(int offset)
offset
- Specify the offset (in bytes) from the start of the buffer
after which the data is sent to the GPU.public int getStride()
setStride(int)
public void setStride(int stride)
If the data is packed in the buffer, then stride is 0, if there's other data that is between the current component and the next component in the buffer, then this specifies the size in bytes of that additional data.
stride
- the stride (in bytes) for the datapublic java.nio.Buffer getData()
format
.public java.nio.Buffer getDataReadOnly()
format
that is safe to read from a separate thread from other readers.public VertexBuffer.Usage getUsage()
VertexBuffer.Usage
for more
information.public void setUsage(VertexBuffer.Usage usage)
usage
- The usage of this buffer. See VertexBuffer.Usage
for more
information.public void setNormalized(boolean normalized)
normalized
- Set to true if integer components should be converted
from their maximal range into the range 0.0 - 1.0 when converted to
a floating-point value for the shader.
E.g. if the VertexBuffer.Format
is VertexBuffer.Format.UnsignedInt
, then
the components will be converted to the range 0.0 - 1.0 by dividing
every integer by 2^32.public boolean isNormalized()
setNormalized(boolean)
public void setInstanced(boolean instanced)
public boolean isInstanced()
public void setInstanceSpan(int i)
public int getInstanceSpan()
public VertexBuffer.Type getBufferType()
public VertexBuffer.Format getFormat()
format
, or data type of the data.public int getNumComponents()
format
per
element.public int getNumElements()
public int getBaseInstanceCount()
public void setupData(VertexBuffer.Usage usage, int components, VertexBuffer.Format format, java.nio.Buffer data)
VertexBuffer
. Must only
be called once.usage
- The usage for the data, or how often will the data
be updated per frame. See the VertexBuffer.Usage
enum.components
- The number of components per element.format
- The format
, or data-type of a single
component.data
- A native buffer, the format of which matches the VertexBuffer.Format
argument.public void updateData(java.nio.Buffer data)
setupData(com.jme3.scene.VertexBuffer.Usage, int, com.jme3.scene.VertexBuffer.Format, java.nio.Buffer)
has been called. Note that it is fine to call this method on the
data already set, e.g. vb.updateData(vb.getData()), this will just
set the proper update flag indicating the data should be sent to the GPU
again.
It is allowed to specify a buffer with different capacity than the originally set buffer, HOWEVER, if you do so, you must call Mesh.updateCounts() otherwise bizarre errors can occur.
data
- The data buffer to setpublic boolean hasDataSizeChanged()
public void clearUpdateNeeded()
NativeObject
clearUpdateNeeded
in class NativeObject
public void convertToHalf()
half
floating-point data.public void compact(int numElements)
numElements
- The number of elements to reduce to.public void setElementComponent(int elementIndex, int componentIndex, java.lang.Object val)
val
parameter must be in the buffer's format:
VertexBuffer.Format
.elementIndex
- The element index to modifycomponentIndex
- The component index to modifyval
- The value to set, either byte, short, int or float depending
on the VertexBuffer.Format
.public java.lang.Object getElementComponent(int elementIndex, int componentIndex)
elementIndex
- The element indexcomponentIndex
- The component indexpublic void copyElement(int inIndex, VertexBuffer outVb, int outIndex)
VertexBuffer
to the given output VertexBuffer.inIndex
- The input element indexoutVb
- The buffer to copy tooutIndex
- The output element indexjava.lang.IllegalArgumentException
- If the formats of the buffers do not
match.public void copyElements(int inIndex, VertexBuffer outVb, int outIndex, int len)
VertexBuffer
to the given output VertexBuffer.inIndex
- The input element indexoutVb
- The buffer to copy tooutIndex
- The output element indexlen
- The number of elements to copyjava.lang.IllegalArgumentException
- If the formats of the buffers do not
match.public static java.nio.Buffer createBuffer(VertexBuffer.Format format, int components, int numElements)
Buffer
that satisfies the given type and size requirements
of the parameters. The buffer will be of the type specified by
format
and would be able to contain the given number
of elements with the given number of components in each element.public VertexBuffer clone()
VertexBuffer
.clone
in class NativeObject
public VertexBuffer clone(VertexBuffer.Type overrideType)
VertexBuffer.Type
.overrideType
- The type of the cloned VertexBufferpublic java.lang.String toString()
toString
in class NativeObject
public void resetObject()
NativeObject
resetObject
in class NativeObject
public void deleteObject(java.lang.Object rendererObject)
NativeObject
deleteObject
in class NativeObject
rendererObject
- The renderer to be used to delete the objectprotected void deleteNativeBuffers()
NativeObject
buffers
.
This is necessary because it is unlikely that native buffers
will be garbage collected naturally (due to how GC works), therefore
the collection must be handled manually.
Only implementations that manage native buffers need to override
this method. Note that the behavior that occurs when a
deleted native buffer is used is not defined, therefore this
method is protecteddeleteNativeBuffers
in class NativeObject
public NativeObject createDestructableClone()
NativeObject
createDestructableClone
in class NativeObject
public long getUniqueId()
NativeObject
getUniqueId
in class NativeObject
public void write(JmeExporter ex) throws java.io.IOException
public void read(JmeImporter im) throws java.io.IOException