Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Android, how to know if GL context is lost?  (Read 2971 times)

0 Members and 1 Guest are viewing this topic.

wqking

  • Newbie
  • *
  • Posts: 5
    • View Profile
Android, how to know if GL context is lost?
« on: February 13, 2017, 11:36:09 am »
Hi all,

On Android, if I put the game to background then get it foreground, there is chance that the GL context is lost and the screen is in black.

My questions:

1, How to detect if the GL context has been lost? If I can detect it, I can reconstruct the context and reload all textures.
2, Do the events, LostFocus and GainedFocus, work on Android for being in background and foreground?

Thanks

wqking

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Android, how to know if GL context is lost?
« Reply #1 on: February 16, 2017, 01:19:20 am »
Nobody knows?
On my Android phone, both my game and SFML sample become black screen after bringing to foreground.
If we can't solve or even detect the OpenGL context loss issue, how can we use SFML on Android?

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Android, how to know if GL context is lost?
« Reply #2 on: February 16, 2017, 02:48:18 pm »
It has been quite some time i did the port of Kroniax on android. But the LostFocus/GainedFocus worked, but you also have to watch for MouseEnter/Leave, they were strangly mapped (Lockscreen iirc).

I never had the issue with only clearing the GPU objects, in my case the RAM did also get cleaned up (savestate). But maybe things have changed because we now have plenty of RAM (at the time of the port 1-2gb were top-notch :D)


AlexAUT

wqking

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Android, how to know if GL context is lost?
« Reply #3 on: February 17, 2017, 01:25:39 am »
It has been quite some time i did the port of Kroniax on android. But the LostFocus/GainedFocus worked, but you also have to watch for MouseEnter/Leave, they were strangly mapped (Lockscreen iirc).

I never had the issue with only clearing the GPU objects, in my case the RAM did also get cleaned up (savestate). But maybe things have changed because we now have plenty of RAM (at the time of the port 1-2gb were top-notch :D)


AlexAUT

Thanks.
Then I have to re-create all GL resources in GainedFocus no matter whether the context is lost or not? I can't know exactly whether the context is lost?

wqking

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Android, how to know if GL context is lost?
« Reply #4 on: February 17, 2017, 03:22:51 am »
Hi Alex, again,

I dowload your Kroniax source code from github, but can't see where you handle the message "gained focus".
How can I see how you deal with context loss in Kroniax?

Thanks

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Android, how to know if GL context is lost?
« Reply #5 on: February 17, 2017, 04:43:02 pm »
The Android code isn't published, but at the time the lowMemory and onSaveState weren't handled by SFML, so I implemented them myself and recompiled SFML


Edit:
Just had a quick look, and they still aren't implemented (https://github.com/SFML/SFML/blob/master/src/SFML/Main/MainAndroid.cpp#L451-L462).


AlexAUT