[Solved] Problem with precision qualifiers in a shader for android

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

[Solved] Problem with precision qualifiers in a shader for android

Post by Bigfoot71 »

I had a problem rendering with a shader for android due to the precision of the float numbers, so I wanted to add these precompilation instructions so that the floats are automatically `highp` if possible.

Code: Select all

#ifdef GL_ES 
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
But I get this error:

Code: Select all

ERROR: highp : overloaded functions must have the same parameter precision qualifiers for argument 1
ERROR: highp : overloaded functions must have the same parameter precision qualifiers for argument 3
ERROR: highp : overloaded functions must have the same parameter precision qualifiers for argument 4
Which matches this line:

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
My question is why? Because on the other examples I've seen on the forum it seems to work for everyone.
The version of OpenGL ES on the device that produces this error is 3.2 if that helps.
Last edited by Bigfoot71 on Sun Jan 22, 2023 3:48 pm, edited 1 time in total.
My avatar code for the curious :D V1, V2, V3.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Problem with precision qualifiers in a shader for android

Post by Bigfoot71 »

Does anyone have any idea about this problem? The only solution I could find is to specify `highp` on a case-by-case basis but this can be problematic on some devices, does anyone use the technique I showed or another?
My avatar code for the curious :D V1, V2, V3.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Problem with precision qualifiers in a shader for android

Post by slime »

Bigfoot71 wrote: Thu Jan 12, 2023 3:29 pm My question is why? Because on the other examples I've seen on the forum it seems to work for everyone.
I don't know about other examples on the forum but that won't work because love declares the effect function before your default precision line, so the declaration would use mediump and the definition would use highp which isn't allowed.

Bigfoot71 wrote: Sun Jan 22, 2023 9:48 am specify `highp` on a case-by-case basis but this can be problematic on some devices
If you're talking about very old devices which don't support highp in pixel shaders at all, you could use the preprocessor to use highp for those variables when it's available and use mediump otherwise.

love does that itself for some of its internal variables, and it has a LOVE_HIGHP_OR_MEDIUMP define to make it a bit simpler to use.

e.g.:

Code: Select all

LOVE_HIGHP_OR_MEDIUMP vec4 foo;
Or you could just not support those old devices for your game. :)
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Problem with precision qualifiers in a shader for android

Post by Bigfoot71 »

slime wrote: Sun Jan 22, 2023 2:06 pm If you're talking about very old devices which don't support highp in pixel shaders at all, you could use the preprocessor to use highp for those variables when it's available and use mediump otherwise.

love does that itself for some of its internal variables, and it has a LOVE_HIGHP_OR_MEDIUMP define to make it a bit simpler to use.

e.g.:

Code: Select all

LOVE_HIGHP_OR_MEDIUMP vec4 foo;
Or you could just not support those old devices for your game. :)
Thank you very much for this solution it is what I needed! :D

And yes I very well could have but I'm doing this for a game using g3d and I've taken the trouble to optimize it so it can run on an old tablet as well as newer hardware, last issue was on a "stupid" shader so I would have liked to do things completely ^^

Besides, I did not find this information in the documentation of Löve, should it have been there? (here or here) (or maybe i searched wrong)
slime wrote: Sun Jan 22, 2023 2:06 pm I don't know about other examples on the forum but that won't work because love declares the effect function before your default precision line, so the declaration would use mediump and the definition would use highp which isn't allowed.
For the other examples I had been able to find on the forum using the example I showed here are two:

viewtopic.php?f=4&t=82087&p=197592
viewtopic.php?f=4&t=83890&p=212185

Thanks again :megagrin:
My avatar code for the curious :D V1, V2, V3.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Problem with precision qualifiers in a shader for android

Post by slime »

Bigfoot71 wrote: Sun Jan 22, 2023 3:36 pm I did not find this information in the documentation of Löve, should it have been there?
It's more of an internal thing, I'm not sure if it should be officially supported like that. It's pretty simple to implement yourself in any case:

Code: Select all

#if defined(VERTEX) || __VERSION__ > 100 || defined(GL_FRAGMENT_PRECISION_HIGH)
	#define MY_HIGHP_OR_MEDIUMP highp
#else
	#define MY_HIGHP_OR_MEDIUMP mediump
#endif
Bigfoot71 wrote: Sun Jan 22, 2023 3:36 pm For the other examples I had been able to find on the forum using the example I showed here are two:
Ah, those were using love 0.10 where it might have incidentally worked because some of love's internals were different - but it was never an officially supported thing.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: [Solved] Problem with precision qualifiers in a shader for android

Post by Bigfoot71 »

Okay, I had roughly thought the same thing in view of the seniority of these posts. Thanks again for these clarifications. :)
My avatar code for the curious :D V1, V2, V3.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 47 guests