Hi Mathias,
Thanks for your suggestion. I think you misunderstood my question. I
am not asking about how to make 2D and 3D rendering working together
on the same surface at the same time, in fact, we are not mixing
lockCanvas()/UnlockCanvasAndPost() with OpenGl eglMakeCurrent()/
eglSwapBuffers() on the same Surface at the same time.
What we did is: with a single Surface, set up an internal flag like
"boolean surfaceBoundToOpenGL". When this flag is set to false, means
we are doing 2D rendering on the surface, let the rendering pipeline
go through the lockCanvas()/UnlockCanvasAndPost(). When this flag is
set to true, means we are doing 3D rendering, then the rendering
pipeline go through the eglMakeCurrent()/eglSwapBuffers().

This solution is working perfectly on both emulator and G1. The only
issue left is once the surface is bound to OpenGL, we are unable to
"un-bind" it from OpenGL when we quit from 3D game session and let 2D
rendering working again. This problem only happens on G1 since the
surface is created on GPU memory.

So the question actually is: how can we tell OpenGL to completely
release the surface when 3D rendering is done and we would like to go
back to 2D.

If you want, I can send you the APK file of our X-benchmark, from
which you can see that on emulator, we successfully enter and quit 3D
rendering with the above solution.

Hongkun
www.omnigsoft.com


On Dec 26, 7:10 pm, Mathias Agopian <[email protected]> wrote:
> Hi,
>
> On Dec 26, 5:00 am, Toothy Bunny <[email protected]> wrote:
>
>
>
> > Hi All,
> > When designing a 3D game running on Android, we need to enter into 3D
> > (OpenGL) rendering and quit back to 2D rendering from time to time,
> > like this control flow: game title page (2D) -> game main menu (2D) ->
> > game window (3D / OpenGL) -> game main menu (2D).
> > We have made this working well on the emulator by following the design
> > pattern required by SurfaceView:
>
> > 1) For 2D rendering:
> > Canvas c = _surfaceHolder.lockCanvas();
> > //Do 2D rendering with canvas
> > _surfaceHolder.unlockCanvasAndPost(c);
>
> > 2) After entering 3D (OpenGL) rendering:
> > egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
> > //Do OpenGL rendering
> > egl.eglSwapBuffers(eglDisplay, eglSurface);
>
> Unfortunately, It is not currently possible to mix and match lockCanvas
> () with eglSwapBuffers().
>
> I would recommend to simply use a regular view to do the 2D rendering.
> You can have a regular view on top of the SurfaceView you use for
> OpenGL (use a layout to stack them up), and simply show and hide the
> "2D" view when needed.
> This requires that the 2D rendering be done in the UI thread though;
> but it will be more efficient and this has the advantage that you can
> use any widget you want (like buttons).
>
> > This works well on the emulator. However on T-Mobile G1 phone,
> > entering 3D (OpenGL) from 2D does not have any problem, but when exit
> > 3D back to 2D, the G1's screen content remained with the last OpenGL
> > rendering and no any 2D rendering can be added on the Surface.
> > I think the reason is because we set the Surface type as
> > "SurfaceHolder.SURFACE_TYPE_GPU" when we create the surface. When I
> > quit from OpenGL, I tried to change the surface type back to
> > "SurfaceHolder.SURFACE_TYPE_NORMAL" but it general IllegalArgument
> > Exception. I guess it is because Android Surface does not allow to
> > change its type dynamically.
>
> Exact.
>
> > So my question is: how can we properly exit from OpenGL and make the
> > Surface work again with all 2D rendering? Is there a way to re-create
> > the surface of the View object?
>
> > By the way, my OpenGl clean-up code is exactly same as the
> > GLSurfaceView sample code, it should have any problem.
>
> > Many thanks for any suggestions!
> > Hongkunwww.omnigsoft.com
>
> I hope this helps.
>
> Mathias
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to