diff options
-rw-r--r-- | sly/render/mesh.scm | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/sly/render/mesh.scm b/sly/render/mesh.scm index 69f89ce..04a8ab2 100644 --- a/sly/render/mesh.scm +++ b/sly/render/mesh.scm @@ -22,12 +22,13 @@ ;;; Code: (define-module (sly render mesh) - #:use-module (system foreign) + #:use-module (ice-9 format) #:use-module (ice-9 match) + #:use-module (rnrs bytevectors) #:use-module (srfi srfi-9) #:use-module (srfi srfi-9 gnu) #:use-module (srfi srfi-43) - #:use-module (rnrs bytevectors) + #:use-module (system foreign) #:use-module (gl) #:use-module (gl low-level) #:use-module (sly utils) @@ -36,14 +37,31 @@ #:use-module (sly render color) #:use-module (sly render shader) #:export (make-vertex-buffer - bytevector->vertex-buffer vector->vertex-buffer - vertex-buffer? index-buffer? - vertex-buffer-id vertex-buffer-type vertex-buffer-usage - vertex-buffer-data vertex-buffer-length - make-mesh build-mesh null-mesh + bytevector->vertex-buffer + vector->vertex-buffer + vertex-buffer? + index-buffer? + vertex-buffer-id + vertex-buffer-type + vertex-buffer-usage + vertex-buffer-data + vertex-buffer-length + vertex-buffer-attribute-size + apply-vertex-buffer + + generate-vertex-array + vertex-attrib-pointer + + make-mesh + build-mesh + null-mesh mesh? - mesh-id mesh-length mesh-ref - apply-mesh with-mesh)) + mesh-id + mesh-vertex-buffers + mesh-length + mesh-ref + apply-mesh + with-mesh)) ;;; ;;; Vertex Buffer @@ -70,7 +88,7 @@ (glGenBuffers 1 (bytevector->pointer bv)) (u32vector-ref bv 0))) -(define (bind-vertex-buffer vbo) +(define (apply-vertex-buffer vbo) (glBindBuffer (vertex-buffer-target vbo) (vertex-buffer-id vbo))) @@ -197,17 +215,17 @@ ;;; (define-record-type <mesh> - (%make-mesh id length vbos) + (%make-mesh id length vertex-buffers) mesh? (id mesh-id) (length mesh-length) - (vbos mesh-vbos)) + (vertex-buffers mesh-vertex-buffers)) (define-guardian mesh-guardian (lambda (mesh) ;; Delete vertex array and vertex buffers. (glDeleteVertexArrays 1 (u32vector (mesh-id mesh))) - (let ((buffers (mesh-vbos mesh))) + (let ((buffers (mesh-vertex-buffers mesh))) (glDeleteBuffers (length buffers) (list->u32vector (map (match-lambda @@ -247,7 +265,7 @@ (with-mesh mesh (vertex-attrib-pointer vertex-position-location position-buffer) (vertex-attrib-pointer vertex-texture-location texture-buffer) - (bind-vertex-buffer index-buffer)) + (apply-vertex-buffer index-buffer)) (mesh-guardian mesh) mesh)) @@ -258,4 +276,4 @@ (make-mesh index-buffer position-buffer texture-buffer))) (define (mesh-ref mesh key) - (assq-ref (mesh-vbos mesh) key)) + (assq-ref (mesh-vertex-buffers mesh) key)) |