Socket
Socket
Sign inDemoInstall

@luma.gl/api

Package Overview
Dependencies
3
Maintainers
7
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 9.0.0-alpha.21 to 9.0.0-alpha.23

dist/adapter/resources/command-buffer.d.ts

12

dist/adapter/canvas-context.js

@@ -88,9 +88,11 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

}
if (typeof useDevicePixels === 'number') {
return useDevicePixels > 0 ? useDevicePixels : 1;
useDevicePixels = useDevicePixels === undefined ? this.props.useDevicePixels : useDevicePixels;
if (!useDevicePixels || useDevicePixels <= 0) {
return 1;
}
if (typeof this.props.useDevicePixels === 'number') {
return this.props.useDevicePixels > 0 ? this.props.useDevicePixels : 1;
if (useDevicePixels === true) {
const dpr = typeof window !== 'undefined' && window.devicePixelRatio;
return dpr || 1;
}
return useDevicePixels || this.props.useDevicePixels ? typeof window !== 'undefined' && window.devicePixelRatio || 1 : 1;
return useDevicePixels;
}

@@ -97,0 +99,0 @@ getPixelSize() {

/// <reference types="dist" />
/// <reference types="offscreencanvas" />
import { StatsManager } from '../lib/utils/stats-manager';
import { TextureFormat } from './types/texture-formats';
import type { TextureFormat } from './types/texture-formats';
import type { CanvasContext, CanvasContextProps } from './canvas-context';

@@ -17,2 +17,3 @@ import type { BufferProps } from './resources/buffer';

import type { ComputePass, ComputePassProps } from './resources/compute-pass';
import type { CommandEncoder, CommandEncoderProps } from './resources/command-encoder';
/** Device properties */

@@ -110,5 +111,5 @@ export declare type DeviceProps = {

abstract isTextureFormatRenderable(format: TextureFormat): boolean;
/** True context is already lost */
/** `true` if device is already lost */
abstract get isLost(): boolean;
/** Promise that resolves when context is lost */
/** Promise that resolves when device is lost */
abstract readonly lost: Promise<{

@@ -118,3 +119,9 @@ reason: 'destroyed';

}>;
/** default canvas context */
/**
* Trigger device loss.
* @returns `true` if context loss could actually be triggered.
* @note primarily intended for testing how application reacts to device loss
*/
loseDevice(): boolean;
/** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */
abstract canvasContext: CanvasContext | null;

@@ -126,5 +133,5 @@ /** Creates a new CanvasContext (WebGPU only) */

/** Create a buffer */
createBuffer(props: BufferProps): Buffer;
createBuffer(data: ArrayBuffer | ArrayBufferView): Buffer;
abstract createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): Buffer;
/** Create a texture */
abstract _createTexture(props: TextureProps): Texture;
createTexture(props: TextureProps): Texture;

@@ -144,11 +151,12 @@ createTexture(data: Promise<TextureData>): Texture;

abstract createComputePipeline(props: ComputePipelineProps): ComputePipeline;
createCommandEncoder(props?: CommandEncoderProps): CommandEncoder;
/** Create a RenderPass */
abstract beginRenderPass(props: RenderPassProps): RenderPass;
abstract beginRenderPass(props?: RenderPassProps): RenderPass;
/** Create a ComputePass */
abstract beginComputePass(props?: ComputePassProps): ComputePass;
/** Get a renderpass that is set up to render to the primary CanvasContext */
abstract getDefaultRenderPass(): RenderPass;
protected abstract _createBuffer(props: BufferProps): Buffer;
protected abstract _createTexture(props: TextureProps): Texture;
protected _getBufferProps(props: BufferProps | ArrayBuffer | ArrayBufferView): BufferProps;
}
export {};
//# sourceMappingURL=device.d.ts.map

@@ -41,8 +41,26 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

}
createBuffer(props) {
loseDevice() {
return false;
}
createTexture(props) {
if (props instanceof Promise || typeof props === 'string') {
props = {
data: props
};
}
return this._createTexture(props);
}
createCommandEncoder() {
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
throw new Error('not implemented');
}
_getBufferProps(props) {
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
return this._createBuffer({
return {
data: props
});
};
}
const newProps = {
...props
};
if ((props.usage || 0) & Buffer.INDEX && !props.indexType) {

@@ -55,14 +73,6 @@ if (props.data instanceof Uint32Array) {

}
return this._createBuffer(props);
return newProps;
}
createTexture(props) {
if (props instanceof Promise || typeof props === 'string') {
props = {
data: props
};
}
return this._createTexture(props);
}
}
_defineProperty(Device, "VERSION", VERSION);
//# sourceMappingURL=device.js.map

@@ -5,8 +5,13 @@ import { TypedArray } from '../..';

export declare type BufferProps = ResourceProps & {
/** Supply a handle to connect to an existing device-specific buffer */
handle?: WebGLBuffer;
/** Specifies how this buffer can be used */
usage?: number;
/** Length in bytes of memory to be allocated. If not specified, `byteLength` of `props.data` will be used. */
byteLength?: number;
/** Data to initialize the buffer with. */
data?: ArrayBuffer | ArrayBufferView | null;
/** Byte offset into the newly created Buffer to store data at */
byteOffset?: number;
/** If props.usage & Buffer.INDEX */
/** If props.usage includes Buffer.INDEX */
indexType?: 'uint16' | 'uint32';

@@ -28,2 +33,4 @@ mappedAtCreation?: boolean;

get [Symbol.toStringTag](): string;
/** Length of buffer in bytes */
abstract byteLength: number;
constructor(device: Device, props: BufferProps);

@@ -30,0 +37,0 @@ write(data: ArrayBufferView, byteOffset?: number): void;

@@ -30,2 +30,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

super(device, deducedProps, DEFAULT_BUFFER_PROPS);
_defineProperty(this, "byteLength", void 0);
}

@@ -32,0 +33,0 @@ write(data, byteOffset) {

@@ -30,2 +30,4 @@ import { Resource, ResourceProps } from './resource';

export declare type CopyBufferToTextureOptions = {
source: Buffer;
byteOffset?: number;
destination: Texture;

@@ -35,4 +37,2 @@ mipLevel?: number;

aspect?: 'all' | 'stencil-only' | 'depth-only';
source: Buffer;
offset: number;
bytesPerRow: number;

@@ -42,4 +42,55 @@ rowsPerImage: number;

};
export declare type CopyTextureToBufferOptions = {};
export declare type CopyTextureToTextureOptions = {};
export declare type CopyTextureToBufferOptions = {
/** Texture to copy to/from. */
source: Texture;
/** Mip-map level of the texture to copy to/from. (Default 0) */
mipLevel?: number;
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from.
* Together with `copySize`, defines the full copy sub-region.
*/
/** Defines which aspects of the texture to copy to/from. */
aspect?: 'all' | 'stencil-only' | 'depth-only';
/** Width to copy */
width?: number;
height?: number;
depthOrArrayLayers?: number;
origin?: number[];
/** Destination buffer */
destination: Buffer;
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
byteOffset?: number;
/**
* The stride, in bytes, between the beginning of each block row and the subsequent block row.
* Required if there are multiple block rows (i.e. the copy height or depth is more than one block).
*/
bytesPerRow?: number;
/**
* Number of block rows per single image of the texture.
* rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.
* Required if there are multiple images (i.e. the copy depth is more than one).
*/
rowsPerImage?: number;
};
export declare type CopyTextureToTextureOptions = {
/** Texture to copy to/from. */
source: Texture;
/** Mip-map level of the texture to copy to/from. (Default 0) */
mipLevel?: number;
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy from. */
/** Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from. */
aspect?: 'all' | 'stencil-only' | 'depth-only';
/** Texture to copy to/from. */
destination: Texture;
/** Mip-map level of the texture to copy to/from. (Default 0) */
destinationMipLevel?: number;
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
destinationOrigin?: number[];
/** Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from. */
destinationAspect?: 'all' | 'stencil-only' | 'depth-only';
origin?: number[];
/** Width to copy */
width?: number;
height?: number;
depthOrArrayLayers?: number;
};
export declare type CommandEncoderProps = ResourceProps & {

@@ -54,2 +105,3 @@ measureExecutionTime?: boolean;

constructor(props: CommandEncoderProps);
abstract finish(): void;
abstract copyBufferToBuffer(options: CopyBufferToBufferOptions): void;

@@ -56,0 +108,0 @@ abstract copyBufferToTexture(options: CopyBufferToTextureOptions): void;

@@ -1,2 +0,2 @@

import type { ColorTextureFormat, DepthStencilTextureFormat } from '../types/texture-formats';
import type { ColorTextureFormat, DepthStencilTextureFormat, TextureFormat } from '../types/texture-formats';
import type { Device } from '../device';

@@ -9,3 +9,3 @@ import { Resource, ResourceProps } from './resource';

colorAttachments?: (Texture | ColorTextureFormat)[];
depthStencilAttachment?: Texture | DepthStencilTextureFormat | null;
depthStencilAttachment?: (Texture | DepthStencilTextureFormat) | null;
};

@@ -22,4 +22,6 @@ /**

height: number;
abstract colorAttachments: Texture[];
abstract depthStencilAttachment: Texture | null;
/** Color attachments */
colorAttachments: Texture[];
/** Depth-stencil attachment, if provided */
depthStencilAttachment: Texture | null;
constructor(device: Device, props?: FramebufferProps);

@@ -30,9 +32,21 @@ /**

*/
resize(size?: {
resize(size: {
width: number;
height: number;
}): void;
/** Implementation of resize */
protected abstract _resizeAttachments(width: number, height: number): void;
resize(size: [width: number, height: number]): void;
resize(): void;
/** Auto creates any textures */
protected autoCreateAttachmentTextures(): void;
/** Create a color texture */
protected createColorTexture(format: TextureFormat): Texture;
/** Create depth stencil texture */
protected createDepthStencilTexture(format: TextureFormat): Texture;
/**
* Default implementation of resize
* Creates new textures with correct size for all attachments.
* and destroys existing textures if owned
*/
protected resizeAttachments(width: number, height: number): void;
}
//# sourceMappingURL=framebuffer.d.ts.map
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
let _Symbol$toStringTag;
import { Resource, DEFAULT_RESOURCE_PROPS } from "./resource.js";
import { Texture } from "./texture.js";
import { log } from "../../lib/utils/log.js";
const DEFAULT_FRAMEBUFFER_PROPS = {

@@ -21,4 +23,4 @@ ...DEFAULT_RESOURCE_PROPS,

_defineProperty(this, "height", void 0);
_defineProperty(this, "colorAttachments", void 0);
_defineProperty(this, "depthStencilAttachment", void 0);
_defineProperty(this, "colorAttachments", []);
_defineProperty(this, "depthStencilAttachment", null);
this.width = this.props.width;

@@ -28,12 +30,76 @@ this.height = this.props.height;

resize(size) {
const updateSize = !size || size.height !== this.height || size.width !== this.width;
let updateSize = !size;
if (size) {
this.width = size === null || size === void 0 ? void 0 : size.width;
this.height = size === null || size === void 0 ? void 0 : size.height;
const [width, height] = Array.isArray(size) ? size : [size.width, size.height];
updateSize = updateSize || height !== this.height || width !== this.width;
this.width = width;
this.height = height;
}
if (updateSize) {
this._resizeAttachments(this.width, this.height);
log.log(2, "Resizing framebuffer ".concat(this.id, " to ").concat(this.width, "x").concat(this.height))();
this.resizeAttachments(this.width, this.height);
}
}
autoCreateAttachmentTextures() {
this.colorAttachments = this.props.colorAttachments.map(attachment => {
if (typeof attachment === 'string') {
const texture = this.createColorTexture(attachment);
this.attachResource(texture);
return texture;
}
return attachment;
});
if (this.props.depthStencilAttachment) {
if (typeof this.props.depthStencilAttachment === 'string') {
const texture = this.createDepthStencilTexture(this.props.depthStencilAttachment);
this.attachResource(texture);
this.depthStencilAttachment = texture;
} else {
this.depthStencilAttachment = this.props.depthStencilAttachment;
}
}
}
createColorTexture(format) {
return this.device.createTexture({
id: 'color-attachment',
usage: Texture.RENDER_ATTACHMENT,
format,
width: this.width,
height: this.height
});
}
createDepthStencilTexture(format) {
return this.device.createTexture({
id: 'depth-stencil-attachment',
usage: Texture.RENDER_ATTACHMENT,
format,
width: this.width,
height: this.height
});
}
resizeAttachments(width, height) {
for (let i = 0; i < this.colorAttachments.length; ++i) {
if (this.colorAttachments[i]) {
const resizedTexture = this.device._createTexture({
...this.colorAttachments[i].props,
width,
height
});
this.destroyAttachedResource(this.colorAttachments[i]);
this.colorAttachments[i] = resizedTexture;
this.attachResource(resizedTexture);
}
}
if (this.depthStencilAttachment) {
const resizedTexture = this.device._createTexture({
...this.depthStencilAttachment.props,
width,
height
});
this.destroyAttachedResource(this.depthStencilAttachment);
this.depthStencilAttachment = resizedTexture;
this.attachResource(resizedTexture);
}
}
}
//# sourceMappingURL=framebuffer.js.map

@@ -5,9 +5,34 @@ import type { Device } from '../device';

import { Framebuffer } from './framebuffer';
import { NumericArray } from '../..';
/**
* - Framebuffer specifies which textures to render into
* - parameters control viewport, scissor rect, blend constant and stencil ref
* - clearColor, depthClearValue, stencilClearValue control clearing at beginning of render pass.
* - discard disables rasterizer.
*/
export declare type RenderPassProps = ResourceProps & {
/** Framebuffer specifies which textures to render into. Default gets framebuffer from canvas context. */
framebuffer?: Framebuffer | null;
parameters?: RenderPassParameters | null;
/** Control viewport, scissor rect, blend constant and stencil ref */
parameters?: RenderPassParameters;
/** Clear value for color attachment, or `load` to preserve the previous value */
clearColor?: NumericArray | false;
/** Clear value for depth attachment, or `load` to preserve the previous value */
clearDepth?: number | false;
/** Clear value for stencil attachment, or `load` to preserve the previous value */
clearStencil?: number | false;
/** Indicates that the depth component is read only. */
depthReadOnly?: boolean;
/** Indicates that the stencil component is read only. */
stencilReadOnly?: boolean;
/** Whether to disable / discard the output of the rasterizer */
discard?: boolean;
};
export declare abstract class RenderPass extends Resource<RenderPassProps> {
/** Default properties for RenderPass */
static defaultProps: Required<RenderPassProps>;
get [Symbol.toStringTag](): string;
constructor(device: Device, props: RenderPassProps);
/** A small set of parameters can be changed between every draw call (viewport, scissorRect, blendColor, stencilReference) */
abstract setParameters(parameters: RenderPassParameters): void;
abstract end(): void;

@@ -14,0 +39,0 @@ abstract pushDebugGroup(groupLabel: string): void;

@@ -1,15 +0,24 @@

import { Resource, DEFAULT_RESOURCE_PROPS } from "./resource.js";
const DEFAULT_RENDERPASS_PROPS = {
...DEFAULT_RESOURCE_PROPS,
framebuffer: null,
parameters: null
};
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
let _Symbol$toStringTag;
import { Resource } from "./resource.js";
_Symbol$toStringTag = Symbol.toStringTag;
export class RenderPass extends Resource {
get [Symbol.toStringTag]() {
get [_Symbol$toStringTag]() {
return 'RenderPass';
}
constructor(device, props) {
super(device, props, DEFAULT_RENDERPASS_PROPS);
super(device, props, RenderPass.defaultProps);
}
}
_defineProperty(RenderPass, "defaultProps", {
...Resource.defaultProps,
framebuffer: null,
parameters: undefined,
clearColor: [0, 0, 0, 0],
clearDepth: 1,
clearStencil: 0,
depthReadOnly: false,
stencilReadOnly: false,
discard: false
});
//# sourceMappingURL=render-pass.js.map
import type { Device } from '../device';
export declare type ResourceProps = {
/** Name of resource, mainly for debugging purposes. A unique name will be assigned if not provided */
id?: string;
/** Handle for the underlying resources (WebGL object or WebGPU handle) */
handle?: any;
/** User provided data stored on this resource */
userData?: {

@@ -9,2 +12,6 @@ [key: string]: any;

};
/**
* Default properties for resource
* @deprecated Use Resource.defaultProps
*/
export declare const DEFAULT_RESOURCE_PROPS: Required<ResourceProps>;

@@ -15,2 +22,4 @@ /**

export declare abstract class Resource<Props extends ResourceProps> {
/** Default properties for resource */
static defaultProps: Required<ResourceProps>;
abstract get [Symbol.toStringTag](): string;

@@ -23,5 +32,8 @@ /** props.id, for debugging. */

private _device;
/** Whether this resource has been destroyed */
destroyed: boolean;
/** For resources that allocate GPU memory */
private allocatedBytes;
/** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
private _attachedResources;
/**

@@ -43,4 +55,19 @@ * Create a new Resource. Called from Subclass

getProps(): object;
/** Called by resource constructor to track object creation */
private addStats;
/**
* Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
* Called automatically when sub resources are auto created but can be called by application
*/
attachResource(resource: Resource<unknown>): void;
/**
* Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
*/
detachResource(resource: Resource<unknown>): void;
/**
* Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
*/
destroyAttachedResource(resource: Resource<unknown>): void;
/** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
destroyAttachedResources(): void;
/** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
protected destroyResource(): void;
/** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */

@@ -52,3 +79,5 @@ protected removeStats(): void;

protected trackDeallocatedMemory(name?: string): void;
/** Called by resource constructor to track object creation */
private addStats;
}
//# sourceMappingURL=resource.d.ts.map

@@ -6,3 +6,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

handle: undefined,
userData: {}
userData: undefined
};

@@ -18,2 +18,3 @@ export class Resource {

_defineProperty(this, "allocatedBytes", 0);
_defineProperty(this, "_attachedResources", new Set());
if (!device) {

@@ -31,3 +32,3 @@ throw new Error('no device');

destroy() {
this.removeStats();
this.destroyResource();
}

@@ -44,9 +45,24 @@ delete() {

}
addStats() {
const stats = this._device.statsManager.getStats('Resource Counts');
const name = this[Symbol.toStringTag];
stats.get('Resources Created').incrementCount();
stats.get("".concat(name, "s Created")).incrementCount();
stats.get("".concat(name, "s Active")).incrementCount();
attachResource(resource) {
this._attachedResources.add(resource);
}
detachResource(resource) {
this._attachedResources.delete(resource);
}
destroyAttachedResource(resource) {
if (this._attachedResources.delete(resource)) {
resource.destroy();
}
}
destroyAttachedResources() {
for (const resource of Object.values(this._attachedResources)) {
resource.destroy();
}
this._attachedResources = new Set();
}
destroyResource() {
this.destroyAttachedResources();
this.removeStats();
this.destroyed = true;
}
removeStats() {

@@ -71,3 +87,11 @@ const stats = this._device.statsManager.getStats('Resource Counts');

}
addStats() {
const stats = this._device.statsManager.getStats('Resource Counts');
const name = this[Symbol.toStringTag];
stats.get('Resources Created').incrementCount();
stats.get("".concat(name, "s Created")).incrementCount();
stats.get("".concat(name, "s Active")).incrementCount();
}
}
_defineProperty(Resource, "defaultProps", DEFAULT_RESOURCE_PROPS);
function selectivelyMerge(props, defaultProps) {

@@ -74,0 +98,0 @@ const mergedProps = {

@@ -11,23 +11,5 @@ /// <reference types="node" />

export declare type ExternalTextureData = HTMLVideoElement;
export declare type DeprecatedWebGLTextureProps = {
/** @deprecated use props.sampler */
parameters?: Record<number, number>;
/** @deprecated use props.data */
pixels?: any;
/** @deprecated use props.format */
dataFormat?: number | null;
/** @deprecated rarely supported */
border?: number;
/** @deprecated WebGL only. */
pixelStore?: object;
/** @deprecated WebGL only. */
textureUnit?: number;
/** @deprecated WebGL only. Use dimension. */
target?: number;
/** @deprecated not supported */
recreate?: boolean;
};
/** Abstract Texture interface */
export declare type TextureProps = ResourceProps & DeprecatedWebGLTextureProps & {
format?: TextureFormat | number;
export declare type TextureProps = ResourceProps & {
format?: TextureFormat;
dimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';

@@ -62,2 +44,18 @@ width?: number | undefined;

};
export declare type DeprecatedWebGLTextureProps = {
/** @deprecated use props.sampler */
parameters?: Record<number, number>;
/** @deprecated use props.data */
pixels?: any;
/** @deprecated use props.format */
dataFormat?: number | null;
/** @deprecated rarely supported */
border?: number;
/** @deprecated WebGL only. */
pixelStore?: object;
/** @deprecated WebGL only. */
textureUnit?: number;
/** @deprecated WebGL only. Use dimension. */
target?: number;
};
/**

@@ -68,3 +66,3 @@ * Abstract Texture interface

*/
export declare abstract class Texture extends Resource<TextureProps> {
export declare abstract class Texture<Props extends TextureProps = TextureProps> extends Resource<Props> {
static COPY_SRC: number;

@@ -76,6 +74,16 @@ static COPY_DST: number;

get [Symbol.toStringTag](): string;
constructor(device: Device, props: TextureProps);
/** Default sampler for this device */
/** dimension of this texture */
readonly dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
/** format of this texture */
readonly format: TextureFormat;
/** width in pixels of this texture */
width: number;
/** height in pixels of this texture */
height: number;
/** depth of this texture */
readonly depth: number;
/** Default sampler for this texture */
abstract sampler: Sampler;
constructor(device: Device, props: Props, defaultProps?: Required<Props>);
}
//# sourceMappingURL=texture.d.ts.map

@@ -9,2 +9,4 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

format: 'rgba8unorm',
width: undefined,
height: undefined,
depth: 1,

@@ -15,7 +17,5 @@ mipmaps: true,

usage: 0,
parameters: {},
pixelStore: {},
pixels: null,
border: 0,
recreate: false
mipLevels: undefined,
samples: undefined,
type: undefined
};

@@ -28,4 +28,15 @@ _Symbol$toStringTag = Symbol.toStringTag;

constructor(device, props) {
super(device, props, DEFAULT_TEXTURE_PROPS);
let defaultProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_TEXTURE_PROPS;
super(device, props, defaultProps);
_defineProperty(this, "dimension", void 0);
_defineProperty(this, "format", void 0);
_defineProperty(this, "width", void 0);
_defineProperty(this, "height", void 0);
_defineProperty(this, "depth", void 0);
_defineProperty(this, "sampler", void 0);
this.dimension = this.props.dimension;
this.format = this.props.format;
this.width = this.props.width;
this.height = this.props.height;
this.depth = this.props.depth;
}

@@ -32,0 +43,0 @@ }

@@ -12,46 +12,82 @@ import { DepthStencilTextureFormat } from './texture-formats';

declare type _RenderParameters = {
/** Defines which polygon orientation will be culled, if any. Only applies to triangle topologies/ */
cullMode?: CullMode;
/** Defines which polygons are considered front-facing. Only applies to triangle topologies. Default to "ccw" */
frontFace?: FrontFace;
/** TBD */
depthClamp?: boolean;
/** Constant depth bias (polygon offset) added to each fragment. */
depthBias?: number;
/** Depth bias (polygon offset) that scales with the fragment’s slope. */
depthBiasSlopeScale?: number;
/** Maximum depth bias of a fragment. */
depthBiasClamp?: number;
};
export declare type RasterizationParameters = _RenderParameters & {
/** The type of primitive to be constructed from the vertex inputs. Defaults to "triangle-list". */
topology?: PrimitiveTopology;
/** For pipelines with strip topologies ("line-strip" or "triangle-strip"), this determines the index buffer format and primitive restart value ("uint16"/0xFFFF or "uint32"/0xFFFFFFFF). It is not allowed on pipelines with non-strip topologies. */
stripIndexFormat?: IndexFormat;
};
/** Types of operations that can be performed on stencil buffers when various tests pass */
export declare type StencilOperation = 'keep' | 'zero' | 'replace' | 'invert' | 'increment-clamp' | 'decrement-clamp' | 'increment-wrap' | 'decrement-wrap';
export declare type DepthStencilParameters = {
/** Whether this GPURenderPipeline can modify depthStencilAttachment depth values. */
depthWriteEnabled?: boolean;
/** The comparison operation used to test fragment depths against existing depthStencilAttachment depth values. */
depthCompare?: CompareFunction;
/** The format of depthStencilAttachment this GPURenderPipeline will be compatible with. */
depthFormat?: DepthStencilTextureFormat;
/** Bitmask controlling which depthStencilAttachment stencil value bits are read when performing stencil comparison tests. */
stencilReadMask?: number;
/** Bitmask controlling which depthStencilAttachment stencil value bits are written to when performing stencil operations. */
stencilWriteMask?: number;
/** The CompareFunction used when testing fragments against depthStencilAttachment stencil values. */
stencilCompare?: CompareFunction;
/** The StencilOperation performed if the fragment stencil comparison test described by compare fails. */
stencilPassOperation?: StencilOperation;
/** The GPUStencilOperation performed if the fragment depth comparison described by depthCompare fails. */
stencilFailOperation?: StencilOperation;
/** The GPUStencilOperation performed if the fragment stencil comparison test described by compare passes. */
stencilDepthFailOperation?: StencilOperation;
};
/** BlendFactor defines how either a source or destination blend factors is calculated */
export declare type BlendFactor = 'zero' | 'one' | 'src-color' | 'one-minus-src-color' | 'src-alpha' | 'one-minus-src-alpha' | 'dst-color' | 'one-minus-dst-color' | 'dst-alpha' | 'one-minus-dst-alpha' | 'src-alpha-saturated' | 'blend-color' | 'one-minus-blend-color';
/** BlendOperation defines the algorithm used to combine source and destination blend factors: */
export declare type BlendOperation = 'add' | 'subtract' | 'reverse-subtract' | 'min' | 'max';
export declare type ColorParameters = {
/** Defines the operation used to calculate the values written to the target attachment components. */
blendColorOperation?: BlendOperation;
/** Defines the operation to be performed on values from the fragment shader. */
blendColorSrcFactor?: BlendFactor;
/** Defines the operation to be performed on values from the target attachment. */
blendColorDstFactor?: BlendFactor;
/** Defines the operation used to calculate the values written to the target attachment components. */
blendAlphaOperation?: BlendOperation;
/** Defines the operation to be performed on values from the fragment shader. */
blendAlphaSrcFactor?: BlendFactor;
/** Defines the operation to be performed on values from the target attachment. */
blendAlphaDstFactor?: BlendFactor;
/** Bitmask controlling which channels are are written to when drawing to this color target. defaulting to 0xF */
colorMask?: number;
};
/** Multisample */
export declare type MultisampleParameters = {
/** Number of samples per pixel. RenderPipeline will be compatible only with attachment textures with matching sampleCounts. */
sampleCount?: number;
/** Mask determining which samples are written to. defaulting to 0xFFFFFFFF */
sampleMask?: number;
/** When true indicates that a fragment’s alpha channel should be used to generate a sample coverage mask. */
sampleAlphaToCoverageEnabled?: boolean;
};
/** These parameters are set on the render pass and are thus easy to change frequently */
export declare type RenderPassParameters = {
viewport: number[];
scissorRect: number[];
blendConstant: number[];
stencilReference: number;
/** Linear map from normalized device coordinates to viewport coordinates [x, y, width, height, minDepth, maxDepth] */
viewport?: number[];
/** Sets scissor rectangle used during rasterization. Discards fragments outside viewport coords [x, y, width, height]. */
scissorRect?: number[];
/** Sets constant blend color and alpha values used with "constant" and "one-minus-constant" blend factors. */
blendConstant?: number[];
/** Stencil operation "replace" sets the value to stencilReference */
stencilReference?: number;
};

@@ -58,0 +94,0 @@ export declare type RenderPipelineParameters = RasterizationParameters & DepthStencilParameters & ColorParameters & MultisampleParameters;

@@ -11,3 +11,3 @@ /** Texture formats */

/** Sized formats unique to WebGL 2. Will perhaps be added to WebGPU? */
export declare type WebGL2ColorTextureFormat = 'r16unorm-webgl' | 'r16snorm-webgl' | 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl' | 'rbg8unorm-webgl' | 'rbg8snorm-webgl' | 'rg16unorm-webgl' | 'rg16snorm-webgl' | 'rgb10a2unorm-webgl' | 'rgb16unorm-webgl' | 'rgb16snorm-webgl' | 'rgba16unorm-webgl' | 'rgba16snorm-webgl' | 'rgb32float-webgl' | 'bc1-rgb-unorm-webgl' | 'bc1-rgb-unorm-srgb-webgl' | 'pvrtc-rgb4unorm-webgl' | 'pvrtc-rgba4unorm-webgl' | 'pvrtc-rbg2unorm-webgl' | 'pvrtc-rgba2unorm-webgl' | 'etc1-rbg-unorm-webgl' | 'atc-rgb-unorm-webgl' | 'atc-rgba-unorm-webgl' | 'atc-rgbai-unorm-webgl';
export declare type WebGL2ColorTextureFormat = 'r16unorm-webgl' | 'r16snorm-webgl' | 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl' | 'rgb8unorm-webgl' | 'rgb8snorm-webgl' | 'rg16unorm-webgl' | 'rg16snorm-webgl' | 'rgb10a2unorm-webgl' | 'rgb16unorm-webgl' | 'rgb16snorm-webgl' | 'rgba16unorm-webgl' | 'rgba16snorm-webgl' | 'rgb32float-webgl' | 'bc1-rgb-unorm-webgl' | 'bc1-rgb-unorm-srgb-webgl' | 'pvrtc-rgb4unorm-webgl' | 'pvrtc-rgba4unorm-webgl' | 'pvrtc-rbg2unorm-webgl' | 'pvrtc-rgba2unorm-webgl' | 'etc1-rbg-unorm-webgl' | 'atc-rgb-unorm-webgl' | 'atc-rgba-unorm-webgl' | 'atc-rgbai-unorm-webgl';
//# sourceMappingURL=texture-formats.d.ts.map

@@ -1,2 +0,2 @@

import { TextureFormat } from './texture-formats';
import type { ColorTextureFormat, DepthStencilTextureFormat, TextureFormat } from './texture-formats';
declare type BufferBindingLayout = {

@@ -36,24 +36,45 @@ location?: number;

};
export declare type ColorAttachmentOptions = {
clearColor?: number[];
storeOp: 'store' | 'discard';
/**
* Framebuffer attachments lets the user specify the textures that will be used for a RenderPass,
* together with some additional options for how to clear.
*/
export declare type ColorAttachment = {
/** Describes the texture subresource that will be output to for this color attachment. */
texture?: Texture;
/** Format of the texture resource. Used to auto create texture if not supplied */
format?: ColorTextureFormat;
/** Value to clear to prior to executing the render pass. Default: [0, 0, 0, 0]. Ignored if loadOp is not "clear". */
clearValue?: number[];
/** load operation to perform on texture prior to executing the render pass. Default: 'clear'. */
loadOp?: 'load' | 'clear';
/** The store operation to perform on texture after executing the render pass. Default: 'store'. */
storeOp?: 'store' | 'discard';
};
export declare type DepthStencilAttachmentOptions = {
/**
* Framebuffer attachments lets the user specify the depth stencil texture that will be used for a RenderPass,
* together with some additional options for how to clear.
*/
export declare type DepthStencilAttachment = {
/** Describes the texture subresource that will be output to and read from for this depth/stencil attachment. */
texture?: Texture;
/** Format of the texture resource. Used to auto create texture if not supplied */
format?: DepthStencilTextureFormat;
/** Value to clear depth component to prior to executing the render pass, if depthLoadOp is "clear". 0.0-1.0. */
depthClearValue?: number;
/** Indicates load operation to perform on depth component prior to executing the render pass. Default 'clear'. */
depthLoadOp?: 'load' | 'clear';
/** Store operation to perform on depth component after executing the render pass. Default: 'store'. */
depthStoreOp?: 'store' | 'discard';
/** Indicates that the depth component is read only. */
depthReadOnly?: boolean;
stencilClearValue?: 'load' | number;
/** Indicates value to clear stencil component to prior to executing the render pass, if stencilLoadOp is "clear". */
stencilClearValue?: number;
/** Indicates load operation to perform on stencil component prior to executing the render pass. Prefer clearing. */
stencilLoadOp?: 'load' | 'clear';
/** Store operation to perform on stencil component after executing the render pass. */
stencilStoreOp?: 'store' | 'discard';
/** Indicates that the stencil component is read only. */
stencilReadOnly?: boolean;
};
/** @todo */
export declare type ColorAttachment = ColorAttachmentOptions & {
texture: Texture | TextureView;
resolveTarget?: Texture;
};
/** @todo */
export declare type DepthStencilAttachment = DepthStencilAttachmentOptions & {
texture: Texture;
};
export {};
//# sourceMappingURL=types.d.ts.map
import { TextureFormat } from '../types/texture-formats';
import { VertexType } from '../types/vertex-formats';
/**
* Decodes a vertex format, returning type, components, byte length and flags (integer, signed, normalized)
*/
export declare function decodeTextureFormat(format: TextureFormat): {
export declare type DecodedTextureFormat = {
format: string;

@@ -18,2 +15,6 @@ components: number;

};
/**
* Decodes a vertex format, returning type, components, byte length and flags (integer, signed, normalized)
*/
export declare function decodeTextureFormat(format: TextureFormat): DecodedTextureFormat;
//# sourceMappingURL=decode-texture-format.d.ts.map

@@ -20,4 +20,82 @@ import { decodeVertexType } from "./decode-data-type.js";

}
throw new Error("Unknown format ".concat(format));
return decodeNonStandardFormat(format);
}
const EXCEPTIONS = {
'rgba4unorm-webgl': {
format: 'rgba',
bpp: 2
},
'rgb565unorm-webgl': {
format: 'rgb',
bpp: 2
},
'rgb5a1unorm-webgl': {
format: 'rgba',
bbp: 2
},
'rgb9e5ufloat': {
format: 'rgb',
bbp: 4
},
'rg11b10ufloat': {
format: 'rgb',
bbp: 4
},
'rgb10a2unorm': {
format: 'rgba',
bbp: 4
},
'rgb10a2unorm-webgl': {
format: 'rgba',
bbp: 4
},
'stencil8': {
components: 1,
bpp: 1,
a: 'stencil'
},
'depth16unorm': {
components: 1,
bpp: 2,
a: 'depth'
},
'depth24plus': {
components: 1,
bpp: 3,
a: 'depth'
},
'depth32float': {
components: 1,
bpp: 4,
a: 'depth'
},
'depth24plus-stencil8': {
components: 2,
bpp: 4,
a: 'depth-stencil'
},
'depth24unorm-stencil8': {
components: 2,
bpp: 4,
a: 'depth-stencil'
},
'depth32float-stencil8': {
components: 2,
bpp: 4,
a: 'depth-stencil'
}
};
function decodeNonStandardFormat(format) {
const data = EXCEPTIONS[format];
if (!data) {
throw new Error("Unknown format ".concat(format));
}
return {
format: data.format || '',
components: data.components || 1,
byteLength: data.bpp || 1,
srgb: false,
unsized: false
};
}
//# sourceMappingURL=decode-texture-format.js.map

@@ -25,4 +25,2 @@ export { VERSION } from './init';

export { ComputePipeline } from './adapter/resources/compute-pipeline';
export type { CommandEncoderProps } from './adapter/resources/command-encoder';
export { CommandEncoder } from './adapter/resources/command-encoder';
export type { RenderPassProps } from './adapter/resources/render-pass';

@@ -32,3 +30,6 @@ export { RenderPass } from './adapter/resources/render-pass';

export { ComputePass } from './adapter/resources/compute-pass';
export type { CompilerMessage } from './lib/compiler-log/compiler-message';
export type { CommandEncoderProps } from './adapter/resources/command-encoder';
export { CommandEncoder } from './adapter/resources/command-encoder';
export type { CommandBufferProps } from './adapter/resources/command-buffer';
export { CommandBuffer } from './adapter/resources/command-buffer';
export type { AccessorObject } from './adapter/types/accessor';

@@ -45,3 +46,6 @@ export type { Parameters, PrimitiveTopology, IndexFormat, CullMode, FrontFace, RasterizationParameters, CompareFunction, StencilOperation, DepthStencilParameters, BlendFactor, BlendOperation, ColorParameters, MultisampleParameters, RenderPassParameters, RenderPipelineParameters } from './adapter/types/parameters';

export { decodeTextureFormat } from './adapter/utils/decode-texture-format';
export type { TypedArray, TypedArrayConstructor, NumberArray, NumericArray, BigIntOrNumberArray, BigIntOrNumericArray, ConstructorOf, PartialBy } from './types';
export type { CompilerMessage } from './lib/compiler-log/compiler-message';
export { formatCompilerLog } from './lib/compiler-log/format-compiler-log';
export type { ConstructorOf, PartialBy } from './types';
export type { TypedArray, TypedArrayConstructor, NumberArray, NumericArray, BigIntOrNumberArray, BigIntOrNumericArray } from './types';
export { StatsManager } from './lib/utils/stats-manager';

@@ -58,3 +62,2 @@ export { assert } from './lib/utils/assert';

export { getRandom, random } from './lib/utils/random';
export { formatCompilerLog } from './lib/compiler-log/format-compiler-log';
export { requestAnimationFrame, cancelAnimationFrame } from './lib/request-animation-frame';

@@ -61,0 +64,0 @@ /**

@@ -14,5 +14,6 @@ export { VERSION } from "./init.js";

export { ComputePipeline } from "./adapter/resources/compute-pipeline.js";
export { CommandEncoder } from "./adapter/resources/command-encoder.js";
export { RenderPass } from "./adapter/resources/render-pass.js";
export { ComputePass } from "./adapter/resources/compute-pass.js";
export { CommandEncoder } from "./adapter/resources/command-encoder.js";
export { CommandBuffer } from "./adapter/resources/command-buffer.js";
export { UniformBufferLayout } from "./lib/uniform-buffer-layout.js";

@@ -22,2 +23,3 @@ export { UniformBlock } from "./lib/uniform-block.js";

export { decodeTextureFormat } from "./adapter/utils/decode-texture-format.js";
export { formatCompilerLog } from "./lib/compiler-log/format-compiler-log.js";
export { StatsManager } from "./lib/utils/stats-manager.js";

@@ -34,5 +36,4 @@ export { assert } from "./lib/utils/assert.js";

export { getRandom, random } from "./lib/utils/random.js";
export { formatCompilerLog } from "./lib/compiler-log/format-compiler-log.js";
export { requestAnimationFrame, cancelAnimationFrame } from "./lib/request-animation-frame.js";
export const glsl = x => "".concat(x);
//# sourceMappingURL=index.js.map
{
"name": "@luma.gl/api",
"version": "9.0.0-alpha.21",
"version": "9.0.0-alpha.23",
"description": "luma.gl API",

@@ -45,3 +45,3 @@ "license": "MIT",

},
"gitHead": "7ee95470a6a2f62753201beb0c36b00e37c70455"
"gitHead": "5e4a30497333bea4be8f2b3f3db33c0b67931b9c"
}

@@ -145,12 +145,16 @@ // luma.gl, MIT license

}
useDevicePixels = useDevicePixels === undefined ? this.props.useDevicePixels : useDevicePixels;
if (!useDevicePixels || useDevicePixels as number <= 0) {
return 1;
}
// The param was mainly provide to support the test cases, could be removed
if (typeof useDevicePixels === 'number') {
return useDevicePixels > 0 ? useDevicePixels : 1;
if (useDevicePixels === true) {
const dpr = typeof window !== 'undefined' && window.devicePixelRatio;
return dpr || 1;
}
if (typeof this.props.useDevicePixels === 'number') {
return this.props.useDevicePixels > 0 ? this.props.useDevicePixels : 1;
}
return useDevicePixels || this.props.useDevicePixels
? (typeof window !== 'undefined' && window.devicePixelRatio) || 1
: 1;
return useDevicePixels;
}

@@ -157,0 +161,0 @@

@@ -6,3 +6,3 @@ // luma.gl, MIT license

import {uid} from '../lib/utils/utils';
import {TextureFormat} from './types/texture-formats';
import type {TextureFormat} from './types/texture-formats';
import type {CanvasContext, CanvasContextProps} from './canvas-context';

@@ -20,2 +20,3 @@ import type {BufferProps} from './resources/buffer';

import type {ComputePass, ComputePassProps} from './resources/compute-pass';
import type {CommandEncoder, CommandEncoderProps} from './resources/command-encoder';

@@ -222,2 +223,4 @@ /** Device properties */

// Capabilities
/** Information about the device (vendor, versions etc) */

@@ -241,9 +244,22 @@ abstract info: DeviceInfo;

/** True context is already lost */
// Device loss
/** `true` if device is already lost */
abstract get isLost(): boolean;
/** Promise that resolves when context is lost */
/** Promise that resolves when device is lost */
abstract readonly lost: Promise<{reason: 'destroyed'; message: string}>;
/** default canvas context */
/**
* Trigger device loss.
* @returns `true` if context loss could actually be triggered.
* @note primarily intended for testing how application reacts to device loss
*/
loseDevice(): boolean {
return false;
}
// Canvas context
/** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */
abstract canvasContext: CanvasContext | null;

@@ -260,25 +276,6 @@

/** Create a buffer */
createBuffer(props: BufferProps): Buffer;
createBuffer(data: ArrayBuffer | ArrayBufferView): Buffer;
abstract createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): Buffer;
createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): Buffer {
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
return this._createBuffer({data: props});
}
// TODO - fragile, as this is done before we merge with default options
// inside the Buffer constructor
// Deduce indexType
if ((props.usage || 0) & Buffer.INDEX && !props.indexType) {
if (props.data instanceof Uint32Array) {
props.indexType = 'uint32';
} else if (props.data instanceof Uint16Array) {
props.indexType = 'uint16';
}
}
return this._createBuffer(props);
}
/** Create a texture */
abstract _createTexture(props: TextureProps): Texture;
createTexture(props: TextureProps): Texture;

@@ -313,4 +310,8 @@ createTexture(data: Promise<TextureData>): Texture;

createCommandEncoder(props: CommandEncoderProps = {}): CommandEncoder {
throw new Error('not implemented');
}
/** Create a RenderPass */
abstract beginRenderPass(props: RenderPassProps): RenderPass;
abstract beginRenderPass(props?: RenderPassProps): RenderPass;

@@ -320,8 +321,27 @@ /** Create a ComputePass */

/** Get a renderpass that is set up to render to the primary CanvasContext */
abstract getDefaultRenderPass(): RenderPass;
// Implementation
// Resource creation helpers
protected abstract _createBuffer(props: BufferProps): Buffer;
protected abstract _createTexture(props: TextureProps): Texture;
protected _getBufferProps(props: BufferProps | ArrayBuffer | ArrayBufferView): BufferProps {
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
return {data: props};
}
// TODO - fragile, as this is done before we merge with default options
// inside the Buffer constructor
const newProps = {...props};
// Deduce indexType
if ((props.usage || 0) & Buffer.INDEX && !props.indexType) {
if (props.data instanceof Uint32Array) {
props.indexType = 'uint32';
} else if (props.data instanceof Uint16Array) {
props.indexType = 'uint16';
}
}
return newProps;
}
}

@@ -7,8 +7,13 @@ // luma.gl, MIT license

export type BufferProps = ResourceProps & {
/** Supply a handle to connect to an existing device-specific buffer */
handle?: WebGLBuffer;
/** Specifies how this buffer can be used */
usage?: number;
/** Length in bytes of memory to be allocated. If not specified, `byteLength` of `props.data` will be used. */
byteLength?: number;
/** Data to initialize the buffer with. */
data?: ArrayBuffer | ArrayBufferView | null;
/** Byte offset into the newly created Buffer to store data at */
byteOffset?: number;
/** If props.usage & Buffer.INDEX */
/** If props.usage includes Buffer.INDEX */
indexType?: 'uint16' | 'uint32';

@@ -61,2 +66,5 @@

/** Length of buffer in bytes */
abstract byteLength: number;
constructor(device: Device, props: BufferProps) {

@@ -63,0 +71,0 @@ const deducedProps = {...props};

@@ -15,44 +15,91 @@ // luma.gl, MIT license

export type WriteTextureOptions = {
destination: Texture,
mipLevel?: number // = 0;
origin?: [number, number, number] | number[],
destination: Texture;
mipLevel?: number; // = 0;
origin?: [number, number, number] | number[];
aspect?: 'all' | 'stencil-only' | 'depth-only';
data: BufferSource,
// dataLayout,
offset: number,
bytesPerRow: number,
rowsPerImage: number,
size: [number, number, number] | number[],
data: BufferSource;
// dataLayout;
offset: number;
bytesPerRow: number;
rowsPerImage: number;
size: [number, number, number] | number[];
}
export type CopyBufferToBufferOptions = {
source: Buffer,
sourceOffset?: number,
destination: Buffer,
destinationOffset?: number,
size: number
source: Buffer;
sourceOffset?: number;
destination: Buffer;
destinationOffset?: number;
size: number;
};
export type CopyBufferToTextureOptions = {
destination: Texture,
source: Buffer;
byteOffset?: number;
destination: Texture;
mipLevel?: number // = 0;
origin?: [number, number, number] | number[],
origin?: [number, number, number] | number[];
aspect?: 'all' | 'stencil-only' | 'depth-only';
source: Buffer,
offset: number,
bytesPerRow: number,
rowsPerImage: number,
size: [number, number, number] | number[],
bytesPerRow: number;
rowsPerImage: number;
size: [number, number, number] | number[];
};
export type CopyTextureToBufferOptions = {
// source: GPUImageCopyTexture,
// destination: GPUImageCopyBuffer,
// copySize: GPUExtent3D
/** Texture to copy to/from. */
source: Texture;
/** Mip-map level of the texture to copy to/from. (Default 0) */
mipLevel?: number;
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from.
* Together with `copySize`, defines the full copy sub-region.
*/
/** Defines which aspects of the texture to copy to/from. */
aspect?: 'all' | 'stencil-only' | 'depth-only';
/** Width to copy */
width?: number;
height?: number;
depthOrArrayLayers?: number;
origin?: number[];
/** Destination buffer */
destination: Buffer;
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
byteOffset?: number;
/**
* The stride, in bytes, between the beginning of each block row and the subsequent block row.
* Required if there are multiple block rows (i.e. the copy height or depth is more than one block).
*/
bytesPerRow?: number;
/**
* Number of block rows per single image of the texture.
* rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.
* Required if there are multiple images (i.e. the copy depth is more than one).
*/
rowsPerImage?: number;
};
export type CopyTextureToTextureOptions = {
// source: GPUImageCopyTexture ,
// destination: GPUImageCopyTexture,
// copySize: GPUExtent3D
/** Texture to copy to/from. */
source: Texture;
/** Mip-map level of the texture to copy to/from. (Default 0) */
mipLevel?: number;
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy from. */
/** Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from. */
aspect?: 'all' | 'stencil-only' | 'depth-only';
/** Texture to copy to/from. */
destination: Texture;
/** Mip-map level of the texture to copy to/from. (Default 0) */
destinationMipLevel?: number;
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
destinationOrigin?: number[];
/** Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from. */
destinationAspect?: 'all' | 'stencil-only' | 'depth-only';
origin?: number[];
/** Width to copy */
width?: number;
height?: number;
depthOrArrayLayers?: number;
};

@@ -95,2 +142,4 @@

}
abstract finish(): void; // TODO - return the CommandBuffer?

@@ -97,0 +146,0 @@ // beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;

@@ -1,6 +0,8 @@

import type {ColorTextureFormat, DepthStencilTextureFormat} from '../types/texture-formats';
// import type {ColorAttachment, DepthStencilAttachment} from '../types/types';
// luma.gl, MIT license
import type {ColorTextureFormat, DepthStencilTextureFormat, TextureFormat} from '../types/texture-formats';
import type {Device} from '../device';
import {Resource, ResourceProps, DEFAULT_RESOURCE_PROPS} from './resource';
import {Texture} from './texture';
import {log} from '../../lib/utils/log';

@@ -11,3 +13,3 @@ export type FramebufferProps = ResourceProps & {

colorAttachments?: (Texture | ColorTextureFormat)[];
depthStencilAttachment?: Texture | DepthStencilTextureFormat | null;
depthStencilAttachment?: (Texture | DepthStencilTextureFormat) | null;
};

@@ -28,3 +30,5 @@

export abstract class Framebuffer extends Resource<FramebufferProps> {
override get [Symbol.toStringTag](): string { return 'Framebuffer'; }
override get [Symbol.toStringTag](): string {
return 'Framebuffer';
}

@@ -35,9 +39,14 @@ /** Width of all attachments in this framebuffer */

height: number;
abstract colorAttachments: Texture[];
abstract depthStencilAttachment: Texture | null;
/** Color attachments */
colorAttachments: Texture[] = [];
/** Depth-stencil attachment, if provided */
depthStencilAttachment: Texture | null = null;
constructor(device: Device, props: FramebufferProps = {}) {
super(device, props, DEFAULT_FRAMEBUFFER_PROPS)
super(device, props, DEFAULT_FRAMEBUFFER_PROPS);
this.width = this.props.width;
this.height = this.props.height;
// NOTE: call from subclass constructor as we cannot call overridden methods here (subclass not yet constructed)
// this.autoCreateAttachmentTextures();
}

@@ -49,15 +58,176 @@

*/
resize(size?: {width: number, height: number}): void {
const updateSize = !size || (size.height !== this.height || size.width !== this.width);
resize(size: {width: number; height: number;}): void;
resize(size: [width: number, height: number]): void;
resize(): void;
resize(size?: {width: number; height: number} | [width: number, height: number]): void {
let updateSize: boolean = !size;
if (size) {
this.width = size?.width;
this.height = size?.height;
const [width, height] = Array.isArray(size) ? size : [size.width, size.height];
updateSize = updateSize || height !== this.height || width !== this.width;
this.width = width;
this.height = height;
}
if (updateSize) {
this._resizeAttachments(this.width, this.height);
log.log(2, `Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)();
this.resizeAttachments(this.width, this.height);
}
}
/** Implementation of resize */
protected abstract _resizeAttachments(width: number, height: number): void;
// /** Returns fully populated attachment object. */
// protected normalizeColorAttachment(
// attachment: Texture | ColorTextureFormat
// ): Required<ColorAttachment> {
// const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {
// texture: undefined!,
// format: undefined!,
// clearValue: [0.0, 0.0, 0.0, 0.0],
// loadOp: 'clear',
// storeOp: 'store'
// };
// if (attachment instanceof Texture) {
// return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};
// }
// if (typeof attachment === 'string') {
// return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};
// }
// return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};
// }
// /** Wraps texture inside fully populated attachment object. */
// protected normalizeDepthStencilAttachment(
// attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat
// ): Required<DepthStencilAttachment> {
// const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {
// texture: undefined!,
// format: undefined!,
// depthClearValue: 1.0,
// depthLoadOp: 'clear',
// depthStoreOp: 'store',
// depthReadOnly: false,
// stencilClearValue: 0,
// stencilLoadOp: 'clear',
// stencilStoreOp: 'store',
// stencilReadOnly: false
// };
// if (typeof attachment === 'string') {
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};
// }
// // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer
// if (attachment.handle || attachment instanceof Texture) {
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};
// }
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};
// }
/** Auto creates any textures */
protected autoCreateAttachmentTextures(){
this.colorAttachments = this.props.colorAttachments.map(attachment => {
if (typeof attachment === 'string') {
const texture = this.createColorTexture(attachment);
this.attachResource(texture);
return texture;
}
return attachment;
});
if (this.props.depthStencilAttachment) {
if (typeof this.props.depthStencilAttachment === 'string') {
const texture = this.createDepthStencilTexture(this.props.depthStencilAttachment);
this.attachResource(texture);
this.depthStencilAttachment = texture;
} else {
this.depthStencilAttachment = this.props.depthStencilAttachment;
}
}
}
/** Create a color texture */
protected createColorTexture(format: TextureFormat): Texture {
return this.device.createTexture({
id: 'color-attachment',
usage: Texture.RENDER_ATTACHMENT,
format,
width: this.width,
height: this.height,
});
}
/** Create depth stencil texture */
protected createDepthStencilTexture(format: TextureFormat): Texture {
return this.device.createTexture({
id: 'depth-stencil-attachment',
usage: Texture.RENDER_ATTACHMENT,
format,
width: this.width,
height: this.height
});
}
/**
* Default implementation of resize
* Creates new textures with correct size for all attachments.
* and destroys existing textures if owned
*/
protected resizeAttachments(width: number, height: number): void {
for (let i = 0; i < this.colorAttachments.length; ++i) {
if (this.colorAttachments[i]) {
const resizedTexture = this.device._createTexture({
...this.colorAttachments[i].props,
width,
height
});
this.destroyAttachedResource(this.colorAttachments[i]);
this.colorAttachments[i] = resizedTexture;
this.attachResource(resizedTexture);
}
}
if (this.depthStencilAttachment) {
const resizedTexture = this.device._createTexture({
...this.depthStencilAttachment.props,
width,
height
});
this.destroyAttachedResource(this.depthStencilAttachment);
this.depthStencilAttachment = resizedTexture;
this.attachResource(resizedTexture);
}
}
/** Create a color attachment for WebGL *
protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {
return this.device._createTexture({
id: `${this.id}-color`,
data: null, // reserves texture memory, but texels are undefined
format,
// type: GL.UNSIGNED_BYTE,
width: this.width,
height: this.height,
// Note: Mipmapping can be disabled by texture resource when we resize the texture
// to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
// behavior we always disable mipmaps.
mipmaps: false,
// Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
// Use LINEAR so subpixel algos like fxaa work.
// Set WRAP modes that support NPOT textures too.
sampler: {
minFilter: 'linear',
magFilter: 'linear',
addressModeU: 'clamp-to-edge',
addressModeV: 'clamp-to-edge'
}
// parameters: {
// [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
// [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
// [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
// [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
// }
});
}
*/
}

@@ -5,3 +5,3 @@ // luma.gl, MIT license

// import {Binding} from '../types/shader-layout';
import {Resource, ResourceProps, DEFAULT_RESOURCE_PROPS} from './resource';
import {Resource, ResourceProps} from './resource';
// import {Buffer} from './buffer';

@@ -11,15 +11,44 @@ // import {RenderPipeline} from './render-pipeline';

import {Framebuffer} from './framebuffer';
import {NumericArray} from '../..';
/**
* - Framebuffer specifies which textures to render into
* - parameters control viewport, scissor rect, blend constant and stencil ref
* - clearColor, depthClearValue, stencilClearValue control clearing at beginning of render pass.
* - discard disables rasterizer.
*/
export type RenderPassProps = ResourceProps & {
/** Framebuffer specifies which textures to render into. Default gets framebuffer from canvas context. */
framebuffer?: Framebuffer | null;
parameters?: RenderPassParameters | null
/** Control viewport, scissor rect, blend constant and stencil ref */
parameters?: RenderPassParameters;
/** Clear value for color attachment, or `load` to preserve the previous value */
clearColor?: NumericArray | false;
/** Clear value for depth attachment, or `load` to preserve the previous value */
clearDepth?: number | false;
/** Clear value for stencil attachment, or `load` to preserve the previous value */
clearStencil?: number | false;
/** Indicates that the depth component is read only. */
depthReadOnly?: boolean;
/** Indicates that the stencil component is read only. */
stencilReadOnly?: boolean;
/** Whether to disable / discard the output of the rasterizer */
discard?: boolean;
};
const DEFAULT_RENDERPASS_PROPS: Required<RenderPassProps> = {
...DEFAULT_RESOURCE_PROPS,
framebuffer: null,
parameters: null
}
export abstract class RenderPass extends Resource<RenderPassProps> {
export abstract class RenderPass extends Resource<RenderPassProps> {
/** Default properties for RenderPass */
static override defaultProps: Required<RenderPassProps> = {
...Resource.defaultProps,
framebuffer: null,
parameters: undefined,
clearColor: [0, 0, 0, 0],
clearDepth: 1,
clearStencil: 0,
depthReadOnly: false,
stencilReadOnly: false,
discard: false
};
override get [Symbol.toStringTag](): string {

@@ -30,5 +59,8 @@ return 'RenderPass';

constructor(device: Device, props: RenderPassProps) {
super(device, props, DEFAULT_RENDERPASS_PROPS);
super(device, props, RenderPass.defaultProps);
}
/** A small set of parameters can be changed between every draw call (viewport, scissorRect, blendColor, stencilReference) */
abstract setParameters(parameters: RenderPassParameters): void;
abstract end(): void;

@@ -35,0 +67,0 @@

@@ -6,11 +6,18 @@ // luma.gl, MIT license

export type ResourceProps = {
/** Name of resource, mainly for debugging purposes. A unique name will be assigned if not provided */
id?: string;
/** Handle for the underlying resources (WebGL object or WebGPU handle) */
handle?: any;
/** User provided data stored on this resource */
userData?: {[key: string]: any};
}
/**
* Default properties for resource
* @deprecated Use Resource.defaultProps
*/
export const DEFAULT_RESOURCE_PROPS: Required<ResourceProps> = {
id: 'undefined',
handle: undefined,
userData: {}
userData: undefined,
};

@@ -22,2 +29,5 @@

export abstract class Resource<Props extends ResourceProps> {
/** Default properties for resource */
static defaultProps: Required<ResourceProps> = DEFAULT_RESOURCE_PROPS
abstract get [Symbol.toStringTag](): string;

@@ -32,6 +42,10 @@

/** Whether this resource has been destroyed */
destroyed: boolean = false;
/** For resources that allocate GPU memory */
private allocatedBytes: number = 0;
/** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
private _attachedResources = new Set<Resource<unknown>>();
/**

@@ -50,4 +64,4 @@ * Create a new Resource. Called from Subclass

this.id = id;
this.userData = this.props.userData || {};
this.userData = this.props.userData || {};
this.addStats();

@@ -60,3 +74,3 @@ }

destroy(): void {
this.removeStats();
this.destroyResource();
}

@@ -82,11 +96,44 @@

// ATTACHED RESOURCES
/**
* Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
* Called automatically when sub resources are auto created but can be called by application
*/
attachResource(resource: Resource<unknown>): void {
this._attachedResources.add(resource);
}
/**
* Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
*/
detachResource(resource: Resource<unknown>): void {
this._attachedResources.delete(resource);
}
/**
* Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
*/
destroyAttachedResource(resource: Resource<unknown>): void {
if (this._attachedResources.delete(resource)) {
resource.destroy();
}
}
/** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
destroyAttachedResources(): void {
for (const resource of Object.values(this._attachedResources)) {
resource.destroy();
}
// don't remove while we are iterating
this._attachedResources = new Set<Resource<unknown>>();
}
// PROTECTED METHODS
/** Called by resource constructor to track object creation */
private addStats(): void {
const stats = this._device.statsManager.getStats('Resource Counts');
const name = this[Symbol.toStringTag];
stats.get('Resources Created').incrementCount();
stats.get(`${name}s Created`).incrementCount();
stats.get(`${name}s Active`).incrementCount();
/** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
protected destroyResource(): void {
this.destroyAttachedResources();
this.removeStats();
this.destroyed = true;
}

@@ -116,2 +163,11 @@

}
/** Called by resource constructor to track object creation */
private addStats(): void {
const stats = this._device.statsManager.getStats('Resource Counts');
const name = this[Symbol.toStringTag];
stats.get('Resources Created').incrementCount();
stats.get(`${name}s Created`).incrementCount();
stats.get(`${name}s Active`).incrementCount();
}
}

@@ -118,0 +174,0 @@

// luma.gl, MIT license
import type {Device} from '../device';
import type {TypedArray, PartialBy} from '../../types';
import type {TypedArray} from '../../types';
import type {TextureFormat} from '../types/texture-formats';

@@ -27,24 +27,5 @@ import {Resource, ResourceProps, DEFAULT_RESOURCE_PROPS} from './resource';

export type DeprecatedWebGLTextureProps = {
/** @deprecated use props.sampler */
parameters?: Record<number, number>;
/** @deprecated use props.data */
pixels?: any;
/** @deprecated use props.format */
dataFormat?: number | null;
/** @deprecated rarely supported */
border?: number;
/** @deprecated WebGL only. */
pixelStore?: object;
/** @deprecated WebGL only. */
textureUnit?: number;
/** @deprecated WebGL only. Use dimension. */
target?: number;
/** @deprecated not supported */
recreate?: boolean;
};
/** Abstract Texture interface */
export type TextureProps = ResourceProps & DeprecatedWebGLTextureProps & {
format?: TextureFormat | number;
export type TextureProps = ResourceProps & {
format?: TextureFormat;
dimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';

@@ -84,3 +65,20 @@ width?: number | undefined;

const DEFAULT_TEXTURE_PROPS: PartialBy<Required<TextureProps>, 'width' | 'height' | 'type' | 'samples' | 'mipLevels' | 'textureUnit' | 'target' | 'dataFormat'> = {
export type DeprecatedWebGLTextureProps = {
/** @deprecated use props.sampler */
parameters?: Record<number, number>;
/** @deprecated use props.data */
pixels?: any;
/** @deprecated use props.format */
dataFormat?: number | null;
/** @deprecated rarely supported */
border?: number;
/** @deprecated WebGL only. */
pixelStore?: object;
/** @deprecated WebGL only. */
textureUnit?: number;
/** @deprecated WebGL only. Use dimension. */
target?: number;
};
const DEFAULT_TEXTURE_PROPS: Required<TextureProps> = {
...DEFAULT_RESOURCE_PROPS,

@@ -90,4 +88,4 @@ data: null,

format: 'rgba8unorm',
// width: undefined,
// height: undefined,
width: undefined!,
height: undefined!,
depth: 1,

@@ -100,7 +98,5 @@ mipmaps: true,

usage: 0,
parameters: {},
pixelStore: {},
pixels: null,
border: 0,
recreate: false
mipLevels: undefined!,
samples: undefined!,
type: undefined!
};

@@ -121,3 +117,3 @@

*/
export abstract class Texture extends Resource<TextureProps> {
export abstract class Texture<Props extends TextureProps = TextureProps> extends Resource<Props> {
static COPY_SRC = 0x01;

@@ -131,9 +127,23 @@ static COPY_DST = 0x02;

constructor(device: Device, props: TextureProps) {
// @ts-expect-error
super(device, props, DEFAULT_TEXTURE_PROPS);
/** dimension of this texture */
readonly dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
/** format of this texture */
readonly format: TextureFormat;
/** width in pixels of this texture */
width: number;
/** height in pixels of this texture */
height: number;
/** depth of this texture */
readonly depth: number;
/** Default sampler for this texture */
abstract sampler: Sampler;
constructor(device: Device, props: Props, defaultProps = DEFAULT_TEXTURE_PROPS as Required<Props>) {
super(device, props, defaultProps);
this.dimension = this.props.dimension;
this.format = this.props.format ;
this.width = this.props.width;
this.height = this.props.height;
this.depth = this.props.depth;
}
/** Default sampler for this device */
abstract sampler: Sampler;
}

@@ -34,7 +34,13 @@ import {DepthStencilTextureFormat} from './texture-formats';

type _RenderParameters = {
/** Defines which polygon orientation will be culled, if any. Only applies to triangle topologies/ */
cullMode?: CullMode;
/** Defines which polygons are considered front-facing. Only applies to triangle topologies. Default to "ccw" */
frontFace?: FrontFace;
/** TBD */
depthClamp?: boolean;
/** Constant depth bias (polygon offset) added to each fragment. */
depthBias?: number;
/** Depth bias (polygon offset) that scales with the fragment’s slope. */
depthBiasSlopeScale?: number;
/** Maximum depth bias of a fragment. */
depthBiasClamp?: number;

@@ -44,3 +50,5 @@ }

export type RasterizationParameters = _RenderParameters & {
/** The type of primitive to be constructed from the vertex inputs. Defaults to "triangle-list". */
topology?: PrimitiveTopology;
/** For pipelines with strip topologies ("line-strip" or "triangle-strip"), this determines the index buffer format and primitive restart value ("uint16"/0xFFFF or "uint32"/0xFFFFFFFF). It is not allowed on pipelines with non-strip topologies. */
stripIndexFormat?: IndexFormat; // WebGPU only

@@ -51,2 +59,3 @@ }

/** Types of operations that can be performed on stencil buffers when various tests pass */
export type StencilOperation =

@@ -63,12 +72,21 @@ 'keep' |

export type DepthStencilParameters = {
/** Whether this GPURenderPipeline can modify depthStencilAttachment depth values. */
depthWriteEnabled?: boolean;
/** The comparison operation used to test fragment depths against existing depthStencilAttachment depth values. */
depthCompare?: CompareFunction;
/** The format of depthStencilAttachment this GPURenderPipeline will be compatible with. */
depthFormat?: DepthStencilTextureFormat;
/** Bitmask controlling which depthStencilAttachment stencil value bits are read when performing stencil comparison tests. */
stencilReadMask?: number;
/** Bitmask controlling which depthStencilAttachment stencil value bits are written to when performing stencil operations. */
stencilWriteMask?: number;
/** The CompareFunction used when testing fragments against depthStencilAttachment stencil values. */
stencilCompare?: CompareFunction;
/** The StencilOperation performed if the fragment stencil comparison test described by compare fails. */
stencilPassOperation?: StencilOperation;
/** The GPUStencilOperation performed if the fragment depth comparison described by depthCompare fails. */
stencilFailOperation?: StencilOperation;
/** The GPUStencilOperation performed if the fragment stencil comparison test described by compare passes. */
stencilDepthFailOperation?: StencilOperation;

@@ -79,2 +97,3 @@ }

/** BlendFactor defines how either a source or destination blend factors is calculated */
export type BlendFactor =

@@ -95,2 +114,3 @@ 'zero' |

/** BlendOperation defines the algorithm used to combine source and destination blend factors: */
export type BlendOperation =

@@ -136,27 +156,42 @@ 'add' |

/* Color parameters are set on the RenderPipeline */
export type ColorParameters = {
/** Defines the operation used to calculate the values written to the target attachment components. */
blendColorOperation?: BlendOperation;
/** Defines the operation to be performed on values from the fragment shader. */
blendColorSrcFactor?: BlendFactor;
/** Defines the operation to be performed on values from the target attachment. */
blendColorDstFactor?: BlendFactor;
/** Defines the operation used to calculate the values written to the target attachment components. */
blendAlphaOperation?: BlendOperation;
/** Defines the operation to be performed on values from the fragment shader. */
blendAlphaSrcFactor?: BlendFactor;
/** Defines the operation to be performed on values from the target attachment. */
blendAlphaDstFactor?: BlendFactor;
/** Bitmask controlling which channels are are written to when drawing to this color target. defaulting to 0xF */
colorMask?: number;
}
// Multisample
/** Multisample */
export type MultisampleParameters = {
/** Number of samples per pixel. RenderPipeline will be compatible only with attachment textures with matching sampleCounts. */
sampleCount?: number; // = 1;
sampleMask?: number; // = 0xFFFFFFFF;
/** Mask determining which samples are written to. defaulting to 0xFFFFFFFF */
sampleMask?: number;
/** When true indicates that a fragment’s alpha channel should be used to generate a sample coverage mask. */
sampleAlphaToCoverageEnabled?: boolean; // = false;
};
// These are set on the render pass encoder and are thus "cheaper" to change
/** These parameters are set on the render pass and are thus easy to change frequently */
export type RenderPassParameters = {
viewport: number[]; // float x, float y, float width, float height, float minDepth, float maxDepth
scissorRect: number[]; // (GPUIntegerCoordinate x, GPUIntegerCoordinate y, GPUIntegerCoordinate width, GPUIntegerCoordinate height);
blendConstant: number[]; // GPUColor
stencilReference: number; // GPUStencilValue
/** Linear map from normalized device coordinates to viewport coordinates [x, y, width, height, minDepth, maxDepth] */
viewport?: number[];
/** Sets scissor rectangle used during rasterization. Discards fragments outside viewport coords [x, y, width, height]. */
scissorRect?: number[]; // ;
/** Sets constant blend color and alpha values used with "constant" and "one-minus-constant" blend factors. */
blendConstant?: number[]; // GPUColor
/** Stencil operation "replace" sets the value to stencilReference */
stencilReference?: number; // GPUStencilValue
};

@@ -163,0 +198,0 @@

@@ -148,4 +148,4 @@ // luma.gl, MIT license

'rgb5a1unorm-webgl' |
'rbg8unorm-webgl' |
'rbg8snorm-webgl' |
'rgb8unorm-webgl' |
'rgb8snorm-webgl' |
'rg16unorm-webgl' |

@@ -152,0 +152,0 @@ 'rg16snorm-webgl' |

// luma.gl, MIT license
import {TextureFormat} from './texture-formats';
import type {ColorTextureFormat, DepthStencilTextureFormat, TextureFormat} from './texture-formats';

@@ -49,26 +49,49 @@ // BINDING LAYOUTS

export type ColorAttachmentOptions = {
clearColor?: number[]; // GPUColor
storeOp: 'store' | 'discard';
}
/**
* Framebuffer attachments lets the user specify the textures that will be used for a RenderPass,
* together with some additional options for how to clear.
*/
export type ColorAttachment = {
/** Describes the texture subresource that will be output to for this color attachment. */
texture?: Texture;
/** Format of the texture resource. Used to auto create texture if not supplied */
format?: ColorTextureFormat;
/* Describes the texture subresource that will receive resolved output for this color attachment if multisampled. */
// resolveTarget?: GPUTextureView;
export type DepthStencilAttachmentOptions = {
depthClearValue?: number; // required (GPULoadOp or float) depthLoadValue;
depthStoreOp?: 'store' | 'discard'; // required GPUStoreOp depthStoreOp;
depthReadOnly?: boolean; // boolean depthReadOnly = false;
/** Value to clear to prior to executing the render pass. Default: [0, 0, 0, 0]. Ignored if loadOp is not "clear". */
clearValue?: number[];
/** load operation to perform on texture prior to executing the render pass. Default: 'clear'. */
loadOp?: 'load' | 'clear';
/** The store operation to perform on texture after executing the render pass. Default: 'store'. */
storeOp?: 'store' | 'discard';
};
stencilClearValue?: 'load' | number; // required (GPULoadOp or GPUStencilValue) stencilLoadValue;
stencilStoreOp?: 'store' | 'discard'; // required GPUStoreOp stencilStoreOp;
stencilReadOnly?: boolean; // boolean stencilReadOnly = false;
}
/**
* Framebuffer attachments lets the user specify the depth stencil texture that will be used for a RenderPass,
* together with some additional options for how to clear.
*/
export type DepthStencilAttachment = {
/** Describes the texture subresource that will be output to and read from for this depth/stencil attachment. */
texture?: Texture;
/** Format of the texture resource. Used to auto create texture if not supplied */
format?: DepthStencilTextureFormat;
/** @todo */
export type ColorAttachment = ColorAttachmentOptions & {
texture: Texture | TextureView; // required GPUTextureView view;
resolveTarget?: Texture; // GPUTextureView resolveTarget;
}
/** Value to clear depth component to prior to executing the render pass, if depthLoadOp is "clear". 0.0-1.0. */
depthClearValue?: number;
/** Indicates load operation to perform on depth component prior to executing the render pass. Default 'clear'. */
depthLoadOp?: 'load' | 'clear';
/** Store operation to perform on depth component after executing the render pass. Default: 'store'. */
depthStoreOp?: 'store' | 'discard';
/** Indicates that the depth component is read only. */
depthReadOnly?: boolean;
/** @todo */
export type DepthStencilAttachment = DepthStencilAttachmentOptions & {
texture: Texture; // required GPUTextureView view;
}
/** Indicates value to clear stencil component to prior to executing the render pass, if stencilLoadOp is "clear". */
stencilClearValue?: number;
/** Indicates load operation to perform on stencil component prior to executing the render pass. Prefer clearing. */
stencilLoadOp?: 'load' | 'clear';
/** Store operation to perform on stencil component after executing the render pass. */
stencilStoreOp?: 'store' | 'discard';
/** Indicates that the stencil component is read only. */
stencilReadOnly?: boolean;
};

@@ -7,6 +7,3 @@ import {TextureFormat} from '../types/texture-formats';

/**
* Decodes a vertex format, returning type, components, byte length and flags (integer, signed, normalized)
*/
export function decodeTextureFormat(format: TextureFormat): {
export type DecodedTextureFormat = {
format: string;

@@ -22,3 +19,8 @@ components: number;

normalized: boolean;
} {
}
/**
* Decodes a vertex format, returning type, components, byte length and flags (integer, signed, normalized)
*/
export function decodeTextureFormat(format: TextureFormat): DecodedTextureFormat {
const matches = REGEX.exec((format as string));

@@ -41,3 +43,4 @@ if (matches) {

}
throw new Error(`Unknown format ${format}`);
return decodeNonStandardFormat(format);
}

@@ -47,4 +50,3 @@

/*
const EXCEPTIONS: Record<TextureFormat, any> = {
const EXCEPTIONS: Partial<Record<TextureFormat, any>> = {
// Packed 16 bit formats

@@ -68,5 +70,20 @@ 'rgba4unorm-webgl': {format: 'rgba', bpp: 2},

// "depth32float-stencil8" feature
"depth32float-stencil8": {components: 2, bpp: 4, a: 'depth-stencil'}
'depth32float-stencil8': {components: 2, bpp: 4, a: 'depth-stencil'}
};
function decodeNonStandardFormat(format: TextureFormat): DecodedTextureFormat {
const data = EXCEPTIONS[format];
if (!data) {
throw new Error(`Unknown format ${format}`);
}
return {
format: data.format || '',
components: data.components || 1,
byteLength: data.bpp || 1,
srgb: false,
unsized: false
} as DecodedTextureFormat;
}
/*
'r8unorm': {s: "float"}, // ✓ ✓ ✓ },

@@ -73,0 +90,0 @@ 'r8snorm': {s: "float"}, // ✓ },

@@ -34,4 +34,2 @@ // luma.gl, MIT license

export {ComputePipeline} from './adapter/resources/compute-pipeline';
export type {CommandEncoderProps} from './adapter/resources/command-encoder';
export {CommandEncoder} from './adapter/resources/command-encoder';
export type {RenderPassProps} from './adapter/resources/render-pass';

@@ -41,6 +39,8 @@ export {RenderPass} from './adapter/resources/render-pass';

export {ComputePass} from './adapter/resources/compute-pass';
export type {CommandEncoderProps} from './adapter/resources/command-encoder';
export {CommandEncoder} from './adapter/resources/command-encoder';
export type {CommandBufferProps} from './adapter/resources/command-buffer';
export {CommandBuffer} from './adapter/resources/command-buffer';
// API TYPES
export type {CompilerMessage} from './lib/compiler-log/compiler-message';
export type {AccessorObject} from './adapter/types/accessor';

@@ -96,3 +96,13 @@ export type {

// COMPILER LOG
export type {CompilerMessage} from './lib/compiler-log/compiler-message';
export {formatCompilerLog} from './lib/compiler-log/format-compiler-log';
// GENERAL TYPES
export type {ConstructorOf, PartialBy} from './types';
// NUMERIC TYPES
// TODO: could be imported from @math.gl/types
export type {

@@ -104,5 +114,3 @@ TypedArray,

BigIntOrNumberArray,
BigIntOrNumericArray,
ConstructorOf,
PartialBy
BigIntOrNumericArray
} from './types';

@@ -124,4 +132,2 @@

export {formatCompilerLog} from './lib/compiler-log/format-compiler-log';
// ENGINE - TODO/move to @luma.gl/engine once that module is webgl-independent?

@@ -128,0 +134,0 @@ export {requestAnimationFrame, cancelAnimationFrame} from './lib/request-animation-frame';

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

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

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

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

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 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc