summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-03-05 08:04:55 -0500
committerDavid Thompson <dthompson2@worcester.edu>2021-03-05 08:04:55 -0500
commit2bed164bdea04034140b843fc4a3cb20488138b6 (patch)
tree698faee8d97dd6ce4e98ab286a816df390e831b6
parent0c88e29f9ecbc026abe9a7fe99fd91ee28b01314 (diff)
graphics: Improve error message when prematurely creating GPU objects.
-rw-r--r--chickadee/graphics/buffer.scm2
-rw-r--r--chickadee/graphics/engine.scm5
-rw-r--r--chickadee/graphics/framebuffer.scm1
-rw-r--r--chickadee/graphics/shader.scm1
-rw-r--r--chickadee/graphics/texture.scm1
5 files changed, 10 insertions, 0 deletions
diff --git a/chickadee/graphics/buffer.scm b/chickadee/graphics/buffer.scm
index f5ec8c6..37a77e4 100644
--- a/chickadee/graphics/buffer.scm
+++ b/chickadee/graphics/buffer.scm
@@ -204,6 +204,7 @@ USAGE may be:
NAME is simply an arbitrary string for debugging purposes that is
never sent to the GPU."
+ (assert-current-graphics-engine)
;; Weird bugs will occur when creating a new vertex buffer while a
;; vertex array is bound.
(with-graphics-state! ((vertex-array null-vertex-array))
@@ -561,6 +562,7 @@ argument may be overridden. The following values are supported:
- triangles
- triangle-strip
- triangle-fan"
+ (assert-current-graphics-engine)
(let ((array (%make-vertex-array (generate-vertex-array)
indices
attributes
diff --git a/chickadee/graphics/engine.scm b/chickadee/graphics/engine.scm
index 4f1250f..1531e3f 100644
--- a/chickadee/graphics/engine.scm
+++ b/chickadee/graphics/engine.scm
@@ -23,6 +23,7 @@
graphics-engine-guard!
graphics-engine-reap!
current-graphics-engine
+ assert-current-graphics-engine
current-projection
with-projection
with-graphics-state
@@ -200,6 +201,10 @@
(define current-graphics-engine (make-parameter #f))
+(define-syntax-rule (assert-current-graphics-engine)
+ (unless (current-graphics-engine)
+ (error "No active graphics engine. Make sure the game loop is running before calling this procedure.")))
+
(define* (graphics-engine-gl-context #:optional (engine (current-graphics-engine)))
(%graphics-engine-gl-context engine))
diff --git a/chickadee/graphics/framebuffer.scm b/chickadee/graphics/framebuffer.scm
index edf97a2..5a8be8d 100644
--- a/chickadee/graphics/framebuffer.scm
+++ b/chickadee/graphics/framebuffer.scm
@@ -101,6 +101,7 @@
(wrap-s 'repeat) (wrap-t 'repeat))
"Create a new framebuffer that renders to a texture with
dimensions WIDTH x HEIGHT."
+ (assert-current-graphics-engine)
(let* ((framebuffer-id (generate-framebuffer))
(renderbuffer-id (generate-renderbuffer))
(texture (make-texture #f width height
diff --git a/chickadee/graphics/shader.scm b/chickadee/graphics/shader.scm
index 335f79c..9b2070b 100644
--- a/chickadee/graphics/shader.scm
+++ b/chickadee/graphics/shader.scm
@@ -712,6 +712,7 @@ them into a GPU shader program."
(error "unsupported attribute size" name size))
(hash-set! table name (make-attribute name location type)))))
table))
+ (assert-current-graphics-engine)
(let ((vertex-id (make-shader-stage (version-2-0 vertex-shader)
vertex-port))
(fragment-id (make-shader-stage (version-2-0 fragment-shader)
diff --git a/chickadee/graphics/texture.scm b/chickadee/graphics/texture.scm
index 30ae9a0..f056be8 100644
--- a/chickadee/graphics/texture.scm
+++ b/chickadee/graphics/texture.scm
@@ -170,6 +170,7 @@ clamp-to-edge. FORMAT specifies the pixel format. Currently only
('clamp-to-border (texture-wrap-mode clamp-to-border-sgis))
('clamp-to-edge (texture-wrap-mode clamp-to-edge-sgis))))
+ (assert-current-graphics-engine)
(let ((texture (%make-texture (gl-generate-texture) #f
min-filter mag-filter wrap-s wrap-t
0 0 width height