我正在解析一個包含頂點及其屬性的二進制文件。這些文件的範圍從50,000-2,000,000個頂點。對於較低的文件,我沒有問題直接分配數組並繪製點,但對於較大的文件,這是一個很大的問題。Android OpenGL OutOfMemory(分配緩衝區)
當我創建一個floatbuffer這樣:
FloatBuffer buf = ByteBuffer.allocateDirect(vertices.length * 4);
我有時會內存溢出錯誤。這不是我繪製的唯一緩衝區,我也是彩色的。有沒有更好的方式繪製頂點或動態分配到緩衝區,並且每次繪製?下面是我使用一些基本的繪圖代碼:
public PointCloud(String passedFileName, Context ctx) {
fileName = passedFileName;
header = new LAS_HeadParser(fileName);
numVertices = (int)header.numberOfPoints;
lasVertices = new float[numVertices*3];
lasColors = new float[numVertices*4];
intensity = new float[numVertices];
vbb = ByteBuffer.allocateDirect(lasVertices.length * 4);
cbb = ByteBuffer.allocateDirect(lasColors.length * 4);
new ProgressTask(ctx).execute();
}
public void setupBuffers(){
// a float is 4 bytes, therefore we multiply the number if
// vertices with 4.
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(lasVertices);
vertexBuffer.position(0);
cbb.order(ByteOrder.nativeOrder());
colorBuffer = cbb.asFloatBuffer();
colorBuffer.put(lasColors);
colorBuffer.position(0);
}
public void draw(GL10 gl) {
//Log.d("Enter Draw", "*****************");
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glPointSize(0.6f);
gl.glDrawArrays(GL10.GL_POINTS, 0, numVertices);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
呼叫new ProgressTask(ctx).execute();
只是解析並填充陣列。我無法繼續解析文件,這需要很長時間。我有什麼選擇?
哪行代碼拋出了OutOfMemory錯誤? – DoomGoober
@DoomGoober - vbb = ByteBuffer.allocateDirect(lasVertices.length * 4); – RedLeader