From 8c6326a46f82ae46cc63bd431b0678d4f6b10d00 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 16 Aug 2021 17:11:28 -0400 Subject: graphics: shader: Add support for cube map samplers. --- chickadee/graphics/shader.scm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/chickadee/graphics/shader.scm b/chickadee/graphics/shader.scm index 80acd02..08e8672 100644 --- a/chickadee/graphics/shader.scm +++ b/chickadee/graphics/shader.scm @@ -47,6 +47,7 @@ float-vec4 mat4 sampler-2d + sampler-cube local-field define-shader-type uniform-namespace? @@ -236,6 +237,16 @@ #:setter gl-uniform1iv #:null 0) +(define-shader-primitive-type sampler-cube + #:name 'sampler-cube + #:size 4 + #:validator integer? + #:serializer + (lambda (bv i texture-unit) + (bytevector-s32-native-set! bv i texture-unit)) + #:setter gl-uniform1iv + #:null 0) + ;;; ;;; Compound Shader Data Types @@ -579,6 +590,7 @@ them into a GPU shader program." ((= type (version-2-0 float-vec4)) float-vec4) ((= type (version-2-0 float-mat4)) mat4) ((= type (version-2-0 sampler-2d)) sampler-2d) + ((= type (version-2-0 sampler-cube)) sampler-cube) (else (error "unsupported OpenGL type" type)))) (define (camel->snake str) @@ -660,7 +672,7 @@ them into a GPU shader program." (location (gl-get-uniform-location id name)) (size (u32vector-ref size-bv 0)) (type (parse-data-type (u32vector-ref type-bv 0))) - (sampler? (eq? type sampler-2d)) + (sampler? (or (eq? type sampler-2d) (eq? type sampler-cube))) (default (cond (sampler? texture-unit) @@ -815,7 +827,8 @@ shader program." ;; most other values. In the case of samplers, they are ;; mapped to OpenGL's "texture units", so we need to ;; ignore them here. - (unless (eq? (uniform-type uniform) sampler-2d) + (unless (or (eq? (uniform-type uniform) sampler-2d) + (eq? (uniform-type uniform) sampler-cube)) (traverse uniform (shader-struct-ref value key)))) uniform) (error "expected shader struct" x))) @@ -854,7 +867,8 @@ shader program." ;; behind the scenes. (shader-uniform-for-each (lambda (uniform) - (when (eq? (uniform-type uniform) sampler-2d) + (when (or (eq? (uniform-type uniform) sampler-2d) + (eq? (uniform-type uniform) sampler-cube)) (set-uniform-value! shader* uniform (uniform-value uniform)))) shader*) exp)) -- cgit v1.2.3