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 178 times)

0 Members and 1 Guest are viewing this topic.

foo

  • Newbie
  • *
  • Posts: 11
    • 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: 11
    • 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.