summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-08-24 21:21:58 -0400
committerDavid Thompson <dthompson2@worcester.edu>2020-08-24 21:21:58 -0400
commitc6ead0aeb6b2ab78d7d77907b2180dea98dcb473 (patch)
tree89f1ac7fd1e783f38cacb9a8e956d8c89ab91614
parente087ad330baa5f392e8ce4a10452354b18e88e6b (diff)
render: Take a stab at GLSL 1.2 compatibility.
I don't have a machine to test on so this is just a best guess. I'm sure there's some bugs that other people will just have to point out to me. It's a start, at least.
-rw-r--r--chickadee/render/particles.scm17
-rw-r--r--chickadee/render/pbr.scm17
-rw-r--r--chickadee/render/phong.scm24
-rw-r--r--chickadee/render/shader.scm4
-rw-r--r--chickadee/render/shapes.scm23
-rw-r--r--chickadee/render/sprite.scm31
6 files changed, 100 insertions, 16 deletions
diff --git a/chickadee/render/particles.scm b/chickadee/render/particles.scm
index d046caf..c81209a 100644
--- a/chickadee/render/particles.scm
+++ b/chickadee/render/particles.scm
@@ -121,14 +121,24 @@ layout (location = 0) in vec2 position;
layout (location = 1) in vec2 tex;
layout (location = 2) in vec2 offset;
layout (location = 3) in float life;
-#elif ifdef GLSL130
+#elif defined(GLSL130)
in vec2 position;
in vec2 tex;
in vec2 offset;
in float life;
+#elif defined(GLSL120)
+attribute vec2 position;
+attribute vec2 tex;
+attribute vec2 offset;
+attribute float life;
#endif
+#ifdef GLSL120
+varying vec2 fragTex;
+varying float t;
+#else
out vec2 fragTex;
out float t;
+#endif
uniform mat4 mvp;
uniform int lifetime;
uniform int animationRows;
@@ -147,8 +157,13 @@ void main(void) {
}
"
"
+#ifdef GLSL120
+attribute vec2 fragTex;
+attribute float t;
+#else
in vec2 fragTex;
in float t;
+#endif
#ifdef GLSL330
out vec4 fragColor;
#endif
diff --git a/chickadee/render/pbr.scm b/chickadee/render/pbr.scm
index ab02659..167334e 100644
--- a/chickadee/render/pbr.scm
+++ b/chickadee/render/pbr.scm
@@ -94,11 +94,18 @@
#ifdef GLSL330
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 texcoord0;
-#elif ifdef GLSL130
+#elif defined(GLSL130)
in vec3 position;
in vec2 texcoord0;
+#elif defined(GLSL120)
+attribute vec3 position;
+attribute vec2 texcoord0;
#endif
+#ifdef GLSL120
+varying vec2 fragTex;
+#else
out vec2 fragTex;
+#endif
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
@@ -109,8 +116,14 @@ void main(void) {
}
"
"
+#ifdef GLSL120
+attribute vec2 fragTex;
+#else
in vec2 fragTex;
+#endif
+#ifdef GLSL330
out vec4 fragColor;
+#endif
uniform vec3 baseColorFactor;
uniform sampler2D baseColorTexture;
@@ -118,7 +131,7 @@ void main (void) {
#ifdef GLSL330
fragColor = texture(baseColorTexture, fragTex) *
vec4(baseColorFactor, 1.0);
-#elif ifdef GLSL130
+#else
gl_FragColor = texture2D(baseColorTexture, fragTex) *
vec4(baseColorFactor, 1.0);
#endif
diff --git a/chickadee/render/phong.scm b/chickadee/render/phong.scm
index 08bd7c7..1c718a8 100644
--- a/chickadee/render/phong.scm
+++ b/chickadee/render/phong.scm
@@ -118,18 +118,27 @@
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 texcoord;
layout (location = 2) in vec3 normal;
-#elif ifdef GLSL130
+#elif defined(GLSL130)
in vec3 position;
in vec2 texcoord;
in vec3 normal;
+#elif defined(GLSL120)
+attribute vec3 position;
+attribute vec2 texcoord;
+attribute vec3 normal;
#endif
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
+#ifdef GLSL120
+varying vec3 fragNorm;
+varying vec2 fragTex;
+#else
out vec3 fragNorm;
out vec2 fragTex;
+#endif
void main() {
gl_Position = projection * view * model * vec4(position, 1.0);
@@ -161,8 +170,13 @@ struct DirectionalLight {
vec3 specular;
};
+#ifdef GLSL120
+attribute vec3 fragNorm;
+attribute vec2 fragTex;
+#else
in vec3 fragNorm;
in vec2 fragTex;
+#endif
#ifdef GLSL330
out vec4 fragColor;
@@ -178,7 +192,7 @@ void main() {
if(material.useAmbientMap) {
#ifdef GLSL330
baseAmbientColor = texture(material.ambientMap, fragTex).xyz;
-#elif ifdef GLSL130
+#else
baseAmbientColor = texture2D(material.ambientMap, fragTex).xyz;
#endif
} else {
@@ -188,7 +202,7 @@ void main() {
// discard transparent fragments.
#ifdef GLSL330
vec4 color = texture(material.diffuseMap, fragTex);
-#elif ifdef GLSL130
+#else
vec4 color = texture2D(material.diffuseMap, fragTex);
#endif
if(color.a == 0.0) { discard; }
@@ -199,7 +213,7 @@ void main() {
if(material.useSpecularMap) {
#ifdef GLSL330
baseSpecularColor = texture(material.specularMap, fragTex).xyz;
-#elif ifdef GLSL130
+#else
baseSpecularColor = texture2D(material.specularMap, fragTex).xyz;
#endif
} else {
@@ -217,7 +231,7 @@ void main() {
vec3 specularColor = specularFactor * baseSpecularColor * material.specular;
#ifdef GLSL330
fragColor = vec4(ambientColor + diffuseColor + specularColor, 1.0);
-#elif ifdef GLSL130
+#else
gl_FragColor = vec4(ambientColor + diffuseColor + specularColor, 1.0);
#endif
}
diff --git a/chickadee/render/shader.scm b/chickadee/render/shader.scm
index d393ef0..6df77f1 100644
--- a/chickadee/render/shader.scm
+++ b/chickadee/render/shader.scm
@@ -519,6 +519,10 @@ them into a GPU shader program."
"#version 130
#define GLSL130
")
+ ((string>= glsl-version "1.2")
+ "#version 120
+#define GLSL120
+")
(else
(error "incompatible GLSL version" glsl-version)))))
(define (make-shader-stage type port)
diff --git a/chickadee/render/shapes.scm b/chickadee/render/shapes.scm
index 245bc51..dd690ec 100644
--- a/chickadee/render/shapes.scm
+++ b/chickadee/render/shapes.scm
@@ -60,8 +60,10 @@
"
#ifdef GLSL330
layout (location = 0) in vec2 position;
-#elif GLSL130
+#elif defined(GLSL130)
in vec2 position;
+#elif defined(GLSL120)
+attribute vec2 position;
#endif
uniform mat4 mvp;
@@ -78,7 +80,7 @@ uniform vec4 color;
void main (void) {
#ifdef GLSL330
fragColor = color;
-#elif ifdef GLSL130
+#else
gl_FragColor = color;
#endif
}
@@ -142,11 +144,18 @@ void main (void) {
#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 defined(GLSL120)
+attribute vec2 position;
+attribute vec2 tex;
#endif
+#ifdef GLSL120
+varying vec2 fragTex;
+#else
out vec2 fragTex;
+#endif
uniform mat4 mvp;
void main(void) {
@@ -155,7 +164,11 @@ void main(void) {
}
"
"
+#ifdef GLSL120
+attribute vec2 fragTex;
+#else
in vec2 fragTex;
+#endif
#ifdef GLSL330
out vec4 fragColor;
#endif
@@ -216,13 +229,13 @@ void main (void) {
if (d <= hw) {
#ifdef GLSL330
fragColor = color;
-#elif ifdef GLSL130
+#else
gl_FragColor = color;
#endif
} else {
#ifdef GLSL330
fragColor = vec4(color.rgb, color.a * (1.0 - ((d - hw) / r)));
-#elif ifdef GLSL130
+#else
gl_FragColor = vec4(color.rgb, color.a * (1.0 - ((d - hw) / r)));
#endif
}
diff --git a/chickadee/render/sprite.scm b/chickadee/render/sprite.scm
index 144c656..a5c25bc 100644
--- a/chickadee/render/sprite.scm
+++ b/chickadee/render/sprite.scm
@@ -55,8 +55,15 @@ layout (location = 1) in vec2 tex;
#elif ifdef GLSL130
in vec2 position;
in vec2 tex;
+#elif ifdef GLSL120
+attribute vec2 position;
+attribute vec2 tex;
#endif
+#ifdef GLSL120
+varying vec2 fragTex;
+#else
out vec2 fragTex;
+#endif
uniform mat4 mvp;
void main(void) {
@@ -66,7 +73,11 @@ void main(void) {
"
"
+#ifdef GLSL120
+attribute vec2 fragTex;
+#else
in vec2 fragTex;
+#endif
#ifdef GLSL330
out vec4 fragColor;
#endif
@@ -76,7 +87,7 @@ uniform vec4 tint;
void main (void) {
#ifdef GLSL330
fragColor = texture(colorTexture, fragTex) * tint;
-#elif ifdef GLSL130
+#else
gl_FragColor = texture2D(colorTexture, fragTex) * tint;
#endif
}
@@ -393,13 +404,22 @@ may be specified via the TEXTURE-REGION argument."
layout (location = 0) in vec2 position;
layout (location = 1) in vec2 tex;
layout (location = 2) in vec4 tint;
-#elif ifdef GLSL130
+#elif defined(GLSL130)
in vec2 position;
in vec2 tex;
in vec4 tint;
+#elif defined(GLSL120)
+attribute vec2 position;
+attribute vec2 tex;
+attribute vec4 tint;
#endif
+#ifdef GLSL120
+varying vec2 fragTex;
+varying vec2 fragTint;
+#else
out vec2 fragTex;
out vec4 fragTint;
+#endif
uniform mat4 mvp;
void main(void) {
@@ -409,8 +429,13 @@ void main(void) {
}
"
"
+#ifdef GLSL120
+attribute vec2 fragTex;
+attribute vec4 fragTint;
+#else
in vec2 fragTex;
in vec4 fragTint;
+#endif
#ifdef GLSL330
out vec4 fragColor;
#endif
@@ -419,7 +444,7 @@ uniform sampler2D colorTexture;
void main (void) {
#ifdef GLSL330
fragColor = texture(colorTexture, fragTex) * fragTint;
-#elif ifdef GLSL130
+#else
gl_FragColor = texture2D(colorTexture, fragTex) * fragTint;
#endif
}