@ThreadSafe
public class JOGLGeometry
extends javax.media.j3d.Geometry
A container for OpenGL geometry.
This class implements Java3D GeometryArray
-like functionality for
standard OpenGL interleaved geometry. It extends the Java3D Geometry
class and may be present in Java3D scenegraphs, and though the
Java3D renderers do not know about it, the renderer in JOGLDisplay
does. In fact, JOGLDisplay
is best-optimized
for JOGLGeometry
; existing Java3D GeometryArray
data
(e.g. as returned from Java3D loaders) can be converted to JOGLGeometry
via extract(javax.media.j3d.GeometryArray, int, java.io.PrintStream)
.
This class is designed to be thread-safe. All state is either final or internally synchronized.
JOGLGeometry.Format
sCopyright (C) 2008 Marsette A. Vona, III
Modifier and Type | Class and Description |
---|---|
static class |
JOGLGeometry.Format
The supported set of OpenGL interleaved vertex formats.
|
Modifier and Type | Field and Description |
---|---|
static int |
ALL_BUT_COLOR
Convenient bitmasks for
extract(GeometryArray, int,
PrintStream) . |
static int |
ALL_BUT_NORMAL
Convenient bitmasks for
extract(GeometryArray, int,
PrintStream) . |
static int |
ALL_BUT_TEXCOORD
Convenient bitmasks for
extract(GeometryArray, int,
PrintStream) . |
protected int[] |
arrayCount
Array holding the array (or strip) lengths for this geometry.
|
protected java.nio.IntBuffer |
countBuffer
Temp storage for passing data to OpenGL.
|
private static java.lang.String |
cvsid |
protected java.nio.IntBuffer |
firstBuffer
Temp storage for passing data to OpenGL.
|
JOGLGeometry.Format |
format
The vertex format for this geometry.
|
protected java.nio.IntBuffer |
indexBuffer
Buffer holding the index data for this geometry, if any.
|
protected com.jogamp.common.nio.PointerBuffer |
indexBufferArray
Temp storage for passing data to OpenGL.
|
static int |
INITIAL_CAPACITY
initial capacity for resizable buffers
|
static java.util.Map<java.lang.Class,java.lang.Integer> |
j3dTypeToGLMode
Unmodifiable mapping from Java3D
GeometryArray type to OpenGL
drawing mode. |
int |
mode
OpenGL drawing mode for this geometry.
|
protected int |
numArrays
Number of arrays (or strips) in this geometry.
|
protected java.nio.FloatBuffer |
vertexBuffer
Buffer holding the interleaved vertex data for this geometry, if
any.
|
int |
vertsPerPrim
Number of vertices per primitive for this geometry.
|
int |
vertsPerStripPrim
For stripped geometry, this is the number of vertices in each prim in a
strip after the first.
|
Constructor and Description |
---|
JOGLGeometry(int mode,
JOGLGeometry.Format format,
int numVertices)
makes a new empty geometry, not indexed, one array
|
JOGLGeometry(int mode,
JOGLGeometry.Format format,
int numVertices,
int numArrays)
makes a new empty geometry, not indexed
|
JOGLGeometry(int mode,
JOGLGeometry.Format format,
int numVertices,
int numIndices,
int numArrays)
Makes a new empty geometry.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(javax.media.opengl.GL2 gl)
draw(GL2, boolean) , with low-level drawing always enabled |
void |
draw(javax.media.opengl.GL2 gl,
boolean glDrawingEnabled)
Draw this geometry.
|
void |
dump()
dump(PrintStream) , to System.out |
void |
dump(java.io.PrintStream s)
dump(String, PrintStream) , prefixed by the class name |
void |
dump(java.lang.String prefix,
java.io.PrintStream s)
dump format data for this geometry
|
void |
dumpVertices()
dumpVertices(String, boolean, PrintStream) , no prefix,
unindex, to System.out. |
void |
dumpVertices(boolean unindex,
java.io.PrintStream s)
dumpVertices(String, boolean, PrintStream) , no prefix |
void |
dumpVertices(java.io.PrintStream s)
dumpVertices(String, boolean, PrintStream) , no prefix,
unindex. |
void |
dumpVertices(java.lang.String prefix,
boolean unindex,
java.io.PrintStream s)
dump vertex data for this geometry
|
static JOGLGeometry |
extract(javax.media.j3d.GeometryArray geometryArray)
Covers
extract(GeometryArray, int, PrintStream) , no error
stream, extract all vertex components. |
static JOGLGeometry |
extract(javax.media.j3d.GeometryArray geometryArray,
int formatMask)
Covers
extract(GeometryArray, int, PrintStream) , no error
stream. |
static JOGLGeometry |
extract(javax.media.j3d.GeometryArray geometryArray,
int j3dFormatMask,
java.io.PrintStream errorStream)
Extract the data from an existing Java3D
GeometryArray into a
new JOGLGeometry . |
int[] |
getArrayCountArray()
Get a ref to the
arrayCount array. |
int |
getCount(int countIndex)
convenience synchronized accessor to
arrayCount array |
java.nio.IntBuffer |
getIndexBuffer()
Get a ref to the
indexBuffer . |
int |
getNumArrays()
get
numArrays |
int |
getNumEnabledArrays()
Get the number of enabled arrays.
|
int |
getNumEnabledVertices()
Get the total number of enabled vertices in this geometry.
|
int |
getNumIndices()
get the capacity of the index buffer (0 if not indexed)
|
int |
getNumValidVertices()
Get the total number of valid vertices in this geometry.
|
int |
getNumVertices()
get the capacity of the vertex buffer
|
java.nio.FloatBuffer |
getVertexBuffer()
Get a ref to the
vertexBuffer . |
boolean |
hasAlpha()
check if this geometry has any alpha component
|
boolean |
hasColors()
check if this geometry has any color components
|
boolean |
isIndexed()
check whether this geometry is indexed
|
static JOGLGeometry.Format |
j3dFormatToJOGLFormat(int j3dFormat)
map a Java3D vertex format to a
JOGLGeometry.Format |
static java.lang.Integer |
j3dTypeToGLMode(java.lang.Class type)
map a Java3D
GeometryArray type to an OpenGL drawing mode |
int |
numPrims()
Compute the total number of primitives in this geometry.
|
void |
resizeCountArray(int newSize)
Resize the
arrayCount array. |
void |
resizeIndexBuffer(int newSize)
J3DUtils.resizeBuffer(IntBuffer, int) the index buffer. |
void |
resizeVertexBuffer(int newSize)
J3DUtils.resizeBuffer(FloatBuffer, int) the vertex buffer. |
void |
scaleGeometry(float scale)
Apply a scale factor to the coordinates of all valid vertices.
|
void |
setCount(int countIndex,
int count)
convenience synchronized accessor to
arrayCount array |
void |
setNumArrays(int numArrays)
Set
numArrays . |
static java.lang.String |
textGLMode(int mode)
map an OpenGL drawing mode to the corresponding string
|
static int |
vertsPerPrim(int mode)
Get the number of vertices per (full) primitive for the given OpenGL
drawing mode.
|
static int |
vertsPerStripPrim(int mode)
Get the number of vertices per primitive after the first in a strip for
the given OpenGL drawing mode.
|
cloneNodeComponent, cloneNodeComponent, duplicateNodeComponent, duplicateNodeComponent, getDuplicateOnCloneTree, setDuplicateOnCloneTree
clearCapability, clearCapabilityIsFrequent, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getName, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setName, setUserData, toString, updateNodeReferences
private static final java.lang.String cvsid
public static final int INITIAL_CAPACITY
public static final int ALL_BUT_COLOR
Convenient bitmasks for extract(GeometryArray, int,
PrintStream)
.
public static final int ALL_BUT_NORMAL
Convenient bitmasks for extract(GeometryArray, int,
PrintStream)
.
public static final int ALL_BUT_TEXCOORD
Convenient bitmasks for extract(GeometryArray, int,
PrintStream)
.
public static final java.util.Map<java.lang.Class,java.lang.Integer> j3dTypeToGLMode
Unmodifiable mapping from Java3D GeometryArray
type to OpenGL
drawing mode.
Used by j3dTypeToGLMode(Class)
.
public final int mode
OpenGL drawing mode for this geometry.
One of
GL_POINTS
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP
*
GL_TRIANGLES
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
GL_POLYGON
*
GL_QUADS
GL_QUADS_STRIP
*,
where modes marked with * have no corresponding Java3D type.
Also see j3dTypeToGLMode
.
public final int vertsPerPrim
Number of vertices per primitive for this geometry.
For stripped geometry, this is the number of vertices in the first prim in a strip.
public final int vertsPerStripPrim
For stripped geometry, this is the number of vertices in each prim in a strip after the first.
For un-stripped geometry, this equals vertsPerPrim
.
public final JOGLGeometry.Format format
The vertex format for this geometry.
A subset of the OpenGL interleaved vertex formats are allowed, see
JOGLGeometry.Format
.
Also see j3dFormatToJOGLFormat(int)
.
protected int numArrays
Number of arrays (or strips) in this geometry.
More precisely, this is the length of the initial part of the arrayCount
array that will be considered, though any non-positive counts
therein do not actually generate geometry.
protected java.nio.FloatBuffer vertexBuffer
Buffer holding the interleaved vertex data for this geometry, if any.
Both the size (see resizeVertexBuffer(int)
) and the existence (see
same) of this buffer are mutable.
Note that the capacity of the vertex buffer can be both greater and
less (in the case of indexed geometry) than getNumValidVertices()
.
protected java.nio.IntBuffer indexBuffer
Buffer holding the index data for this geometry, if any.
This geometry is indexed iff the index buffer is non-null (see isIndexed()
).
Both the size (see resizeIndexBuffer(int)
) and the existence (see
same) of this buffer are mutable.
protected int[] arrayCount
protected java.nio.IntBuffer countBuffer
Temp storage for passing data to OpenGL.
Confined to the thread that calls draw(GL2)
.
protected java.nio.IntBuffer firstBuffer
Temp storage for passing data to OpenGL.
Confined to the thread that calls draw(GL2)
.
protected com.jogamp.common.nio.PointerBuffer indexBufferArray
Temp storage for passing data to OpenGL.
Confined to the thread that calls draw(GL2)
.
public JOGLGeometry(int mode, JOGLGeometry.Format format, int numVertices, int numIndices, int numArrays)
Makes a new empty geometry.
mode
- the OpenGL drawing mode, see mode
(immutable)format
- the OpenGL vertex format, see format
(immutable)numVertices
- the initial capacity of vertexBuffer
(mutable)numIndices
- the initial capacity of indexBuffer
, or
negative if not indexed (mutable)numArrays
- the initial number of arrays (or strips) (mutable)public JOGLGeometry(int mode, JOGLGeometry.Format format, int numVertices, int numArrays)
public JOGLGeometry(int mode, JOGLGeometry.Format format, int numVertices)
public static JOGLGeometry extract(javax.media.j3d.GeometryArray geometryArray, int j3dFormatMask, java.io.PrintStream errorStream)
Extract the data from an existing Java3D GeometryArray
into a
new JOGLGeometry
.
The returned JOGLGeometry
will be indexed iff the passed
geometryArray is indexed. The geometry mode
and vertex
format
will correspond to the passed geometryArray.
j3dFormatMask
- bitmask of allowed J3D vertex format flags. Vertex
components that are masked will not be extracted.errorStream
- if not null then any warnings or errors are printed herepublic static JOGLGeometry extract(javax.media.j3d.GeometryArray geometryArray, int formatMask)
Covers extract(GeometryArray, int, PrintStream)
, no error
stream.
public static JOGLGeometry extract(javax.media.j3d.GeometryArray geometryArray)
Covers extract(GeometryArray, int, PrintStream)
, no error
stream, extract all vertex components.
public static int vertsPerPrim(int mode)
Get the number of vertices per (full) primitive for the given OpenGL drawing mode.
GL_POLYGON
is treated the same as GL_TRIANGLE_FAN
.
public static int vertsPerStripPrim(int mode)
Get the number of vertices per primitive after the first in a strip for the given OpenGL drawing mode.
GL_POLYGON
is treated the same as GL_TRIANGLE_FAN
.
public static java.lang.Integer j3dTypeToGLMode(java.lang.Class type)
GeometryArray
type to an OpenGL drawing modepublic static java.lang.String textGLMode(int mode)
public static JOGLGeometry.Format j3dFormatToJOGLFormat(int j3dFormat)
JOGLGeometry.Format
public void dump(java.lang.String prefix, java.io.PrintStream s)
public void dump(java.io.PrintStream s)
dump(String, PrintStream)
, prefixed by the class namepublic void dump()
dump(PrintStream)
, to System.outpublic void dumpVertices(java.lang.String prefix, boolean unindex, java.io.PrintStream s)
public void dumpVertices(boolean unindex, java.io.PrintStream s)
dumpVertices(String, boolean, PrintStream)
, no prefixpublic void dumpVertices(java.io.PrintStream s)
dumpVertices(String, boolean, PrintStream)
, no prefix,
unindex.
public void dumpVertices()
dumpVertices(String, boolean, PrintStream)
, no prefix,
unindex, to System.out.
public int numPrims()
Compute the total number of primitives in this geometry.
The computation is based on getNumValidVertices()
and depends on
vertsPerPrim
, vertsPerStripPrim
, numArrays
, and
whether the geometry is an OpenGL GL_LINE_LOOP
, which has an extra
implied loop-closure.
GL_POLYGON
is treated the same as GL_TRIANGLE_FAN
.
public int getNumArrays()
numArrays
public int getNumEnabledArrays()
Get the number of enabled arrays.
This may be less than numArrays
because arrays with
non-positive arrayCount
are considered disabled.
public void setNumArrays(int numArrays)
Set numArrays
.
If numArrays is greater than the current capacity of arrayCount
then the capacity will be doubled until it is greater than or
equal to the requested numArrays.
public boolean hasColors()
public boolean hasAlpha()
public int getNumVertices()
public int getNumIndices()
public int getNumValidVertices()
Get the total number of valid vertices in this geometry.
This is not necessarily the same as the vertex buffer capacity as
returned by getNumVertices()
; rather it is the sum of the absolute
values of the first numArrays
arrayCount
s. The result
may be less than the vertex buffer capacity or it may be greater in the
case of indexed geometry.
public int getNumEnabledVertices()
Get the total number of enabled vertices in this geometry.
This is like getNumValidVertices()
but does not include vertices
in arrays with non-postive arrayCount
.
public boolean isIndexed()
public void resizeVertexBuffer(int newSize)
J3DUtils.resizeBuffer(FloatBuffer, int)
the vertex buffer.
newSize
- the new buffer capacity, or negative to free the vertex
bufferpublic void resizeIndexBuffer(int newSize)
J3DUtils.resizeBuffer(IntBuffer, int)
the index buffer.
newSize
- the new buffer capacity, or negative to go unindexedpublic void resizeCountArray(int newSize)
Resize the arrayCount
array.
The old contents are copied to the new array up to the length of the shorter of the two.
public java.nio.FloatBuffer getVertexBuffer()
Get a ref to the vertexBuffer
.
External access to the buffer contents can synchronize on this JOGLGeometry
for thread safety.
public java.nio.IntBuffer getIndexBuffer()
Get a ref to the indexBuffer
.
External access to the buffer contents can synchronize on this JOGLGeometry
for thread safety.
public int[] getArrayCountArray()
Get a ref to the arrayCount
array.
External access to the array contents can synchronize on this JOGLGeometry
for thread safety.
public void setCount(int countIndex, int count)
arrayCount
arraypublic int getCount(int countIndex)
arrayCount
arraypublic void draw(javax.media.opengl.GL2 gl, boolean glDrawingEnabled)
Draw this geometry.
The buffer position
s may be modified by this call.
Note that this call may return before the underlying OGL implementation
has finished accessing the buffers, so external code should not modify
them until a glFinish()
has been done.
gl
- the OGL context, if null then drawing is abortedglDrawingEnabled
- whether to enable or disable the lowest-level
drawing calls, can be useful in measuring overhead vs actual drawing timepublic void draw(javax.media.opengl.GL2 gl)
draw(GL2, boolean)
, with low-level drawing always enabledpublic void scaleGeometry(float scale)
Apply a scale factor to the coordinates of all valid vertices.