Reputation: 3036
I modified a sample opengl application for some speed tests that really make opengl look slow and I would like to know if I am doing something wrong here.
The Setup, Loading&Binding and Rendering are different functions and display a square on the screen but at a measly 6 fps. The same code I wrote is way faster with canvas.
What could I do to speed this up, and I mean speed this seriously up ?
(PS: I already tried glDrawTexiOES and while faster it is still nowhere near canvas)
// Setup of opengl
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
// Loading & Binding of Texture
InputStream is = context.getResources().openRawResource(R.drawable.t2);
map = BitmapFactory.decodeStream(is);
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[i]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, map, 0);
// Rendering
public void draw(GL10 g, int screenx, int screeny, int[] mem)
{ GL11 gl = (GL11) g;
//Point to our buffers
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
//Set the face rotation
gl.glFrontFace(GL10.GL_CCW);
//Enable the vertex and texture state
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
//Bind our only previously generated texture in this case
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
//Draw the vertices as triangles, based on the Index Buffer information
gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);
// Cleanup
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
Upvotes: 0
Views: 1164
Reputation: 31
I tried the code you posted, and that works for me with no problems. Obviously is faster (a lot) on my Galaxy S than on the emulator on a Core i7 920. Seeing that on the actual device you get a slower speed than on the emulator, the problem should be in the file writing on the SD card. Try to comment that, or write on an array/list, and then when you close the app write the array on the SD (warning: array/list size grows fast). Remember that if you're writing on the SD at every frame, OpenGL have to wait at least 15ms every time. If it isn't that, you should give us more info.
Upvotes: 1