AMIGAOS: Improve shader compatibility

OGLES2 doesn't support uniform booleans so we use macros to make it use
integers in this case. For other platforms, this change should be a
noop.
OGLES2 doesn't like float suffix for constants, remove it as well.
This commit is contained in:
Le Philousophe 2022-02-20 21:40:23 +01:00
parent 7061b4109e
commit c9b4949746
24 changed files with 96 additions and 74 deletions

View File

@ -178,14 +178,23 @@ static const char *boxVertex =
"uniform vec2 offsetXY;\n" "uniform vec2 offsetXY;\n"
"uniform vec2 sizeWH;\n" "uniform vec2 sizeWH;\n"
"uniform vec2 texcrop;\n" "uniform vec2 texcrop;\n"
// OGLES2 on AmigaOS doesn't support uniform booleans
#if defined(AMIGAOS)
"uniform mediump int flipY;\n"
#else
"uniform bool flipY;\n" "uniform bool flipY;\n"
#endif
"varying vec2 Texcoord;\n" "varying vec2 Texcoord;\n"
"void main() {\n" "void main() {\n"
"Texcoord = texcoord * texcrop;\n" "Texcoord = texcoord * texcrop;\n"
"vec2 pos = offsetXY + position * sizeWH;\n" "vec2 pos = offsetXY + position * sizeWH;\n"
"pos.x = pos.x * 2.0 - 1.0;\n" "pos.x = pos.x * 2.0 - 1.0;\n"
"pos.y = pos.y * 2.0 - 1.0;\n" "pos.y = pos.y * 2.0 - 1.0;\n"
#if defined(AMIGAOS)
"if (flipY != 0)\n"
#else
"if (flipY)\n" "if (flipY)\n"
#endif
"pos.y *= -1.0;\n" "pos.y *= -1.0;\n"
"gl_Position = vec4(pos, 0.0, 1.0);\n" "gl_Position = vec4(pos, 0.0, 1.0);\n"
"}\n"; "}\n";

View File

@ -2,7 +2,7 @@ in vec2 Texcoord;
in vec4 Color; in vec4 Color;
uniform sampler2D tex; uniform sampler2D tex;
uniform bool textured; uniform UBOOL textured;
uniform float alphaRef; uniform float alphaRef;
uniform float meshAlpha; uniform float meshAlpha;
@ -11,7 +11,7 @@ OUTPUT
void main() void main()
{ {
outColor = Color; outColor = Color;
if (textured) { if (UBOOL_TEST(textured)) {
vec4 texColor = texture(tex, Texcoord); vec4 texColor = texture(tex, Texcoord);
outColor.rgba *= texColor.rgba; outColor.rgba *= texColor.rgba;
outColor.a *= meshAlpha; outColor.a *= meshAlpha;

View File

@ -9,12 +9,12 @@ uniform highp mat4 projMatrix;
uniform highp mat4 extraMatrix; uniform highp mat4 extraMatrix;
uniform highp mat4 normalMatrix; uniform highp mat4 normalMatrix;
uniform highp vec3 cameraPos; uniform highp vec3 cameraPos;
uniform bool textured; uniform UBOOL textured;
uniform bool useVertexAlpha; uniform UBOOL useVertexAlpha;
uniform vec4 uniformColor; uniform vec4 uniformColor;
struct shadow_info { struct shadow_info {
bool _active; UBOOL _active;
vec3 _color; vec3 _color;
vec3 _light; vec3 _light;
vec3 _point; vec3 _point;
@ -32,7 +32,7 @@ void main()
pos = modelMatrix * pos; pos = modelMatrix * pos;
// See http://en.wikipedia.org/wiki/Line-plane_intersection // See http://en.wikipedia.org/wiki/Line-plane_intersection
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
pos /= pos.w; pos /= pos.w;
vec3 l = pos.xyz - shadow._light; vec3 l = pos.xyz - shadow._light;
float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal); float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal);
@ -49,15 +49,15 @@ void main()
gl_Position = projectedPos; gl_Position = projectedPos;
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
Color = vec4(shadow._color, 1.0); Color = vec4(shadow._color, 1.0);
} else { } else {
Color = color; Color = color;
} }
if (!useVertexAlpha) if (!UBOOL_TEST(useVertexAlpha))
Color.a = 1.0; Color.a = 1.0;
Color *= uniformColor; Color *= uniformColor;
if (textured) { if (UBOOL_TEST(textured)) {
Texcoord = texcoord; Texcoord = texcoord;
} else { } else {
Texcoord = vec2(0.0, 0.0); Texcoord = vec2(0.0, 0.0);

View File

@ -2,7 +2,7 @@ in vec2 Texcoord;
in vec4 Color; in vec4 Color;
uniform sampler2D tex; uniform sampler2D tex;
uniform bool textured; uniform UBOOL textured;
uniform float alphaRef; uniform float alphaRef;
uniform float meshAlpha; uniform float meshAlpha;
@ -11,7 +11,7 @@ OUTPUT
void main() void main()
{ {
outColor = Color; outColor = Color;
if (textured) { if (UBOOL_TEST(textured)) {
vec4 texColor = texture(tex, Texcoord); vec4 texColor = texture(tex, Texcoord);
outColor.rgba *= texColor.rgba; outColor.rgba *= texColor.rgba;
outColor.a *= meshAlpha; outColor.a *= meshAlpha;

View File

@ -9,10 +9,10 @@ uniform highp mat4 projMatrix;
uniform highp mat4 extraMatrix; uniform highp mat4 extraMatrix;
uniform highp mat4 normalMatrix; uniform highp mat4 normalMatrix;
uniform highp vec3 cameraPos; uniform highp vec3 cameraPos;
uniform bool textured; uniform UBOOL textured;
uniform bool useVertexAlpha; uniform UBOOL useVertexAlpha;
uniform vec4 uniformColor; uniform vec4 uniformColor;
uniform bool hasAmbient; uniform UBOOL hasAmbient;
const int maxLights = 8; const int maxLights = 8;
uniform vec4 lightsPosition[maxLights]; uniform vec4 lightsPosition[maxLights];
@ -21,7 +21,7 @@ uniform vec4 lightsColor[maxLights];
uniform vec4 lightsParams[maxLights]; uniform vec4 lightsParams[maxLights];
struct shadow_info { struct shadow_info {
bool _active; UBOOL _active;
vec3 _color; vec3 _color;
vec3 _light; vec3 _light;
vec3 _point; vec3 _point;
@ -39,7 +39,7 @@ void main()
pos = modelMatrix * pos; pos = modelMatrix * pos;
// See http://en.wikipedia.org/wiki/Line-plane_intersection // See http://en.wikipedia.org/wiki/Line-plane_intersection
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
pos /= pos.w; pos /= pos.w;
vec3 l = pos.xyz - shadow._light; vec3 l = pos.xyz - shadow._light;
float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal); float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal);
@ -56,15 +56,15 @@ void main()
gl_Position = projectedPos; gl_Position = projectedPos;
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
Color = vec4(shadow._color, 1.0); Color = vec4(shadow._color, 1.0);
} else { } else {
Color = color; Color = color;
} }
if (!useVertexAlpha) if (!UBOOL_TEST(useVertexAlpha))
Color.a = 1.0; Color.a = 1.0;
Color *= uniformColor; Color *= uniformColor;
if (textured) { if (UBOOL_TEST(textured)) {
Texcoord = texcoord; Texcoord = texcoord;
} else { } else {
Texcoord = vec2(0.0, 0.0); Texcoord = vec2(0.0, 0.0);
@ -109,7 +109,7 @@ void main()
light += lightsColor[i].xyz * intensity; light += lightsColor[i].xyz * intensity;
} }
if (!hasAmbient) if (!UBOOL_TEST(hasAmbient))
light += vec3(0.5, 0.5, 0.5); light += vec3(0.5, 0.5, 0.5);
light /= max(1.0, max(max(light.x, light.y), light.z)); light /= max(1.0, max(max(light.x, light.y), light.z));
Color *= vec4(light, 1.0); Color *= vec4(light, 1.0);

View File

@ -2,7 +2,7 @@ in vec2 Texcoord;
in vec4 Color; in vec4 Color;
uniform sampler2D tex; uniform sampler2D tex;
uniform bool textured; uniform UBOOL textured;
uniform float alphaRef; uniform float alphaRef;
uniform float meshAlpha; uniform float meshAlpha;
@ -11,7 +11,7 @@ OUTPUT
void main() void main()
{ {
outColor = Color; outColor = Color;
if (textured) { if (UBOOL_TEST(textured)) {
vec4 texColor = texture(tex, Texcoord); vec4 texColor = texture(tex, Texcoord);
outColor.rgba *= texColor.rgba; outColor.rgba *= texColor.rgba;
outColor.a *= meshAlpha; outColor.a *= meshAlpha;

View File

@ -9,12 +9,12 @@ uniform highp mat4 projMatrix;
uniform highp mat4 extraMatrix; uniform highp mat4 extraMatrix;
uniform highp mat4 normalMatrix; uniform highp mat4 normalMatrix;
uniform highp vec3 cameraPos; uniform highp vec3 cameraPos;
uniform bool textured; uniform UBOOL textured;
uniform bool useVertexAlpha; uniform UBOOL useVertexAlpha;
uniform vec4 uniformColor; uniform vec4 uniformColor;
struct shadow_info { struct shadow_info {
bool _active; UBOOL _active;
vec3 _color; vec3 _color;
vec3 _light; vec3 _light;
vec3 _point; vec3 _point;
@ -43,15 +43,15 @@ void main()
gl_Position = projectedPos; gl_Position = projectedPos;
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
Color = vec4(shadow._color, 1.0); Color = vec4(shadow._color, 1.0);
} else { } else {
Color = color; Color = color;
} }
if (!useVertexAlpha) if (!UBOOL_TEST(useVertexAlpha))
Color.a = 1.0; Color.a = 1.0;
Color *= uniformColor; Color *= uniformColor;
if (textured) { if (UBOOL_TEST(textured)) {
Texcoord = texcoord; Texcoord = texcoord;
} else { } else {
Texcoord = vec2(0.0, 0.0); Texcoord = vec2(0.0, 0.0);

View File

@ -3,8 +3,8 @@ in vec4 Color;
uniform sampler2D tex; uniform sampler2D tex;
uniform sampler2D texZBuf; uniform sampler2D texZBuf;
uniform bool textured; uniform UBOOL textured;
uniform bool hasZBuffer; uniform UBOOL hasZBuffer;
uniform vec2 texcropZBuf; uniform vec2 texcropZBuf;
uniform vec2 screenSize; uniform vec2 screenSize;
uniform float alphaRef; uniform float alphaRef;
@ -35,10 +35,10 @@ void checkZBuffer()
void main() void main()
{ {
if (hasZBuffer) if (UBOOL_TEST(hasZBuffer))
checkZBuffer(); checkZBuffer();
outColor = Color; outColor = Color;
if (textured) { if (UBOOL_TEST(textured)) {
outColor *= texture(tex, Texcoord); outColor *= texture(tex, Texcoord);
} }

View File

@ -11,12 +11,12 @@ uniform highp mat4 modelMatrix;
uniform highp mat4 viewMatrix; uniform highp mat4 viewMatrix;
uniform highp mat4 projMatrix; uniform highp mat4 projMatrix;
uniform highp mat4 extraMatrix; uniform highp mat4 extraMatrix;
uniform bool textured; uniform UBOOL textured;
uniform bool lightsEnabled; uniform UBOOL lightsEnabled;
uniform highp vec2 texScale; uniform highp vec2 texScale;
struct shadow_info { struct shadow_info {
bool _active; UBOOL _active;
vec3 _color; vec3 _color;
vec3 _light; vec3 _light;
vec3 _point; vec3 _point;
@ -33,7 +33,7 @@ void main()
vec4 pos = modelMatrix * extraMatrix * vec4(position, 1.0); vec4 pos = modelMatrix * extraMatrix * vec4(position, 1.0);
// See http://en.wikipedia.org/wiki/Line-plane_intersection // See http://en.wikipedia.org/wiki/Line-plane_intersection
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
pos /= pos.w; pos /= pos.w;
vec3 l = pos.xyz - shadow._light; vec3 l = pos.xyz - shadow._light;
float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal); float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal);
@ -44,13 +44,13 @@ void main()
vec4 positionView = viewMatrix * pos; vec4 positionView = viewMatrix * pos;
gl_Position = projMatrix * positionView; gl_Position = projMatrix * positionView;
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
Color = vec4(shadow._color, 1.0); Color = vec4(shadow._color, 1.0);
} else { } else {
Color = color; Color = color;
} }
if (textured) { if (UBOOL_TEST(textured)) {
Texcoord = vec2(0.0, 1.0) + (texcoord / texScale); Texcoord = vec2(0.0, 1.0) + (texcoord / texScale);
} else { } else {
Texcoord = vec2(0.0, 0.0); Texcoord = vec2(0.0, 0.0);

View File

@ -3,8 +3,8 @@ in vec4 Color;
uniform sampler2D tex; uniform sampler2D tex;
uniform sampler2D texZBuf; uniform sampler2D texZBuf;
uniform bool textured; uniform UBOOL textured;
uniform bool hasZBuffer; uniform UBOOL hasZBuffer;
uniform vec2 texcropZBuf; uniform vec2 texcropZBuf;
uniform vec2 screenSize; uniform vec2 screenSize;
uniform float alphaRef; uniform float alphaRef;
@ -35,10 +35,10 @@ void checkZBuffer()
void main() void main()
{ {
if (hasZBuffer) if (UBOOL_TEST(hasZBuffer))
checkZBuffer(); checkZBuffer();
outColor = Color; outColor = Color;
if (textured) { if (UBOOL_TEST(textured)) {
outColor *= texture(tex, Texcoord); outColor *= texture(tex, Texcoord);
} }

View File

@ -11,8 +11,8 @@ uniform highp mat4 modelMatrix;
uniform highp mat4 viewMatrix; uniform highp mat4 viewMatrix;
uniform highp mat4 projMatrix; uniform highp mat4 projMatrix;
uniform highp mat4 extraMatrix; uniform highp mat4 extraMatrix;
uniform bool textured; uniform UBOOL textured;
uniform bool lightsEnabled; uniform UBOOL lightsEnabled;
uniform highp vec2 texScale; uniform highp vec2 texScale;
const int maxLights = 8; const int maxLights = 8;
@ -22,7 +22,7 @@ uniform vec4 lightsColor[maxLights];
uniform vec4 lightsParams[maxLights]; uniform vec4 lightsParams[maxLights];
struct shadow_info { struct shadow_info {
bool _active; UBOOL _active;
vec3 _color; vec3 _color;
vec3 _light; vec3 _light;
vec3 _point; vec3 _point;
@ -39,7 +39,7 @@ void main()
vec4 pos = modelMatrix * extraMatrix * vec4(position, 1.0); vec4 pos = modelMatrix * extraMatrix * vec4(position, 1.0);
// See http://en.wikipedia.org/wiki/Line-plane_intersection // See http://en.wikipedia.org/wiki/Line-plane_intersection
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
pos /= pos.w; pos /= pos.w;
vec3 l = pos.xyz - shadow._light; vec3 l = pos.xyz - shadow._light;
float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal); float d = dot(shadow._point - shadow._light, shadow._normal) / dot(l, shadow._normal);
@ -50,13 +50,13 @@ void main()
vec4 positionView = viewMatrix * pos; vec4 positionView = viewMatrix * pos;
gl_Position = projMatrix * positionView; gl_Position = projMatrix * positionView;
if (shadow._active) { if (UBOOL_TEST(shadow._active)) {
Color = vec4(shadow._color, 1.0); Color = vec4(shadow._color, 1.0);
} else { } else {
Color = color; Color = color;
} }
if (textured) { if (UBOOL_TEST(textured)) {
Texcoord = vec2(0.0, 1.0) + (texcoord / texScale); Texcoord = vec2(0.0, 1.0) + (texcoord / texScale);
} else { } else {
Texcoord = vec2(0.0, 0.0); Texcoord = vec2(0.0, 0.0);

View File

@ -3,13 +3,13 @@ in vec2 Texcoord;
OUTPUT OUTPUT
uniform sampler2D tex; uniform sampler2D tex;
uniform bool swap; uniform UBOOL swap;
uniform bool swizzle; uniform UBOOL swizzle;
void main() void main()
{ {
vec4 color = texture(tex, Texcoord); vec4 color = texture(tex, Texcoord);
if (swap) color.rgba = color.abgr; if (UBOOL_TEST(swap)) color.rgba = color.abgr;
if (swizzle) color.rgba = color.bgra; if (UBOOL_TEST(swizzle)) color.rgba = color.bgra;
outColor = vec4(color.rgb, 1.0); outColor = vec4(color.rgb, 1.0);
} }

View File

@ -2,13 +2,13 @@ in vec2 Texcoord;
OUTPUT OUTPUT
uniform bool textured; uniform UBOOL textured;
uniform vec4 color; uniform vec4 color;
uniform sampler2D tex; uniform sampler2D tex;
void main() void main()
{ {
outColor = color; outColor = color;
if (textured) if (UBOOL_TEST(textured))
outColor = outColor * texture(tex, Texcoord); outColor = outColor * texture(tex, Texcoord);
} }

View File

@ -5,7 +5,7 @@ uniform vec2 texOffsetXY;
uniform vec2 texSizeWH; uniform vec2 texSizeWH;
uniform vec2 verOffsetXY; uniform vec2 verOffsetXY;
uniform vec2 verSizeWH; uniform vec2 verSizeWH;
uniform bool flipY; uniform UBOOL flipY;
out vec2 Texcoord; out vec2 Texcoord;
@ -18,7 +18,7 @@ void main()
pos.x = pos.x * 2.0 - 1.0; pos.x = pos.x * 2.0 - 1.0;
pos.y = -1.0 * (pos.y * 2.0 - 1.0); pos.y = -1.0 * (pos.y * 2.0 - 1.0);
if (flipY) { if (UBOOL_TEST(flipY)) {
pos.y *= -1.0; pos.y *= -1.0;
} }

View File

@ -3,12 +3,12 @@ in vec3 Color;
OUTPUT OUTPUT
uniform bool textured; uniform UBOOL textured;
uniform sampler2D tex; uniform sampler2D tex;
void main() { void main() {
outColor = vec4(Color, 1.0); outColor = vec4(Color, 1.0);
if (textured) { if (UBOOL_TEST(textured)) {
outColor *= texture(tex, Texcoord); outColor *= texture(tex, Texcoord);
} }
} }

View File

@ -7,7 +7,7 @@ uniform mat4 mvpMatrix;
uniform mat4 projMatrix; uniform mat4 projMatrix;
uniform mat4 modelMatrix; uniform mat4 modelMatrix;
uniform mat4 rotateMatrix; uniform mat4 rotateMatrix;
uniform bool textured; uniform UBOOL textured;
uniform vec3 modelPos; uniform vec3 modelPos;
out vec2 Texcoord; out vec2 Texcoord;
@ -19,7 +19,7 @@ void main() {
vec4 pos = rotateMatrix * vec4(position, 1.0); vec4 pos = rotateMatrix * vec4(position, 1.0);
gl_Position = mvpMatrix * (pos + vec4(modelPos, 1.0)); gl_Position = mvpMatrix * (pos + vec4(modelPos, 1.0));
if (textured) { if (UBOOL_TEST(textured)) {
Color = vec3(1.0); Color = vec3(1.0);
} else { } else {
Color = color; Color = color;

View File

@ -3,13 +3,13 @@ in vec3 Color;
OUTPUT OUTPUT
uniform bool textured; uniform UBOOL textured;
uniform sampler2D tex; uniform sampler2D tex;
void main() { void main() {
outColor = vec4(Color, 1.0); outColor = vec4(Color, 1.0);
if (textured) { if (UBOOL_TEST(textured)) {
outColor *= texture(tex, Texcoord); outColor *= texture(tex, Texcoord);
} }
} }

View File

@ -31,7 +31,7 @@ uniform vec3 bonePosition[maxBones];
uniform Light lights[maxLights]; uniform Light lights[maxLights];
uniform vec3 ambientColor; uniform vec3 ambientColor;
uniform vec3 color; uniform vec3 color;
uniform bool textured; uniform UBOOL textured;
vec4 eyePosition; vec4 eyePosition;
vec3 eyeNormal; vec3 eyeNormal;
@ -94,7 +94,7 @@ void main()
gl_Position = projectionMatrix * eyePosition; gl_Position = projectionMatrix * eyePosition;
// Set the initial vertex color // Set the initial vertex color
if (textured) { if (UBOOL_TEST(textured)) {
Color = vec3(1.0); Color = vec3(1.0);
} else { } else {
Color = color; Color = color;

View File

@ -3,14 +3,14 @@ in vec3 Color;
OUTPUT OUTPUT
uniform bool textured; uniform UBOOL textured;
uniform vec3 color; uniform vec3 color;
uniform sampler2D tex; uniform sampler2D tex;
void main() { void main() {
outColor = vec4(Color, 1.0); outColor = vec4(Color, 1.0);
if (textured) { if (UBOOL_TEST(textured)) {
outColor *= texture(tex, Texcoord); outColor *= texture(tex, Texcoord);
} else { } else {
outColor *= vec4(color, 1.0); outColor *= vec4(color, 1.0);

View File

@ -21,7 +21,7 @@ const int maxLights = 10;
uniform mat4 modelViewMatrix; uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix; uniform mat4 projectionMatrix;
uniform mat3 normalMatrix; uniform mat3 normalMatrix;
uniform bool doubleSided; uniform UBOOL doubleSided;
uniform vec3 ambientColor; uniform vec3 ambientColor;
uniform Light lights[maxLights]; uniform Light lights[maxLights];
@ -62,7 +62,7 @@ vec3 spotLight(vec3 position, vec3 color, float falloffNear, float falloffFar, v
} }
void main() { void main() {
if (doubleSided) { if (UBOOL_TEST(doubleSided)) {
Texcoord = vec2(texcoord.x, 1.0 - texcoord.y); Texcoord = vec2(texcoord.x, 1.0 - texcoord.y);
} else { } else {
Texcoord = vec2(1.0 - texcoord.x, 1.0 - texcoord.y); Texcoord = vec2(1.0 - texcoord.x, 1.0 - texcoord.y);

View File

@ -4,7 +4,7 @@ in vec2 texcoord;
uniform vec2 verOffsetXY; uniform vec2 verOffsetXY;
uniform vec2 verSizeWH; uniform vec2 verSizeWH;
uniform vec2 viewport; uniform vec2 viewport;
uniform bool snapToGrid; uniform UBOOL snapToGrid;
out vec2 Texcoord; out vec2 Texcoord;
@ -14,7 +14,7 @@ void main() {
// Coordinates are [0.0; 1.0], transform to [-1.0; 1.0] // Coordinates are [0.0; 1.0], transform to [-1.0; 1.0]
vec2 pos = verOffsetXY + position * verSizeWH; vec2 pos = verOffsetXY + position * verSizeWH;
if (snapToGrid) { if (UBOOL_TEST(snapToGrid)) {
// Align vertex coordinates to the native pixel grid // Align vertex coordinates to the native pixel grid
// This ensures text does not get garbled by nearest neighbors scaling // This ensures text does not get garbled by nearest neighbors scaling
pos.x = floor(pos.x * viewport.x + 0.5) / viewport.x; pos.x = floor(pos.x * viewport.x + 0.5) / viewport.x;

View File

@ -6,6 +6,6 @@ uniform vec4 color;
out vec4 Color; out vec4 Color;
void main() { void main() {
gl_Position = projMatrix * vec4(position, 0.0f, 1.0); gl_Position = projMatrix * vec4(position, 0.0, 1.0);
Color = color; Color = color;
} }

View File

@ -3,7 +3,7 @@ in vec4 Color;
uniform sampler2D tex; uniform sampler2D tex;
uniform float alphaRef; uniform float alphaRef;
uniform bool alphaTest; uniform UBOOL alphaTest;
OUTPUT OUTPUT
@ -11,7 +11,7 @@ void main() {
vec4 texColor = texture(tex, Texcoord); vec4 texColor = texture(tex, Texcoord);
outColor = Color * texColor; outColor = Color * texColor;
if (alphaTest && outColor.a < alphaRef) { if (UBOOL_TEST(alphaTest) && outColor.a < alphaRef) {
discard; discard;
} }
} }

View File

@ -64,6 +64,18 @@ static const char *compatFragment =
"#define OUTPUT out vec4 outColor;\n" "#define OUTPUT out vec4 outColor;\n"
"#endif\n"; "#endif\n";
// OGLES2 on AmigaOS doesn't support uniform booleans, let's introduce some shim
#if defined(AMIGAOS)
static const char *compatUniformBool =
"#define UBOOL mediump int\n"
"#define UBOOL_TEST(v) (v != 0)\n";
#else
static const char *compatUniformBool =
"#define UBOOL bool\n"
"#define UBOOL_TEST(v) v\n";
#endif
static const GLchar *readFile(const Common::String &filename) { static const GLchar *readFile(const Common::String &filename) {
Common::File file; Common::File file;
Common::String shaderDir; Common::String shaderDir;
@ -127,11 +139,12 @@ static GLuint createCompatShader(const char *shaderSource, GLenum shaderType, co
const GLchar *shaderSources[] = { const GLchar *shaderSources[] = {
versionSource, versionSource,
compatSource, compatSource,
compatUniformBool,
shaderSource shaderSource
}; };
GLuint shader = glCreateShader(shaderType); GLuint shader = glCreateShader(shaderType);
glShaderSource(shader, 3, shaderSources, NULL); glShaderSource(shader, 4, shaderSources, NULL);
glCompileShader(shader); glCompileShader(shader);
GLint status; GLint status;