diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-10-30 20:26:54 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-10-30 20:26:54 -0400 |
commit | 14cad2fd445392e46916a6dffbc376376bd014c7 (patch) | |
tree | 0059381610423064aff1402544b21a4e3e6f17c2 | |
parent | 424353f5fedb4c2b1cd9e0c6621fbbf4b86a1b07 (diff) |
scene: Decouple draw method from scene graph.
* sly/render/renderer.scm (transform-render-op): New procedure.
* sly/scene.scm (scene->renderer): Don't pass transform to draw method.
Instead, transform the resulting render op afterwards.
* sly/mesh.scm (draw): Remove 'transform' parameter.
-rw-r--r-- | sly/mesh.scm | 5 | ||||
-rw-r--r-- | sly/render/renderer.scm | 10 | ||||
-rw-r--r-- | sly/scene.scm | 3 |
3 files changed, 14 insertions, 4 deletions
diff --git a/sly/mesh.scm b/sly/mesh.scm index e662547..2a0c8ec 100644 --- a/sly/mesh.scm +++ b/sly/mesh.scm @@ -58,9 +58,8 @@ (%make-mesh (make-vertex-array indices positions textures) shader texture)) -(define-method (draw (mesh <<mesh>>) transform) +(define-method (draw (mesh <<mesh>>)) (make-render-op #:vertex-array (mesh-vao mesh) #:texture (mesh-texture mesh) #:shader (mesh-shader mesh) - #:uniforms `(("color" ,white)) - #:transform transform)) + #:uniforms `(("color" ,white)))) diff --git a/sly/render/renderer.scm b/sly/render/renderer.scm index d71b89a..3584023 100644 --- a/sly/render/renderer.scm +++ b/sly/render/renderer.scm @@ -38,6 +38,7 @@ render-op-transform render-op-vertex-array render-op-texture render-op-shader render-op-blend-mode render-op-uniforms + transform-render-op make-renderer renderer? renderer-ops render)) @@ -68,6 +69,15 @@ activated or not." (%make-render-op transform vertex-array texture shader uniforms blend-mode depth-test?)) +(define* (transform-render-op op transform) + "Return a new render operation object that is the same as OP, but +with its transformation matrix multiplied by TRANSFORM." + (match op + (($ <render-op> local-transform vertex-array texture shader uniforms + blend-mode depth-test?) + (%make-render-op (transform* transform local-transform) vertex-array + texture shader uniforms blend-mode depth-test?)))) + (define-syntax-rule (with-texture-maybe texture body ...) (if texture (with-texture texture body ...) diff --git a/sly/scene.scm b/sly/scene.scm index e068e60..6cd3a5d 100644 --- a/sly/scene.scm +++ b/sly/scene.scm @@ -78,7 +78,8 @@ display the scene." (scene-node-transform node))) (object (scene-node-object node))) (cons (if object - (draw (scene-node-object node) transform) + (transform-render-op (draw (scene-node-object node)) + transform) '()) (map (cut iter <> transform) (scene-node-children node)))) |