Login  Register

Re: glBufferData and glBufferSubData seems not to work

Posted by Henry Rust on Aug 19, 2011; 1:14pm
URL: https://forum.jogamp.org/glBufferData-and-glBufferSubData-seems-not-to-work-tp3267295p3268013.html

Just tried to call rewind() directly before calling glBufferData. Still doens't work, I tested with

private void setUPVBO(GL2 gl)
        {
                // create vbo
                gl.glGenBuffers(2, vboID, 0);
               
                // create buffer for vbo
                float[] verticesPlain = new float[] {
                                                -1.0f, -1.0f, 0.0f,
                                                1.0f, -1.0f, 0.0f,
                                                1.0f, 1.0f, 0.0f,
                                                -1.0f, 1.0f, 0.0f };
               
                vertexPositions = ByteBuffer.allocateDirect(verticesSizeInBytes).asFloatBuffer();
                vertexPositions.put(verticesPlain);
               
                // DEBUG
                System.out.println("dumping vertexPositions");
                vertexPositions.rewind();
                for (int i = 0; vertexPositions.hasRemaining(); ++i)
                {
                        if ((i % componentsPerVertex) == 0 && i != 0)
                        {
                                System.out.println();
                        }
                        System.out.print(vertexPositions.get() + " ");
                }
                System.out.println();
                // ------
                                               
                // upload data
                gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vboID[0]);
                vertexPositions.rewind();
                gl.glBufferData(GL.GL_ARRAY_BUFFER, verticesSizeInBytes, vertexPositions, GL2.GL_STATIC_DRAW);
                //gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, verticesSizeInBytes, vertexPositions);
               
                gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vboID[1]);
                vertexPositions.rewind();
                gl.glBufferData(GL.GL_ARRAY_BUFFER, verticesSizeInBytes, vertexPositions, GL2.GL_STATIC_DRAW);
                //gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, verticesSizeInBytes, vertexPositions);
               
                vertexPositions = null;
        }
       
        private void setUPIBO(GL2 gl)
        {
                //create ibo
                gl.glGenBuffers(1, iboID, 0);
               
                // create buffer for ibo
                short[] indicesPlain = new short[] { 0, 1, 2, 2, 3, 0 };
               
                indices = ByteBuffer.allocateDirect(indicesSizeInBytes).asShortBuffer();
                indices.put(indicesPlain);
               
                // DEBUG
                System.out.println("dumping indices");
                indices.rewind();
                while (indices.hasRemaining())
                {
                        System.out.print(indices.get() + " ");
                }
                System.out.println();
                // ---------
               
                               
                //upload data
                gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, iboID[0]);
                indices.rewind();
                gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indicesSizeInBytes, indices, GL2.GL_STATIC_DRAW);
               
                indices = null;
        }

Edit: Sorry, I guess this post is useless, didn't see Wake Walker's post