From 932aa58fbd8e593fc1ea78cb5249196ae14f58b1 Mon Sep 17 00:00:00 2001 From: Sandro Steeger <78495486+Stastez@users.noreply.github.com> Date: Sat, 18 Nov 2023 22:19:36 +0100 Subject: [PATCH] Implement attribEnableInt as a wrapper for gl.vertexAttribIPointer(...) to allow binding of integer buffers. --- source/buffer.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/source/buffer.ts b/source/buffer.ts index cffceb14..fadfe860 100644 --- a/source/buffer.ts +++ b/source/buffer.ts @@ -127,7 +127,8 @@ export class Buffer extends AbstractObject implements Bindable { } /** - * Specifies the memory layout of the buffer for a binding point. + * Specifies the memory layout of the buffer for a binding point. Integer data will be cast to float according to + * "normalized". * @param index - Index of the vertex attribute that is to be setup and enabled. * @param size - Number of components per vertex attribute. * @param type - Data type of each component in the array. @@ -136,6 +137,7 @@ export class Buffer extends AbstractObject implements Bindable { * @param offset - Offset in bytes of the first component in the vertex attribute array. * @param bind - Allows to skip binding the object (e.g., when binding is handled outside). * @param unbind - Allows to skip unbinding the object (e.g., when binding is handled outside). + * @see attribEnableInt */ @Initializable.assert_initialized() attribEnable(index: GLuint, size: GLint, type: GLenum, normalized: GLboolean = false, @@ -152,6 +154,32 @@ export class Buffer extends AbstractObject implements Bindable { } } + /** + * Specifies the memory layout of the buffer for a binding point. Only to be used for integers. + * @param index - Index of the vertex attribute that is to be setup and enabled. + * @param size - Number of components per vertex attribute. + * @param type - Data type of each component in the array. + * @param stride - Offset in bytes between the beginning of consecutive vertex attributes. + * @param offset - Offset in bytes of the first component in the vertex attribute array. + * @param bind - Allows to skip binding the object (e.g., when binding is handled outside). + * @param unbind - Allows to skip unbinding the object (e.g., when binding is handled outside). + * @see attribEnable + */ + @Initializable.assert_initialized() + attribEnableInt(index: GLuint, size: GLint, type: GLenum, + stride: GLsizei = 0, offset: GLintptr = 0, bind: boolean = true, unbind: boolean = true): void { + + const gl = this.context.gl; + if (bind) { + this.bind(); + } + gl.vertexAttribIPointer(index, size, type, stride, offset); + gl.enableVertexAttribArray(index); + if (unbind) { + this.unbind(); + } + } + /** * Disables a buffer binding point. * @param index - Index of the vertex attribute that is to be disabled.