summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <davet@gnu.org>2015-06-06 14:54:13 -0400
committerDavid Thompson <davet@gnu.org>2015-06-06 14:54:13 -0400
commite69dd364bdbe15a0ab5d62c609f88b0952462c9d (patch)
tree6fc77c22e4374717cccaeaa89d565e7933d6d6c8
parentd612dd6b1ebbceadfbe310a6a85da3bf62828177 (diff)
render: context: Add with-render-context-excursion macro.
* sly/render/context.scm (with-render-context-excursion): New syntax.
-rw-r--r--sly/render/context.scm23
1 files changed, 22 insertions, 1 deletions
diff --git a/sly/render/context.scm b/sly/render/context.scm
index f87bff2..fe16104 100644
--- a/sly/render/context.scm
+++ b/sly/render/context.scm
@@ -49,7 +49,8 @@
render-context-viewport set-render-context-viewport!
render-context-transform render-context-transform*!
render-context-transform-identity!
- with-transform-excursion))
+ with-transform-excursion
+ with-render-context-excursion))
(define-record-type <gl-parameter>
(%make-gl-parameter default bind value)
@@ -173,3 +174,23 @@
(define (render-context-transform-identity! context)
(copy-transform! identity-transform (render-context-transform context)))
+
+(define-syntax-rule (with-render-context-excursion context body ...)
+ (match context
+ (($ <render-context> blend-mode depth-test? texture shader mesh
+ viewport framebuffer _)
+ (let ((prev-blend-mode (gl-parameter-ref blend-mode))
+ (prev-depth-test? (gl-parameter-ref depth-test?))
+ (prev-texture (gl-parameter-ref texture))
+ (prev-shader (gl-parameter-ref shader))
+ (prev-mesh (gl-parameter-ref mesh))
+ (prev-framebuffer (gl-parameter-ref framebuffer))
+ (prev-viewport (gl-parameter-ref viewport)))
+ body ...
+ (gl-parameter-set! blend-mode prev-blend-mode)
+ (gl-parameter-set! depth-test? prev-depth-test?)
+ (gl-parameter-set! texture prev-texture)
+ (gl-parameter-set! shader prev-shader)
+ (gl-parameter-set! mesh prev-mesh)
+ (gl-parameter-set! framebuffer prev-framebuffer)
+ (gl-parameter-set! viewport prev-viewport)))))