diff options
-rw-r--r-- | chickadee.scm | 4 | ||||
-rw-r--r-- | chickadee/graphics.scm | 14 | ||||
-rw-r--r-- | chickadee/graphics/gpu.scm | 21 |
3 files changed, 34 insertions, 5 deletions
diff --git a/chickadee.scm b/chickadee.scm index e974b9f..ad018be 100644 --- a/chickadee.scm +++ b/chickadee.scm @@ -241,6 +241,8 @@ border is disabled, otherwise it is enabled.") (sdl2:set-gl-attribute! 'context-major-version 2) (sdl2:set-gl-attribute! 'context-profile-mask 1) ; core profile (sdl2:set-gl-attribute! 'stencil-size 8) ; 8-bit stencil buffer + (sdl2:set-gl-attribute! 'multisample-buffers 1) + (sdl2:set-gl-attribute! 'multisample-samples 4) (let* ((window (sdl2:make-window #:opengl? #t #:title window-title #:size (list window-width window-height) @@ -350,6 +352,8 @@ border is disabled, otherwise it is enabled.") (lambda args (display "warning: could not enable vsync\n" (current-error-port)))) + ;; Turn off multisampling by default. + (gl-disable (version-1-3 multisample)) (load) (sdl2:load-game-controller-mappings! (scope-datadir "gamecontrollerdb.txt")) diff --git a/chickadee/graphics.scm b/chickadee/graphics.scm index 4cc21a4..bfa1139 100644 --- a/chickadee/graphics.scm +++ b/chickadee/graphics.scm @@ -38,6 +38,7 @@ current-stencil-test current-texture current-projection + current-multisample with-viewport with-framebuffer with-blend-mode @@ -45,6 +46,7 @@ with-stencil-test with-texture with-projection + with-multisample clear-screen gpu-apply gpu-apply* @@ -53,7 +55,7 @@ (define-record-type <render-context> (make-render-context viewport framebuffer blend-mode depth-test - stencil-test projection textures) + stencil-test projection multisample? textures) render-context? (viewport render-context-viewport set-render-context-viewport!) (framebuffer render-context-framebuffer set-render-context-framebuffer!) @@ -61,6 +63,7 @@ (depth-test render-context-depth-test set-render-context-depth-test!) (stencil-test render-context-stencil-test set-render-context-stencil-test!) (projection render-context-projection set-render-context-projection!) + (multisample? render-context-multisample? set-render-context-multisample!) (textures render-context-textures)) (define render-context @@ -70,6 +73,7 @@ #f #f (make-identity-matrix4) + #f (make-vector 32 null-texture))) (define (current-viewport) @@ -93,6 +97,9 @@ (define (current-projection) (render-context-projection render-context)) +(define (current-multisample) + (render-context-multisample? render-context)) + (define-syntax-rule (with (getter setter value) body ...) (let ((prev (getter render-context))) (setter render-context value) @@ -143,6 +150,10 @@ (with (render-context-projection set-render-context-projection! matrix) body ...)) +(define-syntax-rule (with-multisample multisample? body ...) + (with (render-context-multisample? set-render-context-multisample! multisample?) + body ...)) + (define (keyword->string kw) (symbol->string (keyword->symbol kw))) @@ -167,6 +178,7 @@ (set-gpu-blend-mode! gpu (current-blend-mode)) (set-gpu-depth-test! gpu (current-depth-test)) (set-gpu-stencil-test! gpu (current-stencil-test)) + (set-gpu-multisample! gpu (current-multisample)) (set-gpu-shader! gpu shader) (let loop ((i 0)) (when (< i 32) diff --git a/chickadee/graphics/gpu.scm b/chickadee/graphics/gpu.scm index b8c8ca5..7a70d7e 100644 --- a/chickadee/graphics/gpu.scm +++ b/chickadee/graphics/gpu.scm @@ -17,6 +17,7 @@ (define-module (chickadee graphics gpu) #:use-module (chickadee graphics gl) + #:use-module (gl) #:use-module (gl enums) #:use-module (oop goops) #:use-module (srfi srfi-9) @@ -45,6 +46,7 @@ gpu-vertex-buffer gpu-vertex-array gpu-viewport + gpu-multisample set-gpu-blend-mode! set-gpu-depth-test! set-gpu-stencil-test! @@ -53,7 +55,8 @@ set-gpu-texture! set-gpu-vertex-buffer! set-gpu-vertex-array! - set-gpu-viewport!)) + set-gpu-viewport! + set-gpu-multisample!)) ;;; @@ -110,7 +113,8 @@ from the GPU's memory." textures vertex-buffer vertex-array - viewport) + viewport + multisample) gpu? (gl-context gpu-gl-context) (gl-version gpu-gl-version) @@ -124,7 +128,8 @@ from the GPU's memory." (textures gpu-textures) (vertex-buffer %gpu-vertex-buffer) (vertex-array %gpu-vertex-array) - (viewport %gpu-viewport)) + (viewport %gpu-viewport) + (multisample %gpu-multisample)) (define current-gpu (make-parameter #f)) @@ -134,6 +139,11 @@ from the GPU's memory." (bytevector->pointer bv)) (s32vector-ref bv 0))) +(define (apply-multisample multisample?) + (if multisample? + (gl-enable (version-1-3 multisample)) + (gl-disable (version-1-3 multisample)))) + (define (make-gpu gl-context) (define (extract-version attr) (car (string-split (pointer->string (gl-get-string attr)) #\space))) @@ -176,7 +186,8 @@ from the GPU's memory." (make-gpu-state (module-ref buffer-module 'apply-vertex-array) (module-ref buffer-module 'null-vertex-array)) (make-gpu-state (module-ref viewport-module 'apply-viewport) - (module-ref viewport-module 'null-viewport))))) + (module-ref viewport-module 'null-viewport)) + (make-gpu-state apply-multisample #f)))) (define-syntax-rule (define-gpu-getter name ref) (define (name gpu) @@ -190,6 +201,7 @@ from the GPU's memory." (define-gpu-getter gpu-vertex-buffer %gpu-vertex-buffer) (define-gpu-getter gpu-vertex-array %gpu-vertex-array) (define-gpu-getter gpu-viewport %gpu-viewport) +(define-gpu-getter gpu-multisample %gpu-multisample) (define-syntax-rule (define-gpu-setter name ref) (define (name gpu x) @@ -203,6 +215,7 @@ from the GPU's memory." (define-gpu-setter set-gpu-vertex-buffer! %gpu-vertex-buffer) (define-gpu-setter set-gpu-vertex-array! %gpu-vertex-array) (define-gpu-setter set-gpu-viewport! %gpu-viewport) +(define-gpu-setter set-gpu-multisample! %gpu-multisample) (define (gpu-texture gpu texture-unit) (gpu-state-ref (vector-ref (gpu-textures gpu) texture-unit))) |