diff options
-rw-r--r-- | chickadee.scm | 6 | ||||
-rw-r--r-- | chickadee/render/gl.scm | 7 | ||||
-rw-r--r-- | chickadee/render/gpu.scm | 18 |
3 files changed, 29 insertions, 2 deletions
diff --git a/chickadee.scm b/chickadee.scm index defa0a0..7b43888 100644 --- a/chickadee.scm +++ b/chickadee.scm @@ -235,6 +235,12 @@ border is disabled, otherwise it is enabled.") (sdl-init) (start-text-input) (init-audio) + ;; Hint that we want OpenGL 3.2 Core profile. Doesn't mean we'll + ;; get it, though! + (sdl2:set-gl-attribute! 'context-major-version 3) + (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 (let* ((window (sdl2:make-window #:opengl? #t #:title window-title #:size (list window-width window-height) diff --git a/chickadee/render/gl.scm b/chickadee/render/gl.scm index 7b23697..295a7bb 100644 --- a/chickadee/render/gl.scm +++ b/chickadee/render/gl.scm @@ -299,3 +299,10 @@ object.") (%glUniform4f . gl-uniform4f)) (re-export (%glPointSize . gl-point-size)) + + +;;; +;;; Context Queries +;;; + +(re-export (%glGetString . gl-get-string)) diff --git a/chickadee/render/gpu.scm b/chickadee/render/gpu.scm index 66510fc..554e263 100644 --- a/chickadee/render/gpu.scm +++ b/chickadee/render/gpu.scm @@ -16,8 +16,11 @@ ;;; <http://www.gnu.org/licenses/>. (define-module (chickadee render gpu) + #:use-module (chickadee render gl) + #:use-module (gl enums) #:use-module (oop goops) #:use-module (srfi srfi-9) + #:use-module (system foreign) #:export (make-gpu-state gpu-state-ref gpu-state-set! @@ -30,6 +33,8 @@ current-gpu gpu? gpu-gl-context + gpu-gl-version + gpu-glsl-version gpu-blend-mode gpu-depth-test gpu-framebuffer @@ -91,6 +96,8 @@ from the GPU's memory." (define-record-type <gpu> (%make-gpu gl-context + gl-version + glsl-version blend-mode depth-test framebuffer @@ -101,6 +108,8 @@ from the GPU's memory." viewport) gpu? (gl-context gpu-gl-context) + (gl-version gpu-gl-version) + (glsl-version gpu-glsl-version) (blend-mode %gpu-blend-mode) (depth-test %gpu-depth-test) (framebuffer %gpu-framebuffer) @@ -113,6 +122,8 @@ from the GPU's memory." (define current-gpu (make-parameter #f)) (define (make-gpu gl-context) + (define (extract-version attr) + (car (string-split (pointer->string (gl-get-string attr)) #\space))) (let ((textures (make-vector 32)) ;; Lazily resolve bindings to avoid circular dependencies. (blend-module (resolve-interface '(chickadee render blend))) @@ -120,7 +131,9 @@ from the GPU's memory." (framebuffer-module (resolve-interface '(chickadee render framebuffer))) (shader-module (resolve-interface '(chickadee render shader))) (texture-module (resolve-interface '(chickadee render texture))) - (viewport-module (resolve-interface '(chickadee render viewport)))) + (viewport-module (resolve-interface '(chickadee render viewport))) + (gl-version (extract-version (string-name version))) + (glsl-version (extract-version (version-2-0 shading-language-version)))) ;; Create state for 32 texture units. (let loop ((i 0)) (when (< i 32) @@ -131,7 +144,8 @@ from the GPU's memory." (module-ref texture-module 'null-texture)))) (loop (+ i 1)))) (%make-gpu gl-context - ;; Use @ and @@ to avoid circular module dependencies. + gl-version + glsl-version (make-gpu-state (module-ref blend-module 'apply-blend-mode) 'replace) (make-gpu-state (module-ref blend-module 'apply-depth-test) |