summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-02-23 20:31:16 -0500
committerDavid Thompson <dthompson2@worcester.edu>2016-02-23 20:31:16 -0500
commit08ed505d9fafe853cf66507e916d1129106c89a7 (patch)
tree589b739405b66592a3df74ad38cb6143a1d58d6b
parent9382bb1dfba13222a57ded43becc60249dce2c70 (diff)
render: sprite-batch: Implement in terms of a mesh.
* sly/render/sprite-batch.scm (<sprite-batch>): Replace 'vao' field with 'mesh' field. (make-sprite-batch): Use 'make-mesh'. (sprite-batch-flush!): Use 'set-graphics-mesh!'
-rw-r--r--sly/render/sprite-batch.scm21
1 files changed, 5 insertions, 16 deletions
diff --git a/sly/render/sprite-batch.scm b/sly/render/sprite-batch.scm
index 7caef67..1f591c2 100644
--- a/sly/render/sprite-batch.scm
+++ b/sly/render/sprite-batch.scm
@@ -56,7 +56,7 @@
(define-record-type <sprite-batch>
(%make-sprite-batch texture size capacity index-buffer
- position-buffer texture-buffer vao)
+ position-buffer texture-buffer mesh)
sprite-batch?
(texture sprite-batch-texture set-sprite-batch-texture!)
(size sprite-batch-size set-sprite-batch-size!)
@@ -64,25 +64,15 @@
(index-buffer sprite-batch-index-buffer)
(position-buffer sprite-batch-position-buffer)
(texture-buffer sprite-batch-texture-buffer)
- (vao sprite-batch-vao))
-
-;; TODO: Add guardian.
+ (mesh sprite-batch-mesh))
(define (make-sprite-batch capacity)
"Make a sprite batch that can hold CAPACITY sprites."
(let* ((index (make-streaming-vertex-buffer 'index (* capacity 6)))
(pos (make-streaming-vertex-buffer 'vec3 (* capacity 4)))
(tex (make-streaming-vertex-buffer 'vec2 (* capacity 4)))
- (vao (generate-vertex-array)))
-
- ;; Build the vertex array for the buffer.
- (glBindVertexArray vao)
- (vertex-attrib-pointer vertex-position-location pos)
- (vertex-attrib-pointer vertex-texture-location tex)
- (apply-vertex-buffer index)
- (glBindVertexArray 0)
-
- (%make-sprite-batch #f 0 capacity index pos tex vao)))
+ (mesh (make-mesh index pos tex)))
+ (%make-sprite-batch #f 0 capacity index pos tex mesh)))
(define (same-texture? t1 t2)
(define (maybe-parent-texture t)
@@ -238,13 +228,12 @@
(unmap-vertex-buffer! (sprite-batch-position-buffer batch))
(unmap-vertex-buffer! (sprite-batch-texture-buffer batch))
- (glBindVertexArray (sprite-batch-vao batch))
+ (set-graphics-mesh! context (sprite-batch-mesh batch))
(glDrawElements (begin-mode triangles)
;; 6 indices per sprite.
(* (sprite-batch-size batch) 6)
(data-type unsigned-int)
%null-pointer)
- (glBindVertexArray 0)
(sprite-batch-reset! batch)))))))))