-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored and remove global state
- Loading branch information
aardgoose
committed
Jan 11, 2024
1 parent
66aa8ff
commit 1bc9388
Showing
7 changed files
with
213 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
class CommonUniformBuffer { | ||
|
||
constructor( bufferSize = 0, alignment = 0 ) { | ||
|
||
let buffer = null; | ||
|
||
if ( bufferSize > 0 ) { | ||
|
||
buffer = new Float32Array( bufferSize ); | ||
|
||
} | ||
|
||
// offset in bytes to first free buffer entry | ||
|
||
this.startFree = 0; | ||
this.buffer = buffer; | ||
this.aligment = alignment; | ||
|
||
} | ||
|
||
allocate( byteLength ) { | ||
|
||
if ( this.startFree + length > this.byteLength ) return false; | ||
|
||
// uniformGroups within buffer must be aligned correctly per WebGPU spec. | ||
const paddedByteLength = Math.ceil( byteLength / this.aligment ) * this.aligment; | ||
|
||
const bpe = this.buffer.BYTES_PER_ELEMENT; | ||
|
||
const buffer = this.buffer.subarray( this.startFree / bpe , ( this.startFree + byteLength ) / bpe ); | ||
|
||
this.startFree += paddedByteLength; | ||
|
||
return buffer; | ||
|
||
} | ||
|
||
get byteLength() { | ||
|
||
return this.buffer === null ? 0 : this.buffer.byteLength; | ||
|
||
} | ||
|
||
get arrayBuffer() { | ||
|
||
return this.buffer.buffer; | ||
|
||
} | ||
|
||
} | ||
|
||
export default CommonUniformBuffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters