LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.05k stars 139 forks source link

How to implement off-screen rendering on Android? #124

Closed jayzhen521 closed 1 month ago

jayzhen521 commented 2 months ago

Thank you very much for your previous help. My app can be previewed on Android, but I don't know how to do off-screen rendering. I didn't find any code related to eglCreatePbufferSurface in the source code. In your submission, you mentioned that LLGL can do offscreen rendering, but I don't know how to do it. Can you give me some tips?:

commit fe9dd615dcc17446e5111f05fd062e8a5d79a270 Author: Laura Hermanns lukas.hermanns90@gmail.com Date: Thu Jul 4 10:13:04 2024 -0400

[GL] Refactored GLContext management in GL backend.

- Finally create new GL contexts if another swap-chain or render-target with higher sample count is requested.
- Create a default GL context if none if exists in all the context dependeny RenderSystem::Create* functions,
  to ensure those functions can be called before a swap-chain is created.
- These changes enable the GL backend for offscreen rendering:
  An app can simply render into render-targets without ever having to create a swap-chain.

TODO: Some GL objects that are considered lightweight, such as VAOs and sync objects, cannot be shared across GL contexts
      and must hence be created for each of these contexts.
      For this reason, it is still required for LLGL to create a vertex buffer *after* the GLContext
      that is being used for rendering was created.
LukasBanana commented 2 months ago

eglCreatePbufferSurface is not yet supported in the GL backend for Android, but I'll put it on my todo list since I'm already actively making updates for Android support. Can you share how your app is intending to use LLGL for offscreen rendering only? On Desktop your app could be entirely a background application, but I'm not aware of Android apps allowing to run entirely in the background at least I never heard of such an app that also uses GPU rendering.

jayzhen521 commented 2 months ago

My application is a video editor, similar to After Effects but relatively simpler. Users can edit and preview scenes, then export the final video. I plan to use off-screen rendering during video export, and during this process, it might display rendering progress or advertisements. Do you have any better suggestions? This is a workflow that I came up with myself.

LukasBanana commented 2 months ago

I see, so your app is still drawing to a surface but you need the GL rendering to happen in the background, into a pbuffer that is. I can try porting the Offscreen example to Android and we can go from there.

jayzhen521 commented 2 months ago

Great, I look forward to seeing your updates soon!!!

jayzhen521 commented 1 month ago

Excuse me, can the development of off-screen rendering of opengles be advanced, or tell me when it will start, we really need this feature. I really appreciate your help!

LukasBanana commented 1 month ago

I’m on vacation right now, but I might be able to continue with the Android support this weekend. If this is urgent, you can try to extend AndroidGLContext and AndroidGLSwapChainContext to create a pbuffer surface instead of a window surface.

jayzhen521 commented 1 month ago

Enjoy your time! There's no rush on my end.

LukasBanana commented 1 month ago

I started with porting the C99 examples, especially the Offscreen example, to Android with f31eb23. This introduced the Pbuffer EGLSurface but needs testing. I'll see if I can find some time this week to continue with this.

LukasBanana commented 1 month ago

With ffadc60, I ported the Offscreen C99 example to Android which does not require a native window to render into the Pbuffer. The result is written to the Documents/ folder as shown below (tested on a Galaxy Tab A8):

OffscreenExample_Android