summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sly/render/context.scm88
1 files changed, 34 insertions, 54 deletions
diff --git a/sly/render/context.scm b/sly/render/context.scm
index aec04b0..1e23f17 100644
--- a/sly/render/context.scm
+++ b/sly/render/context.scm
@@ -65,11 +65,11 @@
(%make-render-context blend-mode depth-test? texture shader
mesh transform-stack)
render-context?
- (blend-mode render-context-blend-mode %set-render-context-blend-mode!)
- (depth-test? render-context-depth-test? %set-render-context-depth-test?!)
- (texture render-context-texture %set-render-context-texture!)
- (shader render-context-shader %set-render-context-shader!)
- (mesh render-context-mesh %set-render-context-mesh!)
+ (blend-mode render-context-blend-mode)
+ (depth-test? render-context-depth-test?)
+ (texture render-context-texture)
+ (shader render-context-shader)
+ (mesh render-context-mesh)
(transform-stack render-context-transform-stack))
(define (make-null-transform)
@@ -84,64 +84,44 @@
stack))
(define* (make-render-context #:optional (transform-stack-size 32))
- (%make-render-context #f #f #f #f #f
+ (%make-render-context (make-gl-parameter #f apply-blend-mode)
+ (make-gl-parameter #t apply-depth-test)
+ (make-gl-parameter null-texture apply-texture)
+ (make-gl-parameter null-shader-program
+ apply-shader-program)
+ (make-gl-parameter null-mesh apply-mesh)
(make-transform-stack transform-stack-size)))
(define (render-context-reset! context)
- (gl-disable (enable-cap blend))
- (%set-render-context-blend-mode! context #f)
- (gl-disable (enable-cap depth-test))
- (%set-render-context-depth-test?! context #f)
- (glBindTexture (texture-target texture-2d) 0)
- (%set-render-context-texture! context null-texture)
- (glUseProgram 0)
- (%set-render-context-shader! context #f)
- (glBindVertexArray 0)
- (%set-render-context-mesh! context null-mesh))
+ (gl-parameter-reset! (render-context-blend-mode context))
+ (gl-parameter-reset! (render-context-depth-test? context))
+ (gl-parameter-reset! (render-context-texture context))
+ (gl-parameter-reset! (render-context-shader context))
+ (gl-parameter-reset! (render-context-mesh context)))
(define-syntax-rule (with-render-context context body ...)
(begin (render-context-reset! context)
body ...
(render-context-reset! context)))
-(define (set-render-context-blend-mode! context blend-mode)
- (unless (equal? (render-context-blend-mode context) blend-mode)
- (if blend-mode
- (begin
- (gl-enable (enable-cap blend))
- (apply-blend-mode blend-mode))
- ;; Turn off blending if there is no blend-mode specified.
- (gl-disable (enable-cap blend)))
- (%set-render-context-blend-mode! context blend-mode)))
-
-(define (set-render-context-depth-test?! context depth-test?)
- (unless (eq? (render-context-depth-test? context) depth-test?)
- (if depth-test?
- (gl-enable (enable-cap depth-test))
- (gl-disable (enable-cap depth-test)))
- (%set-render-context-depth-test?! context depth-test?)))
-
-(define (set-render-context-texture! context texture)
- (let ((current-texture (render-context-texture context)))
- (unless (equal? current-texture texture)
- (if texture
- (begin
- ;; Enable texturing if it was disabled.
- (unless current-texture
- (gl-enable (enable-cap texture-2d)))
- (apply-texture texture))
- (gl-disable (enable-cap texture-2d)))
- (%set-render-context-texture! context texture))))
-
-(define (set-render-context-shader! context shader)
- (unless (equal? (render-context-shader context) shader)
- (apply-shader-program shader)
- (%set-render-context-shader! context shader)))
-
-(define (set-render-context-mesh! context mesh)
- (unless (equal? (render-context-mesh context) mesh)
- (apply-mesh mesh)
- (%set-render-context-mesh! context mesh)))
+(define-syntax-rule (define-context-setter name accessor)
+ (define (name context value)
+ (gl-parameter-set! (accessor context) value)))
+
+(define-context-setter set-render-context-blend-mode!
+ render-context-blend-mode)
+
+(define-context-setter set-render-context-depth-test?!
+ render-context-depth-test?)
+
+(define-context-setter set-render-context-texture!
+ render-context-texture)
+
+(define-context-setter set-render-context-shader!
+ render-context-shader)
+
+(define-context-setter set-render-context-mesh!
+ render-context-mesh)
;; emacs: (put 'with-temp-transform 'scheme-indent-function 2)
(define-syntax-rule (with-temp-transform context name body ...)