Package org.lwjgl.util.mapped
Class MappedObject
java.lang.Object
org.lwjgl.util.mapped.MappedObject
Base superclass of all mapped objects. Classes that require
data mapping should extend this class and registered with
MappedObjectTransformer.register(Class)
.
Subclasses may only specify the default constructor. Any code
inside that constructor is optional, but will not run when the
view is instantiated, see runViewConstructor()
.
Bounds checking may be enabled through a JVM system property: org.lwjgl.util.mapped.Checks=true- Author:
- Riven
-
Field Summary
FieldsModifier and TypeFieldDescriptionlong
The mapped object base memory address, in bytes.static int
Holds the value of sizeof of the sub-type of this MappedObject
The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.SIZEOF
will yield 8 (2 floats)
Vec3.SIZEOF
will yield 12 (3 floats)
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality.int
The mapped object view offset, in elements.long
The mapped object view memory address, in bytes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <T extends MappedObject>
T[]asArray()
final ByteBuffer
Returns theByteBuffer
that backs this mapped object.final int
capacity()
Returns the number of mapped objects that fit in the mapped buffer.final <T extends MappedObject>
voidcopyRange
(T target, int instances) Copies and amount ofSIZEOF * instances
bytes, from the current mapped object, to the specified mapped object.final <T extends MappedObject>
voidcopyTo
(T target) Copies and amount ofSIZEOF - padding
bytes, from the current mapped object, to the specified mapped object.final <T extends MappedObject>
Tdup()
Creates an identical new MappedObject instance, comparable to the contract ofByteBuffer.duplicate()
.static <T extends MappedObject>
Iterable<T> foreach
(T mapped) Creates anIterable
that will step through capacity()
views, leaving theview
at the last valid value.static <T extends MappedObject>
Iterable<T> foreach
(T mapped, int elementCount) Creates anIterable
that will step through elementCount
views, leaving theview
at the last valid value.final int
getAlign()
Returns the mapped object memory alignment, in bytes.final int
Returns the mapped object memory sizeof, in bytes.protected final long
getViewAddress
(int view) static <T extends MappedObject>
Tmalloc
(int elementCount) Creates a MappedObject instance, mapping the memory region of an allocated direct ByteBuffer with a capacity ofelementCount*SIZEOF
static <T extends MappedObject>
Tmap
(long address, int capacity) Creates a MappedObject instance, mapping the memory region specified.static <T extends MappedObject>
Tmap
(ByteBuffer bb) Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer.final void
next()
Moves the current view to the next element.final void
Any code in the default constructor will not run automatically.final void
setViewAddress
(long address) final <T extends MappedObject>
Tslice()
Creates a new MappedObject instance, with a base offset equal to the offset of the current view, comparable to the contract ofByteBuffer.slice()
.
-
Field Details
-
baseAddress
public long baseAddressThe mapped object base memory address, in bytes. Read-only. -
viewAddress
public long viewAddressThe mapped object view memory address, in bytes. Read-only. -
SIZEOF
public static int SIZEOFHolds the value of sizeof of the sub-type of this MappedObject
The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.SIZEOF
will yield 8 (2 floats)
Vec3.SIZEOF
will yield 12 (3 floats)
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality. -
view
public int viewThe mapped object view offset, in elements. Read/write. This is a virtual field, used as a convenient getter/setter for .
-
-
Constructor Details
-
MappedObject
protected MappedObject()
-
-
Method Details
-
getViewAddress
protected final long getViewAddress(int view) -
setViewAddress
public final void setViewAddress(long address) -
getAlign
public final int getAlign()Returns the mapped object memory alignment, in bytes.- Returns:
- the memory alignment
-
getSizeof
public final int getSizeof()Returns the mapped object memory sizeof, in bytes.- Returns:
- the sizeof value
-
capacity
public final int capacity()Returns the number of mapped objects that fit in the mapped buffer.- Returns:
- the mapped object capacity
-
map
Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer. The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.map(buffer)
will return a mapped Vec2 instance.
Vec3.map(buffer)
will return a mapped Vec3 instance.
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality. -
map
Creates a MappedObject instance, mapping the memory region specified. This is useful for mapping arbitrary regions in memory, e.g. OpenCL CLMem objects, without creating a ByteBuffer first. The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.map(buffer)
will return a mapped Vec2 instance.
Vec3.map(buffer)
will return a mapped Vec3 instance.
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality. -
malloc
Creates a MappedObject instance, mapping the memory region of an allocated direct ByteBuffer with a capacity ofelementCount*SIZEOF
The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.malloc(int)
will return a mapped Vec2 instance.
Vec3.malloc(int)
will return a mapped Vec3 instance.
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality. -
dup
Creates an identical new MappedObject instance, comparable to the contract ofByteBuffer.duplicate()
. This is useful when more than one views of the mapped object are required at the same time, e.g. in multithreaded access. -
slice
Creates a new MappedObject instance, with a base offset equal to the offset of the current view, comparable to the contract ofByteBuffer.slice()
. -
runViewConstructor
public final void runViewConstructor()Any code in the default constructor will not run automatically. This method can be used to execute that code on the current view. -
next
public final void next()Moves the current view to the next element. -
copyTo
Copies and amount ofSIZEOF - padding
bytes, from the current mapped object, to the specified mapped object. -
copyRange
Copies and amount ofSIZEOF * instances
bytes, from the current mapped object, to the specified mapped object. Note that this includes any padding bytes that are part of SIZEOF. -
foreach
Creates anIterable
that will step through capacity()
views, leaving theview
at the last valid value.
For convenience you are encouraged to static-import this specific method:import static org.lwjgl.util.mapped.MappedObject.foreach;
-
foreach
Creates anIterable
that will step through elementCount
views, leaving theview
at the last valid value.
For convenience you are encouraged to static-import this specific method:import static org.lwjgl.util.mapped.MappedObject.foreach;
-
asArray
-
backingByteBuffer
Returns theByteBuffer
that backs this mapped object.- Returns:
- the backing buffer
-