Login  Register

Poor Performance with glVertexAttribPointer

Posted by bgroenks96 on Jan 12, 2014; 7:42am
URL: https://forum.jogamp.org/Poor-Performance-with-glVertexAttribPointer-tp4031170.html

I'm trying to use glVertexAttribPointer to get both the position and texture coordinates from a single VBO into my vertex shader.  The vertex shader is basic and doesn't do much other than transform and output.

The test scene is a few non-textured quads, a non-textured background quad, and several hundred textured quads.

With the following code and no textured quads I get a solid ~2200 fps

                        gl.glEnableVertexAttribArray(0);
                        gl.glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);

                        gl.glMultiDrawArrays(buffObj.drawFunc.getGLCommand(), buffObj.vertIndices, 0, buffObj.vertNum, 0, buffObj.objCount);

                        // disable arrays
                        gl.glBindBuffer(GL_ARRAY_BUFFER, 0);
                        gl.glDisableVertexAttribArray(0);

Note: the VBOs for the non-textured quads are allocated to only hold position coordinates.

Adding the tex coord vertex attribute drops it down to <100 fps:

                        gl.glEnableVertexAttribArray(0);
                        gl.glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
                        if(texBound && texEnabled) {
                                gl.glEnableVertexAttribArray(1);
                                gl.glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 2 * buffObj.nverts * Buffers.SIZEOF_FLOAT);
                        }

                        gl.glMultiDrawArrays(buffObj.drawFunc.getGLCommand(), buffObj.vertIndices, 0, buffObj.vertNum, 0, buffObj.objCount);

                        // disable arrays
                        gl.glBindBuffer(GL_ARRAY_BUFFER, 0);
                        gl.glDisableVertexAttribArray(0);
                        if(texBound && texEnableD)
                            gl.glDisableVertexAttribArray(1);

The load shouldn't be a problem.  The same scene ran at ~2000 fps using fixed function glVertexPointer and glTexCoordPointer with the same VBO setup.

Am I doing something wrong?  What kind of state calls or optimizations should I consider with setting vertex attribute pointers?