question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expand support for GLSL integer attributes

See original GitHub issue

Expanding 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:open
  • Created 2 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Mugen87commented, Apr 7, 2021

Thanks for the additional information! That made it more clear. To sum up:

  • The renderer currently only supports Int32BufferAttribute (gl.INT) and Uint32BufferAttribute (gl.UNSIGNED_INT) in context of vertexAttribIPointer(). Other types of integer attributes (gl.BYTE, gl.UNSIGNED_BYTE, gl.SHORT, gl.UNSIGNED_SHORT) are currently not supported.
  • The purpose of this issue is to add support for the above types.

How about add a new flag to Int8BufferAttribute, Uint8BufferAttribute, Uint16BufferAttribute and Int16BufferAttribute to control how the data should be interpreted? I would prefer this instead of changing BufferAttribute.

1reaction
gkjohnsoncommented, Sep 8, 2022

For ‘native’ vertex attributes like position, which our shaders assume to be floats, either make an exception to (1), or explicitly cast from int to float in the shader.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebGL: How to Use Integer Attributes in GLSL - Stack Overflow
My vertex data contains integers and I want to define the vertex attributes like this: attribute vec3 POSITION; attribute int INDEX[8]; ...
Read more >
Core Language (GLSL) - OpenGL Wiki - Khronos Group
It allows GLSL to function when there is no ability to write arbitrarily to memory, which is true of most shader hardware (though...
Read more >
Advanced GLSL - LearnOpenGL
The integer variable gl_VertexID holds the current ID of the vertex we're drawing. When doing indexed rendering (with glDrawElements ) this variable holds...
Read more >
OpenGL Shading Language Course Chapter 2 – GLSL Basics ...
full support for a wide range of integer operations. Because of their intended (limited) ... attribute vec4 gl Color; // Filled with glColorxx...
Read more >
An Overview of the OpenGL Shading Language | Shader ...
This section provides an overview of the shading language used within OpenGL. GLSL shares many traits with C++ and Java, and is used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found