OpenGL really faster then Canvas drawing for 2D ?

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

OpenGL really faster then Canvas drawing for 2D ?

Postby cg0601 » Fri Aug 07, 2009 7:48 am

I am writing a framework for a game which uses bitmaps and a particle engine to draw aircrafts in flight. My game framework allows me to switch from Canvas drawing to OpenGL drawing and I came to some results I did not expect.
When I use Canvas drawing, I have a nice fluent game with up to 10 planes and using DDMS and Logcat I can see that no GC activity takes place at all. I did not calculate the FPS, but since I have a time delay of 50 ms, it is close to 20FPS. Planes fly smoothly without any shocks in the images.

However if I switch to OpenGL, simply replacing the drawing routines with OpenGL, my game becomes very "jittery", planes seem to leap from one position to another. And the worst thing is that I see a lot of GC activity. Now if you know that a typical GC needs around 300 ms, you can imagine what it does on my game.

Since the game framework is the same and since I do not allocate new objects in my drawing code, I can conclude only that the OpenGLES calls are really not efficient and allocating objects. This brings the usability of OpenGL for 2D programs down a lot for me, so much that I will continue using Canvas for writing games.

I'd like to hear from other users if they have similar experiences? I know that I still can optimize my OpenGL code perhaps by using VBO buffers, but I still need to learn about it. (I have ordered some OpenGL books :D )

I have appended a screenshot of my game, using the Canvas draw methods.

All tests were executed on my HTC Magic, I do not know if it is more/less/equals performing compared to other platforms.
Attachments
def-canvas.png
def-canvas.png (12.51 KiB) Viewed 16613 times
cg0601
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Aug 04, 2009 8:53 am

Top

Postby cg0601 » Fri Aug 07, 2009 8:54 am

After looking around some more I found this thread in the Android developers newsgroup.
So it looks that until this issue is fixed, OpenGL will not really perform well for games.
cg0601
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Aug 04, 2009 8:53 am

OpenGL VBO buffers make a difference

Postby cg0601 » Mon Aug 10, 2009 9:26 am

After experimenting some more, I found that using the hardware VBO buffers allowed me to get rid of the garbage collection. The trick is to use the GL11 extensions (which might not be supported on all hardware). Because this is a tutorial forum, I will share my code here.

Note 1: The gl11.glDrawArrays() call does not use VBO buffers, and that is why you need to convert the call to use gl11.glDrawElements.

Here is how I initialized the different buffers:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     protected void initVertexBuffers()
  2.  
  3.     {
  4.  
  5.         int one = 65536;
  6.  
  7.         int particleScale = 2 * one;
  8.  
  9.         int particleVertices[] =
  10.  
  11.         {
  12.  
  13.                 // FRONT
  14.  
  15.                 -particleScale, particleScale, 0, particleScale, particleScale, 0, -particleScale, -particleScale, 0,
  16.  
  17.                 particleScale, -particleScale, 0
  18.  
  19.         };
  20.  
  21.         int aircraftScale = 32 * one;
  22.  
  23.         int aircraftVertices[] =
  24.  
  25.         {
  26.  
  27.                 // FRONT
  28.  
  29.                 -aircraftScale, aircraftScale, 0, aircraftScale, aircraftScale, 0, -aircraftScale, -aircraftScale, 0,
  30.  
  31.                 aircraftScale, -aircraftScale, 0
  32.  
  33.         };
  34.  
  35.         int texCoords[] =
  36.  
  37.         {
  38.  
  39.                 // FRONT
  40.  
  41.                 0, one, one, one, 0, 0, one, 0
  42.  
  43.         };
  44.  
  45.         int normals[] =
  46.  
  47.         {
  48.  
  49.                 0, 0, -one, 0, 0, -one, 0, 0, -one, 0, 0, -one
  50.  
  51.         };
  52.  
  53.  
  54.  
  55.         short indices[] =
  56.  
  57.         {
  58.  
  59.                 0, 2, 1, 2, 3, 1
  60.  
  61.         };
  62.  
  63.         // Buffers to be passed to gl*Pointer() functions must be direct, i.e.,
  64.  
  65.         // they must be placed on the native heap where the garbage collector
  66.  
  67.         // cannot move them.
  68.  
  69.         //
  70.  
  71.         // Buffers with multi-byte data types (e.g., short, int, float) must
  72.  
  73.         // have their byte order set to native order
  74.  
  75.         ByteBuffer vbb = ByteBuffer.allocateDirect(particleVertices.length * 4);
  76.  
  77.         vbb.order(ByteOrder.nativeOrder());
  78.  
  79.         vertexBuffer = vbb.asIntBuffer();
  80.  
  81.         vertexBuffer.put(particleVertices);
  82.  
  83.         vertexBuffer.position(0);
  84.  
  85.  
  86.  
  87.         // ...
  88.  
  89.         ByteBuffer vbb2 = ByteBuffer.allocateDirect(aircraftVertices.length * 4);
  90.  
  91.         vbb2.order(ByteOrder.nativeOrder());
  92.  
  93.         vertex2Buffer = vbb2.asIntBuffer();
  94.  
  95.         vertex2Buffer.put(aircraftVertices);
  96.  
  97.         vertex2Buffer.position(0);
  98.  
  99.  
  100.  
  101.         // ...
  102.  
  103.         ByteBuffer tbb = ByteBuffer.allocateDirect(texCoords.length * 4);
  104.  
  105.         tbb.order(ByteOrder.nativeOrder());
  106.  
  107.         textureBuffer = tbb.asIntBuffer();
  108.  
  109.         textureBuffer.put(texCoords);
  110.  
  111.         textureBuffer.position(0);
  112.  
  113.         // ...
  114.  
  115.         ByteBuffer nbb = ByteBuffer.allocateDirect(normals.length * 4);
  116.  
  117.         nbb.order(ByteOrder.nativeOrder());
  118.  
  119.         normalBuffer = nbb.asIntBuffer();
  120.  
  121.         normalBuffer.put(normals);
  122.  
  123.         normalBuffer.position(0);
  124.  
  125.  
  126.  
  127.         ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
  128.  
  129.         ibb.order(ByteOrder.nativeOrder());
  130.  
  131.         indexBuffer = ibb.asShortBuffer();
  132.  
  133.         indexBuffer.put(indices);
  134.  
  135.         indexBuffer.position(0);
  136.  
  137.     }
  138.  
  139.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Maybe not optimal and it also requires that your bitmaps point "down". This means that if you want to draw an aircraft going up and use no rotatation, the image should have the aircraft point down (or rotated 180 degrees)

After initializing the vertices and index, I copy them to the hardware buffers in my graphics card. They are very small, so there should be ample space to copy them.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void generateHardwareBuffers(GL10 gl)
  2.  
  3.     {
  4.  
  5.         if (particleVertBufferIndex == 0)
  6.  
  7.         {
  8.  
  9.             if (gl instanceof GL11)
  10.  
  11.             {
  12.  
  13.                 GL11 gl11 = (GL11) gl;
  14.  
  15.                 int[] buffer = new int[1];
  16.  
  17.  
  18.  
  19.                 // Allocate and fill the vertex buffer.
  20.  
  21.                 gl11.glGenBuffers(1, buffer, 0);
  22.  
  23.                 particleVertBufferIndex = buffer[0];
  24.  
  25.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, particleVertBufferIndex);
  26.  
  27.                 final int vertexSize = vertexBuffer.capacity() * 4;
  28.  
  29.                 gl11.glBufferData(GL11.GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL11.GL_STATIC_DRAW);
  30.  
  31.  
  32.  
  33.                 int error = gl11.glGetError();
  34.  
  35.                 if (error != GL10.GL_NO_ERROR)
  36.  
  37.                 {
  38.  
  39.                     Log.e("AirDefender", "Generate vertex buffer GLError: " + error);
  40.  
  41.                 }
  42.  
  43.  
  44.  
  45.                 // Allocate and fill the vertex buffer.
  46.  
  47.                 gl11.glGenBuffers(1, buffer, 0);
  48.  
  49.                 aircraftVertBufferIndex = buffer[0];
  50.  
  51.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, aircraftVertBufferIndex);
  52.  
  53.                 final int vertex2Size = vertex2Buffer.capacity() * 4;
  54.  
  55.                 gl11.glBufferData(GL11.GL_ARRAY_BUFFER, vertex2Size, vertex2Buffer, GL11.GL_STATIC_DRAW);
  56.  
  57.  
  58.  
  59.                 error = gl11.glGetError();
  60.  
  61.                 if (error != GL10.GL_NO_ERROR)
  62.  
  63.                 {
  64.  
  65.                     Log.e("AirDefender", "Generate vertex buffer GLError: " + error);
  66.  
  67.                 }
  68.  
  69.  
  70.  
  71.                 // Allocate and fill the texture coordinate buffer.
  72.  
  73.                 gl11.glGenBuffers(1, buffer, 0);
  74.  
  75.                 textureCoordBufferIndex = buffer[0];
  76.  
  77.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureCoordBufferIndex);
  78.  
  79.                 final int texCoordSize = textureBuffer.capacity() * 4;
  80.  
  81.                 gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoordSize, textureBuffer, GL11.GL_STATIC_DRAW);
  82.  
  83.  
  84.  
  85.                 error = gl11.glGetError();
  86.  
  87.                 if (error != GL10.GL_NO_ERROR)
  88.  
  89.                 {
  90.  
  91.                     Log.e("AirDefender", "Generate texture buffer GLError: " + error);
  92.  
  93.                 }
  94.  
  95.                 // Unbind the array buffer.
  96.  
  97.                 gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
  98.  
  99.  
  100.  
  101.                 // Allocate and fill the index buffer.
  102.  
  103.                 gl11.glGenBuffers(1, buffer, 0);
  104.  
  105.                 indexBufferIndex = buffer[0];
  106.  
  107.                 gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBufferIndex);
  108.  
  109.                 // A char is 2 bytes.
  110.  
  111.                 final int indexSize = indexBuffer.capacity() * 2;
  112.  
  113.                 gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, indexSize, indexBuffer, GL11.GL_STATIC_DRAW);
  114.  
  115.  
  116.  
  117.                 error = gl11.glGetError();
  118.  
  119.                 if (error != GL10.GL_NO_ERROR)
  120.  
  121.                 {
  122.  
  123.                     Log.e("AirDefender", "Generate index buffer GLError: " + error);
  124.  
  125.                 }
  126.  
  127.                 // Unbind the element array buffer.
  128.  
  129.                 gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
  130.  
  131.             }
  132.  
  133.         }
  134.  
  135.     }
  136.  
  137.  
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


To use the buffers simply refer to the HW buffers:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     @Override
  2.  
  3.     public void draw(GL10 gl)
  4.  
  5.     {
  6.  
  7.         gl.glEnable(GL10.GL_TEXTURE_2D);
  8.  
  9.         gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  10.  
  11.         gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  12.  
  13.  
  14.  
  15.         gl.glPushMatrix();
  16.  
  17.         gl.glTranslatef(x, y, 0);
  18.  
  19.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
  20.  
  21.         gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  22.  
  23.  
  24.  
  25.         GL11 gl11 = (GL11) gl;
  26.  
  27.         // draw using hardware buffers
  28.  
  29.         gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, SimpleGLRenderer.aircraftVertBufferIndex);
  30.  
  31.         gl11.glVertexPointer(3, GL10.GL_FIXED, 0, 0);
  32.  
  33.  
  34.  
  35.         gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, SimpleGLRenderer.textureCoordBufferIndex);
  36.  
  37.         gl11.glTexCoordPointer(2, GL11.GL_FIXED, 0, 0);
  38.  
  39.  
  40.  
  41.         gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, SimpleGLRenderer.indexBufferIndex);
  42.  
  43.         gl11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_SHORT, 0);
  44.  
  45.  
  46.  
  47.         gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
  48.  
  49.         gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
  50.  
  51.  
  52.  
  53.         gl.glPopMatrix();
  54.  
  55.         engine.draw(gl);
  56.  
  57.     }
  58.  
  59.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


After stopping the program, don't forget to release the buffers, otherwise your graphics card might run out of space (I am not sure if this is true, since I do not know if the Graphics card would replace the buffers ?)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void freeHardwareBuffers(GL10 gl)
  2.  
  3.     {
  4.  
  5.         if (particleVertBufferIndex != 0)
  6.  
  7.         {
  8.  
  9.             if (gl instanceof GL11)
  10.  
  11.             {
  12.  
  13.                 GL11 gl11 = (GL11) gl;
  14.  
  15.                 int[] buffer = new int[1];
  16.  
  17.                 buffer[0] = particleVertBufferIndex;
  18.  
  19.                 gl11.glDeleteBuffers(1, buffer, 0);
  20.  
  21.  
  22.  
  23.                 buffer[0] = aircraftVertBufferIndex;
  24.  
  25.                 gl11.glDeleteBuffers(1, buffer, 0);
  26.  
  27.  
  28.  
  29.                 buffer[0] = textureCoordBufferIndex;
  30.  
  31.                 gl11.glDeleteBuffers(1, buffer, 0);
  32.  
  33.  
  34.  
  35.                 buffer[0] = indexBufferIndex;
  36.  
  37.                 gl11.glDeleteBuffers(1, buffer, 0);
  38.  
  39.             }
  40.  
  41.  
  42.  
  43.             forgetHardwareBuffers();
  44.  
  45.         }
  46.  
  47.     }
  48.  
  49.  
  50.  
  51.     private void forgetHardwareBuffers()
  52.  
  53.     {
  54.  
  55.        particleVertBufferIndex = 0;
  56.  
  57.        aircraftVertBufferIndex = 0;
  58.  
  59.        textureCoordBufferIndex = 0;
  60.  
  61.        indexBufferIndex = 0;
  62.  
  63.     }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Note 2: I borrowed a lot of code from the SpriteMethodTest program which uses different methods to show performance
cg0601
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Aug 04, 2009 8:53 am

a real difference?

Postby guian » Tue Aug 18, 2009 10:10 am

HI cg0601!
I've writen all my 2D app with OpenGL and I didn't find any problem before I tried it on the Samsung Galaxy (I developed it on my HTC magic (the french 'myTouch' ;) )

On the samsung the result is so bad that I wonder if I shouldn't use only a Canvas drawing style in order to optimise it ...
Do you think with your experience that the 'hardware VBO buffers trick' could be a solution ? .... if it's the graphics hardware on the galaxy which is really poor I think it won't help ... (moreover with the use of the GL11 extensions... :S )

I'll be glad to read any comment about this.
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

2D Canvas

Postby cg0601 » Wed Aug 26, 2009 9:52 am

I did some more tests and so far it looks like the VBO based application gives the best performance. The Canvas itself contains also very powerful API's, but clearly is slower when dealing with multiple objects. It is good enough for "slow" updates like 1-5 FPS, but will not be able to do the 25+ FPS typically needed for fluent games.

OpenGL without VBO is fast enough, but causes garbage collection (GC) and while the GC is running in your vm, nothing else can be done. This causes annoying "stuttering", because a GC can take anywhere between 100 and 400 ms. Especially the latter is a FPS killer, because 400 ms could mean that you missed like 20 frames.

My test application is coming along fine and uses VBO buffers and has no dropped frames or whatever. I use particles, "framed" explosions, etc but everything just works fine without any delays. See the attched image as an example of how the game looks so far.
BTW, I am using a 3D projection, but use it rather as semi 2D.
Attachments
explosion02.png
Game screendump
explosion02.png (17.07 KiB) Viewed 15562 times
cg0601
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Aug 04, 2009 8:53 am

Postby WarrenFaith » Wed Aug 26, 2009 4:36 pm

I started playing with OpenGL too, but didn't run into trouble like you.
I made 50 objects (ok all the same but 50 times displayed in differenz z-level) and rotate it... smoothly.

Can you provide a minimum example to show so we can see it?
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Examples provided

Postby cg0601 » Thu Aug 27, 2009 4:26 pm

I have appended 2 versions of the game. One is suing the Canvas for drawing and displays everything reasonable fluently, but as soon as you try to use the "blue" button you will see that there are artifacts in the rotated blimps.
But the important thing is that the Canvas does not show (or almost none) GC when the game is running.
There are quite a lot of drawings done. For example the "smoke" on the plane is a particle engine which draws > 100 partices (circles) every frame.
The game FPS is limited to 40 FPS by my timer loop (and the eventual delays in drawing)

The second example uses far less objects to draw. tap the red button to fire a missile and you will see that the missile is "stuttering" across the screen and taking long jumps.
If you stop and start the OpenGL version, it does not always return, try once more and it can succeed. I am working on this.

Now when you check the LogCat (with Eclipse or by using "adb logcat" with the device on USB) you can see that the second version generates a lot off GC and this causes the "jumps" in the code, since when the GC is running nothing else happens.

To install the application you can use "adb install AirdefnderOGL.apk" and "adb install AirDefenderCanvas.apk"

Since both programs contain the same logic and I double checked for any programming that could cause this exhaustive GC, I can only assume that the GC is because of the DrawArrays call which I use. (or the ByteBuffers ?)

I also have a version which uses the GL11 extensions and VBO buffers, which does not have any GC activity either. Again it is using the same logic, only the drawing calls are slightly different. I did not include it here yet because I still have some issues with pausing and restarting and I am not sure where it could come from.

Please note that this game is just a prototype so there might be bugs and other issues. Also the graphics are not yet complete, but I like the explosions. The collision detection is not correct either, so you have to hit a blimp really in the middle.

I am interested to see if anybody else sees this same GC activity over and over.
Attachments
AirdefenderOGL.apk
(214.01 KiB) Downloaded 280 times
AirDefenderCanvas.apk
(149.67 KiB) Downloaded 252 times
cg0601
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Aug 04, 2009 8:53 am

Postby WarrenFaith » Thu Aug 27, 2009 5:01 pm

Code: Select all
08-27 17:51:03.037: DEBUG/dalvikvm(21219): GC freed 19276 objects / 484584 bytes in 171ms
08-27 17:51:06.717: DEBUG/dalvikvm(1058): threadid=13: bogus mon 1+0>0; adjusting
08-27 17:51:10.427: DEBUG/dalvikvm(21219): GC freed 22133 objects / 531424 bytes in 124ms
08-27 17:51:11.427: DEBUG/dalvikvm(1125): GC freed 205 objects / 10408 bytes in 259ms
08-27 17:51:18.967: DEBUG/dalvikvm(21219): GC freed 21832 objects / 524120 bytes in 146ms
08-27 17:51:27.457: DEBUG/dalvikvm(21219): GC freed 21834 objects / 524168 bytes in 133ms
08-27 17:51:36.077: DEBUG/dalvikvm(21219): GC freed 21839 objects / 524288 bytes in 137ms
08-27 17:51:45.647: DEBUG/dalvikvm(21219): GC freed 21839 objects / 524288 bytes in 130ms
08-27 17:51:54.557: DEBUG/dalvikvm(21219): GC freed 21839 objects / 524288 bytes in 120ms
08-27 17:52:00.597: DEBUG/dalvikvm(1058): GC freed 27792 objects / 1504472 bytes in 534ms
08-27 17:52:02.207: DEBUG/dalvikvm(21219): GC freed 21839 objects / 524288 bytes in 130ms
08-27 17:52:09.247: DEBUG/dalvikvm(21219): GC freed 21839 objects / 524288 bytes in 246ms

I see what you mean :)

And i checked my 3d app too, found the same thing :(
Code: Select all
08-27 17:54:03.547: DEBUG/dalvikvm(21519): GC freed 10715 objects / 370368 bytes in 140ms
08-27 17:54:11.047: DEBUG/dalvikvm(1125): GC freed 187 objects / 9320 bytes in 226ms
08-27 17:54:13.927: DEBUG/dalvikvm(21519): GC freed 16595 objects / 532320 bytes in 166ms
08-27 17:54:24.747: DEBUG/dalvikvm(21519): GC freed 18601 objects / 567904 bytes in 157ms
08-27 17:54:34.497: DEBUG/dalvikvm(21519): GC freed 17621 objects / 538064 bytes in 172ms
08-27 17:54:44.570: DEBUG/dalvikvm(21519): GC freed 17179 objects / 524816 bytes in 161ms


This is very interesting. If you don't mind, I would love to see your code. My code is pretty simple and you can find it on my blog (look at my signature). If you want to share it, contact me and maybe we will find a solution and publish it here for everyone.
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Sources provided

Postby cg0601 » Thu Aug 27, 2009 7:54 pm

I have appended my "GL11" version sources, this version does not have any GC collection at all, but whenever I resume the application without the debugger, I get errors like this:

Code: Select all
D/RosieMEM(  127): VM free memory : 840472
D/RosieMEM(  127): VM max memory : 33554432
D/RosieMEM(  127): VM total memory : 4792288
D/AIRDEFENDER(  966): onResume()
D/SurfaceFlinger(   64): pid 966 requesting gpu surface (current owner = -1)
D/SurfaceFlinger(   64): gpu surface granted to pid 966
D/SurfaceFlinger(   64): pid 127 requesting gpu core (owner = 966)
D/SurfaceFlinger(   64): pid 966 requesting gpu surface (current owner = 127)
D/EGL     (  127): CONTEXT_LOST: Releasing GPU upon request from SurfaceFlinger.
D/EGL.oem (  127): SMI  region at virtual=0x46e10000, physical=0x0, size=7340032 offset=0
D/EGL.oem (  127): EBI1 region at virtual=0x47510000, physical=0x25800000, size=8388608 offset=1228800
D/EGL.oem (  127): REGS region at virtual=0x46d10000, physical=0xa0000000, size=1048576, offset=0
E/GLLogger(  127): 0: eglInitialize() failed (EGL_CONTEXT_LOST)
W/InputManagerService(   64): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@437e7108
D/SurfaceFlinger(   64): gpu surface granted to pid 966
E/SurfaceComposerClient(  966): using an invalid surface id=1, identity=65 should be 70
E/GLLogger(  966): validate_display_surface:488 error 300d (EGL_BAD_SURFACE)
D/dalvikvm(  511): GC freed 1176 objects / 75784 bytes in 204ms
D/HardwareService(   64): GetPreferredValue (settings.display.brightness): read from data = 197
D/dalvikvm(  298): GC freed 708 objects / 35672 bytes in 183ms


I see this error:
Code: Select all
E/SurfaceComposerClient(  966): using an invalid surface id=1, identity=65 should be 70
and I think it is at the base of my problem, but I don't have a clue what I should do about it.
Any suggestions ?
Attachments
adext.zip
OpenGL sources for GL11
(577.67 KiB) Downloaded 357 times
cg0601
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Aug 04, 2009 8:53 am

Error found

Postby cg0601 » Fri Aug 28, 2009 1:49 pm

It turns out that this error is a basic beginners error :D

I needed to add view.onResume() and view.onPause() to my activity onResume() and onPause() methods

It is documented in the GLSurfaceView api docs
cg0601
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Aug 04, 2009 8:53 am

Postby WarrenFaith » Tue Sep 08, 2009 8:42 pm

Hey,

i was about to change a bit of my opengl stuff and i found out that the GC vanished. I moved my objects without any GC for more than 2 minutes (than i stopped testing).

Source Code attached. I am happy if you can test it too and maybe you can find out why it stopped.
Attachments
3dsample.zip
(5.53 KiB) Downloaded 380 times
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby Ferrat » Fri Sep 25, 2009 12:46 pm

Can confirm that my emulator does not do any GC actions with your source, don't know about 1.5 but 1.6 has a few updates to OpenGL and guessing GC handling is one of the main once since that was a problem before, specially for games since you had to do all kinds of stuff to handle it better.
Ferrat
Freshman
Freshman
 
Posts: 4
Joined: Fri Sep 25, 2009 12:37 pm

Re: Error found

Postby aaronzheng » Thu Jan 14, 2010 9:36 am

[quote="cg0601"]It turns out that this error is a basic beginners error :D

I needed to add view.onResume() and view.onPause() to my activity onResume() and onPause() methods

It is documented in the GLSurfaceView api docs[/quote]


hi buddy,
I download your project and add view.onResume() and view.onPause() to activity, but whenever I switch to
the home screen and then switch back to the game, I can only see a blue background , all of the drawing
objects are disappeared.

what's the problem? i use my G1 to test the programme.
aaronzheng
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 13, 2010 12:07 pm

Top

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

Who is online

Users browsing this forum: No registered users and 3 guests