Browse Source

GLBufferAttribute: Add `normalized` property. (#31268)

* Update the screenshot of `webgl_buffergeometry_glbufferattribute` example

* Add property `normalized` to `GLBufferAttribute`

Update documentation and unit test.

Update doc

* Use `normalized` property in `webgl_buffergeometry_glbufferattribute` for the color buffer

More efficient storage of colors in the GPU buffer and demonstration of the feature.
Christian Winter 8 months ago
parent
commit
827509127a

+ 39 - 18
docs/api/ar/core/GLBufferAttribute.html

@@ -19,9 +19,14 @@
 			أكثر حالات الاستخدام شيوعًا لهذه الفئة هي عندما يتداخل نوع من
 			حسابات GPGPU أو حتى ينتج VBOs المعنية.
 		</p>
-	
+
+		<h2>Examples</h2>
+		<p>
+			[example:webgl_buffergeometry_glbufferattribute Points with custom buffers]<br />
+		</p>
+
 		<h2>المنشئ (Constructor)</h2>
-		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count] )</h3>
+		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count], [param:Boolean normalized] )</h3>
 		<p>
 			`buffer` — يجب أن يكون
 			[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLBuffer WebGLBuffer].
@@ -47,6 +52,16 @@
 			<li>gl.UNSIGNED_BYTE: 1</li>
 		</ul>
 		<p>`count` — عدد الرؤوس المتوقع في VBO.</p>
+		<p>
+		`normalized` — (optional) Applies to integer data only.
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL code. For instance, if [page:WebGLBuffer buffer] contains data of
+			`gl.UNSIGNED_SHORT`, and [page:Boolean normalized] is true, the values `0 -
+			+65535` in the buffer data will be mapped to 0.0f - +1.0f in the GLSL
+			attribute. A `gl.SHORT` (signed) would map from -32768 - +32767 to -1.0f
+			- +1.0f. If [page:Boolean normalized] is false, the values will be
+			converted to floats unmodified, i.e. 32767 becomes 32767.0f.
+		</p>
 	
 		<h2>الخصائص (Properties)</h2>
 	
@@ -59,21 +74,33 @@
 		<h3>[property:Integer count]</h3>
 		<p>عدد الرؤوس المتوقع في VBO.</p>
 	
+		<h3>[property:Integer elementSize]</h3>
+		<p>
+			يخزن الحجم المقابل بالبايت لقيمة خاصية `type` الحالية.
+		</p>
+		<p>انظر أعلاه (المُنشئ) لقائمة بأحجام الأنواع المعروفة.</p>
+	
 		<h3>[property:Boolean isGLBufferAttribute]</h3>
 		<p>للقراءة فقط. دائمًا `true`.</p>
 	
 		<h3>[property:Integer itemSize]</h3>
 		<p>كم عدد القيم التي تشكل كل عنصر (رأس).</p>
 	
-		<h3>[property:Integer elementSize]</h3>
+		<h3>[property:String name]</h3>
 		<p>
-			يخزن الحجم المقابل بالبايت لقيمة خاصية `type` الحالية.
+			اسم اختياري لهذه الحالة من السمة. الافتراضي هو سلسلة فارغة.
 		</p>
-		<p>انظر أعلاه (المُنشئ) لقائمة بأحجام الأنواع المعروفة.</p>
 	
-		<h3>[property:String name]</h3>
+		<h3>[property:Boolean needsUpdate]</h3>
 		<p>
-			اسم اختياري لهذه الحالة من السمة. الافتراضي هو سلسلة فارغة.
+			الافتراضي هو `false`. تعيين هذا إلى true يزاد
+			[page:GLBufferAttribute.version version].
+		</p>
+
+		<h3>[property:Boolean normalized]</h3>
+		<p>
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL shader code. See the constructor above for details.
 		</p>
 	
 		<h3>[property:GLenum type]</h3>
@@ -85,6 +112,11 @@
 			باستخدام طريقة `setType`.
 		</p>
 	
+		<h3>[property:Integer version]</h3>
+		<p>
+			رقم إصدار، يزاد كل مرة يتم فيها تعيين خاصية needsUpdate على true.
+		</p>
+	
 		<h2>الوظائف (Methods)</h2>
 	
 		<h3>[method:this setBuffer]( buffer )</h3>
@@ -98,17 +130,6 @@
 	
 		<h3>[method:this setCount]( count )</h3>
 		<p>تضبط خاصية `count`.</p>
-	
-		<h3>[property:Integer version]</h3>
-		<p>
-			رقم إصدار، يزاد كل مرة يتم فيها تعيين خاصية needsUpdate على true.
-		</p>
-	
-		<h3>[property:Boolean needsUpdate]</h3>
-		<p>
-			الافتراضي هو `false`. تعيين هذا إلى true يزاد
-			[page:GLBufferAttribute.version version].
-		</p>
 
 		<h2>المصدر (Source)</h2>
 		<p>

+ 39 - 19
docs/api/en/core/GLBufferAttribute.html

@@ -20,8 +20,13 @@
 			calculation interferes or even produces the VBOs in question.
 		</p>
 
+		<h2>Examples</h2>
+		<p>
+			[example:webgl_buffergeometry_glbufferattribute Points with custom buffers]<br />
+		</p>
+
 		<h2>Constructor</h2>
-		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count] )</h3>
+		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count], [param:Boolean normalized] )</h3>
 		<p>
 			`buffer` — Must be a
 			[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLBuffer WebGLBuffer].
@@ -48,6 +53,15 @@
 			<li>gl.UNSIGNED_BYTE: 1</li>
 		</ul>
 		`count` — The expected number of vertices in VBO.
+		<br />
+		`normalized` — (optional) Applies to integer data only.
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL code. For instance, if [page:WebGLBuffer buffer] contains data of
+			`gl.UNSIGNED_SHORT`, and [page:Boolean normalized] is true, the values `0 -
+			+65535` in the buffer data will be mapped to 0.0f - +1.0f in the GLSL
+			attribute. A `gl.SHORT` (signed) would map from -32768 - +32767 to -1.0f
+			- +1.0f. If [page:Boolean normalized] is false, the values will be
+			converted to floats unmodified, i.e. 32767 becomes 32767.0f.
 
 		<h2>Properties</h2>
 
@@ -60,12 +74,6 @@
 		<h3>[property:Integer count]</h3>
 		<p>The expected number of vertices in VBO.</p>
 
-		<h3>[property:Boolean isGLBufferAttribute]</h3>
-		<p>Read-only. Always `true`.</p>
-
-		<h3>[property:Integer itemSize]</h3>
-		<p>How many values make up each item (vertex).</p>
-
 		<h3>[property:Integer elementSize]</h3>
 		<p>
 			Stores the corresponding size in bytes for the current `type` property
@@ -73,11 +81,29 @@
 		</p>
 		<p>See above (constructor) for a list of known type sizes.</p>
 
+		<h3>[property:Boolean isGLBufferAttribute]</h3>
+		<p>Read-only. Always `true`.</p>
+
+		<h3>[property:Integer itemSize]</h3>
+		<p>How many values make up each item (vertex).</p>
+
 		<h3>[property:String name]</h3>
 		<p>
 			Optional name for this attribute instance. Default is an empty string.
 		</p>
 
+		<h3>[property:Boolean needsUpdate]</h3>
+		<p>
+			Default is `false`. Setting this to true increments
+			[page:GLBufferAttribute.version version].
+		</p>
+
+		<h3>[property:Boolean normalized]</h3>
+		<p>
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL shader code. See the constructor above for details.
+		</p>
+
 		<h3>[property:GLenum type]</h3>
 		<p>
 			A
@@ -88,6 +114,12 @@
 			using the `setType` method.
 		</p>
 
+		<h3>[property:Integer version]</h3>
+		<p>
+			A version number, incremented every time the needsUpdate property is set
+			to true.
+		</p>
+
 		<h2>Methods</h2>
 
 		<h3>[method:this setBuffer]( buffer )</h3>
@@ -102,18 +134,6 @@
 		<h3>[method:this setCount]( count )</h3>
 		<p>Sets the `count` property.</p>
 
-		<h3>[property:Integer version]</h3>
-		<p>
-			A version number, incremented every time the needsUpdate property is set
-			to true.
-		</p>
-
-		<h3>[property:Boolean needsUpdate]</h3>
-		<p>
-			Default is `false`. Setting this to true increments
-			[page:GLBufferAttribute.version version].
-		</p>
-
 		<h2>Source</h2>
 		<p>
 			[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

+ 36 - 16
docs/api/it/core/GLBufferAttribute.html

@@ -20,8 +20,13 @@
       calcolo GPGPU interferisce o addirittura produce i VBO in questione.
 		</p>
 
+		<h2>Examples</h2>
+		<p>
+			[example:webgl_buffergeometry_glbufferattribute Points with custom buffers]<br />
+		</p>
+
 		<h2>Costruttore</h2>
-		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count] )</h3>
+		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count], [param:Boolean normalized] )</h3>
 		<p>
 		`buffer` — Deve essere un [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLBuffer WebGLBuffer].
 		<br />
@@ -41,6 +46,15 @@
 			<li>gl.UNSIGNED_BYTE: 1</li>
 		</ul>
 		`count` — Il numero previsto di vertici in VBO.
+		<br />
+		`normalized` — (optional) Applies to integer data only.
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL code. For instance, if [page:WebGLBuffer buffer] contains data of
+			`gl.UNSIGNED_SHORT`, and [page:Boolean normalized] is true, the values `0 -
+			+65535` in the buffer data will be mapped to 0.0f - +1.0f in the GLSL
+			attribute. A `gl.SHORT` (signed) would map from -32768 - +32767 to -1.0f
+			- +1.0f. If [page:Boolean normalized] is false, the values will be
+			converted to floats unmodified, i.e. 32767 becomes 32767.0f.
 		</p>
 
 		<h2>Proprietà</h2>
@@ -55,6 +69,14 @@
       Il numero previsto di vertici in VBO.
 		</p>
 
+		<h3>[property:Integer elementSize]</h3>
+		<p>
+      Memorizza la dimensione corrispondente in byte per il valore della proprietà del `type` corrente.
+		</p>
+		<p>
+      Vedi sopra (costruttore) per un elenco di dimensioni di type conosciute.
+		</p>
+
 		<h3>[property:Boolean isGLBufferAttribute]</h3>
 		<p>
       Solo lettura. Sempre `true`.
@@ -65,17 +87,20 @@
       Quanti valori compongono ogni elemento (vertice).
 		</p>
 
-		<h3>[property:Integer elementSize]</h3>
+		<h3>[property:String name]</h3>
 		<p>
-      Memorizza la dimensione corrispondente in byte per il valore della proprietà del `type` corrente.
+      Un nome opzionale per questa istanza dell'attributo. Il valore predefinito è una stringa vuota.
 		</p>
+
+		<h3>[property:Boolean needsUpdate]</h3>
 		<p>
-      Vedi sopra (costruttore) per un elenco di dimensioni di type conosciute.
+      Il valore predefinito è `false`. Impostando questo metodo a true incrementa la [page:GLBufferAttribute.version versione].
 		</p>
 
-		<h3>[property:String name]</h3>
+		<h3>[property:Boolean normalized]</h3>
 		<p>
-      Un nome opzionale per questa istanza dell'attributo. Il valore predefinito è una stringa vuota.
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL shader code. See the constructor above for details.
 		</p>
 
 		<h3>[property:GLenum type]</h3>
@@ -88,6 +113,11 @@
       di usare il metodo `setType`.
 		</p>
 
+		<h3>[property:Integer version]</h3>
+		<p>
+      Un numero di versione, incrementato ogni volta che la proprietà needsUpdate è impostata a true.
+		</p>
+
 		<h2>Metodi</h2>
 
 		<h3>[method:this setBuffer]( buffer ) </h3>
@@ -102,16 +132,6 @@
 		<h3>[method:this setCount]( count ) </h3>
 		<p>Imposta la proprietà `count`.</p>
 
-		<h3>[property:Integer version]</h3>
-		<p>
-      Un numero di versione, incrementato ogni volta che la proprietà needsUpdate è impostata a true.
-		</p>
-
-		<h3>[property:Boolean needsUpdate]</h3>
-		<p>
-      Il valore predefinito è `false`. Impostando questo metodo a true incrementa la [page:GLBufferAttribute.version versione].
-		</p>
-
 		<h2>Source</h2>
 		<p>
 			[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

+ 36 - 16
docs/api/ko/core/GLBufferAttribute.html

@@ -17,8 +17,13 @@
 			이 클래스의 가장 일반적인 사용 사례는 어떤 종류의 GPGPU 계산이 해당 VBO를 방해하거나 심지어 생성하는 경우입니다.
 		</p>
 
+		<h2>Examples</h2>
+		<p>
+			[example:webgl_buffergeometry_glbufferattribute Points with custom buffers]<br />
+		</p>
+
 		<h2>생성자</h2>
-		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count] )</h3>
+		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count], [param:Boolean normalized] )</h3>
 		<p>
 		*buffer* — 반드시 [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLBuffer WebGLBuffer]여야 합니다.
 		<br />
@@ -38,6 +43,15 @@
 			<li>gl.UNSIGNED_BYTE: 1</li>
 		</ul>
 		*count* — 예상되는 VBO의 꼭짓점 수.
+		<br />
+		*normalized* — (optional) Applies to integer data only.
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL code. For instance, if [page:WebGLBuffer buffer] contains data of
+			`gl.UNSIGNED_SHORT`, and [page:Boolean normalized] is true, the values `0 -
+			+65535` in the buffer data will be mapped to 0.0f - +1.0f in the GLSL
+			attribute. A `gl.SHORT` (signed) would map from -32768 - +32767 to -1.0f
+			- +1.0f. If [page:Boolean normalized] is false, the values will be
+			converted to floats unmodified, i.e. 32767 becomes 32767.0f.
 		</p>
 
 		<h2>프로퍼티</h2>
@@ -52,6 +66,14 @@
 			VBO의 꼭짓점 수.
 		</p>
 
+		<h3>[property:Integer elementSize]</h3>
+		<p>
+			현재의 *type* 속성 값에 맞는 바이트 사이즈를 저장.
+		</p>
+		<p>
+			알려진 타입 크기 리스트는 위의 (생성자)를 참고.
+		</p>
+
 		<h3>[property:Boolean isGLBufferAttribute]</h3>
 		<p>
 			읽기 전용. 언제나 *true*입니다.
@@ -62,17 +84,20 @@
 			각 항목을 구성하는 값의 크기 (꼭짓점).
 		</p>
 
-		<h3>[property:Integer elementSize]</h3>
+		<h3>[property:String name]</h3>
 		<p>
-			현재의 *type* 속성 값에 맞는 바이트 사이즈를 저장.
+		이 속성 인스턴스의 임시 이름. 기본값은 빈 문자열입니다.
 		</p>
+
+		<h3>[property:Boolean needsUpdate]</h3>
 		<p>
-			알려진 타입 크기 리스트는 위의 (생성자)를 참고.
+		기본값은 *false* 입니다. true로 설정하면 [page:GLBufferAttribute.version version]을 증가시킵니다.
 		</p>
 
-		<h3>[property:String name]</h3>
+		<h3>[property:Boolean normalized]</h3>
 		<p>
-		이 속성 인스턴스의 임시 이름. 기본값은 빈 문자열입니다.
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL shader code. See the constructor above for details.
 		</p>
 
 		<h3>[property:GLenum type]</h3>
@@ -84,6 +109,11 @@
 			*elementSize*와 함께 이 속성을 설정합니다. 추천하는 방법은 *setType* 메서드를 사용하는 것입니다.
 		</p>
 
+		<h3>[property:Integer version]</h3>
+		<p>
+		버전 넘버이며 needsUpdate 속성이 true가 될 때마다 증가합니다.
+		</p>
+
 		<h2>메서드</h2>
 
 		<h3>[method:this setBuffer]( buffer ) </h3>
@@ -98,16 +128,6 @@
 		<h3>[method:this setCount]( count ) </h3>
 		<p>*count* 속성을 설정합니다.</p>
 
-		<h3>[property:Integer version]</h3>
-		<p>
-		버전 넘버이며 needsUpdate 속성이 true가 될 때마다 증가합니다.
-		</p>
-
-		<h3>[property:Boolean needsUpdate]</h3>
-		<p>
-		기본값은 *false* 입니다. true로 설정하면 [page:GLBufferAttribute.version version]을 증가시킵니다.
-		</p>
-
 		<h2>소스코드</h2>
 		<p>
 			[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

+ 36 - 16
docs/api/zh/core/GLBufferAttribute.html

@@ -16,7 +16,7 @@
 		</p>
 
 		<h2>构造方法(Constructor)</h2>
-		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count] )</h3>
+		<h3>[name]( [param:WebGLBuffer buffer], [param:GLenum type], [param:Integer itemSize], [param:Integer elementSize], [param:Integer count], [param:Boolean normalized] )</h3>
 		<p>
 		*buffer* — 必须是 [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLBuffer WebGLBuffer].
 		<br />
@@ -35,6 +35,20 @@
 			<li>gl.UNSIGNED_BYTE: 1</li>
 		</ul>
 		*count* — VBO 中预期的顶点数。
+		<br />
+		*normalized* — (optional) Applies to integer data only.
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL code. For instance, if [page:WebGLBuffer buffer] contains data of
+			`gl.UNSIGNED_SHORT`, and [page:Boolean normalized] is true, the values `0 -
+			+65535` in the buffer data will be mapped to 0.0f - +1.0f in the GLSL
+			attribute. A `gl.SHORT` (signed) would map from -32768 - +32767 to -1.0f
+			- +1.0f. If [page:Boolean normalized] is false, the values will be
+			converted to floats unmodified, i.e. 32767 becomes 32767.0f.
+		</p>
+
+		<h2>Examples</h2>
+		<p>
+			[example:webgl_buffergeometry_glbufferattribute Points with custom buffers]<br />
 		</p>
 
 		<h2>特性(Properties)</h2>
@@ -49,6 +63,14 @@
 			VBO 中的预期顶点数。
 		</p>
 
+		<h3>[property:Integer elementSize]</h3>
+		<p>
+			存储当前类型属性值的相应大小(以字节为单位)。
+		</p>
+		<p>
+			有关已知类型大小的列表,请参见上面的(构造函数)。
+		</p>
+
 		<h3>[property:Boolean isGLBufferAttribute]</h3>
 		<p>
 			只读。值永远为"true"。
@@ -59,17 +81,20 @@
 			每个项目(顶点)组成多少个值。
 		</p>
 
-		<h3>[property:Integer elementSize]</h3>
+		<h3>[property:String name]</h3>
 		<p>
-			存储当前类型属性值的相应大小(以字节为单位)
+			该attribute实例的别名,默认值为空字符串
 		</p>
+
+		<h3>[property:Boolean needsUpdate]</h3>
 		<p>
-			有关已知类型大小的列表,请参见上面的(构造函数)。
+			默认为假。将此设置为 true 增量[page:GLBufferAttribute.version 版本]
 		</p>
 
-		<h3>[property:String name]</h3>
+		<h3>[property:Boolean normalized]</h3>
 		<p>
-			该attribute实例的别名,默认值为空字符串。
+			Indicates how the underlying data in the buffer maps to the values in the
+			GLSL shader code. See the constructor above for details.
 		</p>
 
 		<h3>[property:GLenum type]</h3>
@@ -80,6 +105,11 @@
 			将此属性与elementSize一起设置。推荐的方法是使用setType方法。
 		</p>
 
+		<h3>[property:Integer version]</h3>
+		<p>
+		版本号,每次将needsUpdate属性设置为true时递增。
+		</p>
+
 		<h2>方法(Methods)</h2>
 
 		<h3>[method:this setBuffer]( buffer ) </h3>
@@ -94,16 +124,6 @@
 		<h3>[method:this setCount]( count ) </h3>
 		<p>设置计数属性。</p>
 
-		<h3>[property:Integer version]</h3>
-		<p>
-		版本号,每次将needsUpdate属性设置为true时递增。
-		</p>
-
-		<h3>[property:Boolean needsUpdate]</h3>
-		<p>
-			默认为假。将此设置为 true 增量[page:GLBufferAttribute.version 版本]
-		</p>
-
 		<h2>源代码(Source)</h2>
 		<p>
 			[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

BIN
examples/screenshots/webgl_buffergeometry_glbufferattribute.jpg


+ 4 - 3
examples/webgl_buffergeometry_glbufferattribute.html

@@ -91,7 +91,8 @@
 
 					color.setRGB( vx, vy, vz, THREE.SRGBColorSpace );
 
-					colors.push( color.r, color.g, color.b );
+					const hex = color.getHex( THREE.LinearSRGBColorSpace );
+					colors.push( hex >> 16 & 255, hex >> 8 & 255, hex & 255 );
 
 				}
 
@@ -107,7 +108,7 @@
 
 				const rgb = gl.createBuffer();
 				gl.bindBuffer( gl.ARRAY_BUFFER, rgb );
-				gl.bufferData( gl.ARRAY_BUFFER, new Float32Array( colors ), gl.STATIC_DRAW );
+				gl.bufferData( gl.ARRAY_BUFFER, new Uint8Array( colors ), gl.STATIC_DRAW );
 
 				const posAttr1 = new THREE.GLBufferAttribute( pos, gl.FLOAT, 3, 4, particles );
 				const posAttr2 = new THREE.GLBufferAttribute( pos2, gl.FLOAT, 3, 4, particles );
@@ -121,7 +122,7 @@
 
 				}, 2000 );
 
-				geometry.setAttribute( 'color', new THREE.GLBufferAttribute( rgb, gl.FLOAT, 3, 4, particles ) );
+				geometry.setAttribute( 'color', new THREE.GLBufferAttribute( rgb, gl.UNSIGNED_BYTE, 3, 1, particles, true ) );
 
 				//
 

+ 1 - 1
src/core/BufferAttribute.js

@@ -88,7 +88,7 @@ class BufferAttribute {
 		/**
 		 * Applies to integer data only. Indicates how the underlying data in the buffer maps to
 		 * the values in the GLSL code. For instance, if `array` is an instance of `UInt16Array`,
-		 * and `normalized` is `true`, the values `0 -+65535` in the array data will be mapped to
+		 * and `normalized` is `true`, the values `0 - +65535` in the array data will be mapped to
 		 * `0.0f - +1.0f` in the GLSL attribute. If `normalized` is `false`, the values will be converted
 		 * to floats unmodified, i.e. `65535` becomes `65535.0f`.
 		 *

+ 13 - 1
src/core/GLBufferAttribute.js

@@ -19,8 +19,9 @@ class GLBufferAttribute {
 	 * @param {number} itemSize - The item size.
 	 * @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
 	 * @param {number} count - The expected number of vertices in VBO.
+	 * @param {boolean} [normalized=false] - Whether the data are normalized or not.
 	 */
-	constructor( buffer, type, itemSize, elementSize, count ) {
+	constructor( buffer, type, itemSize, elementSize, count, normalized = false ) {
 
 		/**
 		 * This flag can be used for type testing.
@@ -73,6 +74,17 @@ class GLBufferAttribute {
 		 */
 		this.count = count;
 
+		/**
+		 * Applies to integer data only. Indicates how the underlying data in the buffer maps to
+		 * the values in the GLSL code. For instance, if `buffer` contains data of `gl.UNSIGNED_SHORT`,
+		 * and `normalized` is `true`, the values `0 - +65535` in the buffer data will be mapped to
+		 * `0.0f - +1.0f` in the GLSL attribute. If `normalized` is `false`, the values will be converted
+		 * to floats unmodified, i.e. `65535` becomes `65535.0f`.
+		 *
+		 * @type {boolean}
+		 */
+		this.normalized = normalized;
+
 		/**
 		 * A version number, incremented every time the `needsUpdate` is set to `true`.
 		 *

+ 6 - 0
test/unit/src/core/GLBufferAttribute.tests.js

@@ -51,6 +51,12 @@ export default QUnit.module( 'Core', () => {
 
 		} );
 
+		QUnit.todo( 'normalized', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
 		QUnit.todo( 'version', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );

粤ICP备19079148号