summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle Licht <jlicht@fsfe.org>2020-10-06 13:50:25 +0200
committerDavid Thompson <dthompson2@worcester.edu>2020-10-06 08:17:46 -0400
commit08bcf7f42534a61d29c96a44e19e15611ed6e4f8 (patch)
tree2faddea04b33a4cf15867d07f1bd7b16c980947a
parent5ff661f1e191ce486000b727d6c979779e24efe8 (diff)
graphics: Improve GLSL 1.2 compatibility.
-rw-r--r--chickadee/graphics/particles.scm8
-rw-r--r--chickadee/graphics/phong.scm4
-rw-r--r--chickadee/graphics/shapes.scm29
-rw-r--r--chickadee/graphics/sprite.scm12
4 files changed, 40 insertions, 13 deletions
diff --git a/chickadee/graphics/particles.scm b/chickadee/graphics/particles.scm
index 0cd275e..90cfa11 100644
--- a/chickadee/graphics/particles.scm
+++ b/chickadee/graphics/particles.scm
@@ -148,7 +148,7 @@ void main(void) {
t = life / lifetime;
int numTiles = animationRows * animationColumns;
int tile = int(numTiles * (1.0 - t));
- float tx = float(tile % animationColumns) / animationColumns;
+ float tx = float(mod(tile, animationColumns)) / animationColumns;
float ty = float(tile / animationColumns) / animationRows;
float tw = 1.0 / animationColumns;
float th = 1.0 / animationRows;
@@ -158,8 +158,8 @@ void main(void) {
"
"
#ifdef GLSL120
-attribute vec2 fragTex;
-attribute float t;
+varying vec2 fragTex;
+varying float t;
#else
in vec2 fragTex;
in float t;
@@ -174,7 +174,7 @@ uniform vec4 endColor;
void main (void) {
#ifdef GLSL330
fragColor = mix(endColor, startColor, t) * texture(color_texture, fragTex);
-#elif ifdef GLSL130
+#elif defined(GLSL130)
gl_FragColor = mix(endColor, startColor, t) * texture2D(color_texture, fragTex);
#endif
}
diff --git a/chickadee/graphics/phong.scm b/chickadee/graphics/phong.scm
index ab34fce..514bb24 100644
--- a/chickadee/graphics/phong.scm
+++ b/chickadee/graphics/phong.scm
@@ -171,8 +171,8 @@ struct DirectionalLight {
};
#ifdef GLSL120
-attribute vec3 fragNorm;
-attribute vec2 fragTex;
+varying vec3 fragNorm;
+varying vec2 fragTex;
#else
in vec3 fragNorm;
in vec2 fragTex;
diff --git a/chickadee/graphics/shapes.scm b/chickadee/graphics/shapes.scm
index 79a73b6..e5d985c 100644
--- a/chickadee/graphics/shapes.scm
+++ b/chickadee/graphics/shapes.scm
@@ -165,7 +165,7 @@ void main(void) {
"
"
#ifdef GLSL120
-attribute vec2 fragTex;
+varying vec2 fragTex;
#else
in vec2 fragTex;
#endif
@@ -196,6 +196,32 @@ void main (void) {
}
dy = abs(v);
+#ifdef GLSL120
+ // none
+ if (cap == 0) {
+ d = infinity;
+ }
+ // butt
+ else if (cap == 1) {
+ d = max(dx + w / 2 - 2 * r, dy);
+ }
+ // square
+ else if (cap == 2) {
+ d = max(dx, dy);
+ }
+ // round
+ else if (cap == 3) {
+ d = sqrt(dx * dx + dy * dy);
+ }
+ // triangle out
+ else if (cap == 4) {
+ d = dx + dy;
+ }
+ // triangle in
+ else if (cap == 5) {
+ d = max(dy, w / 2 - r + dx - dy);
+ }
+#else
switch (cap) {
// none
case 0:
@@ -222,6 +248,7 @@ void main (void) {
d = max(dy, w / 2 - r + dx - dy);
break;
}
+#endif
} else {
d = abs(v);
}
diff --git a/chickadee/graphics/sprite.scm b/chickadee/graphics/sprite.scm
index 4a78292..5fc3203 100644
--- a/chickadee/graphics/sprite.scm
+++ b/chickadee/graphics/sprite.scm
@@ -52,10 +52,10 @@
#ifdef GLSL330
layout (location = 0) in vec2 position;
layout (location = 1) in vec2 tex;
-#elif ifdef GLSL130
+#elif defined(GLSL130)
in vec2 position;
in vec2 tex;
-#elif ifdef GLSL120
+#elif defined(GLSL120)
attribute vec2 position;
attribute vec2 tex;
#endif
@@ -74,7 +74,7 @@ void main(void) {
"
#ifdef GLSL120
-attribute vec2 fragTex;
+varying vec2 fragTex;
#else
in vec2 fragTex;
#endif
@@ -415,7 +415,7 @@ attribute vec4 tint;
#endif
#ifdef GLSL120
varying vec2 fragTex;
-varying vec2 fragTint;
+varying vec4 fragTint;
#else
out vec2 fragTex;
out vec4 fragTint;
@@ -430,8 +430,8 @@ void main(void) {
"
"
#ifdef GLSL120
-attribute vec2 fragTex;
-attribute vec4 fragTint;
+varying vec2 fragTex;
+varying vec4 fragTint;
#else
in vec2 fragTex;
in vec4 fragTint;