diff options
Diffstat (limited to 'chickadee/render/shader.scm')
-rw-r--r-- | chickadee/render/shader.scm | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/chickadee/render/shader.scm b/chickadee/render/shader.scm index ddf2098..b5f9b7d 100644 --- a/chickadee/render/shader.scm +++ b/chickadee/render/shader.scm @@ -42,6 +42,7 @@ shader-uniforms uniform? uniform-name + uniform-type uniform-value uniform-default-value set-uniform-value! @@ -199,7 +200,6 @@ ;; ('int-vec2 (vector2 0 0)) ;; ('int-vec3 (vector3 0 0 0)) ;; ('int-vec4 (vector4 0 0 0 0)) - ('sampler-2d 0) ('mat4 %default-mat4))) (define (uniform-setter-for-type type) @@ -221,7 +221,8 @@ (define (extract-uniforms id) (let ((total (uniform-count id)) (table (make-hash-table))) - (let loop ((i 0)) + (let loop ((i 0) + (texture-unit 0)) (unless (= i total) (let ((length-bv (make-u32vector 1)) (size-bv (make-u32vector 1)) @@ -238,17 +239,22 @@ (location (gl-get-uniform-location id name)) (size (u32vector-ref size-bv 0)) (type (gl-type->symbol (u32vector-ref type-bv 0))) - (default (default-uniform-value type)) + (sampler? (eq? type 'sampler-2d)) + (default (if sampler? + texture-unit + (default-uniform-value type))) (setter (uniform-setter-for-type type))) ;; TODO: Handle uniform arrays. (unless (= size 1) (error "unsupported uniform size" name size)) - (unless (eq? type 'sampler-2d) - (hash-set! table - name - (make-uniform name location type default setter))))) - (loop (1+ i)))) + (hash-set! table + name + (make-uniform name location type default setter)) + (loop (1+ i) + (if sampler? + (1+ texture-unit) + texture-unit)))))) table)) (define (attribute-count id) |