Skip to content

Commit

Permalink
Merge pull request #289 from Stastez/attribEnable-for-int
Browse files Browse the repository at this point in the history
Implement a wrapper for gl.vertexAttribIPointer in the Buffer class
  • Loading branch information
scheibel authored Jan 18, 2024
2 parents 1d0c2fc + 932aa58 commit 168e1f6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion source/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export class Buffer extends AbstractObject<WebGLBuffer> 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.
Expand All @@ -136,6 +137,7 @@ export class Buffer extends AbstractObject<WebGLBuffer> 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,
Expand All @@ -152,6 +154,32 @@ export class Buffer extends AbstractObject<WebGLBuffer> 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.
Expand Down

0 comments on commit 168e1f6

Please sign in to comment.