TR1X
TR1X copied to clipboard
Adding shaders for playing also with OpenGL 2.1.
I was wondering what you think about adding some extra shaders programs for running the engine also with OpenGL 2.1. I tested the engine with a Raspberry PI computer board and at the beginning it didn't work because because it just supports programs up to version 1.20 while the ones in the current development branch run from version 1.30. However, I have been able to add extra support also for previous version of OpenGL, to be used if support for OpenGL 3.0 is missing. After that, testing with the above computer module gave an excellent result.
Into the bin/shaders
directory there are these files:
2d.fsh 2d.vsh 3d.fsh 3d.vsh
I have seen that 2d.vsh
and 3d.vsh
can be set to version 1.20 safely because they don't use any specific command from version 1.30 and newer.
Instead, 2d.fsh
and 3d.fsh
required some extra work.
Actually, after downgrading to version 1.20, I replaced command texture
with texture2D
into both scripts.
I had also to remove support smoothingEnabled
from 3d.fsh
because I don't know how it could be replaced at this time. Probably, there is a better way to handle it.
However, it was enough for making the engine working.
Perhaps, it may be worth to evaluate the chance to fall down to use a program able to run on a previous version of the GL library, if the preferred support for OpenGL 3.0 is rejected.
I looked into this earlier, and came to these conclusions:
- The shader files have a syntax error. They use v330 syntax, but identify as v130. Most windows GPU drivers work regardless, some don't.
- Proper fallback from GLSL v330 to v130 cannot be achieved solely by changing the external shader files. Because the v130 absence of "layout(location = something)" must be handled in the source code with glBindAttribLocation.
See also issue #327 See also issue #644
Because the v130 absence of "layout(location = something)" must be handled in the source code with glBindAttribLocation.
I don't think so. They are properly handled by OGL extension which I have even on OGL 2.1 hardware (Intel).
@carlo-bramini
I had also to remove support smoothingEnabled from 3d.fsh because I don't know how it could be replaced at this time. Probably, there is a better way to handle it.
You can conditionally compile corresponding part, i.e.#ifdef GL_EXT_gpu_shader4
.
From what I understand now, when older openGL hardware is used with drivers updated with the ARB_explicit_attrib_location feature, it can parse the layout syntax. In that way, it is not strictly GLSL-version specific.
reference: https://stackoverflow.com/questions/7668599/glsl-equivalent-of-layout-location-1-in-version-130