Reputation: 344
Now I have more than 3 million points to deal with. I am using openGL
and it's verticesbuffer
to store them. so, the vertices array will be roughly 9 million elements( each point has x,y,z). When I load them into float array, it crashed app by throwing java.lang.OutOfMemoryError
exception.
I tried to split up it into several arrays, but how do I draw them one after another in a single render? or create multiple renders to deal with different vertices array?
Here is my render class
public class Render implements Renderer{
private Points points;
public Render( ){
//do nothing
}
@Override
public void onDrawFrame( final GL10 gl ) {
gl.glClear( GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT );
gl.glLoadIdentity();
points.draw(gl);
}
@Override
public void onSurfaceChanged( final GL10 gl, final int width, final int height ) {
gl.glViewport( 0, 0, width, height );
gl.glMatrixMode( GL10.GL_PROJECTION );
gl.glLoadIdentity();
GLU.gluPerspective( gl, 125.0f, (float)width / (float)height, 50f, 500f );
gl.glMatrixMode( GL10.GL_MODELVIEW );
gl.glLoadIdentity();
}
@Override
public void onSurfaceCreated( final GL10 gl, final EGLConfig config ) {
/**pass Point array to points class */
points = new Points( arrayPoints );
}
here is my Points class
private float[] vertices;
private FloatBuffer vertexBuffer;
public Points( final float[] pointsArray ){
this.vertices=pointsArray;
ByteBuffer byteBuf = ByteBuffer.allocateDirect( vertices.length *4 );
byteBuf.order( ByteOrder.nativeOrder() );
vertexBuffer = byteBuf.asFloatBuffer();
vertexBuffer.put( vertices );
vertexBuffer.position( 0 );
}
public void draw( final GL10 gl ) {
gl.glEnableClientState( GL10.GL_VERTEX_ARRAY );
/**point size*/
gl.glPointSize(1);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_POINTS, 0, vertices.length/3);
gl.glDisableClientState( GL10.GL_VERTEX_ARRAY );
}
Upvotes: 0
Views: 896
Reputation: 12375
You're likely overflowing the heap size. Newer phones have a max heap size of something like 256MB. That's the max size for one application.
You can find more details about this here.
A solution would be to store these alternatively - do you really need to display 9 million vertices explicitly? Can you stream them somehow?
Upvotes: 1