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

Author Topic: SFML 2.5.1 with GL ES 2.0 shader support for mobile devices  (Read 9889 times)

0 Members and 2 Guests are viewing this topic.

foo

  • Newbie
  • *
  • Posts: 20
    • View Profile
SFML 2.5.1 with GL ES 2.0 shader support for mobile devices
« on: January 12, 2020, 06:17:02 pm »
Go directly to github



I needed better shaders for SFML to run on mobile. This adds ES 2.0 shader support. Every render texture comes with a
setDefaultShader(sf::Shader*)
routine that allows you to define the default shader. If you don't set a default shader on mobile it will either be completely black or crash. On mobile, shaders need both fragment and vertex shader for its constructor.

Because mobile stores image data flipped by the Y axis, you must also use
 flipTexture(bool flip)
if you're doing post-processing.

Besides that it's normal SFML 2.5.1. If you're on desktop those new functions won't be available. Add these checks using the
 __ANDROID__
pre-processor.


sf::Texture loadingScreenSnapshot = ENGINE.GetRenderSurface().getTexture();

#ifdef __ANDROID__
    loadingScreenSnapshot.flip(true);
#endif


Because the texels/s in mobile GPUs are restricted compared to desktop, making a copy of a render surface, applying post process effects, and displaying it on the same frame can choke. SFML sends a lot of stuff back and forth from GPU <-> CPU and this is costly. If SFML had a way to represent a proxy render surface by an OpenGL ID, it could skip passing the texture data over to CPU and apply shader post-effects all in the GPU before rendering to screen. This would make real-time post-processing effects possible on mobile.

I've been using this custom fork for my Open Net Battle engine. View references on using SFML for mobile >> here <<

Some videos of SFML on mobile:




SwooshLib for SFML also works with SFML 2.5.1 custom fork. Use swoosh to make professional looking games with cool shaders, screen transitions, app management, ease functions, and more.




MrOnlineCoder

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: SFML 2.5.1 with GL ES 2.0 shader support for mobile devices
« Reply #1 on: January 12, 2020, 08:54:53 pm »
Not coding with SFML for Android, but seems that you've done nice work. Did you make a pull request, so it can be added to main SFML repo?

foo

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: SFML 2.5.1 with GL ES 2.0 shader support for mobile devices
« Reply #2 on: January 13, 2020, 06:30:32 pm »
Thank you.

Per making a fork:

No I have not because the design of this feature has been in limbo from the main devs for some time.

The biggest point being breakage of the existing SFML API.
How do they support custom shaders's named attributes and uniforms... or how should SFML behave with default shaders?
Should it have a built-in one or should users always supply a default shader in order to get their first SFML app running?

These kinds of questions never seem to get any resolve so I made the features myself.

jonc

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML 2.5.1 with GL ES 2.0 shader support for mobile devices
« Reply #3 on: March 25, 2021, 10:07:08 am »
I am interested in getting shaders to work on Android and iOS. Does this also work on iOS or only Android?

foo

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: SFML 2.5.1 with GL ES 2.0 shader support for mobile devices
« Reply #4 on: April 23, 2021, 09:22:12 pm »
I am interested in getting shaders to work on Android and iOS. Does this also work on iOS or only Android?

Hey jonc, it should work on both. All I did was change out the GL stuff for GLES 2.0 which 99% of mobile devices support.

I will be revisiting this project later this year to add more features for both mobile devices.