Skip to content

Commit

Permalink
WebGLRenderer: Add support for integer attributes with WebGL2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Apr 2, 2020
1 parent 754a6b8 commit 3f7dff2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ function WebGLRenderer( parameters ) {
}

_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
_gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
state.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );

} else {

Expand All @@ -963,7 +963,7 @@ function WebGLRenderer( parameters ) {
}

_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
_gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
state.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );

}

Expand Down
1 change: 1 addition & 0 deletions src/renderers/webgl/WebGLState.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class WebGLState {
enableAttribute( attribute: number ): void;
enableAttributeAndDivisor( attribute: number, meshPerAttribute: number ): void;
disableUnusedAttributes(): void;
vertexAttribPointer( index: number, size: number, type: number, normalized: boolean, stride: number, offset: number ): void;
enable( id: number ): void;
disable( id: number ): void;
useProgram( program: any ): boolean;
Expand Down
15 changes: 15 additions & 0 deletions src/renderers/webgl/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,20 @@ function WebGLState( gl, extensions, capabilities ) {

}

function vertexAttribPointer( index, size, type, normalized, stride, offset ) {

if ( isWebGL2 === true && ( type === gl.INT || type === gl.UNSIGNED_INT ) ) {

gl.vertexAttribIPointer( index, size, type, normalized, stride, offset );

} else {

gl.vertexAttribPointer( index, size, type, normalized, stride, offset );

}

}

function enable( id ) {

if ( enabledCapabilities[ id ] !== true ) {
Expand Down Expand Up @@ -980,6 +994,7 @@ function WebGLState( gl, extensions, capabilities ) {
enableAttribute: enableAttribute,
enableAttributeAndDivisor: enableAttributeAndDivisor,
disableUnusedAttributes: disableUnusedAttributes,
vertexAttribPointer: vertexAttribPointer,
enable: enable,
disable: disable,

Expand Down

0 comments on commit 3f7dff2

Please sign in to comment.