public synchronized int getGLBuffer(GL2GL3 gl) { // The buffer may not have been initialized yet if (_glVertBuffer == -1) { setupBuffer(gl); } if (_glBufferDirty) { int totalVerts = 0; for (double[] d : _vertices) { totalVerts += d.length; } FloatBuffer fb = FloatBuffer.allocate(totalVerts); for (double[] ds : _vertices) { for (double d : ds) { fb.put((float) d); } } fb.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _glVertBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, totalVerts * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); _glBufferDirty = false; } return _glVertBuffer; }
private void setupBuffer(GL2GL3 gl) { // Create an OpenGL buffer int[] buffs = new int[1]; gl.glGenBuffers(1, buffs, 0); _glVertBuffer = buffs[0]; _glBufferDirty = true; }