Reputation: 86
i have implemented a tile based layer in my game, but after the first time that it was drawn, just the first time i try to update it (to add tiny decals, like blood splats, craters, etc. thingies that are added to the map and that i don't want to draw separately every loop) i have a huge hiccup of 3~ seconds.
after some test, i have find the only call that hangs.
gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, x, y, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuffer);
the decal is really tiny(32 * 32 pixel), there is no opengl error after this call, and i really don't get the whole thing (i mean.....the creation of the whole tile layer actually takes much lesser than 1 second, and is done by a thousand of glTexSubImage2D command on a large blank texture.....3 seconds is pretty huge).
i already have a workaround (a "fake" update just before the splash screen goes off) but i really want to understand this odd(for me, at least) behaviour.. :|
(i'm deeply sorry for my enGrish, i hope that's understandable)
METHOD:
public static void replaceSubImg(GL10 gl, int hwdId , int x,int y,int width, int height,Buffer pixelBuffer) {
gl.glFinish();
gl.glBindTexture(GL10.GL_TEXTURE_2D, hwdId);
long time = System.currentTimeMillis();
gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, x, y, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuffer);
Log.d("testApps","openglUtil,@@@@@@@@@@@@@@@@@@@@@@@@@ subImg replaced in "+(System.currentTimeMillis()-time)+" ms");
}
LOG:
DEBUG/testApps(3809): openglUtil,@@@@@@@@@@@@@@@@@@@@@@@@@ subImg replaced in 2811 ms
DEBUG/testApps(3809): openglUtil,@@@@@@@@@@@@@@@@@@@@@@@@@ subImg replaced in 1 ms(this is the 2d run)
Upvotes: 1
Views: 2262
Reputation: 86
after a ton of tests, i have isolated the whole thing and this looks like just a bug in the implementation of the opengl in the last cyanogenmod(or just gingerbread, i don't have tested this yet....) :
cyanogen(gingerbread, 7rc2) :
on froyo ( stock, frf91) :
there is anyway a little delay, but understandable this time.
Upvotes: 1
Reputation: 182083
OpenGL instructions can be pipelined and may not be executed immediately. It seems likely that the glTexSubImage2D
call itself is fast, but has to wait for some other operation to complete.
To figure this out, it might be instructive to call glFinish
after some major operations, and see when that takes a long time. You may find that the actual time is spent elsewhere... for example, in a thousand glTexSubImage2D
calls?
Upvotes: 0
Reputation: 26925
I'm not sure if I'm understanding you correctly, but:
Do you have gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, x, y, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuffer);
code in every iteration? That call is pretty expensive and it shouldn't be iterated every frame (it's like you're creating the texture every time you draw).
You need to load your textures in the onSurfaceCreated
callback, store your GL pointer
and assign that pointer to a Texture
object (an object that just holds the pointer into OpenGL
memory).
After that you can just bind it using glBindTexture(GL10.GL_TEXTURE_2D, yourPointer);
.
Upvotes: 0