opengl/arrays
packed GLfloat arrays for buffer uploads.
Since: v0.2.0
FloatArray
(FloatArray)
opaque handle to a heap block of packed 32-bit floats.
make-float-array
(make-float-array [n : int] :)
allocate a zeroed array of n packed float32 slots.
| n | number of float slots (a negative n is treated as 0) |
A FloatArray that must be consumed exactly once by delete-float-array.
(let [a (make-float-array 9)]
(float-array-set! a 0 0.6)
(delete-float-array a))
Since: v0.2.0
delete-float-array
(delete-float-array [a : FloatArray] :)
free an array, consuming the handle.
| a | the array to release |
(delete-float-array a)
Since: v0.2.0
float-array-set!
(float-array-set! [^borrow a : FloatArray i : int v : float] :)
store v at index i, narrowed to float32.
| a | the array (borrowed) | |
| i | slot index; out of range is a no-op | |
| v | the value, narrowed from float64 to GLfloat |
(float-array-set! a 2 7.1)
Since: v0.2.0
float-array-get
(float-array-get [^borrow a : FloatArray i : int] :)
read slot i, widened back to float64.
| a | the array (borrowed) | |
| i | slot index; out of range answers 0.0 |
The stored value. Note it round-trips through float32, so it is the nearest GLfloat to what was written, not the original float64.
(float-array-get a 2) ; => 7.1
Since: v0.2.0
float-array-len
(float-array-len [^borrow a : FloatArray] :)
number of float slots.
| a | the array (borrowed) |
The slot count passed to make-float-array.
(float-array-len a) ; => 9
Since: v0.2.0
float-array-bytes
(float-array-bytes [^borrow a : FloatArray] :)
payload size in bytes, for upload-vertices.
| a | the array (borrowed) |
len * 4 -- the byte size GL wants alongside the pointer.
(upload-vertices (float-array-ptr a) (float-array-bytes a) ":static-draw")
Since: v0.2.0
float-array-ptr
(float-array-ptr [^borrow a : FloatArray] :)
address of the packed payload.
| a | the array (borrowed) |
An :int pointer valid until delete-float-array. Pass it to upload-vertices; do not retain it past the array's lifetime.
(upload-vertices (float-array-ptr a) (float-array-bytes a) ":static-draw")
Since: v0.2.0
with-float-array
(with-float-array [a n & body])
allocate an array for the duration of body, then free
| a | symbol to bind the FloatArray handle | |
| n | number of float slots | |
| body | one or more expressions executed with a in scope |
(with-float-array verts 9
(float-array-set! verts 0 0.6)
(upload-vertices (float-array-ptr verts)
(float-array-bytes verts) ":static-draw"))
Since: v0.2.0
Internal definitions
__fa-alloc-- calloc a length header plus n float32 slots.__fa-free-- release a block from __fa-alloc.__fa-len-- read the length header.__fa-set!-- bounds-checked narrowing store.__fa-get-- bounds-checked widening load.__fa-data-- address of the payload, past the length header.