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
FieldsModifier and TypeFieldDescriptionprotected ColorDefault flat color for the complete geometryprotected int[]protected intnumber of channels per color, 3 for {r,g,b}, 4 for {r,g,b,a}protected FloatBufferThe (direct) float buffer storing colors in GPU.protected booleanprotected booleanprotected int[]protected IntBufferThe (non-mandatory) int buffer storing geometry indices in GPU.protected IntBufferThe (non-mandatory) int buffer storing geometry indices in GPU.protected com.jogamp.common.nio.PointerBufferprotected intNumber of element (geometries) in the element buffer.protected IntBufferprotected IntBufferThe (non-mandatory) int buffer storing geometry indices in GPU.protected intprotected static intnumber of vertext per geometry, 3 for triangles, 4 for quadsprotected intstore the Geometry type in OpenGL, GL_TRIANGLES, GL_POLYGONS, etcprotected booleanprotected booleanprotected booleanprotected IGLLoader<DrawableVBO2>protected static org.apache.logging.log4j.Loggerprotected int[]protected Normal.NormalModeShould be true AND the element array provided to be able to process averaged normal.protected intByte shift between to access a vertice normal in the vertex buffer.protected FloatBufferThe (direct) float buffer storing normals in GPU.static intPrimitive restart is NOT working for now.protected booleanprotected static intprotected static intstatic intnumber of dimensions for vertex, 3 for {x,y,z}protected int[]protected intByte shift between two vertices in the vertex buffer.protected FloatBufferThe (direct) float buffer storing vertices in GPU.protected intnumber 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, wireframeWithLineLoopFields inherited from class org.jzy3d.plot3d.primitives.Drawable
bbox, boundingBoxColor, boundingBoxDisplayed, displayed, hasListeners, legend, legendDisplayed, listeners, spaceTransformer, transform, transformBefore -
Constructor Summary
ConstructorsConstructorDescriptionDrawableVBO2(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 TypeMethodDescriptionvoidapplyGeometryTransform(Transform transform) protected voidapplyPrimitiveRestartIfEnabled(com.jogamp.opengl.GL gl) Experimental - not working yet How it should workprotected voidprotected voidprotected voiddoDrawElements(IPainter painter) Perform rendering of this VBO.protected voiddoDrawGeometries(com.jogamp.opengl.GL2 gl2) Actually do draw by applying the GL geometry defined byglGeometryType.voidCall OpenGL2 routines for rendering the object.static DrawableVBO2fromComposites(List<Composite> composites) Build a VBO out of a list of composites made of simple polygons.getColor()int[]intint[]com.jogamp.common.nio.PointerBufferprotected com.jogamp.opengl.GLintint[]int[]intbooleanReturn true if mount(...) has been called at least one timebooleanbooleanbooleanbooleanKept 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 VBOBufferLoaderForPolygonsmakeLoader(List<Polygon> polygons, int verticesPerGeometry) voidInvoke the loader.protected voidregisterColors(com.jogamp.opengl.GL gl, FloatBuffer newColors) protected voidregisterElements(com.jogamp.opengl.GL gl, IntBuffer newElements) protected voidregisterNormals(com.jogamp.opengl.GL gl, FloatBuffer newNormals) protected voidprotected voidregisterVertices(com.jogamp.opengl.GL gl, FloatBuffer newVertices) voidvoidsetColorChannels(int colorChannels) voidsetColors(float[] colors) Set the next color buffer to apply to this VBO.voidsetComputeNormals(boolean computeNormals) If false, normals are not computed and light processing might depend on GPU capabilitiesvoidsetData(IPainter painter, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) voidsetData(IPainter painter, IntBuffer elementsCount, com.jogamp.common.nio.PointerBuffer elementsIndices, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) voidsetData(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.voidsetData(IPainter painter, IntBuffer elementsStarts, IntBuffer elementsLength, FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors, BoundingBox3d bounds) voidsetGLGeometryType(int glGeometryType) voidsetHasColorBuffer(boolean hasColorBuffer) voidsetHasNormalInVertexArray(boolean hasNormal) voidsetPrimitiveRestart(boolean primitiveRestart) Kept for prototyping, but not supported for now.voidsetVerticesPerGeometry(int geometrySize) voidMethods 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, setWireframeWidthMethods 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 thepointsarray 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 byGraphwhen the application initialize and aGLcontext is available for feeding the GPU with arrays.- Specified by:
mountin interfaceIGLBindedResource
-
hasMountedOnce
public boolean hasMountedOnce()Description copied from interface:IGLBindedResourceReturn true if mount(...) has been called at least one time- Specified by:
hasMountedOncein 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 theIGLLoaderwhenmount(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:DrawableCall OpenGL2 routines for rendering the object.- Specified by:
drawin interfaceIGLRenderer- Specified by:
drawin 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:
applyGeometryTransformin classDrawable
-
updateBounds
public void updateBounds()- Specified by:
updateBoundsin 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()
-