diff --git a/docs/api/en/core/BufferAttribute.html b/docs/api/en/core/BufferAttribute.html index fc0ded08ba4c8218a2c43bf469ef99ce2351fc30..4be6c0525392716c4e74dec5a9eaa261f5ac4b57 100644 --- a/docs/api/en/core/BufferAttribute.html +++ b/docs/api/en/core/BufferAttribute.html @@ -58,16 +58,6 @@ then this will count the number of such vectors stored.

-

[property:Boolean dynamic]

-

- Whether the buffer is dynamic or not. Default is *false*.
- - If false, the GPU is informed that contents of the buffer are likely to be used often and not change often. - This corresponds to the [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData gl.STATIC_DRAW] flag.
- if true, the GPU is informed that contents of the buffer are likely to be used often and change often. - This corresponds to the [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData gl.DYNAMIC_DRAW] flag. -

-

[property:Boolean isBufferAttribute]

Used to check whether this or derived classes are BufferAttributes. Default is *true*.

@@ -111,10 +101,16 @@ related to color).

+

[property:Usage usage]

+

+ Defines the intended usage pattern of the data store for optimization purposes. Corresponds to the *usage* parameter of + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData WebGLRenderingContext.bufferData](). + Default is *THREE.StaticDrawUsage*. +

+

[property:Integer version]

A version number, incremented every time the [page:BufferAttribute.needsUpdate needsUpdate] property is set to true.

-

Methods

[method:BufferAttribute clone]()

@@ -178,8 +174,8 @@ being a [page:TypedArray].

-

[method:BufferAttribute setDynamic] ( [param:Boolean value] )

-

Set [page:BufferAttribute.dynamic dynamic] to value.

+

[method:BufferAttribute setUsage] ( [param:Usage value] )

+

Set [page:BufferAttribute.usage usage] to value.

[method:BufferAttribute setX]( [param:Integer index], [param:Float x] )

Sets the x component of the vector at the given index.

diff --git a/docs/api/en/core/InterleavedBuffer.html b/docs/api/en/core/InterleavedBuffer.html index a657be0b47e535792f5a9f757aa834521bf2d700..5f00e5f05f4af1107d9c7f96a28f99f5f856478a 100644 --- a/docs/api/en/core/InterleavedBuffer.html +++ b/docs/api/en/core/InterleavedBuffer.html @@ -44,11 +44,6 @@ Gives the total number of elements in the array.

-

[property:Boolean dynamic]

-

- Default is *false*. -

-

[property:Object updateRange]

Object containing offset and count. @@ -79,13 +74,14 @@ Default is *false*. Setting this to true increments [page:InterleavedBuffer.version version].

-

Methods

- -

[method:InterleavedBuffer setDynamic] ( [param:Boolean value] )

+

[property:Usage usage]

- Set [page:InterleavedBuffer.dynamic dynamic] to value. + Defines the intended usage pattern of the data store for optimization purposes. Corresponds to the *usage* parameter of + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData WebGLRenderingContext.bufferData]().

+

Methods

+

[method:InterleavedBuffer copy]( [param:InterleavedBuffer source] )

Copies another [name] to this [name]. @@ -107,6 +103,9 @@ Creates a clone of this [name].

+

[method:BufferAttribute setUsage] ( [param:Usage value] )

+

Set [page:BufferAttribute.usage usage] to value.

+

Source

diff --git a/docs/api/zh/core/BufferAttribute.html b/docs/api/zh/core/BufferAttribute.html index b6ee6e7aad7a930f455a1fa4880479eb03447ee1..ca5486bfe0e75e2fd1faa94b573533f1c5192aa7 100644 --- a/docs/api/zh/core/BufferAttribute.html +++ b/docs/api/zh/core/BufferAttribute.html @@ -52,16 +52,6 @@ 若缓存存储三元组(例如顶点位置、法向量、颜色值),则该值应等于队列中三元组的个数。

-

[property:Boolean dynamic]

-

- 不论缓存是否是动态的,默认值都将是 *false*
- - 如果该值为 false,即告知 GPU 缓存中的数据会经常使用但不经常变化。 - 该值与 [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData gl.STATIC_DRAW] 标志位相一致。
- 如果该值为 true,即告知 GPU 缓存中的数据会经常使用且经常变化。 - 该值与 [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData gl.DYNAMIC_DRAW] 标志位相一致。 -

-

[property:Boolean isBufferAttribute]

指示当前类或派生类是 BufferAttributes. 默认值为 *true*.

@@ -101,6 +91,13 @@ 该值只可以被用于更新某些矢量数据(例如,颜色相关数据)。

+

[property:Usage usage]

+

+ Defines the intended usage pattern of the data store for optimization purposes. Corresponds to the *usage* parameter of + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData WebGLRenderingContext.bufferData](). + Default is *THREE.StaticDrawUsage*. +

+

[property:Integer version]

版本号,当 [page:BufferAttribute.needsUpdate needsUpdate] 被设置为 true 时,该值会自增。

@@ -158,8 +155,8 @@ 特别的, 对将 [page:Array value] 转为 [page:TypedArray] 的要求详见上述链接。

-

[method:BufferAttribute setDynamic] ( [param:Boolean value] )

-

将 [page:BufferAttribute.dynamic dynamic] 设置为 value.

+

[method:BufferAttribute setUsage] ( [param:Usage value] )

+

Set [page:BufferAttribute.usage usage] to value.

[method:BufferAttribute setX]( [param:Integer index], [param:Float x] )

设置给定索引的矢量的第一维数据(设置 X 值)。

diff --git a/docs/api/zh/core/InterleavedBuffer.html b/docs/api/zh/core/InterleavedBuffer.html index 7e6c1a2e8b45431a26cb4a74b858f34fcba0e5c4..16a16904f4deafb5679d841598a495db53c87add 100644 --- a/docs/api/zh/core/InterleavedBuffer.html +++ b/docs/api/zh/core/InterleavedBuffer.html @@ -44,11 +44,6 @@ 类型化队列中,所有元素的数目。

-

[property:Boolean dynamic]

-

- 默认值为 *false*。 -

-

[property:Object updateRange]

对象存储着需要更新的数据的偏移量和数量。 @@ -79,13 +74,14 @@ 默认值为 *false*。该值被设置为 true 时,会导致 [page:InterleavedBuffer.version version] 增加。

-

方法

- -

[method:InterleavedBuffer setDynamic] ( [param:Boolean value] )

+

[property:Usage usage]

- 根据输入参数设置 [page:InterleavedBuffer.dynamic dynamic] 的值。 + Defines the intended usage pattern of the data store for optimization purposes. Corresponds to the *usage* parameter of + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData WebGLRenderingContext.bufferData]().

+

方法

+

[method:InterleavedBuffer copy]( [param:InterleavedBuffer source] )

将参数指定的 [name] 拷贝到当前 [name]。 @@ -107,6 +103,9 @@ 克隆当前 [name]。

+

[method:BufferAttribute setUsage] ( [param:Usage value] )

+

Set [page:BufferAttribute.usage usage] to value.

+

源代码

diff --git a/examples/js/geometries/LightningStrike.js b/examples/js/geometries/LightningStrike.js index 3a05b34013326e4a18d1fa383cd3894e15187cce..73862e6a1d0819fd12e0c46a5e0bc036ed23cf74 100644 --- a/examples/js/geometries/LightningStrike.js +++ b/examples/js/geometries/LightningStrike.js @@ -430,11 +430,11 @@ THREE.LightningStrike.prototype.createMesh = function () { if ( ! this.isStatic ) { - this.index.dynamic = true; - this.positionAttribute.dynamic = true; + this.index.usage = THREE.DynamicDrawUsage; + this.positionAttribute.usage = THREE.DynamicDrawUsage; if ( this.generateUVs ) { - this.uvsAttribute.dynamic = true; + this.uvsAttribute.usage = THREE.DynamicDrawUsage; } diff --git a/examples/jsm/geometries/LightningStrike.js b/examples/jsm/geometries/LightningStrike.js index 0f5e75dd8d651dc43281a8e25564bc260e9a1f93..b971cd37b0e6dc0c7e99d06b5455c45d36ec2917 100644 --- a/examples/jsm/geometries/LightningStrike.js +++ b/examples/jsm/geometries/LightningStrike.js @@ -103,6 +103,7 @@ import { BufferGeometry, + DynamicDrawUsage, Float32BufferAttribute, Math as _Math, Uint32BufferAttribute, @@ -439,11 +440,11 @@ LightningStrike.prototype.createMesh = function () { if ( ! this.isStatic ) { - this.index.dynamic = true; - this.positionAttribute.dynamic = true; + this.index.usage = DynamicDrawUsage; + this.positionAttribute.usage = DynamicDrawUsage; if ( this.generateUVs ) { - this.uvsAttribute.dynamic = true; + this.uvsAttribute.usage = DynamicDrawUsage; } diff --git a/examples/webgl_buffergeometry_custom_attributes_particles.html b/examples/webgl_buffergeometry_custom_attributes_particles.html index 3a5e7a3efca7794d6a777eb16239240288e77585..8a2a7fd47f9e8104bc00aa3b358448290d8ef850 100644 --- a/examples/webgl_buffergeometry_custom_attributes_particles.html +++ b/examples/webgl_buffergeometry_custom_attributes_particles.html @@ -114,7 +114,7 @@ geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) ); geometry.addAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) ); - geometry.addAttribute( 'size', new THREE.Float32BufferAttribute( sizes, 1 ).setDynamic( true ) ); + geometry.addAttribute( 'size', new THREE.Float32BufferAttribute( sizes, 1 ).setUsage( THREE.DynamicDrawUsage ) ); particleSystem = new THREE.Points( geometry, shaderMaterial ); diff --git a/examples/webgl_buffergeometry_drawrange.html b/examples/webgl_buffergeometry_drawrange.html index 50c4f6162fbf9716659cbe43e0ca7bc64378e935..834eaf2d1e4a6b603d7405c64219afd3f9e18008 100644 --- a/examples/webgl_buffergeometry_drawrange.html +++ b/examples/webgl_buffergeometry_drawrange.html @@ -139,7 +139,7 @@ } particles.setDrawRange( 0, particleCount ); - particles.addAttribute( 'position', new THREE.BufferAttribute( particlePositions, 3 ).setDynamic( true ) ); + particles.addAttribute( 'position', new THREE.BufferAttribute( particlePositions, 3 ).setUsage( THREE.DynamicDrawUsage ) ); // create the particle system pointCloud = new THREE.Points( particles, pMaterial ); @@ -147,8 +147,8 @@ var geometry = new THREE.BufferGeometry(); - geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).setDynamic( true ) ); - geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).setDynamic( true ) ); + geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).setUsage( THREE.DynamicDrawUsage ) ); + geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).setUsage( THREE.DynamicDrawUsage ) ); geometry.computeBoundingSphere(); diff --git a/examples/webgl_buffergeometry_instancing_dynamic.html b/examples/webgl_buffergeometry_instancing_dynamic.html index 6940e6729b09f456298685bedc39108e2d4aeef1..64cab48af4fd0755f51c4d271b8e101bd9f10895 100644 --- a/examples/webgl_buffergeometry_instancing_dynamic.html +++ b/examples/webgl_buffergeometry_instancing_dynamic.html @@ -147,7 +147,7 @@ } offsetAttribute = new THREE.InstancedBufferAttribute( new Float32Array( offsets ), 3 ); - orientationAttribute = new THREE.InstancedBufferAttribute( new Float32Array( orientations ), 4 ).setDynamic( true ); + orientationAttribute = new THREE.InstancedBufferAttribute( new Float32Array( orientations ), 4 ).setUsage( THREE.DynamicDrawUsage ); geometry.addAttribute( 'offset', offsetAttribute ); geometry.addAttribute( 'orientation', orientationAttribute ); diff --git a/examples/webgl_buffergeometry_instancing_interleaved_dynamic.html b/examples/webgl_buffergeometry_instancing_interleaved_dynamic.html index fad7112279982fc05457e8b035c644e570e565d8..6fc4e129762bfc77168852964e93f0283e678b32 100644 --- a/examples/webgl_buffergeometry_instancing_interleaved_dynamic.html +++ b/examples/webgl_buffergeometry_instancing_interleaved_dynamic.html @@ -162,7 +162,7 @@ geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) ); // per instance data - instanceBuffer = new THREE.InstancedInterleavedBuffer( new Float32Array( instances * 8 ), 8, 1 ).setDynamic( true ); + instanceBuffer = new THREE.InstancedInterleavedBuffer( new Float32Array( instances * 8 ), 8, 1 ).setUsage( THREE.DynamicDrawUsage ); var offsets = new THREE.InterleavedBufferAttribute( instanceBuffer, 3, 0 ); var vector = new THREE.Vector4(); diff --git a/examples/webgl_geometry_dynamic.html b/examples/webgl_geometry_dynamic.html index 5f73fb0e28523c1c8deecd530ffcb73340eb73a4..1de8d067d0f7d551010b34f96f60d193d66b762e 100644 --- a/examples/webgl_geometry_dynamic.html +++ b/examples/webgl_geometry_dynamic.html @@ -58,7 +58,7 @@ geometry.rotateX( - Math.PI / 2 ); var position = geometry.attributes.position; - position.dynamic = true; + position.usage = THREE.DynamicDrawUsage; for ( var i = 0; i < position.count; i ++ ) { diff --git a/examples/webgl_points_dynamic.html b/examples/webgl_points_dynamic.html index 29db8030ce91f9f82546876cc9bb19729b9cea1e..f54d3243a84cbd529555ab83d12b87d7b652794c 100644 --- a/examples/webgl_points_dynamic.html +++ b/examples/webgl_points_dynamic.html @@ -180,7 +180,7 @@ geometry.addAttribute( 'position', positions.clone() ); geometry.addAttribute( 'initialPosition', positions.clone() ); - geometry.attributes.position.setDynamic( true ); + geometry.attributes.position.setUsage( THREE.DynamicDrawUsage ); var clones = [ diff --git a/examples/webgl_simple_gi.html b/examples/webgl_simple_gi.html index c139d8a23e4e3791e079df8d40c9f3327f589ecc..fbeb534735fd24e009de71211456d6b6bdf0df6d 100644 --- a/examples/webgl_simple_gi.html +++ b/examples/webgl_simple_gi.html @@ -73,7 +73,7 @@ if ( attributes.color === undefined ) { var colors = new Float32Array( positions.length ); - geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).setDynamic( true ) ); + geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).setUsage( THREE.DynamicDrawUsage ) ); } diff --git a/examples/webvr_paint.html b/examples/webvr_paint.html index 21e48ec66974ede3d61766b1daf06af541223c65..69f83e4b73dc37474148fcc9b02e9f824cbf93ed 100644 --- a/examples/webvr_paint.html +++ b/examples/webvr_paint.html @@ -146,15 +146,15 @@ var geometry = new THREE.BufferGeometry(); var positions = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 ); - positions.dynamic = true; + positions.usage = THREE.DynamicDrawUsage; geometry.addAttribute( 'position', positions ); var normals = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 ); - normals.dynamic = true; + normals.usage = THREE.DynamicDrawUsage; geometry.addAttribute( 'normal', normals ); var colors = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 ); - colors.dynamic = true; + colors.usage = THREE.DynamicDrawUsage; geometry.addAttribute( 'color', colors ); geometry.drawRange.count = 0; diff --git a/examples/webvr_vive_paint.html b/examples/webvr_vive_paint.html index 2b3bb0ff759f8db263eb1bfec285b0b947683fc5..1fbc7e978b842ca0154825ce763624c9c1586d2c 100644 --- a/examples/webvr_vive_paint.html +++ b/examples/webvr_vive_paint.html @@ -169,15 +169,15 @@ var geometry = new THREE.BufferGeometry(); var positions = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 ); - positions.dynamic = true; + positions.usage = THREE.DynamicDrawUsage; geometry.addAttribute( 'position', positions ); var normals = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 ); - normals.dynamic = true; + normals.usage = THREE.DynamicDrawUsage; geometry.addAttribute( 'normal', normals ); var colors = new THREE.BufferAttribute( new Float32Array( 1000000 * 3 ), 3 ); - colors.dynamic = true; + colors.usage = THREE.DynamicDrawUsage; geometry.addAttribute( 'color', colors ); geometry.drawRange.count = 0; diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js index 08557138b288f7ac99e6d41072d092e916a4d9f2..6980b98bbf32d7550083412c8ec757272521fc69 100644 --- a/src/Three.Legacy.js +++ b/src/Three.Legacy.js @@ -5,7 +5,11 @@ import { Audio } from './audio/Audio.js'; import { AudioAnalyser } from './audio/AudioAnalyser.js'; import { PerspectiveCamera } from './cameras/PerspectiveCamera.js'; -import { FlatShading } from './constants.js'; +import { + FlatShading, + StaticDrawUsage, + DynamicDrawUsage +} from './constants.js'; import { Float64BufferAttribute, Float32BufferAttribute, @@ -1163,13 +1167,33 @@ Object.defineProperties( BufferAttribute.prototype, { console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' ); return this.array.length; + } + }, + dynamic: { + get: function () { + + console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' ); + return this.usage === DynamicDrawUsage; + + }, + set: function ( value ) { + + console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' ); + this.setUsage( value ); + } } } ); Object.assign( BufferAttribute.prototype, { + setDynamic: function ( value ) { + + console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' ); + this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage ); + return this; + }, copyIndicesArray: function ( /* indices */ ) { console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' ); @@ -1185,7 +1209,6 @@ Object.assign( BufferAttribute.prototype, { return this; } - } ); Object.assign( BufferGeometry.prototype, { @@ -1247,8 +1270,33 @@ Object.defineProperties( BufferGeometry.prototype, { } ); +Object.defineProperties( InterleavedBuffer.prototype, { + + dynamic: { + get: function () { + + console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' ); + return this.usage === DynamicDrawUsage; + + }, + set: function ( value ) { + + console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' ); + this.setUsage( value ); + + } + } + +} ); + Object.assign( InterleavedBuffer.prototype, { + setDynamic: function ( value ) { + console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' ); + this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage ); + return this; + + }, setArray: function ( array ) { console.warn( 'THREE.InterleavedBuffer: .setArray has been deprecated. Use BufferGeometry .setAttribute to replace/resize attribute buffers' ); @@ -1259,7 +1307,6 @@ Object.assign( InterleavedBuffer.prototype, { return this; } - } ); // diff --git a/src/constants.d.ts b/src/constants.d.ts index 8d200621acbfbd3f8a0146422bd43d081404ae80..fe5f5a623fb15bc73a65503d0b8e15084fa47d58 100644 --- a/src/constants.d.ts +++ b/src/constants.d.ts @@ -275,3 +275,15 @@ export const GreaterStencilFunc: StencilFunc; export const NotEqualStencilFunc: StencilFunc; export const GreaterEqualStencilFunc: StencilFunc; export const AlwaysStencilFunc: StencilFunc; + +// usage types +export enum Usage {} +export const StaticDrawUsage: Usage; +export const DynamicDrawUsage: Usage; +export const StreamDrawUsage: Usage; +export const StaticReadUsage: Usage; +export const DynamicReadUsage: Usage; +export const StreamReadUsage: Usage; +export const StaticCopyUsage: Usage; +export const DynamicCopyUsage: Usage; +export const StreamCopyUsage: Usage; diff --git a/src/constants.js b/src/constants.js index 8e398a8a2937d450e23f91fedf005686dabffe74..7b3cb214cec56c139e26f7dc698ace1e9c9de977 100644 --- a/src/constants.js +++ b/src/constants.js @@ -166,3 +166,13 @@ export var GreaterStencilFunc = 516; export var NotEqualStencilFunc = 517; export var GreaterEqualStencilFunc = 518; export var AlwaysStencilFunc = 519; + +export var StaticDrawUsage = 35044; +export var DynamicDrawUsage = 35048; +export var StreamDrawUsage = 35040; +export var StaticReadUsage = 35045; +export var DynamicReadUsage = 35049; +export var StreamReadUsage = 35041; +export var StaticCopyUsage = 35046; +export var DynamicCopyUsage = 35050; +export var StreamCopyUsage = 35042; diff --git a/src/core/BufferAttribute.d.ts b/src/core/BufferAttribute.d.ts index 00843fe96b534ebc144846010262c20f0b438507..aa4980470909f6df22d498b42ab54bff45ac3e14 100644 --- a/src/core/BufferAttribute.d.ts +++ b/src/core/BufferAttribute.d.ts @@ -1,3 +1,7 @@ +import { + Usage +} from '../constants'; + /** * @see src/core/BufferAttribute.js */ @@ -8,7 +12,7 @@ export class BufferAttribute { name: string; array: ArrayLike; itemSize: number; - dynamic: boolean; + usage: Usage; updateRange: { offset: number; count: number }; version: number; normalized: boolean; @@ -16,7 +20,7 @@ export class BufferAttribute { count: number; onUpload: Function; - setDynamic( dynamic: boolean ): BufferAttribute; + setUsage( usage: Usage ): BufferAttribute; clone(): this; copy( source: BufferAttribute ): this; copyAt( diff --git a/src/core/BufferAttribute.js b/src/core/BufferAttribute.js index e011f1ff22c6f0a17bb6723db2720e09dd850e82..507b43e7de27575186f2ee6907efd1f93dc0b422 100644 --- a/src/core/BufferAttribute.js +++ b/src/core/BufferAttribute.js @@ -2,6 +2,7 @@ import { Vector4 } from '../math/Vector4.js'; import { Vector3 } from '../math/Vector3.js'; import { Vector2 } from '../math/Vector2.js'; import { Color } from '../math/Color.js'; +import { StaticDrawUsage } from '../constants.js'; /** * @author mrdoob / http://mrdoob.com/ @@ -22,7 +23,7 @@ function BufferAttribute( array, itemSize, normalized ) { this.count = array !== undefined ? array.length / itemSize : 0; this.normalized = normalized === true; - this.dynamic = false; + this.usage = StaticDrawUsage; this.updateRange = { offset: 0, count: - 1 }; this.version = 0; @@ -45,9 +46,9 @@ Object.assign( BufferAttribute.prototype, { onUploadCallback: function () {}, - setDynamic: function ( value ) { + setUsage: function ( value ) { - this.dynamic = value; + this.usage = value; return this; @@ -61,7 +62,7 @@ Object.assign( BufferAttribute.prototype, { this.count = source.count; this.normalized = source.normalized; - this.dynamic = source.dynamic; + this.usage = source.usage; return this; diff --git a/src/core/InterleavedBuffer.d.ts b/src/core/InterleavedBuffer.d.ts index 7d039b9d19512550899d9813703c60664d1ee6ad..690e07ee0e454c00a6e0a2ad6a90247e0c448ac1 100644 --- a/src/core/InterleavedBuffer.d.ts +++ b/src/core/InterleavedBuffer.d.ts @@ -1,4 +1,5 @@ import { InterleavedBufferAttribute } from './InterleavedBufferAttribute'; +import { Usage } from '../constants'; /** * @see src/core/InterleavedBuffer.js @@ -9,14 +10,14 @@ export class InterleavedBuffer { array: ArrayLike; stride: number; - dynamic: boolean; + usage: Usage; updateRange: { offset: number; count: number }; version: number; length: number; count: number; needsUpdate: boolean; - setDynamic( dynamic: boolean ): InterleavedBuffer; + setUsage( usage: Usage ): InterleavedBuffer; clone(): this; copy( source: InterleavedBuffer ): this; copyAt( diff --git a/src/core/InterleavedBuffer.js b/src/core/InterleavedBuffer.js index 0cb50dd73bf2f3a84a923901f1be227a59b5bd28..c40422a54338625064e7215f44aa346b229f8c68 100644 --- a/src/core/InterleavedBuffer.js +++ b/src/core/InterleavedBuffer.js @@ -1,3 +1,4 @@ +import { StaticDrawUsage } from '../constants.js'; /** * @author benaadams / https://twitter.com/ben_a_adams @@ -9,7 +10,7 @@ function InterleavedBuffer( array, stride ) { this.stride = stride; this.count = array !== undefined ? array.length / stride : 0; - this.dynamic = false; + this.usage = StaticDrawUsage; this.updateRange = { offset: 0, count: - 1 }; this.version = 0; @@ -32,9 +33,9 @@ Object.assign( InterleavedBuffer.prototype, { onUploadCallback: function () {}, - setDynamic: function ( value ) { + setUsage: function ( value ) { - this.dynamic = value; + this.usage = value; return this; @@ -45,7 +46,7 @@ Object.assign( InterleavedBuffer.prototype, { this.array = new source.array.constructor( source.array ); this.count = source.count; this.stride = source.stride; - this.dynamic = source.dynamic; + this.usage = source.usage; return this; diff --git a/src/renderers/webgl/WebGLAttributes.js b/src/renderers/webgl/WebGLAttributes.js index 586ef5853c314f63fb0f645bde5a17e64aaf581e..059d1f49c14670887d7ed90a3653ce3cb4f1c86d 100644 --- a/src/renderers/webgl/WebGLAttributes.js +++ b/src/renderers/webgl/WebGLAttributes.js @@ -9,7 +9,7 @@ function WebGLAttributes( gl ) { function createBuffer( attribute, bufferType ) { var array = attribute.array; - var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW; + var usage = attribute.usage; var buffer = gl.createBuffer(); @@ -70,20 +70,12 @@ function WebGLAttributes( gl ) { gl.bindBuffer( bufferType, buffer ); - if ( attribute.dynamic === false ) { - - gl.bufferData( bufferType, array, gl.STATIC_DRAW ); - - } else if ( updateRange.count === - 1 ) { + if ( updateRange.count === - 1 ) { // Not using update ranges gl.bufferSubData( bufferType, 0, array ); - } else if ( updateRange.count === 0 ) { - - console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' ); - } else { gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, diff --git a/test/unit/src/core/BufferAttribute.tests.js b/test/unit/src/core/BufferAttribute.tests.js index 1c5ef58fce440f816809134aeec7e79b9094fc17..ac4135fa3c5cc0a42e4202d2bd89e7b57321eaa0 100644 --- a/test/unit/src/core/BufferAttribute.tests.js +++ b/test/unit/src/core/BufferAttribute.tests.js @@ -8,6 +8,7 @@ import { Color } from '../../../../src/math/Color'; import { Vector2 } from '../../../../src/math/Vector2'; import { Vector3 } from '../../../../src/math/Vector3'; import { Vector4 } from '../../../../src/math/Vector4'; +import { DynamicDrawUsage } from '../../../../src/constants'; export default QUnit.module( 'Core', () => { @@ -42,23 +43,26 @@ export default QUnit.module( 'Core', () => { } ); - QUnit.todo( "setDynamic", ( assert ) => { + QUnit.test( "setUsage", ( assert ) => { - assert.ok( false, "everything's gonna be alright" ); + var attr = new BufferAttribute(); + attr.setUsage( DynamicDrawUsage ); + + assert.strictEqual( attr.usage, DynamicDrawUsage, "Usage was set" ); } ); QUnit.test( "copy", ( assert ) => { var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ); - attr.setDynamic( true ); + attr.setUsage( DynamicDrawUsage ); attr.needsUpdate = true; var attrCopy = new BufferAttribute().copy( attr ); assert.ok( attr.count === attrCopy.count, 'count is equal' ); assert.ok( attr.itemSize === attrCopy.itemSize, 'itemSize is equal' ); - assert.ok( attr.dynamic === attrCopy.dynamic, 'dynamic is equal' ); + assert.ok( attr.usage === attrCopy.usage, 'usage is equal' ); assert.ok( attr.array.length === attrCopy.array.length, 'array length is equal' ); assert.ok( attr.version === 1 && attrCopy.version === 0, 'version is not copied which is good' ); diff --git a/test/unit/src/core/InterleavedBuffer.tests.js b/test/unit/src/core/InterleavedBuffer.tests.js index f1118320c7b1ef469ab20933539e1bb9608e6ad7..36f8194146a1c53347c3c2829955f19835a73c98 100644 --- a/test/unit/src/core/InterleavedBuffer.tests.js +++ b/test/unit/src/core/InterleavedBuffer.tests.js @@ -4,6 +4,7 @@ /* global QUnit */ import { InterleavedBuffer } from '../../../../src/core/InterleavedBuffer'; +import { DynamicDrawUsage } from '../../../../src/constants'; export default QUnit.module( 'Core', () => { @@ -20,7 +21,7 @@ export default QUnit.module( 'Core', () => { } assert.ok( copiedInstance.stride === instance.stride, "stride was copied" ); - assert.ok( copiedInstance.dynamic === true, "dynamic was copied" ); + assert.ok( copiedInstance.usage === DynamicDrawUsage, "usage was copied" ); } @@ -49,9 +50,12 @@ export default QUnit.module( 'Core', () => { } ); - QUnit.todo( "setDynamic", ( assert ) => { + QUnit.test( "setUsage", ( assert ) => { - assert.ok( false, "everything's gonna be alright" ); + var instance = new InterleavedBuffer(); + instance.setUsage( DynamicDrawUsage ); + + assert.strictEqual( instance.usage, DynamicDrawUsage, "Usage was set" ); } ); @@ -59,7 +63,7 @@ export default QUnit.module( 'Core', () => { var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ); var instance = new InterleavedBuffer( array, 3 ); - instance.setDynamic( true ); + instance.setUsage( DynamicDrawUsage ); checkInstanceAgainstCopy( instance, instance.copy( instance ), assert ); @@ -92,7 +96,7 @@ export default QUnit.module( 'Core', () => { var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ); var instance = new InterleavedBuffer( array, 3 ); - instance.setDynamic( true ); + instance.setUsage( DynamicDrawUsage ); checkInstanceAgainstCopy( instance, instance.clone(), assert );