diff options
Diffstat (limited to 'chickadee/render/shader.scm')
-rw-r--r-- | chickadee/render/shader.scm | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/chickadee/render/shader.scm b/chickadee/render/shader.scm index baf0302..d393ef0 100644 --- a/chickadee/render/shader.scm +++ b/chickadee/render/shader.scm @@ -505,9 +505,27 @@ them into a GPU shader program." (info-log gl-get-shaderiv gl-get-shader-info-log id)) (define (linking-error id) (info-log gl-get-programiv gl-get-program-info-log id)) + (define (glsl-preprocessor-source) + ;; Set up preprocessor directives dynamically based on the current + ;; OpenGL context's GLSL version so that we can write shaders that + ;; are compatible with as many systems as possible. + (let ((glsl-version (gpu-glsl-version (current-gpu)))) + (cond + ((string>= glsl-version "3.3") + "#version 330 +#define GLSL330 +") + ((string>= glsl-version "1.3") + "#version 130 +#define GLSL130 +") + (else + (error "incompatible GLSL version" glsl-version))))) (define (make-shader-stage type port) (let ((id (gl-create-shader type)) - (source (get-bytevector-all port))) + (source (string->utf8 + (string-append (glsl-preprocessor-source) + (get-string-all port))))) (gl-shader-source id 1 (bytevector->pointer (u64vector |