Skip to content

Commit 5457a9d

Browse files
authored
WebGLUniformsGroups: Fix buffer offset calculation. (#28834)
1 parent 4c14bb1 commit 5457a9d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/renderers/webgl/WebGLUniformsGroups.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,27 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
240240

241241
const info = getUniformSize( value );
242242

243-
// Calculate the chunk offset
244-
const chunkOffsetUniform = offset % chunkSize;
243+
const chunkOffset = offset % chunkSize; // offset in the current chunk
244+
const chunkPadding = chunkOffset % info.boundary; // required padding to match boundary
245+
const chunkStart = chunkOffset + chunkPadding; // the start position in the current chunk for the data
246+
247+
offset += chunkPadding;
245248

246249
// Check for chunk overflow
247-
if ( chunkOffsetUniform !== 0 && ( chunkSize - chunkOffsetUniform ) < info.boundary ) {
250+
if ( chunkStart !== 0 && ( chunkSize - chunkStart ) < info.storage ) {
248251

249252
// Add padding and adjust offset
250-
offset += ( chunkSize - chunkOffsetUniform );
253+
offset += ( chunkSize - chunkStart );
251254

252255
}
253256

254257
// the following two properties will be used for partial buffer updates
255-
256258
uniform.__data = new Float32Array( info.storage / Float32Array.BYTES_PER_ELEMENT );
257259
uniform.__offset = offset;
258260

259-
260261
// Update the global offset
261262
offset += info.storage;
262263

263-
264264
}
265265

266266
}

0 commit comments

Comments
 (0)