2
0
Эх сурвалжийг харах

WebGLRenderer: Improve interger attribute support. (#21606)

* WebGLRenderer: Improve interger attribute support.

* BufferAttribute: Fix property definition.

* BufferAttribute: Honor `integer` in `copy()`.

* BufferAttribute: Use `gpuType` instead of `integer`.
Michael Herzog 2 жил өмнө
parent
commit
94c43c95c8

+ 49 - 1
src/core/BufferAttribute.js

@@ -1,7 +1,7 @@
 import { Vector3 } from '../math/Vector3.js';
 import { Vector2 } from '../math/Vector2.js';
 import { denormalize, normalize } from '../math/MathUtils.js';
-import { StaticDrawUsage } from '../constants.js';
+import { StaticDrawUsage, FloatType } from '../constants.js';
 import { fromHalfFloat, toHalfFloat } from '../extras/DataUtils.js';
 
 const _vector = /*@__PURE__*/ new Vector3();
@@ -378,6 +378,18 @@ class Int8BufferAttribute extends BufferAttribute {
 
 		super( new Int8Array( array ), itemSize, normalized );
 
+		this.gpuType = FloatType;
+
+	}
+
+	copy( source ) {
+
+		super.copy( source );
+
+		this.gpuType = source.gpuType;
+
+		return this;
+
 	}
 
 }
@@ -388,6 +400,18 @@ class Uint8BufferAttribute extends BufferAttribute {
 
 		super( new Uint8Array( array ), itemSize, normalized );
 
+		this.gpuType = FloatType;
+
+	}
+
+	copy( source ) {
+
+		super.copy( source );
+
+		this.gpuType = source.gpuType;
+
+		return this;
+
 	}
 
 }
@@ -408,6 +432,18 @@ class Int16BufferAttribute extends BufferAttribute {
 
 		super( new Int16Array( array ), itemSize, normalized );
 
+		this.gpuType = FloatType;
+
+	}
+
+	copy( source ) {
+
+		super.copy( source );
+
+		this.gpuType = source.gpuType;
+
+		return this;
+
 	}
 
 }
@@ -418,6 +454,18 @@ class Uint16BufferAttribute extends BufferAttribute {
 
 		super( new Uint16Array( array ), itemSize, normalized );
 
+		this.gpuType = FloatType;
+
+	}
+
+	copy( source ) {
+
+		super.copy( source );
+
+		this.gpuType = source.gpuType;
+
+		return this;
+
 	}
 
 }

+ 13 - 5
src/renderers/webgl/WebGLBindingStates.js

@@ -1,4 +1,6 @@
-function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
+import { IntType } from '../../constants.js';
+
+function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
 
 	const maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
 
@@ -315,9 +317,9 @@
 
 	}
 
-	function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
+	function vertexAttribPointer( index, size, type, normalized, stride, offset, integer ) {
 
-		if ( capabilities.isWebGL2 === true && ( type === gl.INT || type === gl.UNSIGNED_INT ) ) {
+		if ( integer === true ) {
 
 			gl.vertexAttribIPointer( index, size, type, stride, offset );
 
@@ -375,6 +377,10 @@
 					const type = attribute.type;
 					const bytesPerElement = attribute.bytesPerElement;
 
+					// check for integer attributes (WebGL 2 only)
+
+					const integer = ( capabilities.isWebGL2 === true && ( type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType ) );
+
 					if ( geometryAttribute.isInterleavedBufferAttribute ) {
 
 						const data = geometryAttribute.data;
@@ -415,7 +421,8 @@
 								type,
 								normalized,
 								stride * bytesPerElement,
-								( offset + ( size / programAttribute.locationSize ) * i ) * bytesPerElement
+								( offset + ( size / programAttribute.locationSize ) * i ) * bytesPerElement,
+								integer
 							);
 
 						}
@@ -456,7 +463,8 @@
 								type,
 								normalized,
 								size * bytesPerElement,
-								( size / programAttribute.locationSize ) * i * bytesPerElement
+								( size / programAttribute.locationSize ) * i * bytesPerElement,
+								integer
 							);
 
 						}