public class SoCpuBufferObject extends SoBufferObject
By default memory allocations have the maximum possible alignment to allow use with (for example) SSE instructions.
Memory is managed using the new/delete operators. On Microsoft Windows platforms it is possible to use VirtualAlloc/VirtualFree instead by setting OIV_BUFFER_USE_VIRTUAL_ALLOC (see SoPreferences
).
See SoBufferObject
for general information about buffer objects.
See SoBufferedShape
for an example of storing vertices in a CPU buffer.
Load data into a buffer object from an array in memory:
float[] vertices = { 1.0f, 0.5f,0.0f, 0.0f, 1.0f,0.0f, -1.0f,0.5f,0.0f, -1.0f,-1.0f,0.0f, 1.0f,-1.0f,0.0f, 1.0f,0.0f,0.0f, -1.0f,0.0f,0.0f, -1.0f,-1.5f,0.0f, 1.0f,-1.5f,0.0f }; // Create a CPU buffer object and set its size (allocate memory) SoCpuBufferObject cpuBuffer = new SoCpuBufferObject(); cpuBuffer.setSize( vertices.length * Float.SIZE/8 ); // Copy vertex data into the buffer object FloatBuffer vertData = cpuBuffer.map( SoBufferObject.AccessModes.SET ).asFloatBuffer(); vertData.put(vertices); cpuBuffer.unmap();
Access data stored in a buffer object.
See also:ByteBuffer data = cpuBuffer.map( SoBufferObject.AccessModes.READ_ONLY ); byte value = data.get(0); . . . cpuBuffer.unmap();
SoBufferObject.AccessModes
Inventor.ConstructorCommand
SO_BUFFER_SIZE_ALL
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoCpuBufferObject()
Default constructor.
|
SoCpuBufferObject(java.nio.ByteBuffer buffer)
Constructor that takes an existing block of CPU memory.
|
Modifier and Type | Method and Description |
---|---|
void |
clearInstance()
Free the memory allocated by the buffer object.
|
void |
setBuffer(java.nio.ByteBuffer buffer)
Request that the buffer object manage an existing block of memory.
|
boolean |
setSize(long size)
Sets the size in bytes of the buffer object.
|
createInstance, dispose, getBufferObjectCache, getContext, getMappedBufferObject, getMappedBufferObjectAccessMode, getMappedBufferObjectPosition, getMappedBufferObjectSize, getSize, isDisposable, lockBuffer, map, map, map, map, map, map, memcpy, memcpy, memcpy, memcpy, unlockBuffer, unmap, unmap
getNativeResourceHandle
public SoCpuBufferObject()
public SoCpuBufferObject(java.nio.ByteBuffer buffer)
buffer
- Pointer to the buffer to manage.
size
- Size of buffer in bytes.public void clearInstance()
SoBufferObject
clearInstance
in class SoBufferObject
public boolean setSize(long size)
SoBufferObject
If the requested size is the same as the current size, this method does nothing and returns true. If there is existing memory that is owned by the buffer object, that memory is released. If the requested size is zero, the buffer object is now empty.
setSize
in class SoBufferObject
size
- The requested size in bytes.
public void setBuffer(java.nio.ByteBuffer buffer)
We recommend to use the most aligned memory pointer possible to enable optimized algorithm usage.
NOTE: If another buffer object is currently mapped into another buffer, the other buffer is automatically unmapped and its contents are undefined.
Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com