Speeding the display

Posted by Dex55 on
URL: https://forum.jogamp.org/Speeding-the-display-tp4032405.html

Hello,
I am speeding the display of animations in a java application that simulate the evolution of a plant cells in 3D dimensions .the cells are the elements of an octree. Each cell is a cube with 4 possibles colors . I'm using VBO. The thing is that the refreshing of the view is made every unity of cycles ( determined by the user ) and every unity of cycles for example 5 the cache ( containing the cells ) is sent to the GPU in order to display the new model ( cells are added in every cycle based on the modele of evolution the user choose ) so every cycle the cache gets more big leading to slowing the display in a lot of cases . I have been thinking that i can send only the new celles created in the last unity of cycles to the GPU but then how to display the old ones once the refresh is made ?

here is the code responsable for updating the VBO :

private void updateBuffers(GL2 gl) {
               
                /**
                     * Cache is used as intermediate between a {@link NTree} and a OpenGL
                     * manager to convert model data in {@link CellQuadBuffer}s to be used by OpenGL
                      * drawing methods.
             */
                synchronized (cache) {
                        minPoint = (cache.getMinPoint() == null)? new Vector3d() : new Vector3d(cache.getMinPoint());
                        maxPoint = (cache.getMaxPoint() == null)? new Vector3d() : new Vector3d(cache.getMaxPoint());

                        int[] gpuBuffers;
                       /**
                        * CellQuadBuffer stores {@link Cell}s in {@link Buffer}s and in a format usable by
                       * OpenGL.
                       * <p>
                       * {@link Cell}s are represented to match the OpenGL GL_QUADS primitive shape,
                       * with their unique color. </br> The outlines color of a cube is the inverse of
                       * the color of this cube (except that the alpha value is the same).
                       */
                        List<CellQuadBuffer> oldList = listBuffers;
                        listBuffers = new ArrayList<>(cache.getCellBuffers());

                        Buffer vertices, colors, outlinesColors, indices;

                          if (vboEnabled) {
                                for (CellQuadBuffer cb : oldList) {
                                        // delete existing buffers
                                        gpuBuffers = new int[] { cb.gpuBufferVertices, cb.gpuBufferColors, cb.gpuBufferIndices,
                                                        cb.gpuBufferOutlinesColors };

                                        gl.glDeleteBuffers(CellQuadBuffer.NUMBER_OF_BUFFERS, IntBuffer.wrap(gpuBuffers));
                                }

                                oldList.clear();

                                for (CellQuadBuffer cb : listBuffers) {

                                        // generate new buffers
                                        gpuBuffers = new int[] { cb.gpuBufferVertices, cb.gpuBufferColors, cb.gpuBufferIndices,
                                                        cb.gpuBufferOutlinesColors };

                                        gl.glDeleteBuffers(CellQuadBuffer.NUMBER_OF_BUFFERS, IntBuffer.wrap(gpuBuffers));
                   
                   
                                        gl.glGenBuffers(CellQuadBuffer.NUMBER_OF_BUFFERS, IntBuffer.wrap(gpuBuffers));
                                       
                                        cb.gpuBufferVertices = gpuBuffers[0];
                                        cb.gpuBufferColors = gpuBuffers[1];
                                        cb.gpuBufferIndices = gpuBuffers[2];
                                        cb.gpuBufferOutlinesColors = gpuBuffers[3];

                                        vertices = cb.getVertices();
                                        colors = cb.getColors();
                                        outlinesColors = cb.getOutlinesColors();
                                        indices = cb.getIndices();

                                        // vertex buffer
                                        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferVertices);
                                        gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity() * Buffers.sizeOfBufferElem(vertices), vertices,
                                                GL.GL_STATIC_DRAW);

                                        // color buffer
                                        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferColors);
                                    gl.glBufferData(GL.GL_ARRAY_BUFFER, colors.capacity() * Buffers.sizeOfBufferElem(colors), colors,
                                                        GL.GL_STATIC_DRAW);

                                        // outlines color buffer
                                        gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferOutlinesColors);
                                        gl.glBufferData(GL.GL_ARRAY_BUFFER, outlinesColors.capacity() * Buffers.sizeOfBufferElem(outlinesColors),
                                                        outlinesColors, GL.GL_STATIC_DRAW);

                                        // indices buffer
                                        gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, cb.gpuBufferIndices);
                                        gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * Buffers.sizeOfBufferElem(indices), indices,
                                                        GL.GL_STATIC_DRAW);

                                        cb.resetBuffer();
                                }
                        }

                        cache.resetData();
                        cache.dataUsed();
                }
        }


Thank you .