Class DrawableVBO2

  • All Implemented Interfaces:
    IGLBindedResource, IGLRenderer, ISortableDraw

    public class DrawableVBO2
    extends Wireframeable
    implements IGLBindedResource
    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 Detail

      • log

        protected static org.apache.logging.log4j.Logger log
      • PRIMITIVE_RESTART_VALUE

        public static int PRIMITIVE_RESTART_VALUE
        Primitive 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
      • hasNormalInVertexArray

        protected boolean hasNormalInVertexArray
      • primitiveRestart

        protected boolean primitiveRestart
      • debug

        protected boolean debug
      • computeNormals

        protected boolean computeNormals
      • vertices

        protected FloatBuffer vertices
        The (direct) float buffer storing vertices in GPU. If none of the non mandatory element buffer are defined, will render with GL#glDrawArrays()
      • normals

        protected FloatBuffer normals
        The (direct) float buffer storing normals in GPU.
      • colors

        protected FloatBuffer colors
        The (direct) float buffer storing colors in GPU.
      • elements

        protected IntBuffer elements
        The (non-mandatory) int buffer storing geometry indices in GPU. If defined, will render with GL#glDrawElements()
      • elementsStarts

        protected IntBuffer elementsStarts
        The (non-mandatory) int buffer storing geometry indices in GPU. If defined, will render with GL#glMultiDrawArrays
      • elementsLength

        protected IntBuffer elementsLength
      • elementsCount

        protected IntBuffer elementsCount
        The (non-mandatory) int buffer storing geometry indices in GPU. If defined, will render with GL#glMultiDrawElements
      • elementsIndices

        protected com.jogamp.common.nio.PointerBuffer elementsIndices
      • vertexOffset

        protected int vertexOffset
        Byte shift between two vertices in the vertex buffer.
      • normalOffset

        protected int normalOffset
        Byte shift between to access a vertice normal in the vertex buffer.
      • elementSize

        protected int elementSize
        Number 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_SIZE
        number of vertext per geometry, 3 for triangles, 4 for quads
      • VERTEX_DIMENSIONS

        public static int VERTEX_DIMENSIONS
        number of dimensions for vertex, 3 for {x,y,z}
      • verticesPerGeometry

        protected int verticesPerGeometry
        number of vertex per geometry
      • colorChannels

        protected int colorChannels
        number of channels per color, 3 for {r,g,b}, 4 for {r,g,b,a}
      • glGeometryType

        protected int glGeometryType
        store the Geometry type in OpenGL, GL_TRIANGLES, GL_POLYGONS, etc
      • hasColorBuffer

        protected boolean hasColorBuffer
      • color

        protected Color color
        Default flat color for the complete geometry
      • normalMode

        protected Normal.NormalMode 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 Detail

      • 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 by setColor(Color). When using a Light, 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. See {@link DrawableVBO2(double[], int, int[]).
        See Also:
        constructor for detailed arguments.
      • DrawableVBO2

        public DrawableVBO2​(float[] points,
                            int pointDimensions,
                            IColorMap colormap)
        Initialize a VBO object with arrays with a colormap but no vertex sharing scheme.
        See Also:
        constructor for detailed arguments.
      • DrawableVBO2

        public DrawableVBO2​(float[] points,
                            int pointDimensions,
                            int[] elements,
                            IColorMap colormap)
        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 the points 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 by setColor(Color) adn shaded by Light
      • 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 by setColor(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 invoking DrawableVBO2(double[], int)
        See Also:
        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

        public DrawableVBO2​(List<Polygon> polygons)
        Build a VBO out of simple polygons. Assume the same number of vertices for all polygons given the list.
      • DrawableVBO2

        public DrawableVBO2​(Composite composite)
        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

        public DrawableVBO2​(IGLLoader<DrawableVBO2> loader)
        Initialize a VBO object with a customizable loader.
    • Method Detail

      • fromComposites

        public static DrawableVBO2 fromComposites​(List<Composite> composites)
        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 IGLLoader<DrawableVBO2> makeLoader​(float[] points,
                                                         int pointDimensions,
                                                         int[][] elementIndices,
                                                         float[] colors,
                                                         float[] normals)
      • makeLoader

        public static IGLLoader<DrawableVBO2> makeLoader​(float[] points,
                                                         int pointDimensions,
                                                         int[] elementStart,
                                                         int[] elementLength,
                                                         float[] coloring,
                                                         Normal.NormalMode normalMode)
      • mount

        public void mount​(IPainter painter)
        Invoke the loader. This is called by Graph when the application initialize and a GL context is available for feeding the GPU with arrays.
        Specified by:
        mount in interface IGLBindedResource
      • 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 the IGLLoader when mount(IPainter) is invoked. The result is that all non null provided buffers are binded to the GPU.
        See Also:
        constructor documentation for argument description.
      • registerVertexAndNormalOffsets

        protected void registerVertexAndNormalOffsets()
      • registerVertices

        protected void registerVertices​(com.jogamp.opengl.GL gl,
                                        FloatBuffer newVertices)
      • registerNormals

        protected void registerNormals​(com.jogamp.opengl.GL gl,
                                       FloatBuffer newNormals)
      • registerColors

        protected void registerColors​(com.jogamp.opengl.GL gl,
                                      FloatBuffer newColors)
      • registerElements

        protected void registerElements​(com.jogamp.opengl.GL gl,
                                        IntBuffer newElements)
      • draw

        public void draw​(IPainter painter)
        Description copied from class: Drawable
        Call OpenGL2 routines for rendering the object.
        Specified by:
        draw in interface IGLRenderer
        Specified by:
        draw in class Drawable
      • doDrawElements

        protected void doDrawElements​(IPainter painter)
        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 by glGeometryType. 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

        public Color getColor()
      • setColor

        public void setColor​(Color color)
      • hasNormalInVertexArray

        public boolean hasNormalInVertexArray()
      • setHasNormalInVertexArray

        public void setHasNormalInVertexArray​(boolean hasNormal)
      • getColorChannels

        public int getColorChannels()
      • setColorChannels

        public void setColorChannels​(int colorChannels)
      • getGL

        protected com.jogamp.opengl.GL getGL​(IPainter painter)
      • getElements

        public IntBuffer getElements()
      • getElementsStarts

        public IntBuffer getElementsStarts()
      • getElementsLength

        public IntBuffer getElementsLength()
      • getElementsCount

        public IntBuffer 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. @see applyPrimitiveRestartIfEnabled(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 with Chart.render().
      • debugMultiDrawElements

        protected void debugMultiDrawElements()
      • debugMultiDrawArray

        protected void debugMultiDrawArray()