summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <davet@gnu.org>2015-06-06 09:30:42 -0400
committerDavid Thompson <davet@gnu.org>2015-06-06 09:30:42 -0400
commitde2abeb1a9bb6a51b0057baa5097b64c06590297 (patch)
treed00bd781b7d7bfdcb65b3932d7737196d98dffe9
parentbef0b89e4e8eec38fac455f19657ecff979aa287 (diff)
render: Bypass texture rendering when a model uses the null texture.
* data/shaders/default-fragment.glsl (use_texture): New uniform. (main): Skip texture rendering when 'use_texture' is false. * sly/render/model.scm (draw-model): Set 'use_texture' uniform before rendering. * sly/render/shader.scm (load-default-shader): Register 'use_texture' uniform.
-rw-r--r--data/shaders/default-fragment.glsl5
-rw-r--r--sly/render/model.scm1
-rw-r--r--sly/render/shader.scm2
3 files changed, 7 insertions, 1 deletions
diff --git a/data/shaders/default-fragment.glsl b/data/shaders/default-fragment.glsl
index 21bb756..a447a79 100644
--- a/data/shaders/default-fragment.glsl
+++ b/data/shaders/default-fragment.glsl
@@ -3,7 +3,12 @@
in vec2 frag_tex;
uniform vec4 color;
uniform sampler2D color_texture;
+uniform bool use_texture;
void main (void) {
+ if(use_texture) {
gl_FragColor = texture2D(color_texture, frag_tex) * color;
+ } else {
+ gl_FragColor = color;
+ }
}
diff --git a/sly/render/model.scm b/sly/render/model.scm
index 8f83ed5..4d15dc5 100644
--- a/sly/render/model.scm
+++ b/sly/render/model.scm
@@ -155,6 +155,7 @@ CONTEXT."
;; TODO: Support user-defined uniforms.
(uniform-set! shader "mvp" (render-context-transform context))
(uniform-set! shader "color" color)
+ (uniform-set! shader "use_texture" (not (texture-null? texture)))
(glDrawElements (begin-mode triangles)
(mesh-length mesh)
(data-type unsigned-int)
diff --git a/sly/render/shader.scm b/sly/render/shader.scm
index f9949fa..9f80d2a 100644
--- a/sly/render/shader.scm
+++ b/sly/render/shader.scm
@@ -305,7 +305,7 @@ VERTEX-SHADER and FRAGMENT-SHADER."
"/shaders/default-vertex.glsl")
(string-append %pkgdatadir
"/shaders/default-fragment.glsl")
- '("mvp" "color")
+ '("mvp" "color" "use_texture")
'("position" "tex")))))
;;;