summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sly/render/renderer.scm25
-rw-r--r--sly/render/scene.scm4
2 files changed, 17 insertions, 12 deletions
diff --git a/sly/render/renderer.scm b/sly/render/renderer.scm
index dc48a32..fc9e5e6 100644
--- a/sly/render/renderer.scm
+++ b/sly/render/renderer.scm
@@ -33,6 +33,7 @@
#:use-module (sly math transform)
#:use-module (sly math vector)
#:use-module (sly render utils)
+ #:use-module (sly render camera)
#:use-module (sly render context)
#:use-module (sly render vertex-array)
#:export (make-render-op render-op?
@@ -79,9 +80,10 @@ with its transformation matrix multiplied by TRANSFORM."
(%make-render-op (transform* transform local-transform) vertex-array
texture shader uniforms blend-mode depth-test?))))
-(define (apply-render-op context op)
- "Render OP by applying its texture, shader, vertex array, uniforms,
-blend mode, etc.."
+(define (apply-render-op context view op)
+ "Render OP by applying its transform (multiplied by VIEW), texture,
+shader, vertex array, uniforms, blend mode, etc. to the render
+CONTEXT."
(match op
(($ <render-op> transform vertex-array texture shader uniforms
blend-mode depth-test?)
@@ -94,7 +96,7 @@ blend mode, etc.."
(match uniform
((name value)
(uniform-set! shader name value))))
- `(("mvp" ,transform)
+ `(("mvp" ,(transform* view transform))
,@uniforms))
(glDrawElements (begin-mode triangles)
(vertex-array-length vertex-array)
@@ -102,18 +104,23 @@ blend mode, etc.."
%null-pointer))))
(define-record-type <renderer>
- (%make-renderer context ops)
+ (%make-renderer context cameras ops)
renderer?
(context renderer-context)
+ (cameras renderer-cameras)
(ops renderer-ops))
-(define (make-renderer ops)
- (%make-renderer (make-render-context) ops))
+(define (make-renderer cameras ops)
+ (%make-renderer (make-render-context) cameras ops))
(define (render renderer)
"Apply all of the render operations in RENDERER. The render
operations are applied once for each camera."
(let ((context (renderer-context renderer)))
(with-render-context context
- (for-each (cut apply-render-op context <>)
- (renderer-ops renderer)))))
+ (for-each (lambda (camera)
+ (let ((view (transform* (camera-projection camera)
+ (camera-location camera))))
+ (for-each (cut apply-render-op context view <>)
+ (renderer-ops renderer))))
+ (renderer-cameras renderer)))))
diff --git a/sly/render/scene.scm b/sly/render/scene.scm
index 7d66ef0..e2961a0 100644
--- a/sly/render/scene.scm
+++ b/sly/render/scene.scm
@@ -111,9 +111,7 @@ display the scene."
(map (cut iter <> transform)
(scene-node-children node))))
'())))
- (let ((view (transform* (camera-projection camera)
- (camera-location camera))))
- (make-renderer (flatten (iter node view)))))
+ (make-renderer (list camera) (flatten (iter node identity-transform))))
(define (draw-scene node camera)
"Draw the scene defined by NODE, as seen by CAMERA."