Saturday, April 27, 2013

[android help] Responsiveness issues with Android and OpenGL ES 2.0


I have been working on a simple finger-tracing program on Android with a display implementation on a GLSurface Renderer instead of a canvas. Right now, all I am drawing are simple line segments comprised of points, with each line segment stored in an arraylist. For a relatively small number of line strips (~10), performance is responsive. Yet, when I start adding more than 15 or so segments, performance degrades significantly. Here's my onDraw call for the Renderer



public void onDrawFrame(GL10 unused) {
GLES20.glClearColor(mRed, mGreen, mBlue, 1.0f);
GLES20.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

GLES20.glViewport(0, 0, mWidth, mHeight);

try{
strokes = SurfaceView.getStrokes();
Iterator itr = strokes.iterator();
while(itr.hasNext()){
Stroke s = itr.next();
s.draw();
}


}catch (Exception e){
e.printStackTrace();
System.exit(1);
}


}


And for each stroke s, the draw call is below:



float[] lineCoords = convertFloat(pointList);
int vertexCount = lineCoords.length / COORDS_PER_VERTEX;
int vertexStride = COORDS_PER_VERTEX * 4; // 4 bytes per vertex
createStroke(lineCoords);

// Add program to OpenGL ES environment
GLES20.glUseProgram(mProgram);

// get handle to vertex shader's vPosition member
mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

// Enable a handle to the triangle vertices
GLES20.glEnableVertexAttribArray(mPositionHandle);

// Prepare the triangle coordinate data
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
vertexStride, vertexBuffer);

// get handle to fragment shader's vColor member
mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

// Set color for drawing the line
GLES20.glUniform4fv(mColorHandle, 1, color, 0);

// Draw the line
//GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, vertexCount);
GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, vertexCount);
//GLES20.glDrawArrays(GLES20.GL_POINTS, 0, vertexCount);

// Disable vertex array
GLES20.glDisableVertexAttribArray(mPositionHandle);


And the important shader settings are here:



private final static String vertexShaderCode =
"attribute vec4 vPosition;" +
"void main() {" +
" gl_Position = vPosition;" +
"}";

private final static String fragmentShaderCode =
"precision mediump float;" +
"uniform vec4 vColor;" +
"void main() {" +
" gl_FragColor = vColor;" +
"}";
// number of coordinates per vertex in this array
static final int COORDS_PER_VERTEX = 2;


I only render on dirty, so no drawing is being performed without the user pressing his finger on the screen.


I'm still getting used to openGL on Android, so maybe I'm just missing something obvious here. But does anything look egregiously wrong such that performance would drop to incredibly low sampling of points per stroke? I definitely wouldn't expect this type of refresh to be so taxing. Thanks.



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...