diff options
-rw-r--r-- | chickadee/graphics/engine.scm | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/chickadee/graphics/engine.scm b/chickadee/graphics/engine.scm index a1d3352..3b8e743 100644 --- a/chickadee/graphics/engine.scm +++ b/chickadee/graphics/engine.scm @@ -90,6 +90,8 @@ (define name (let ((spec (make-graphics-state-spec 'name args ...))) (hashq-set! *graphics-states* 'name spec) + (when (current-graphics-engine) + (install-graphics-state (current-graphics-engine) spec)) spec)) (define* (getter #:optional (engine (current-graphics-engine))) (graphics-engine-state-ref 'name engine)))) @@ -148,6 +150,8 @@ (define name (let ((var (make-graphics-variable 'name (lambda () init-form)))) (hashq-set! *graphics-variables* var var) + (when (current-graphics-engine) + (install-graphics-variable (current-graphics-engine) var)) var))) @@ -171,6 +175,18 @@ (modified-states graphics-engine-modified-states) (variables graphics-engine-variables)) +(define (install-graphics-state engine spec) + (let ((binder (graphics-state-spec-binder spec)) + (default (graphics-state-spec-default spec))) + (hashq-set! (graphics-engine-states engine) + (graphics-state-spec-name spec) + (make-graphics-state binder default)))) + +(define (install-graphics-variable engine var) + (hashq-set! (graphics-engine-variables engine) + var + (eval-graphics-variable var))) + (define (make-graphics-engine gl-context) (define (max-texture-size) (let ((bv (make-s32vector 1))) @@ -181,32 +197,24 @@ (car (string-split (pointer->string (gl-get-string attr)) #\space))) (define (glsl-version) (extract-version (version-2-0 shading-language-version))) - (define (make-states) - (let ((table (make-hash-table))) - (hash-for-each (lambda (key spec) - (let ((binder (graphics-state-spec-binder spec)) - (default (graphics-state-spec-default spec))) - (hashq-set! table - (graphics-state-spec-name spec) - (make-graphics-state binder default)))) - *graphics-states*) - table)) - (let* ((variables (make-hash-table)) - (engine (%make-graphics-engine gl-context - (extract-version (string-name version)) - (glsl-version) - (max-texture-size) - (make-identity-matrix4) - (make-guardian) - (make-states) - (make-hash-table) - variables))) + (let ((engine (%make-graphics-engine gl-context + (extract-version (string-name version)) + (glsl-version) + (max-texture-size) + (make-identity-matrix4) + (make-guardian) + (make-hash-table) + (make-hash-table) + (make-hash-table)))) ;; Variable initialization must be delayed until after engine ;; creation because variable initializers may modify graphics ;; engine state to create shaders, textures, etc. (parameterize ((current-graphics-engine engine)) + (hash-for-each (lambda (key spec) + (install-graphics-state engine spec)) + *graphics-states*) (hash-for-each (lambda (key var) - (hashq-set! variables var (eval-graphics-variable var))) + (install-graphics-variable engine var)) *graphics-variables*)) engine)) |