0
votes

I have around 500 vec4's that need to be available but only ~15 per object, and than changed to 15 others of those 500 for the next object to draw and so on.

At first I tried to store all at once in a "uniform vec4 lines[500]" this worked great on some devices but for instance on the Galaxy SII this results in an instant crash, with outOfMemory exception. Than I tried to copy those needed 15 for every object form CPU side to GPU using:

GLES20.glUniform4f(GLES20.glGetformLocation(programHandle, "lines["+i/4+"]"), 
      lines[i], lines[i+1], lines[i+2], lines[i+3]);

since there are quite some objects to be drawn this results in alot of vec4's to be passed to the GPU and for the Garbage Collector to be called every ~2 seconds.

"lines" is a float[4*lineCount], maybe one call that uploads the whole float[] will be faster & more memory efficient already, does anyone know how to do that?

I belive UBO's would be great for this problem but they can't be used on android right?

Does anyone know a better solution for this? Thanks a lot!

Galaxy SII users depend on you ^_^

2
Why can't you simply use attribute array?Kimi
those 15 vec4's need to be the same for around 1000 vertexes drawn (a partial circle) and than 15 new vec4's for the next 1000 vertexes so using an attribute array will be much more expensive I guess, if you think otherwise I will try it that way, or if you know a way to store the 500 vec4's once on GPU memory and than access them partially to put into a uniform that would be great.Jelle Postma

2 Answers

0
votes

If you can use OpenGL ES3.0,then you can work with Uniform Buffers.Any Android device that supports ES3.0 should support UBOs.

0
votes

There are a few things going on here:

  • You have to reconsider your solution if you are making the garbage collector run because of Opengl. It will likely cause you inconsistent framerates.

  • It seems to me, you might confuse attribute arrays with uniforms. An attribute array would be the solution here, because you want to minimize the amount of data that you have to move to the gpu every frame.

  • Uniform buffer objects are not supported on Galaxy SII, it only has OpenGL ES2.0

    • If you really want to use a large uniform dataset, the only way would it be to use textures for that. (But it's really not recommended in this case.)