From 03072ef67af0623758a660e2cd3fb5e153133efa Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 24 May 2023 08:09:03 -0400 Subject: Update chickadee manual. --- manuals/chickadee/Buffers.html | 130 ++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 65 deletions(-) (limited to 'manuals/chickadee/Buffers.html') diff --git a/manuals/chickadee/Buffers.html b/manuals/chickadee/Buffers.html index ffb4714..ac5fb02 100644 --- a/manuals/chickadee/Buffers.html +++ b/manuals/chickadee/Buffers.html @@ -1,6 +1,6 @@ - - + --> + - + Buffers (The Chickadee Game Toolkit) - - - - - - - - - - - + + + + + + + + + + + - + @@ -84,7 +84,7 @@ ul.no-bullet {list-style: none}

Next: , Previous: , Up: Graphics   [Contents][Index]

-
+

5.3.12 Buffers

Alright, let’s brush aside all of those pretty high level abstractions @@ -99,25 +99,25 @@ API for manipulating GPU buffers. that could be transformed into a GPU buffer that packs together vertex position and texture coordinates:

-
-
(use-modules (chickadee graphics buffer) (srfi srfi-4))
-(define data
-  (f32vector -8.0 -8.0 ; 2D vertex
-             0.0 0.0   ; 2D texture coordinate
-             8.0 -8.0  ; 2D vertex
-             1.0 0.0   ; 2D texture coordinate
-             8.0 8.0   ; 2D vertex
-             1.0 1.0   ; 2D texture coordinate
-             -8.0 8.0  ; 2D vertex
-             0.0 1.0)) ; 2D texture coordinate
-
+
+
(use-modules (chickadee graphics buffer) (srfi srfi-4))
+(define data
+  (f32vector -8.0 -8.0 ; 2D vertex
+             0.0 0.0   ; 2D texture coordinate
+             8.0 -8.0  ; 2D vertex
+             1.0 0.0   ; 2D texture coordinate
+             8.0 8.0   ; 2D vertex
+             1.0 1.0   ; 2D texture coordinate
+             -8.0 8.0  ; 2D vertex
+             0.0 1.0)) ; 2D texture coordinate
+

This data represents a textured 16x16 square centered on the origin. To send this data to the GPU, the make-buffer procedure is needed:

-
-
(define buffer (make-buffer data #:stride 16))
+
+
(define buffer (make-buffer data #:stride 16))
 

The #:stride keyword argument indicates how many bytes make up @@ -131,18 +131,18 @@ particular data type. In this case, there are two attributes packed into the buffer. To define vertex attributes, the make-vertex-attribute procedure is needed:

-
-
(define vertices
-  (make-vertex-attribute #:buffer buffer
-                         #:type 'vec2
-                         #:component-type 'float
-                         #:length 4))
-(define texcoords
-  (make-vertex-attribute #:buffer buffer
-                         #:type 'vec2
-                         #:component-type 'float
-                         #:length 4
-                         #:offset 8))
+
+
(define vertices
+  (make-vertex-attribute #:buffer buffer
+                         #:type 'vec2
+                         #:component-type 'float
+                         #:length 4))
+(define texcoords
+  (make-vertex-attribute #:buffer buffer
+                         #:type 'vec2
+                         #:component-type 'float
+                         #:length 4
+                         #:offset 8))
 

To render a square, the GPU needs to draw two triangles, which means @@ -152,14 +152,14 @@ for a square, but 2 of them must be repeated for each triangle. To work with deduplicated vertex data, an “index buffer” must be created.

-
-
(define index-buffer
-  (make-buffer (u32vector 0 3 2 0 2 1)
-               #:target 'index)
-(define indices
-  (make-vertex-attribute #:type 'scalar
-                         #:component-type 'unsigned-int
-                         #:buffer index-buffer))
+
+
(define index-buffer
+  (make-buffer (u32vector 0 3 2 0 2 1)
+               #:target 'index)
+(define indices
+  (make-vertex-attribute #:type 'scalar
+                         #:component-type 'unsigned-int
+                         #:buffer index-buffer))
 

Note the use of the #:target keyword argument. It is required @@ -172,11 +172,11 @@ each vertex attribute with an attribute index on the GPU. The indices that are chosen must correspond with the indices that the shader (see Shaders) expects for each attribute.

-
-
(define vertex-array
-  (make-vertex-array #:indices indices
-                     #:attributes `((0 . ,vertices)
-                                    (1 . ,texcoords))))
+
+
(define vertex-array
+  (make-vertex-array #:indices indices
+                     #:attributes `((0 . ,vertices)
+                                    (1 . ,texcoords))))
 

With the vertex array created, the GPU is now fully aware of how to @@ -190,7 +190,7 @@ shapes, or particles to see GPU buffers in action.

Without further ado, the API reference:

-
Procedure: make-buffer data [#:name "anonymous"] [#:length] [#:offset 0] [#:stride 0] [#:target vertex] [#:usage static]
+
Procedure: make-buffer data [#:name "anonymous"] [#:length] [#:offset 0] [#:stride 0] [#:target vertex] [#:usage static]

Upload data, a bytevector, to the GPU. By default, the entire bytevector is uploaded. A subset of the data may be uploaded by @@ -304,7 +304,7 @@ contents dynamically, such as a sprite batch.

-
Procedure: make-vertex-attribute #:buffer #:type #:component-type #:length [#:offset 0] [#:divisor 1] [#:name "anonymous"]
+
Procedure: make-vertex-attribute #:buffer #:type #:component-type #:length [#:offset 0] [#:divisor 1] [#:name "anonymous"]

Return a new vertex attribute for buffer starting at byte index offset of length elements, where each element is of @@ -411,10 +411,10 @@ attributes indices and the vertex attribute data within

attributes is an alist mapping shader attribute indices to vertex attributes:

-
-
`((1 . ,vertex-attribute-a)
-  (2 . ,vertex-attribute-b)
-  …)
+
+
`((1 . ,vertex-attribute-a)
+  (2 . ,vertex-attribute-b)
+  ...)
 

By default, the vertex array is interpreted as containing a series of @@ -470,7 +470,7 @@ data for vertex-array.

Render state for vertex arrays (see Rendering Engine.)

-
+

Next: , Previous: , Up: Graphics   [Contents][Index]

-- cgit v1.2.3