diff options
Diffstat (limited to 'manuals/chickadee/Buffers.html')
-rw-r--r-- | manuals/chickadee/Buffers.html | 130 |
1 files changed, 65 insertions, 65 deletions
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 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> -<!-- Copyright (C) 2017-2021 David Thompson davet@gnu.org +<!-- Copyright (C) 2017-2023 David Thompson dthompson2@worcester.edu Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 @@ -17,25 +17,25 @@ Foundation Web site at http://www.gnu.org/licenses/fdl.html. The document was typeset with http://www.texinfo.org/ (GNU Texinfo). - --> -<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> + --> +<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> <head> -<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Buffers (The Chickadee Game Toolkit)</title> -<meta name="description" content="Buffers (The Chickadee Game Toolkit)"> -<meta name="keywords" content="Buffers (The Chickadee Game Toolkit)"> -<meta name="resource-type" content="document"> -<meta name="distribution" content="global"> -<meta name="Generator" content="makeinfo"> -<link href="index.html" rel="start" title="Top"> -<link href="Index.html" rel="index" title="Index"> -<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> -<link href="Graphics.html" rel="up" title="Graphics"> -<link href="Shaders.html" rel="next" title="Shaders"> -<link href="Meshes.html" rel="prev" title="Meshes"> +<meta name="description" content="Buffers (The Chickadee Game Toolkit)" /> +<meta name="keywords" content="Buffers (The Chickadee Game Toolkit)" /> +<meta name="resource-type" content="document" /> +<meta name="distribution" content="global" /> +<meta name="Generator" content="makeinfo" /> +<link href="index.html" rel="start" title="Top" /> +<link href="Index.html" rel="index" title="Index" /> +<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents" /> +<link href="Graphics.html" rel="up" title="Graphics" /> +<link href="Shaders.html" rel="next" title="Shaders" /> +<link href="Meshes.html" rel="prev" title="Meshes" /> <style type="text/css"> -<!-- +<!-- a.summary-letter {text-decoration: none} blockquote.indentedblock {margin-right: 0em} div.display {margin-left: 3.2em} @@ -72,9 +72,9 @@ ul.no-bullet {list-style: none} } } ---> +--> </style> -<link rel="stylesheet" type="text/css" href="https://dthompson.us/css/dthompson.css"> +<link rel="stylesheet" type="text/css" href="https://dthompson.us/css/dthompson.css" /> </head> @@ -84,7 +84,7 @@ ul.no-bullet {list-style: none} <p> Next: <a href="Shaders.html" accesskey="n" rel="next">Shaders</a>, Previous: <a href="Meshes.html" accesskey="p" rel="prev">Meshes</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> </div> -<hr> +<hr /> <span id="Buffers-1"></span><h4 class="subsection">5.3.12 Buffers</h4> <p>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: </p> -<div class="example"> -<pre class="example">(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 -</pre></div> +<div class="lisp"> +<pre class="lisp"><span class="syntax-open">(</span><span class="syntax-symbol">use-modules</span> <span class="syntax-open">(</span><span class="syntax-symbol">chickadee</span> <span class="syntax-symbol">graphics</span> <span class="syntax-symbol">buffer</span><span class="syntax-close">)</span> <span class="syntax-open">(</span><span class="syntax-symbol">srfi</span> <span class="syntax-symbol">srfi-4</span><span class="syntax-close">)</span><span class="syntax-close">)</span> +<span class="syntax-open">(</span><span class="syntax-special">define</span> <span class="syntax-symbol">data</span> + <span class="syntax-open">(</span><span class="syntax-symbol">f32vector</span> <span class="syntax-symbol">-8.0</span> <span class="syntax-symbol">-8.0</span> <span class="syntax-comment">; 2D vertex +</span> <span class="syntax-symbol">0.0</span> <span class="syntax-symbol">0.0</span> <span class="syntax-comment">; 2D texture coordinate +</span> <span class="syntax-symbol">8.0</span> <span class="syntax-symbol">-8.0</span> <span class="syntax-comment">; 2D vertex +</span> <span class="syntax-symbol">1.0</span> <span class="syntax-symbol">0.0</span> <span class="syntax-comment">; 2D texture coordinate +</span> <span class="syntax-symbol">8.0</span> <span class="syntax-symbol">8.0</span> <span class="syntax-comment">; 2D vertex +</span> <span class="syntax-symbol">1.0</span> <span class="syntax-symbol">1.0</span> <span class="syntax-comment">; 2D texture coordinate +</span> <span class="syntax-symbol">-8.0</span> <span class="syntax-symbol">8.0</span> <span class="syntax-comment">; 2D vertex +</span> <span class="syntax-symbol">0.0</span> <span class="syntax-symbol">1.0</span><span class="syntax-close">)</span><span class="syntax-close">)</span> <span class="syntax-comment">; 2D texture coordinate +</span></pre></div> <p>This data represents a textured 16x16 square centered on the origin. To send this data to the GPU, the <code>make-buffer</code> procedure is needed: </p> -<div class="example"> -<pre class="example">(define buffer (make-buffer data #:stride 16)) +<div class="lisp"> +<pre class="lisp"><span class="syntax-open">(</span><span class="syntax-special">define</span> <span class="syntax-symbol">buffer</span> <span class="syntax-open">(</span><span class="syntax-symbol">make-buffer</span> <span class="syntax-symbol">data</span> <span class="syntax-keyword">#:stride</span> <span class="syntax-symbol">16</span><span class="syntax-close">)</span><span class="syntax-close">)</span> </pre></div> <p>The <code>#:stride</code> 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 <code>make-vertex-attribute</code> procedure is needed: </p> -<div class="example"> -<pre class="example">(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)) +<div class="lisp"> +<pre class="lisp"><span class="syntax-open">(</span><span class="syntax-special">define</span> <span class="syntax-symbol">vertices</span> + <span class="syntax-open">(</span><span class="syntax-symbol">make-vertex-attribute</span> <span class="syntax-keyword">#:buffer</span> <span class="syntax-symbol">buffer</span> + <span class="syntax-keyword">#:type</span> <span class="syntax-symbol">'vec2</span> + <span class="syntax-keyword">#:component-type</span> <span class="syntax-symbol">'float</span> + <span class="syntax-keyword">#:length</span> <span class="syntax-symbol">4</span><span class="syntax-close">)</span><span class="syntax-close">)</span> +<span class="syntax-open">(</span><span class="syntax-special">define</span> <span class="syntax-symbol">texcoords</span> + <span class="syntax-open">(</span><span class="syntax-symbol">make-vertex-attribute</span> <span class="syntax-keyword">#:buffer</span> <span class="syntax-symbol">buffer</span> + <span class="syntax-keyword">#:type</span> <span class="syntax-symbol">'vec2</span> + <span class="syntax-keyword">#:component-type</span> <span class="syntax-symbol">'float</span> + <span class="syntax-keyword">#:length</span> <span class="syntax-symbol">4</span> + <span class="syntax-keyword">#:offset</span> <span class="syntax-symbol">8</span><span class="syntax-close">)</span><span class="syntax-close">)</span> </pre></div> <p>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. </p> -<div class="example"> -<pre class="example">(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)) +<div class="lisp"> +<pre class="lisp"><span class="syntax-open">(</span><span class="syntax-special">define</span> <span class="syntax-symbol">index-buffer</span> + <span class="syntax-open">(</span><span class="syntax-symbol">make-buffer</span> <span class="syntax-open">(</span><span class="syntax-symbol">u32vector</span> <span class="syntax-symbol">0</span> <span class="syntax-symbol">3</span> <span class="syntax-symbol">2</span> <span class="syntax-symbol">0</span> <span class="syntax-symbol">2</span> <span class="syntax-symbol">1</span><span class="syntax-close">)</span> + <span class="syntax-keyword">#:target</span> <span class="syntax-symbol">'index</span><span class="syntax-close">)</span> +<span class="syntax-open">(</span><span class="syntax-special">define</span> <span class="syntax-symbol">indices</span> + <span class="syntax-open">(</span><span class="syntax-symbol">make-vertex-attribute</span> <span class="syntax-keyword">#:type</span> <span class="syntax-symbol">'scalar</span> + <span class="syntax-keyword">#:component-type</span> <span class="syntax-symbol">'unsigned-int</span> + <span class="syntax-keyword">#:buffer</span> <span class="syntax-symbol">index-buffer</span><span class="syntax-close">)</span><span class="syntax-close">)</span> </pre></div> <p>Note the use of the <code>#:target</code> 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 <a href="Shaders.html">Shaders</a>) expects for each attribute. </p> -<div class="example"> -<pre class="example">(define vertex-array - (make-vertex-array #:indices indices - #:attributes `((0 . ,vertices) - (1 . ,texcoords)))) +<div class="lisp"> +<pre class="lisp"><span class="syntax-open">(</span><span class="syntax-special">define</span> <span class="syntax-symbol">vertex-array</span> + <span class="syntax-open">(</span><span class="syntax-symbol">make-vertex-array</span> <span class="syntax-keyword">#:indices</span> <span class="syntax-symbol">indices</span> + <span class="syntax-keyword">#:attributes</span> <span class="syntax-symbol">`</span><span class="syntax-open">(</span><span class="syntax-open">(</span><span class="syntax-symbol">0</span> <span class="syntax-symbol">.</span> <span class="syntax-symbol">,vertices</span><span class="syntax-close">)</span> + <span class="syntax-open">(</span><span class="syntax-symbol">1</span> <span class="syntax-symbol">.</span> <span class="syntax-symbol">,texcoords</span><span class="syntax-close">)</span><span class="syntax-close">)</span><span class="syntax-close">)</span><span class="syntax-close">)</span> </pre></div> <p>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. <p>Without further ado, the API reference: </p> <dl> -<dt id="index-make_002dbuffer">Procedure: <strong>make-buffer</strong> <em>data [#:name "anonymous"] [#:length] [#:offset 0] [#:stride 0] [#:target <code>vertex</code>] [#:usage <code>static</code>]</em></dt> +<dt id="index-make_002dbuffer">Procedure: <strong>make-buffer</strong> <em>data [#:name "anonymous"] [#:length] [#:offset 0] [#:stride 0] [#:target <code>vertex</code>] [#:usage <code>static</code>]</em></dt> <dd> <p>Upload <var>data</var>, 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. </p></dd></dl> <dl> -<dt id="index-make_002dvertex_002dattribute">Procedure: <strong>make-vertex-attribute</strong> <em>#:buffer #:type #:component-type #:length [#:offset <code>0</code>] [#:divisor <code>1</code>] [#:name <code>"anonymous"</code>]</em></dt> +<dt id="index-make_002dvertex_002dattribute">Procedure: <strong>make-vertex-attribute</strong> <em>#:buffer #:type #:component-type #:length [#:offset <code>0</code>] [#:divisor <code>1</code>] [#:name <code>"anonymous"</code>]</em></dt> <dd> <p>Return a new vertex attribute for <var>buffer</var> starting at byte index <var>offset</var> of <var>length</var> elements, where each element is of @@ -411,10 +411,10 @@ attributes <var>indices</var> and the vertex attribute data within <p><var>attributes</var> is an alist mapping shader attribute indices to vertex attributes: </p> -<div class="example"> -<pre class="example">`((1 . ,vertex-attribute-a) - (2 . ,vertex-attribute-b) - …) +<div class="lisp"> +<pre class="lisp"><span class="syntax-symbol">`</span><span class="syntax-open">(</span><span class="syntax-open">(</span><span class="syntax-symbol">1</span> <span class="syntax-symbol">.</span> <span class="syntax-symbol">,vertex-attribute-a</span><span class="syntax-close">)</span> + <span class="syntax-open">(</span><span class="syntax-symbol">2</span> <span class="syntax-symbol">.</span> <span class="syntax-symbol">,vertex-attribute-b</span><span class="syntax-close">)</span> + <span class="syntax-symbol">...</span><span class="syntax-close">)</span> </pre></div> <p>By default, the vertex array is interpreted as containing a series of @@ -470,7 +470,7 @@ data for <var>vertex-array</var>. <dd><p>Render state for vertex arrays (see <a href="Rendering-Engine.html">Rendering Engine</a>.) </p></dd></dl> -<hr> +<hr /> <div class="header"> <p> Next: <a href="Shaders.html" accesskey="n" rel="next">Shaders</a>, Previous: <a href="Meshes.html" accesskey="p" rel="prev">Meshes</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> |