0

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 );

}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Saddy
  • 313
  • 4
  • 22

2 Answers2

1

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?

Community
  • 1
  • 1
Codeman
  • 12,157
  • 10
  • 53
  • 91
  • I think I need to display them all. they are geomorphic data. User should be able to view them in detail. What do you mean by stream them? could you give more details? – Saddy Jan 09 '14 at 21:51
  • Show a limited resolution of them at a "zoomed out" level and show more detail with a limited scope at a "zoomed in" level. Think how google maps shows streets - when you view the whole country, you only see highways, but when you zoom in, you see everything. – Codeman Jan 09 '14 at 21:57
0

Another solution is to use NDK. There is no strict memory limitation.

Lev
  • 730
  • 12
  • 32
  • I am using ndk to read all points. Do you mean use openGL in native code? – Saddy Jan 09 '14 at 21:54
  • Do not attempt to load large data set in Java. Do all processing in NDK, including OpenGL calls. – Lev Jan 10 '14 at 23:25