Reflecting GLBase in shaders

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Reflecting GLBase in shaders

Post by Rado1 »

The basic problem here is to write a shader which would work for both ZApplication.GLBase settings, for the Compatible mode and for the ES/GL3 mode.

The most effective way, is to obtain this information in the form of preprocessor macro/variable, because it should influence shader code compilation; a uniform variable does not seem to be an optimal solution. If we look at what is already available in GLSL, we can use GL_ES and __VERSION__. I tried the following:

Code: Select all

#if defined GL_ES  || __VERSION__ >= 130
#define ES2_GL3
#endif
#ifdef ES2_GL3
...
but these shaders do not work on Android. Could you please tell me where's the problem?

Anyway, even if __VERSION__ and GL_ES macros are used, they do not reflect setting of the ZApplication.GLBase propety; but just what version of the shading language is available on the device.

The desired solution would be to write code like this:

Code: Select all

#ifdef ES2_GL3
...
#endif
...
Of course, there is no ES2_GL3 macro defined (yet). Isn't it possible to define this (or similar) macro in ZGE used to reflect the ZApplication.GLBase property in its shaders?
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Hi,

I Googled and there does not seem to be a way to externally define preprocessor macros so that ES2_GL3 could be predefined by ZGE.

As for your first attempt, try breaking it up like this and see if it helps:

Code: Select all

#ifdef GL_ES
#define ES2_GL3
#endif

#if __VERSION__ >= 130
#define ES2_GL3
#endif

#ifdef ES2_GL3 
...
/Ville
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hmm,

Perhaps you could go with / write a super basic parser that goes through the shader source and generates the appropriate source / string depending on the platform you're building to. That way only the platform specific implementation ends up in the build.

K
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Ville, unfortunately we cannot rely on the __VERSION__ variable - it returns 110 even if my GPU supports GLSL 4.20.
Kjell, the parser you mentioned is probably the only reliable solution to reflect ZApplication.GLBase in shaders. It can be relatively simple: e.g. to replace predefined string (e.g. GLBASE) to the value of ZApplication.GLBase (0 or 1). It would be possible to write:

Code: Select all

#if GLBASE == 1
precision mediump float;
#endif
But having this feature is not of very high importance, because for Android-compatible applications a simple rule can be used: if no shaders are used in the project - compatibility mode can be used; if shaders are used - they should be GLSL-compatible and ES2/GL3 mode should be used.

Of course, another reliable solution is to have 2 versions of shaders for the both GLBase modes and to use just one of them in a Material component, depending on setting the ZApplication.GLBase property. I'm using this style now, but it is difficult to maintain.
Post Reply