Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integer attributes to Geometry #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/core/Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// instanced - default null. Pass divisor amount
// type - gl enum default gl.UNSIGNED_SHORT for 'index', gl.FLOAT for others
// normalized - boolean default false
// integer - boolean default false

// buffer - gl buffer, if buffer exists, don't need to provide data - although needs position data for bounds calculation
// stride - default 0 - for when passing in buffer
Expand Down Expand Up @@ -65,6 +66,7 @@ export class Geometry {
: attr.data.constructor === Uint16Array
? this.gl.UNSIGNED_SHORT
: this.gl.UNSIGNED_INT); // Uint32Array
attr.integer = attr.integer || false;
attr.target = key === 'index' ? this.gl.ELEMENT_ARRAY_BUFFER : this.gl.ARRAY_BUFFER;
attr.normalized = attr.normalized || false;
attr.stride = attr.stride || 0;
Expand Down Expand Up @@ -153,7 +155,12 @@ export class Geometry {
const offset = numLoc === 1 ? 0 : numLoc * 4;

for (let i = 0; i < numLoc; i++) {
this.gl.vertexAttribPointer(location + i, size, attr.type, attr.normalized, attr.stride + stride, attr.offset + i * offset);
if(attr.integer && this.gl.renderer.isWebgl2){
this.gl.vertexAttribIPointer(location + i, size, attr.type, attr.stride + stride, attr.offset + i * offset);
}
else{
this.gl.vertexAttribPointer(location + i, size, attr.type, attr.normalized, attr.stride + stride, attr.offset + i * offset);
}
this.gl.enableVertexAttribArray(location + i);

// For instanced attributes, divisor needs to be set.
Expand Down
1 change: 1 addition & 0 deletions types/core/Geometry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Attribute {
instanced: null | number | boolean;
type: GLenum;
normalized: boolean;
integer: boolean;

buffer: WebGLBuffer;
stride: number;
Expand Down