Class DrawableVBO2
java.lang.Object
org.jzy3d.plot3d.primitives.Drawable
org.jzy3d.plot3d.primitives.Wireframeable
org.jzy3d.plot3d.primitives.vbo.drawable.DrawableVBO2
- All Implemented Interfaces:
IGLBindedResource
,IGLRenderer
,ISortableDraw
A
DrawableVBO2
is able to efficiently draw a large collection of geometries.
Effect of repeated vertices
Repeated vertices make all vertice normal being processed with the only three vertices of a
triangle. A collection of neighbour triangles hence have normals producing sharp light reaction
as bellow.
Shared vertices between triangles based on element index
Sharing vertices among triangles avoid repeating data, and also allows knowing all surrounding
triangles to a point, hence allowing to compute a normal based on the mean of all triangles
normal. This produce a smooth light reaction at the triangle edges.
Not processing normals in java
Is faster and yield to this light reaction.
Using a colormap
Initializing DrawableVBO2
AWTChartFactory f = new AWTChartFactory();
Chart chart = f.newChart(Quality.Intermediate());
int dimensions = TestMesh.DIMENSIONS;
double[] vertices = TestMesh.makeArray4();
int[] elements = TestMesh.makeElementArray4();
int nVertices = TestMesh.nVertices(vertices);
DrawableVBO2 vbo = new DrawableVBO2(vertices, dimensions, elements, null);
chart.add(vbo);
chart.open();
-
Field Summary
Modifier and TypeFieldDescriptionprotected Color
Default flat color for the complete geometryprotected int[]
protected int
number of channels per color, 3 for {r,g,b}, 4 for {r,g,b,a}protected FloatBuffer
The (direct) float buffer storing colors in GPU.protected boolean
protected boolean
protected int[]
protected IntBuffer
The (non-mandatory) int buffer storing geometry indices in GPU.protected IntBuffer
The (non-mandatory) int buffer storing geometry indices in GPU.protected com.jogamp.common.nio.PointerBuffer
protected int
Number of element (geometries) in the element buffer.protected IntBuffer
protected IntBuffer
The (non-mandatory) int buffer storing geometry indices in GPU.protected int
protected static int
number of vertext per geometry, 3 for triangles, 4 for quadsprotected int
store the Geometry type in OpenGL, GL_TRIANGLES, GL_POLYGONS, etcprotected boolean
protected boolean
protected boolean
protected IGLLoader<DrawableVBO2>
protected static org.apache.logging.log4j.Logger
protected int[]
protected Normal.NormalMode
Should be true AND the element array provided to be able to process averaged normal.protected int
Byte shift between to access a vertice normal in the vertex buffer.protected FloatBuffer
The (direct) float buffer storing normals in GPU.static int
Primitive restart is NOT working for now.protected boolean
protected static int
protected static int
static int
number of dimensions for vertex, 3 for {x,y,z}protected int[]
protected int
Byte shift between two vertices in the vertex buffer.protected FloatBuffer
The (direct) float buffer storing vertices in GPU.protected int
number of vertex per geometryFields inherited from class org.jzy3d.plot3d.primitives.Wireframeable
depthFunctionChangeForWireframe, faceDisplayed, materialAmbiantReflection, materialDiffuseReflection, materialEmission, materialShininess, materialSpecularReflection, NO_OVERLAP_DEPTH_RATIO, polygonOffsetFactor, polygonOffsetFillEnable, polygonOffsetUnit, polygonWireframeDepthTrick, reflectLight, wireframeColor, wireframeColorFromPolygonPoints, wireframeDisplayed, wireframeWidth, wireframeWithLineLoop
Fields inherited from class org.jzy3d.plot3d.primitives.Drawable
bbox, boundingBoxColor, boundingBoxDisplayed, displayed, hasListeners, legend, legendDisplayed, listeners, spaceTransformer, transform, transformBefore
-
Constructor Summary
ConstructorDescriptionDrawableVBO2
(float[] points, int pointDimensions) Initialize a VBO object with arrays with no colormap and no vertex sharing scheme.DrawableVBO2
(float[] points, int[][] elementIndices, float[] colors) DrawableVBO2
(float[] points, int[][] elementIndices, float[] colors, float[] normals) DrawableVBO2
(float[] points, int[][] elementIndices, float[] colors, Normal.NormalMode normalMode) DrawableVBO2
(float[] points, int[] elementStart, int[] elementLength, float[] colors) DrawableVBO2
(float[] points, int[] elements, int elementSize, float[] colors) DrawableVBO2
(float[] points, int pointDimensions, int[] elements) Initialize a VBO object with arrays with no colormap.DrawableVBO2
(float[] points, int pointDimensions, int[][] elementIndices, float[] colors) DrawableVBO2
(float[] points, int pointDimensions, int[] elementStart, int[] elementLength, float[] colors) DrawableVBO2
(float[] points, int pointDimensions, int[] elements, int elementSize, float[] colors) This constructor will only work correctly for triangle geometry.DrawableVBO2
(float[] points, int pointDimensions, int[] elements, IColorMap colormap) Initialize a VBO object with arrays with the following content.DrawableVBO2
(float[] points, int pointDimensions, int[] elements, IColorMap colormap, Normal.NormalMode normalMode) DrawableVBO2
(float[] points, int pointDimensions, IColorMap colormap) Initialize a VBO object with arrays with a colormap but no vertex sharing scheme.DrawableVBO2
(List<Polygon> polygons) Build a VBO out of simple polygons.DrawableVBO2
(IGLLoader<DrawableVBO2> loader) Initialize a VBO object with a customizable loader.DrawableVBO2
(Composite composite) Build a VBO out of a composite made of simple polygons. -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyGeometryTransform
(Transform transform) protected void
applyPrimitiveRestartIfEnabled
(com.jogamp.opengl.GL gl) Experimental - not working yet How it should workprotected void
protected void
protected void
doDrawElements
(IPainter painter) Perform rendering of this VBO.protected void
doDrawGeometries
(com.jogamp.opengl.GL2 gl2) Actually do draw by applying the GL geometry defined byglGeometryType
.void
Call OpenGL2 routines for rendering the object.static DrawableVBO2
fromComposites
(List<Composite> composites) Build a VBO out of a list of composites made of simple polygons.getColor()
int[]
int
int[]
com.jogamp.common.nio.PointerBuffer
protected com.jogamp.opengl.GL
int
int[]
int[]
int
boolean
Return true if mount(...) has been called at least one timeboolean
boolean
boolean
boolean
Kept for prototyping, but not supported for nowstatic IGLLoader<DrawableVBO2>
makeLoader
(float[] points, int elementSize) static IGLLoader<DrawableVBO2>
makeLoader
(float[] points, int pointDimensions, int[][] elementIndices, float[] colors, float[] normals) static IGLLoader<DrawableVBO2>
makeLoader
(float[] points, int pointDimensions, int[][] elementIndices, float[] colors, Normal.NormalMode perVertex) static IGLLoader<DrawableVBO2>
makeLoader
(float[] points, int pointDimensions, int[] elementStart, int[] elementLength, float[] coloring, Normal.NormalMode normalMode) static IGLLoader<DrawableVBO2>
makeLoader
(float[] points, int pointDimensions, int[] elements, int elementSize, IColorMap colormap, float[] coloring, Normal.NormalMode normalMode) static VBOBufferLoaderForPolygons
makeLoader
(List<Polygon> polygons, int verticesPerGeometry) void
Invoke the loader.protected void
registerColors
(com.jogamp.opengl.GL gl, FloatBuffer newColors) protected void
registerElements
(com.jogamp.opengl.GL gl, IntBuffer newElements) protected void
registerNormals
(com.jogamp.opengl.GL gl, FloatBuffer newNormals) protected void
protected void
registerVertices
(com.jogamp.opengl.GL gl, FloatBuffer newVertices) void
void
setColorChannels
(int colorChannels) void
setColors
(float[] colors) Set the next color buffer to apply to this VBO.void
setComputeNormals
(boolean computeNormals) If false, normals are not computed and light processing might depend on GPU capabilitiesvoid
setData
(IPainter painter, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) void
setData
(IPainter painter, IntBuffer elementsCount, com.jogamp.common.nio.PointerBuffer elementsIndices, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) void
setData
(IPainter painter, IntBuffer elements, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) Configure a VBO with vertices, colors, and indices describing vertex references for building triangles.void
setData
(IPainter painter, IntBuffer elementsStarts, IntBuffer elementsLength, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) void
setGLGeometryType
(int glGeometryType) void
setHasColorBuffer
(boolean hasColorBuffer) void
setHasNormalInVertexArray
(boolean hasNormal) void
setPrimitiveRestart
(boolean primitiveRestart) Kept for prototyping, but not supported for now.void
setVerticesPerGeometry
(int geometrySize) void
Methods inherited from class org.jzy3d.plot3d.primitives.Wireframeable
applyDepthRangeDefault, applyDepthRangeForOverlying, applyDepthRangeForUnderlying, applyMaterial, doDrawBoundsIfDisplayed, getMaterialAmbiantReflection, getMaterialDiffuseReflection, getMaterialEmission, getMaterialShininess, getMaterialSpecularReflection, getPolygonOffsetFactor, getPolygonOffsetUnit, getWireframeColor, getWireframeWidth, isFaceDisplayed, isPolygonOffsetFillEnable, isPolygonWireframeDepthTrick, isReflectLight, isWireframeColorFromPolygonPoints, isWireframeDisplayed, polygonOffsetFillDisable, polygonOffsetFillEnable, polygonOffsetLineDisable, polygonOffsetLineEnable, setFaceDisplayed, setMaterialAmbiantReflection, setMaterialDiffuseReflection, setMaterialEmission, setMaterialShininess, setMaterialSpecularReflection, setPolygonOffsetFactor, setPolygonOffsetFillEnable, setPolygonOffsetUnit, setPolygonWireframeDepthTrick, setReflectLight, setWireframeColor, setWireframeColorFromPolygonPoints, setWireframeDisplayed, setWireframeWidth
Methods inherited from class org.jzy3d.plot3d.primitives.Drawable
addDrawableListener, asWireframeable, dispose, doTransform, fireDrawableChanged, fireDrawableChanged, getBarycentre, getBoundingBoxColor, getBounds, getDistance, getLegend, getLongestDistance, getShortestDistance, getSpaceTransformer, getTransform, getTransformBefore, hasLegend, isBoundingBoxDisplayed, isDisplayed, isLegendDisplayed, removeDrawableListener, setBoundingBoxColor, setBoundingBoxDisplayed, setDisplayed, setLegend, setLegendDisplayed, setSpaceTransformer, setTransform, setTransformBefore, toString, toString
-
Field Details
-
log
protected static org.apache.logging.log4j.Logger log -
PRIMITIVE_RESTART_VALUE
public static int PRIMITIVE_RESTART_VALUEPrimitive restart is NOT working for now. Kept here for further debugging https://forum.jogamp.org/Using-glPrimitiveRestartIndex-to-declare-multiple-geometries-in-the-same-VBO-td4041307.html -
loader
-
hasNormalInVertexArray
protected boolean hasNormalInVertexArray -
primitiveRestart
protected boolean primitiveRestart -
debug
protected boolean debug -
computeNormals
protected boolean computeNormals -
vertices
The (direct) float buffer storing vertices in GPU. If none of the non mandatory element buffer are defined, will render withinvalid @link
GL#glDrawArrays()
-
normals
The (direct) float buffer storing normals in GPU. -
colors
The (direct) float buffer storing colors in GPU. -
elements
The (non-mandatory) int buffer storing geometry indices in GPU. If defined, will render withinvalid @link
GL#glDrawElements()
-
elementsStarts
The (non-mandatory) int buffer storing geometry indices in GPU. If defined, will render withinvalid @link
GL#glMultiDrawArrays
-
elementsLength
-
elementsCount
The (non-mandatory) int buffer storing geometry indices in GPU. If defined, will render withinvalid @link
GL#glMultiDrawElements
-
elementsIndices
protected com.jogamp.common.nio.PointerBuffer elementsIndices -
vertexOffset
protected int vertexOffsetByte shift between two vertices in the vertex buffer. -
normalOffset
protected int normalOffsetByte shift between to access a vertice normal in the vertex buffer. -
elementSize
protected int elementSizeNumber of element (geometries) in the element buffer. -
firstCoordOffset
protected int firstCoordOffset -
colorArrayIds
protected int[] colorArrayIds -
vertexArrayIds
protected int[] vertexArrayIds -
normalArrayIds
protected int[] normalArrayIds -
elementArrayIds
protected int[] elementArrayIds -
hasMountedOnce
protected boolean hasMountedOnce -
QUAD_SIZE
protected static int QUAD_SIZE -
TRIANGLE_SIZE
protected static int TRIANGLE_SIZE -
GEOMETRY_SIZE
protected static int GEOMETRY_SIZEnumber of vertext per geometry, 3 for triangles, 4 for quads -
VERTEX_DIMENSIONS
public static int VERTEX_DIMENSIONSnumber of dimensions for vertex, 3 for {x,y,z} -
verticesPerGeometry
protected int verticesPerGeometrynumber of vertex per geometry -
colorChannels
protected int colorChannelsnumber of channels per color, 3 for {r,g,b}, 4 for {r,g,b,a} -
glGeometryType
protected int glGeometryTypestore the Geometry type in OpenGL, GL_TRIANGLES, GL_POLYGONS, etc -
hasColorBuffer
protected boolean hasColorBuffer -
color
Default flat color for the complete geometry -
normalMode
Should be true AND the element array provided to be able to process averaged normal. If any of these two conditions is not fullfilled, then one normal per point is computed.
-
-
Constructor Details
-
DrawableVBO2
public DrawableVBO2(float[] points, int pointDimensions) Initialize a VBO object with arrays with no colormap and no vertex sharing scheme. The object has a uniform color given bysetColor(Color)
. When using aLight
, the object will have edges looking sharp as shown on the picture below. One can obtain smoother edges by avoiding vertex repetitions and instead define an element array indicating which unique vertex should be used in each triangle. Seeinvalid @link
{@link DrawableVBO2(double[], int, int[]).
- See Also:
-
-
invalid @see
constructor for detailed arguments.
-
-
DrawableVBO2
Initialize a VBO object with arrays with a colormap but no vertex sharing scheme.
- See Also:
-
-
invalid @see
constructor for detailed arguments.
-
-
DrawableVBO2
Initialize a VBO object with arrays with the following content.- Parameters:
points
- contains an array of vertices[x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, ..]
pointDimensions
- indicate the number of dimension in the array for each vertex, as the input array may contain extra dimensions for each vertex, e.g. [x1, y1, z1, m1, x2, y2, z2, m2, ...]elements
- contains reference to points that may be used in several elements. E.g. the array[1, 3, 2, 4, 3, 2, ...]
indicates that the two first triangles are sharing vertices 3 and 2. This assume the user of this class is aware that this class will build triangles made of 3 vertices each. It may be null, in that case thepoints
array will be drawn as a sequence of vertices defining elements, without sharing vertices between elements.colormap
- defines how to color vertices. It may be null, in that case the object is colored bysetColor(Color)
adn shaded byLight
-
DrawableVBO2
public DrawableVBO2(float[] points, int pointDimensions, int[] elements) Initialize a VBO object with arrays with no colormap. The object has a uniform color given bysetColor(Color)
. Providing an element array allows defining which points form a triangle without having to repeat these points. When such constructor is used, shared vertices allow computing shared normals for each point, hence each point normal is computed as a mean of the normals of all triangles that share this point. The result is smoother light transition between polygons, which differ from the light transition of repeated-vertex schemes as processed when the element array is null (or when invokinginvalid @link
DrawableVBO2(double[], int)
- See Also:
-
-
invalid @see
constructor for detailed arguments.
-
-
DrawableVBO2
public DrawableVBO2(float[] points, int pointDimensions, int[] elements, IColorMap colormap, Normal.NormalMode normalMode) -
DrawableVBO2
public DrawableVBO2(float[] points, int pointDimensions, int[] elements, int elementSize, float[] colors) This constructor will only work correctly for triangle geometry. The elementSize parameter is mainly used for processing normals. If one wish to draw multiple polygons of 4 or more point, then use a loader suitable for this.- Parameters:
points
-pointDimensions
-elements
-elementSize
-colors
-
-
DrawableVBO2
public DrawableVBO2(float[] points, int[] elements, int elementSize, float[] colors) -
DrawableVBO2
public DrawableVBO2(float[] points, int[] elementStart, int[] elementLength, float[] colors) -
DrawableVBO2
public DrawableVBO2(float[] points, int pointDimensions, int[] elementStart, int[] elementLength, float[] colors) -
DrawableVBO2
Build a VBO out of simple polygons. Assume the same number of vertices for all polygons given the list. -
DrawableVBO2
Build a VBO out of a composite made of simple polygons. Assume the same number of vertices for all polygons given the list. -
DrawableVBO2
public DrawableVBO2(float[] points, int[][] elementIndices, float[] colors) -
DrawableVBO2
public DrawableVBO2(float[] points, int[][] elementIndices, float[] colors, float[] normals) -
DrawableVBO2
public DrawableVBO2(float[] points, int[][] elementIndices, float[] colors, Normal.NormalMode normalMode) -
DrawableVBO2
public DrawableVBO2(float[] points, int pointDimensions, int[][] elementIndices, float[] colors) -
DrawableVBO2
Initialize a VBO object with a customizable loader.
-
-
Method Details
-
fromComposites
Build a VBO out of a list of composites made of simple polygons. Assume the same number of vertices for all polygons given the list. -
makeLoader
public static VBOBufferLoaderForPolygons makeLoader(List<Polygon> polygons, int verticesPerGeometry) -
makeLoader
public static IGLLoader<DrawableVBO2> makeLoader(float[] points, int pointDimensions, int[][] elementIndices, float[] colors, Normal.NormalMode perVertex) -
makeLoader
public static IGLLoader<DrawableVBO2> makeLoader(float[] points, int pointDimensions, int[][] elementIndices, float[] colors, float[] normals) -
makeLoader
public static IGLLoader<DrawableVBO2> makeLoader(float[] points, int pointDimensions, int[] elements, int elementSize, IColorMap colormap, float[] coloring, Normal.NormalMode normalMode) -
makeLoader
-
makeLoader
public static IGLLoader<DrawableVBO2> makeLoader(float[] points, int pointDimensions, int[] elementStart, int[] elementLength, float[] coloring, Normal.NormalMode normalMode) -
mount
Invoke the loader. This is called byGraph
when the application initialize and aGL
context is available for feeding the GPU with arrays.- Specified by:
mount
in interfaceIGLBindedResource
-
hasMountedOnce
public boolean hasMountedOnce()Description copied from interface:IGLBindedResource
Return true if mount(...) has been called at least one time- Specified by:
hasMountedOnce
in interfaceIGLBindedResource
-
setData
public void setData(IPainter painter, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) -
setData
public void setData(IPainter painter, IntBuffer elements, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) Configure a VBO with vertices, colors, and indices describing vertex references for building triangles. This is supposed to be called by theIGLLoader
whenmount(IPainter)
is invoked. The result is that all non null provided buffers are binded to the GPU.- See Also:
-
-
invalid @see
constructor documentation for argument description.
-
-
setData
public void setData(IPainter painter, IntBuffer elementsStarts, IntBuffer elementsLength, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) -
setData
public void setData(IPainter painter, IntBuffer elementsCount, com.jogamp.common.nio.PointerBuffer elementsIndices, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) -
registerVertexAndNormalOffsets
protected void registerVertexAndNormalOffsets() -
registerVertices
-
registerNormals
-
registerColors
-
registerElements
-
draw
Description copied from class:Drawable
Call OpenGL2 routines for rendering the object.- Specified by:
draw
in interfaceIGLRenderer
- Specified by:
draw
in classDrawable
-
doDrawElements
Perform rendering of this VBO.- Parameters:
painter
- holds a GL instance to invoke the GPU.
-
doDrawGeometries
protected void doDrawGeometries(com.jogamp.opengl.GL2 gl2) Actually do draw by applying the GL geometry defined byglGeometryType
. Either use non indexed mode, simple index mode, or multi-index mode. Expect glPolygonMode to be defined before to define if we are drawing wireframe or filling polygon. -
applyPrimitiveRestartIfEnabled
protected void applyPrimitiveRestartIfEnabled(com.jogamp.opengl.GL gl) Experimental - not working yet How it should work -
isHasColorBuffer
public boolean isHasColorBuffer() -
setHasColorBuffer
public void setHasColorBuffer(boolean hasColorBuffer) -
getColor
-
setColor
-
hasNormalInVertexArray
public boolean hasNormalInVertexArray() -
setHasNormalInVertexArray
public void setHasNormalInVertexArray(boolean hasNormal) -
getColorChannels
public int getColorChannels() -
setColorChannels
public void setColorChannels(int colorChannels) -
applyGeometryTransform
- Specified by:
applyGeometryTransform
in classDrawable
-
updateBounds
public void updateBounds()- Specified by:
updateBounds
in classDrawable
-
getGL
-
getVertices
-
getNormals
-
getColors
-
getElements
-
getElementsStarts
-
getElementsLength
-
getElementsCount
-
getElementsIndices
public com.jogamp.common.nio.PointerBuffer getElementsIndices() -
getColorArrayIds
public int[] getColorArrayIds() -
getVertexArrayIds
public int[] getVertexArrayIds() -
getNormalArrayIds
public int[] getNormalArrayIds() -
getElementArrayIds
public int[] getElementArrayIds() -
getGLGeometryType
public int getGLGeometryType() -
setGLGeometryType
public void setGLGeometryType(int glGeometryType) -
getVerticesPerGeometry
public int getVerticesPerGeometry() -
setVerticesPerGeometry
public void setVerticesPerGeometry(int geometrySize) -
isPrimitiveRestart
public boolean isPrimitiveRestart()Kept for prototyping, but not supported for now -
setPrimitiveRestart
public void setPrimitiveRestart(boolean primitiveRestart) Kept for prototyping, but not supported for now. Do not change this setting. @seeapplyPrimitiveRestartIfEnabled(GL)
-
isComputeNormals
public boolean isComputeNormals() -
setComputeNormals
public void setComputeNormals(boolean computeNormals) If false, normals are not computed and light processing might depend on GPU capabilities -
setColors
public void setColors(float[] colors) Set the next color buffer to apply to this VBO. The color will be updated at next rendering, which may be forced withChart.render()
. -
debugMultiDrawElements
protected void debugMultiDrawElements() -
debugMultiDrawArray
protected void debugMultiDrawArray()
-