diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-10-29 21:50:54 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-10-29 21:52:37 -0400 |
commit | 424353f5fedb4c2b1cd9e0c6621fbbf4b86a1b07 (patch) | |
tree | 802f3ec833356033548119fbf5a2293e42f14bba | |
parent | 58c6c9c3c3ebf3870a5c0320d963f3a5f64ffcd7 (diff) |
render: Remove knowledge of cameras from renderer.
* sly/render/renderer.scm (renderer-cameras): Delete.
(apply-render-op): Remove 'view' parameter.
(make-renderer): Remove 'cameras' parameter.
(render): Remove camera logic.
* sly/scene.scm (scene->render-list): Renamed.
(scene->renderer): New procedure. Return a renderer instead of a list
of render ops.
(draw-scene): New procedure.
-rw-r--r-- | sly/render/renderer.scm | 24 | ||||
-rw-r--r-- | sly/scene.scm | 21 |
2 files changed, 22 insertions, 23 deletions
diff --git a/sly/render/renderer.scm b/sly/render/renderer.scm index 76cc4aa..d71b89a 100644 --- a/sly/render/renderer.scm +++ b/sly/render/renderer.scm @@ -33,14 +33,13 @@ #:use-module (sly transform) #:use-module (sly math vector) #:use-module (sly render utils) - #:use-module (sly render camera) #:use-module (sly render vertex-array) #:export (make-render-op render-op? render-op-transform render-op-vertex-array render-op-texture render-op-shader render-op-blend-mode render-op-uniforms make-renderer renderer? - renderer-cameras renderer-ops + renderer-ops render)) ;; Representation of a single OpenGL render call. @@ -74,10 +73,9 @@ activated or not." (with-texture texture body ...) (begin body ...))) -(define (apply-render-op view op) - "Render the contents of OP. The transform of OP is multiplied by -the VIEW transform before rendering and passed to the shader as the -uniform variable 'mvp'." +(define (apply-render-op op) + "Render OP by applying its texture, shader, vertex array, uniforms, +blend mode, etc.." (match op (($ <render-op> transform vertex-array texture shader uniforms blend-mode depth-test?) @@ -93,7 +91,7 @@ uniform variable 'mvp'." (match uniform ((name value) (uniform-set! shader name value)))) - `(("mvp" ,(transform* view transform)) + `(("mvp" ,transform) ,@uniforms)) (with-vertex-array vertex-array (with-texture-maybe texture @@ -105,18 +103,12 @@ uniform variable 'mvp'." (gl-disable (enable-cap depth-test)))))) (define-record-type <renderer> - (make-renderer cameras ops) + (make-renderer ops) renderer? - (cameras renderer-cameras) (ops renderer-ops)) (define (render renderer) "Apply all of the render operations in RENDERER. The render operations are applied once for each camera." - (define (render-with-camera camera) - (apply-viewport (camera-viewport camera)) - (let ((view (transform* (camera-projection camera) - (camera-location camera)))) - (for-each (cut apply-render-op view <>) - (renderer-ops renderer)))) - (for-each render-with-camera (renderer-cameras renderer))) + (for-each (cut apply-render-op <>) + (renderer-ops renderer))) diff --git a/sly/scene.scm b/sly/scene.scm index 8b58d10..e068e60 100644 --- a/sly/scene.scm +++ b/sly/scene.scm @@ -31,12 +31,13 @@ #:use-module (sly transform) #:use-module (sly math vector) #:use-module (sly render utils) + #:use-module (sly render camera) #:use-module (sly render renderer) #:export (scene-node make-scene-node scene-node? scene-node-object scene-node-transform scene-node-visible? scene-node-children - scene->render-list)) + draw-scene)) (define-record-type <scene-node> (%make-scene-node object transform visible? children) @@ -66,11 +67,10 @@ whether to draw the node and all of its children or not." (cons elem memo))) '() lst)) -(define (scene->render-list node) - "Traverse the scene graph defined by NODE and its children and -return a list of the render operations needed to display the scene. -Additionally, NODE or any of its children may be a signal to allow for -dynamic changes to the scene." +(define (scene->renderer node camera) + "Traverse the scene graph defined by NODE and its children, as seen +by CAMERA, and return a list of the render operations needed to +display the scene." (define (iter node parent-transform) (signal-let ((node node)) (if (scene-node-visible? node) @@ -83,4 +83,11 @@ dynamic changes to the scene." (map (cut iter <> transform) (scene-node-children node)))) '()))) - (flatten (iter node identity-transform))) + (let ((view (transform* (camera-projection camera) + (camera-location camera)))) + (make-renderer (flatten (iter node view))))) + +(define (draw-scene node camera) + "Draw the scene defined by NODE, as seen by CAMERA." + (apply-viewport (camera-viewport camera)) + (render (scene->renderer node camera))) |