Skip to content

GLBufferAttribute: Add normalized property. #1694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ index 142ff43b..903b59ee 100644
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 4000);
camera.position.z = 1750;
diff --git a/examples-testing/examples/webgl_buffergeometry_glbufferattribute.ts b/examples-testing/examples/webgl_buffergeometry_glbufferattribute.ts
index aea462cf..f66207e2 100644
index 80fa828b..77f1bc38 100644
--- a/examples-testing/examples/webgl_buffergeometry_glbufferattribute.ts
+++ b/examples-testing/examples/webgl_buffergeometry_glbufferattribute.ts
@@ -2,11 +2,11 @@ import * as THREE from 'three';
Expand Down Expand Up @@ -2598,7 +2598,7 @@ index aea462cf..f66207e2 100644

const positions = [];
const positions2 = [];
@@ -71,15 +71,15 @@ function init() {
@@ -72,15 +72,15 @@ function init() {

const gl = renderer.getContext();

Expand All @@ -2615,7 +2615,7 @@ index aea462cf..f66207e2 100644
- const rgb = gl.createBuffer();
+ 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);

diff --git a/examples-testing/examples/webgl_buffergeometry_indexed.ts b/examples-testing/examples/webgl_buffergeometry_indexed.ts
index a2f9f379..4ad49d3c 100644
Expand Down
19 changes: 18 additions & 1 deletion types/three/src/core/GLBufferAttribute.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ export class GLBufferAttribute {
* @param itemSize How many values make up each item (vertex). See {@link GLBufferAttribute.itemSize | .itemSize}
* @param elementSize `1`, `2` or `4`. The corresponding size (in bytes) for the given {@link type} param. See {@link GLBufferAttribute.elementSize | .elementSize}
* @param count The expected number of vertices in VBO. See {@link GLBufferAttribute.count | .count}
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor(buffer: WebGLBuffer, type: GLenum, itemSize: number, elementSize: 1 | 2 | 4, count: number);
constructor(
buffer: WebGLBuffer,
type: GLenum,
itemSize: number,
elementSize: 1 | 2 | 4,
count: number,
normalized?: boolean,
);

/**
* Read-only flag to check if a given object is of type {@link GLBufferAttribute}.
Expand Down Expand Up @@ -87,6 +95,15 @@ export class GLBufferAttribute {
*/
count: number;

/**
* 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`.
*/
normalized: boolean;

/**
* A version number, incremented every time the needsUpdate property is set to true.
* @remarks Expects a `Integer`
Expand Down
Loading