Memory allocation problems for drawing

Problems with Canvas, OpenGL, etc...

Memory allocation problems for drawing

Postby marcom » Sun May 22, 2011 12:03 pm

Hi all,

I'm very new to Android and I'm writing my first app which consists of drawing STL data (a bunch of triangles).
For a small number of triangles (~ 4000), my app works great. But as soon as I try to load large data (~ 100000 triangles), I get memory allocation problems. Here is basically what I do:

I am using a GLSurfaceView for my rendering

a) I read in my data, creating a list of triangles (3 * X/Y/Z and a normal vector for each triangle)
b) I create ByteBuffers using allocateDirect() for the vertex data, the normals and the indices.
c) I add the data into the ByteBuffers
d) I call glVertexPointer, glNormalPointer and I assign the bytebuffers
e) I call glDrawElements() using the indexBuffer

As soon as I try to allocate around 10MB by calling allocateDirect(), my application crashes. I tried to calll allocate() instead, which works, but then the glVertexPointer method crashes (even for a small number of triangles)

Am I doing something wrong?

Also, do I have to call glVertexPointer, glNormalPointer every time I redraw or is it enough to call it in the surfaceChanged method?

Thanks a lot,

Mark
marcom
Freshman
Freshman
 
Posts: 2
Joined: Sun May 22, 2011 11:48 am

Top

Re: Memory allocation problems for drawing

Postby Codehead » Sat May 28, 2011 1:05 am

Some sort of buffer size limit? On another note I'd imagine you certainly can't draw a mesh on an Android phone that big at any kind of decent frame rate (esp. with lighting - since you have normals). Sounds like you need to chunk up your giant lump of mesh data off-line and then display only the parts of the mesh that are really needed on-screen at any time (i.e. do some scene culling). That would get around the crashing. Hope I'm not pointing out the obvious BTW ;).

In theory once you bind vertex data, it's supposed to stay bound (loss of context notwithstanding). However I've read of people seeing issues on some HTC phones with a certain Qualcomm Chipset where it doesn't work. I.e. sounds like the GL ES drivers are broken and don't conform to the spec.

-M
User avatar
Codehead
Freshman
Freshman
 
Posts: 2
Joined: Fri May 27, 2011 5:26 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest