diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-10-26 13:44:16 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-10-26 13:46:35 -0400 |
commit | 22c0b280f3b8b1d32e25362b80263ab22ce07e69 (patch) | |
tree | bae00550434ff21a23ec47216c9f1e6e97278f76 | |
parent | 8f283b90e4882fe3fb3e2031a17629b2914fc3b0 (diff) |
render: Add blend-mode field to render operations.
* sly/render/renderer.scm (render-op-blend-mode): New syntax.
(make-render-op): Add 'blend-mode' parameter.
(apply-render-op): Set blending mode.
-rw-r--r-- | sly/render/renderer.scm | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/sly/render/renderer.scm b/sly/render/renderer.scm index 857c8bc..b600b35 100644 --- a/sly/render/renderer.scm +++ b/sly/render/renderer.scm @@ -32,11 +32,13 @@ #:use-module (sly shader) #:use-module (sly texture) #:use-module (sly transform) + #:use-module (sly math vector) + #:use-module (sly render utils) #: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-uniforms + render-op-blend-mode render-op-uniforms make-renderer renderer? renderer-cameras renderer-ops render)) @@ -44,25 +46,28 @@ ;; Representation of a single OpenGL render call. (define-record-type <render-op> (%make-render-op transform vertex-array texture shader uniforms - depth-test?) + blend-mode depth-test?) render-op? (transform render-op-transform) (vertex-array render-op-vertex-array) (texture render-op-texture) (shader render-op-shader) (uniforms render-op-uniforms) + (blend-mode render-op-blend-mode) (depth-test? render-op-depth-test?)) (define* (make-render-op #:optional #:key (transform identity-transform) (vertex-array #f) (texture #f) (shader #f) - (uniforms '()) (depth-test? #t)) + (uniforms '()) (blend-mode default-blend-mode) + (depth-test? #t)) "Create a new render operation object. Optional arguments include: TRANSFORM, a model transformation matrix. VERTEX-ARRAY, the geometry container. TEXTURE, the texture object to bind. SHADER, the shader program to bind. UNIFORMS, the variables to be passed to the shader. And DEPTH-TEST?, a flag that determines whether the depth buffer is activated or not." - (%make-render-op transform vertex-array texture shader uniforms depth-test?)) + (%make-render-op transform vertex-array texture shader uniforms + blend-mode depth-test?)) (define-syntax-rule (with-texture-maybe texture body ...) (if texture @@ -74,9 +79,15 @@ activated or not." the VIEW transform before rendering and passed to the shader as the uniform variable 'mvp'." (match op - (($ <render-op> transform vertex-array texture shader uniforms depth-test?) + (($ <render-op> transform vertex-array texture shader uniforms + blend-mode depth-test?) (when depth-test? (gl-enable (enable-cap depth-test))) + (if blend-mode + (begin + (gl-enable (enable-cap blend)) + (apply-blend-mode blend-mode)) + (gl-disable (enable-cap blend))) (with-shader-program shader (for-each (lambda (uniform) (match uniform |