Skip to content

Commit 168e1f6

Browse files
authored
Merge pull request #289 from Stastez/attribEnable-for-int
Implement a wrapper for gl.vertexAttribIPointer in the Buffer class
2 parents 1d0c2fc + 932aa58 commit 168e1f6

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

source/buffer.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ export class Buffer extends AbstractObject<WebGLBuffer> implements Bindable {
127127
}
128128

129129
/**
130-
* Specifies the memory layout of the buffer for a binding point.
130+
* Specifies the memory layout of the buffer for a binding point. Integer data will be cast to float according to
131+
* "normalized".
131132
* @param index - Index of the vertex attribute that is to be setup and enabled.
132133
* @param size - Number of components per vertex attribute.
133134
* @param type - Data type of each component in the array.
@@ -136,6 +137,7 @@ export class Buffer extends AbstractObject<WebGLBuffer> implements Bindable {
136137
* @param offset - Offset in bytes of the first component in the vertex attribute array.
137138
* @param bind - Allows to skip binding the object (e.g., when binding is handled outside).
138139
* @param unbind - Allows to skip unbinding the object (e.g., when binding is handled outside).
140+
* @see attribEnableInt
139141
*/
140142
@Initializable.assert_initialized()
141143
attribEnable(index: GLuint, size: GLint, type: GLenum, normalized: GLboolean = false,
@@ -152,6 +154,32 @@ export class Buffer extends AbstractObject<WebGLBuffer> implements Bindable {
152154
}
153155
}
154156

157+
/**
158+
* Specifies the memory layout of the buffer for a binding point. Only to be used for integers.
159+
* @param index - Index of the vertex attribute that is to be setup and enabled.
160+
* @param size - Number of components per vertex attribute.
161+
* @param type - Data type of each component in the array.
162+
* @param stride - Offset in bytes between the beginning of consecutive vertex attributes.
163+
* @param offset - Offset in bytes of the first component in the vertex attribute array.
164+
* @param bind - Allows to skip binding the object (e.g., when binding is handled outside).
165+
* @param unbind - Allows to skip unbinding the object (e.g., when binding is handled outside).
166+
* @see attribEnable
167+
*/
168+
@Initializable.assert_initialized()
169+
attribEnableInt(index: GLuint, size: GLint, type: GLenum,
170+
stride: GLsizei = 0, offset: GLintptr = 0, bind: boolean = true, unbind: boolean = true): void {
171+
172+
const gl = this.context.gl;
173+
if (bind) {
174+
this.bind();
175+
}
176+
gl.vertexAttribIPointer(index, size, type, stride, offset);
177+
gl.enableVertexAttribArray(index);
178+
if (unbind) {
179+
this.unbind();
180+
}
181+
}
182+
155183
/**
156184
* Disables a buffer binding point.
157185
* @param index - Index of the vertex attribute that is to be disabled.

0 commit comments

Comments
 (0)