Skip to content

Commit

Permalink
Merge pull request #18418 from aardgoose/dev
Browse files Browse the repository at this point in the history
WebGLAttributes: Reduce heap allocations when using WebGL2 and partial buffer updates.
  • Loading branch information
Mugen87 authored Jan 22, 2020
2 parents edc28b0 + 90d0d0e commit d78d60d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function WebGLRenderer( parameters ) {
info = new WebGLInfo( _gl );
properties = new WebGLProperties();
textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
attributes = new WebGLAttributes( _gl );
attributes = new WebGLAttributes( _gl, capabilities );
geometries = new WebGLGeometries( _gl, attributes, info );
objects = new WebGLObjects( _gl, geometries, attributes, info );
morphtargets = new WebGLMorphtargets( _gl );
Expand Down
3 changes: 2 additions & 1 deletion src/renderers/webgl/WebGLAttributes.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { WebGLCapabilities } from "./WebGLCapabilities";
import { BufferAttribute } from "../../core/BufferAttribute";
import { InterleavedBufferAttribute } from "../../core/InterleavedBufferAttribute";

export class WebGLAttributes {

constructor( gl: WebGLRenderingContext | WebGL2RenderingContext );
constructor( gl: WebGLRenderingContext | WebGL2RenderingContext, capabilities: WebGLCapabilities );

get( attribute: BufferAttribute | InterleavedBufferAttribute ): {
buffer: WebGLBuffer,
Expand Down
15 changes: 12 additions & 3 deletions src/renderers/webgl/WebGLAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author mrdoob / http://mrdoob.com/
*/

function WebGLAttributes( gl ) {
function WebGLAttributes( gl, capabilities ) {

var buffers = new WeakMap();

Expand Down Expand Up @@ -78,8 +78,17 @@ function WebGLAttributes( gl ) {

} else {

gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
if ( capabilities.isWebGL2 ) {

gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
array, updateRange.offset, updateRange.count );

} else {

gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );

}

updateRange.count = - 1; // reset range

Expand Down

0 comments on commit d78d60d

Please sign in to comment.