@luma.gl/core
Advanced tools
Comparing version 9.0.0-alpha.42 to 9.0.0-alpha.43
@@ -64,2 +64,3 @@ export { VERSION } from './init'; | ||
export { uid, isPowerOfTwo, isObjectEmpty } from './lib/utils/utils'; | ||
export { isUniformValue, splitUniformsAndBindings } from './lib/utils/uniform'; | ||
export { formatValue } from './lib/utils/format-value'; | ||
@@ -66,0 +67,0 @@ export { stubRemovedMethods } from './lib/utils/stub-methods'; |
@@ -34,2 +34,3 @@ export { VERSION } from "./init.js"; | ||
export { uid, isPowerOfTwo, isObjectEmpty } from "./lib/utils/utils.js"; | ||
export { isUniformValue, splitUniformsAndBindings } from "./lib/utils/uniform.js"; | ||
export { formatValue } from "./lib/utils/format-value.js"; | ||
@@ -36,0 +37,0 @@ export { stubRemovedMethods } from "./lib/utils/stub-methods.js"; |
@@ -42,2 +42,6 @@ import type { ShaderUniformType } from '../../adapter/types/shader-types'; | ||
getUniformBufferData(uniformBufferName: keyof TUniformGroups): Uint8Array; | ||
/** Create an unmanaged uniform buffer, initialized with current / supplied values */ | ||
createUniformBuffer(device: Device, uniformBufferName: keyof TUniformGroups, uniforms?: Partial<{ | ||
[group in keyof TUniformGroups]: Partial<TUniformGroups[group]>; | ||
}>): Buffer; | ||
/** Get the managed uniform buffer */ | ||
@@ -44,0 +48,0 @@ getManagedUniformBuffer(device: Device, uniformBufferName: keyof TUniformGroups): Buffer; |
@@ -42,2 +42,15 @@ import { Buffer } from "../../adapter/resources/buffer.js"; | ||
} | ||
createUniformBuffer(device, uniformBufferName, uniforms) { | ||
const byteLength = this.getUniformBufferByteLength(uniformBufferName); | ||
const uniformBuffer = device.createBuffer({ | ||
usage: Buffer.UNIFORM, | ||
byteLength | ||
}); | ||
if (uniforms) { | ||
this.setUniforms(uniforms); | ||
} | ||
const uniformBufferData = this.getUniformBufferData(uniformBufferName); | ||
uniformBuffer.write(uniformBufferData); | ||
return uniformBuffer; | ||
} | ||
getManagedUniformBuffer(device, uniformBufferName) { | ||
@@ -44,0 +57,0 @@ if (!this.uniformBuffers[uniformBufferName]) { |
{ | ||
"name": "@luma.gl/core", | ||
"version": "9.0.0-alpha.42", | ||
"version": "9.0.0-alpha.43", | ||
"description": "luma.gl API", | ||
@@ -45,3 +45,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "61f38eaaa9cc42fa08d1c00690e370fa85681e30" | ||
"gitHead": "1527d42e56ce203938534bf0d3318d303ebde066" | ||
} |
@@ -141,2 +141,3 @@ // luma.gl, MIT license | ||
export {uid, isPowerOfTwo, isObjectEmpty} from './lib/utils/utils'; | ||
export {isUniformValue, splitUniformsAndBindings} from './lib/utils/uniform'; | ||
export {formatValue} from './lib/utils/format-value'; | ||
@@ -143,0 +144,0 @@ export {stubRemovedMethods} from './lib/utils/stub-methods'; |
@@ -10,3 +10,3 @@ // luma.gl, MIT license | ||
/** | ||
/** | ||
* A uniform store holds a uniform values for one or more uniform blocks, | ||
@@ -28,11 +28,17 @@ * - It can generate binary data for any uniform buffer | ||
* Create a new UniformStore instance | ||
* @param blocks | ||
* @param blocks | ||
*/ | ||
constructor( | ||
blocks: Record<keyof TUniformGroups, { | ||
uniformTypes?: Record<string, ShaderUniformType>; | ||
defaultUniforms?: Record<string, UniformValue>; | ||
}> | ||
blocks: Record< | ||
keyof TUniformGroups, | ||
{ | ||
uniformTypes?: Record<string, ShaderUniformType>; | ||
defaultUniforms?: Record<string, UniformValue>; | ||
} | ||
> | ||
) { | ||
this.uniformBlocks = {} as Record<keyof TUniformGroups, UniformBlock<Record<string, UniformValue>>>; | ||
this.uniformBlocks = {} as Record< | ||
keyof TUniformGroups, | ||
UniformBlock<Record<string, UniformValue>> | ||
>; | ||
this.uniformBufferLayouts = {} as Record<keyof TUniformGroups, UniformBufferLayout>; | ||
@@ -44,3 +50,3 @@ this.uniformBuffers = {} as Record<keyof TUniformGroups, Buffer>; | ||
// Create a layout object to help us generate correctly formatted binary uniform buffers | ||
// Create a layout object to help us generate correctly formatted binary uniform buffers | ||
const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes || {}); | ||
@@ -63,7 +69,9 @@ this.uniformBufferLayouts[uniformBufferName] = uniformBufferLayout; | ||
/** | ||
* Set uniforms | ||
/** | ||
* Set uniforms | ||
* Makes all properties partial | ||
*/ | ||
setUniforms(uniforms: Partial<{[group in keyof TUniformGroups]: Partial<TUniformGroups[group]>}>): void { | ||
setUniforms( | ||
uniforms: Partial<{[group in keyof TUniformGroups]: Partial<TUniformGroups[group]>}> | ||
): void { | ||
for (const [blockName, uniformValues] of Object.entries(uniforms)) { | ||
@@ -89,2 +97,19 @@ this.uniformBlocks[blockName].setUniforms(uniformValues); | ||
/** Create an unmanaged uniform buffer, initialized with current / supplied values */ | ||
createUniformBuffer( | ||
device: Device, | ||
uniformBufferName: keyof TUniformGroups, | ||
uniforms?: Partial<{[group in keyof TUniformGroups]: Partial<TUniformGroups[group]>}> | ||
): Buffer { | ||
const byteLength = this.getUniformBufferByteLength(uniformBufferName); | ||
const uniformBuffer = device.createBuffer({usage: Buffer.UNIFORM, byteLength}); | ||
if (uniforms) { | ||
this.setUniforms(uniforms); | ||
} | ||
// This clears the needs redraw flag | ||
const uniformBufferData = this.getUniformBufferData(uniformBufferName); | ||
uniformBuffer.write(uniformBufferData); | ||
return uniformBuffer; | ||
} | ||
/** Get the managed uniform buffer */ | ||
@@ -111,3 +136,3 @@ getManagedUniformBuffer(device: Device, uniformBufferName: keyof TUniformGroups): Buffer { | ||
const uniformBufferData = this.getUniformBufferData(uniformBufferName); | ||
const uniformBuffer = this.uniformBuffers[uniformBufferName]; | ||
@@ -118,3 +143,8 @@ uniformBuffer.write(uniformBufferData); | ||
const uniformValues = this.uniformBlocks[uniformBufferName].getAllUniforms(); | ||
log.log(4, `Writing to uniform buffer ${String(uniformBufferName)}`, uniformBufferData, uniformValues)(); | ||
log.log( | ||
4, | ||
`Writing to uniform buffer ${String(uniformBufferName)}`, | ||
uniformBufferData, | ||
uniformValues | ||
)(); | ||
} | ||
@@ -121,0 +151,0 @@ return reason; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
920337
287
14059