opengl/buffers
make-vao
(make-vao :)
generate a Vertex Array Object.
Opaque :int VAO handle (GLuint stored as int64).
(let [vao (make-vao)] ...)
Since: v0.1.0
make-vbo
(make-vbo :)
generate a Vertex Buffer Object.
Opaque :int VBO handle.
Since: v0.1.0
make-ebo
(make-ebo :)
generate an Element Buffer Object (index buffer).
Opaque :int EBO handle.
Since: v0.1.0
bind-vao
(bind-vao [^borrow vao : Vao] :)
make a VAO current. Borrows the handle (use unbind-vao to clear).
| vao | VAO handle from make-vao (borrowed, not consumed) |
(bind-vao vao) ... (unbind-vao)
Since: v0.1.0
bind-vbo
(bind-vbo [^borrow vbo : Vbo] :)
bind a VBO to GL_ARRAY_BUFFER. Borrows the handle.
| vbo | VBO handle from make-vbo (borrowed, not consumed) |
Since: v0.1.0
bind-ebo
(bind-ebo [^borrow ebo : Ebo] :)
bind an EBO to GL_ELEMENT_ARRAY_BUFFER. Borrows the handle.
| ebo | EBO handle from make-ebo (borrowed, not consumed) |
Since: v0.1.0
unbind-vao
(unbind-vao :)
clear the current VAO binding (glBindVertexArray(0)).
Since: v0.3.0
unbind-vbo
(unbind-vbo :)
clear the GL_ARRAY_BUFFER binding.
Since: v0.3.0
unbind-ebo
(unbind-ebo :)
clear the GL_ELEMENT_ARRAY_BUFFER binding.
Since: v0.3.0
delete-vao
(delete-vao [vao : Vao] :)
delete a VAO (glDeleteVertexArrays), consuming the handle.
| vao | VAO handle from make-vao (consumed) |
Since: v0.3.0
delete-vbo
(delete-vbo [vbo : Vbo] :)
delete a VBO (glDeleteBuffers), consuming the handle.
| vbo | VBO handle from make-vbo (consumed) |
Since: v0.3.0
delete-ebo
(delete-ebo [ebo : Ebo] :)
delete an EBO (glDeleteBuffers), consuming the handle.
| ebo | EBO handle from make-ebo (consumed) |
Since: v0.3.0
upload-vertices
(upload-vertices [data : int size : int usage : cstr] :)
stream a float array into the currently-bound VBO.
| data | pointer to packed vertex data; float-array-ptr on an | |
| opengl/arrays FloatArray, or your own malloc'd block | ||
| size | byte size of the data | |
| usage | draw usage keyword: :static-draw | :dynamic-draw | :stream-draw |
(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.1.0
upload-indices
(upload-indices [data : int size : int usage : cstr] :)
stream an integer index array into the currently-bound EBO.
| data | pointer to index data (opaque :int) | |
| size | byte size of the data | |
| usage | draw usage keyword |
(upload-indices idx-data (* 36 4) ":static-draw")
Since: v0.1.0
vertex-attrib
(vertex-attrib [index : int components : int type : cstr normalized : bool stride : int offset : int] :)
describe a vertex attribute pointer and enable it.
| index | attribute location (matches layout(location=N) in GLSL) | |
| components | number of components per vertex (1-4) | |
| type | component type keyword: :float | :int | :uint | :byte | |
| normalized | true to normalise integer values to [-1,1] or [0,1] | |
| stride | byte distance between the start of consecutive vertices | |
| offset | byte offset of this attribute within the stride |
;; attribute 0: xyz position (3 floats), tightly packed stride=12 (vertex-attrib 0 3 ":float" false 12 0) ;; attribute 1: uv coords (2 floats), interleaved after xyz, stride=20 (vertex-attrib 1 2 ":float" false 20 12)
Since: v0.1.0
with-vao
(with-vao [v & body])
bind a new VAO for the duration of body, then unbind and delete
| v | symbol to bind the VAO handle | |
| body | one or more expressions executed with v in scope |
(with-vao v
(bind-vbo vbo)
(upload-vertices data size ":static-draw")
(vertex-attrib 0 3 ":float" false 12 0))
Since: v0.1.0