Package com.jme3.scene
Class VertexBuffer
java.lang.Object
com.jme3.util.NativeObject
com.jme3.scene.VertexBuffer
A 
VertexBuffer contains a particular type of geometry
 data used by Meshes. 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:
- Element - A single element is the largest individual object inside a VertexBuffer. E.g. if the VertexBuffer is used to store 3D position data, then an element will be a single 3D vector.
- Component - A component represents the parts inside an element. For a 3D vector, a single component is one of the dimensions, X, Y or Z.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumSpecifies format of the data stored in the buffer.static enumType of buffer.static enumThe usage of the VertexBuffer, specifies how often the buffer is used.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected VertexBuffer.Typeprotected intprotected intderived from components * format.getComponentSize()protected Bufferprotected booleanprotected VertexBuffer.Formatprotected intprotected intprotected Stringprotected booleanprotected intprotected intprotected VertexBuffer.UsageFields inherited from class com.jme3.util.NativeObjecthandleRef, id, INVALID_ID, objectManager, OBJTYPE_AUDIOBUFFER, OBJTYPE_AUDIOSTREAM, OBJTYPE_BO, OBJTYPE_FILTER, OBJTYPE_FRAMEBUFFER, OBJTYPE_SHADER, OBJTYPE_SHADERSOURCE, OBJTYPE_TEXTURE, OBJTYPE_VERTEXBUFFER, updateNeeded
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedSerialization only.protectedVertexBuffer(int id) Creates an empty, uninitialized buffer.
- 
Method SummaryModifier and TypeMethodDescriptionvoidInternal use only.clone()Creates a deep clone of theVertexBuffer.clone(VertexBuffer.Type overrideType) Creates a deep clone of this VertexBuffer but overrides theVertexBuffer.Type.voidcompact(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.voidConverts single floating-point data tohalffloating-point data.voidcopyElement(int inIndex, VertexBuffer outVb, int outIndex) Copies a single element of data from thisVertexBufferto the given output VertexBuffer.voidcopyElements(int inIndex, VertexBuffer outVb, int outIndex, int len) Copies a sequence of elements of data from thisVertexBufferto the given output VertexBuffer.static BuffercreateBuffer(VertexBuffer.Format format, int components, int numElements) Creates aBufferthat satisfies the given type and size requirements of the parameters.Creates a shallow clone of this GL Object.protected voidDeletes any associated nativebuffers.voiddeleteObject(Object rendererObject) Deletes the GL object from the GPU when it is no longer used.intReturns the number of 'instances' in this VertexBuffer.getData()Returns the raw internal data buffer used by this VertexBuffer.Returns a safe read-only version of this VertexBuffer's data.getElementComponent(int elementIndex, int componentIndex) Get the component inside an element.intgetName()Returns the name of this `VertexBuffer`.intintintintlongReturns a unique ID for this NativeObject.getUsage()booleanReturns true if the data size of the VertexBuffer has changed.booleanbooleanbooleanvoidread(JmeImporter im) voidCalled when the GL context is restarted to reset all IDs.voidsetElementComponent(int elementIndex, int componentIndex, Object val) Modify a component inside an element.voidsetInstanced(boolean instanced) Sets the instanceSpan to 1 or 0 depending on the value of instanced and the existing value of instanceSpan.voidsetInstanceSpan(int i) Sets how this vertex buffer matches with rendered instances where 0 means no instancing at all, ie: all elements are per vertex.voidSets a custom name for this `VertexBuffer`.voidsetNormalized(boolean normalized) voidsetOffset(int offset) voidsetStride(int stride) Set the stride (in bytes) for the data.voidsetupData(VertexBuffer.Usage usage, int components, VertexBuffer.Format format, Buffer data) Called to initialize the data in theVertexBuffer.voidsetUsage(VertexBuffer.Usage usage) toString()voidupdateData(Buffer data) Called to update the data in the buffer with new data.voidwrite(JmeExporter ex) Methods inherited from class com.jme3.util.NativeObjectdispose, getId, getWeakRef, isUpdateNeeded, setId, setUpdateNeeded
- 
Field Details- 
offsetprotected int offset
- 
lastLimitprotected int lastLimit
- 
strideprotected int stride
- 
componentsprotected int components
- 
componentsLengthprotected transient int componentsLengthderived from components * format.getComponentSize()
- 
data
- 
usage
- 
bufType
- 
format
- 
normalizedprotected boolean normalized
- 
instanceSpanprotected int instanceSpan
- 
dataSizeChangedprotected transient boolean dataSizeChanged
- 
name
 
- 
- 
Constructor Details- 
VertexBufferCreates an empty, uninitialized buffer. Must call setupData() to initialize.- Parameters:
- type- the type of VertexBuffer, such as Position or Binormal
 
- 
VertexBufferprotected VertexBuffer()Serialization only. Do not use.
- 
VertexBufferprotected VertexBuffer(int id) 
 
- 
- 
Method Details- 
invariantpublic boolean invariant()
- 
getOffsetpublic int getOffset()- Returns:
- The offset after which the data is sent to the GPU.
- See Also:
 
- 
setOffsetpublic void setOffset(int offset) - Parameters:
- offset- Specify the offset (in bytes) from the start of the buffer after which the data is sent to the GPU.
 
- 
getStridepublic int getStride()- Returns:
- The stride (in bytes) for the data.
- See Also:
 
- 
setStridepublic void setStride(int stride) Set the stride (in bytes) for the data.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. - Parameters:
- stride- the stride (in bytes) for the data
 
- 
getDataReturns the raw internal data buffer used by this VertexBuffer. This buffer is not safe to call from multiple threads since buffers have their own internal position state that cannot be shared. Call getData().duplicate(), getData().asReadOnlyBuffer(), or the more convenient getDataReadOnly() if the buffer may be accessed from multiple threads.- Returns:
- A native buffer, in the specified format.
 
- 
getDataReadOnlyReturns a safe read-only version of this VertexBuffer's data. The contents of the buffer will reflect whatever changes are made on other threads (eventually) but these should not be used in that way. This method provides a read-only buffer that is safe to _read_ from a separate thread since it has its own book-keeping state (position, limit, etc.)- Returns:
- A rewound native buffer in the specified formatthat is safe to read from a separate thread from other readers.
 
- 
getUsage- Returns:
- The usage of this buffer. See VertexBuffer.Usagefor more information.
 
- 
setUsage- Parameters:
- usage- The usage of this buffer. See- VertexBuffer.Usagefor more information.
 
- 
setNormalizedpublic void setNormalized(boolean normalized) - Parameters:
- 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.Formatis- VertexBuffer.Format.UnsignedInt, then the components will be converted to the range 0.0 - 1.0 by dividing every integer by 2^32.
 
- 
isNormalizedpublic boolean isNormalized()- Returns:
- True if integer components should be converted to the range 0-1.
- See Also:
 
- 
setInstancedpublic void setInstanced(boolean instanced) Sets the instanceSpan to 1 or 0 depending on the value of instanced and the existing value of instanceSpan.- Parameters:
- instanced- true for instanced, false for not instanced
 
- 
isInstancedpublic boolean isInstanced()- Returns:
- true if buffer contains per-instance data, otherwise false
 
- 
setInstanceSpanpublic 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. If set to 1 then each element goes with one instance. If set to 2 then each element goes with two instances and so on.- Parameters:
- i- the desired number of instances per element
 
- 
getInstanceSpanpublic int getInstanceSpan()
- 
getBufferType- Returns:
- The type of information that this buffer has.
 
- 
getFormat- Returns:
- The format, or data type of the data.
 
- 
getNumComponentspublic int getNumComponents()- Returns:
- The number of components of the given formatper element.
 
- 
getNumElementspublic int getNumElements()- Returns:
- The total number of data elements in the data buffer.
 
- 
getBaseInstanceCountpublic int getBaseInstanceCount()Returns the number of 'instances' in this VertexBuffer. This is dependent on the current instanceSpan. When instanceSpan is 0 then 'instances' is 1. Otherwise, instances is elements * instanceSpan. It is possible to render a mesh with more instances but the instance data begins to repeat.- Returns:
- the number of instances
 
- 
setupDatapublic void setupData(VertexBuffer.Usage usage, int components, VertexBuffer.Format format, Buffer data) Called to initialize the data in theVertexBuffer. Must only be called once.- Parameters:
- usage- The usage for the data, or how often will the data be updated per frame. See the- VertexBuffer.Usageenum.
- 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.Formatargument.
 
- 
updateDataCalled to update the data in the buffer with new data. Can only be called aftersetupData(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. - Parameters:
- data- The data buffer to set
 
- 
hasDataSizeChangedpublic boolean hasDataSizeChanged()Returns true if the data size of the VertexBuffer has changed. Internal use only.- Returns:
- true if the data size has changed
 
- 
clearUpdateNeededpublic void clearUpdateNeeded()Description copied from class:NativeObjectInternal use only. Indicates that the state changes were applied.- Overrides:
- clearUpdateNeededin class- NativeObject
 
- 
convertToHalfpublic void convertToHalf()Converts single floating-point data tohalffloating-point data.
- 
compactpublic 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.- Parameters:
- numElements- The number of elements to reduce to.
 
- 
setElementComponentModify a component inside an element. Thevalparameter must be in the buffer's format:VertexBuffer.Format.- Parameters:
- elementIndex- The element index to modify
- componentIndex- The component index to modify
- val- The value to set, either byte, short, int or float depending on the- VertexBuffer.Format.
 
- 
getElementComponentGet the component inside an element.- Parameters:
- elementIndex- The element index
- componentIndex- The component index
- Returns:
- The component, as one of the primitive types, byte, short, int or float.
 
- 
copyElementCopies a single element of data from thisVertexBufferto the given output VertexBuffer.- Parameters:
- inIndex- The input element index
- outVb- The buffer to copy to
- outIndex- The output element index
- Throws:
- IllegalArgumentException- If the formats of the buffers do not match.
 
- 
copyElementsCopies a sequence of elements of data from thisVertexBufferto the given output VertexBuffer.- Parameters:
- inIndex- The input element index
- outVb- The buffer to copy to
- outIndex- The output element index
- len- The number of elements to copy
- Throws:
- IllegalArgumentException- If the formats of the buffers do not match.
 
- 
createBufferCreates aBufferthat satisfies the given type and size requirements of the parameters. The buffer will be of the type specified byformatand would be able to contain the given number of elements with the given number of components in each element.- Parameters:
- format- the desired format of components, such as Float or Half
- components- the number of components per element (≥1, ≤4)
- numElements- the desired capacity (number of elements)
- Returns:
- a new Buffer
 
- 
cloneCreates a deep clone of theVertexBuffer.- Overrides:
- clonein class- NativeObject
- Returns:
- Deep clone of this buffer
 
- 
cloneCreates a deep clone of this VertexBuffer but overrides theVertexBuffer.Type.- Parameters:
- overrideType- The type of the cloned VertexBuffer
- Returns:
- A deep clone of the buffer
 
- 
toString- Overrides:
- toStringin class- NativeObject
 
- 
resetObjectpublic void resetObject()Description copied from class:NativeObjectCalled when the GL context is restarted to reset all IDs. Prevents "white textures" on display restart.- Specified by:
- resetObjectin class- NativeObject
 
- 
deleteObjectDescription copied from class:NativeObjectDeletes the GL object from the GPU when it is no longer used. Called automatically by the GL object manager.- Specified by:
- deleteObjectin class- NativeObject
- Parameters:
- rendererObject- The renderer to be used to delete the object
 
- 
deleteNativeBuffersprotected void deleteNativeBuffers()Description copied from class:NativeObjectDeletes any associated nativebuffers. 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 protected- Overrides:
- deleteNativeBuffersin class- NativeObject
 
- 
createDestructableCloneDescription copied from class:NativeObjectCreates a shallow clone of this GL Object. The deleteObject method should be functional for this object.- Specified by:
- createDestructableClonein class- NativeObject
- Returns:
- a new instance
 
- 
getUniqueIdpublic long getUniqueId()Description copied from class:NativeObjectReturns a unique ID for this NativeObject. No other NativeObject shall have the same ID.- Specified by:
- getUniqueIdin class- NativeObject
- Returns:
- unique ID for this NativeObject.
 
- 
write- Specified by:
- writein interface- Savable
- Throws:
- IOException
 
- 
read- Specified by:
- readin interface- Savable
- Throws:
- IOException
 
- 
getNameReturns the name of this `VertexBuffer`. If no name has been explicitly set, a default name is generated based on its class name and buffer type (e.g., "VertexBuffer(Position)").- Returns:
- The name of the `VertexBuffer`.
 
- 
setNameSets a custom name for this `VertexBuffer`.- Parameters:
- name- The new name for the `VertexBuffer`. Can be null to revert to the default generated name.
 
 
-