Expand support for GLSL integer attributes
See original GitHub issueExpanding on the vertexAttribIPointer
support added in https://github.com/mrdoob/three.js/pull/19019, I would like to propose a new property:
BufferAttribute.targetType = FloatType
(default)
This property would support values of the existing constants FloatType
(default) and IntType
.
This would expand support for integer attributes (beyond the current int32
and uint32
) without changing any existing behavior.
The property would ultimately get passed through to WebGLBindingStates.vertexAttribPointer()
where the code impact is minimal:
-function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
+function vertexAttribPointer( index, size, type, normalized, stride, offset, targetType ) {
- if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
+ if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 || targetType == IntType ) ) {
gl.vertexAttribIPointer( index, size, type, stride, offset );
} else {
gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
}
}
Alternatively, this could be a boolean attribute such as BufferAttribute.toIntegers = true
, as it looks like WebGL only supports vertexAttribPointer
(float) and vertexAttribIPointer
(int) – not vertexAttribLPointer
(double).
Apologies if I’m missing anything obvious. Thank you!
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (1 by maintainers)
Top GitHub Comments
Thanks for the additional information! That made it more clear. To sum up:
Int32BufferAttribute
(gl.INT
) andUint32BufferAttribute
(gl.UNSIGNED_INT
) in context ofvertexAttribIPointer()
. Other types of integer attributes (gl.BYTE
,gl.UNSIGNED_BYTE
,gl.SHORT
,gl.UNSIGNED_SHORT
) are currently not supported.How about add a new flag to
Int8BufferAttribute
,Uint8BufferAttribute
,Uint16BufferAttribute
andInt16BufferAttribute
to control how the data should be interpreted? I would prefer this instead of changingBufferAttribute
.I commented here but to expand a bit on this comment - I’d prefer to not to have this kind of “magic” used internally (ie providing an exception only for
position
, etc). It feels like a recognition that this capability and flexibility is valuable while precluding users from being able to take advantage of it.