Skip to content

Commit

Permalink
chore(core): Even less exports (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Mar 7, 2024
1 parent c948447 commit db20629
Show file tree
Hide file tree
Showing 79 changed files with 385 additions and 363 deletions.
4 changes: 2 additions & 2 deletions examples/api/animation/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
import {dirlight} from '@luma.gl/shadertools';
import {Matrix4, radians} from '@math.gl/core';

import {makeRandomNumberGenerator} from '@luma.gl/core';
import {makeRandomGenerator} from '@luma.gl/engine';

// Ensure repeatable rendertests
const random = makeRandomNumberGenerator();
const random = makeRandomGenerator();

const INFO_HTML = `\
Key frame animation based on multiple hierarchical timelines.
Expand Down
5 changes: 3 additions & 2 deletions examples/api/cubemap/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Device, loadImage, glsl} from '@luma.gl/core';
import {Device, glsl} from '@luma.gl/core';
import {
AnimationLoopTemplate,
AnimationProps,
CubeGeometry,
Model,
ModelProps
ModelProps,
loadImage
} from '@luma.gl/engine';
import {Matrix4, radians} from '@math.gl/core';

Expand Down
7 changes: 4 additions & 3 deletions examples/api/texture-3d/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Ported from PicoGL.js example: https://tsherif.github.io/picogl.js/examples/3Dtexture.html

import {makeRandomNumberGenerator, glsl} from '@luma.gl/core';
import {AnimationLoopTemplate, AnimationProps, Model} from '@luma.gl/engine';
import {glsl} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, Model, makeRandomGenerator} from '@luma.gl/engine';
import {Matrix4, radians} from '@math.gl/core';
import {perlin, lerp, shuffle, range} from './perlin';

const random = makeRandomNumberGenerator();
const random = makeRandomGenerator();

const INFO_HTML = `
<p>
Expand Down
5 changes: 3 additions & 2 deletions examples/showcase/instancing/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//
import type {ShaderUniformType, NumberArray} from '@luma.gl/core';
import {Device, Framebuffer, makeRandomNumberGenerator, glsl} from '@luma.gl/core';
import {Device, Framebuffer, glsl} from '@luma.gl/core';
import type {AnimationProps, ModelProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, CubeGeometry, Timeline, Model, _ShaderInputs} from '@luma.gl/engine';
import {makeRandomGenerator} from '@luma.gl/engine';
import {picking, dirlight} from '@luma.gl/shadertools';
import {Matrix4, radians} from '@math.gl/core';

Expand All @@ -16,7 +17,7 @@ single GPU draw call using instanced vertex attributes.

// INSTANCE CUBE

const random = makeRandomNumberGenerator();
const random = makeRandomGenerator();

// WGSL

Expand Down
12 changes: 9 additions & 3 deletions examples/showcase/persistence/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type {NumberArray, ShaderUniformType} from '@luma.gl/core';
import {UniformStore, Framebuffer, makeRandomNumberGenerator, glsl} from '@luma.gl/core';
import {UniformStore, Framebuffer, glsl} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, Geometry, SphereGeometry, Model} from '@luma.gl/engine';
import {
AnimationLoopTemplate,
Geometry,
SphereGeometry,
Model,
makeRandomGenerator
} from '@luma.gl/engine';
import {Matrix4, Vector3, radians} from '@math.gl/core';

const INFO_HTML = `
Expand Down Expand Up @@ -269,7 +275,7 @@ void main(void) {
}
`;

const random = makeRandomNumberGenerator();
const random = makeRandomGenerator();

const CORE_COUNT = 64;
const ELECTRON_COUNT = 64;
Expand Down
5 changes: 3 additions & 2 deletions examples/tutorials/hello-cube/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// Copyright (c) vis.gl contributors

import type {NumberArray, ShaderUniformType} from '@luma.gl/core';
import {glsl, Texture, UniformStore, loadImage} from '@luma.gl/core';
import {AnimationLoopTemplate, AnimationProps, Model, CubeGeometry} from '@luma.gl/engine';
import {glsl, Texture, UniformStore} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, Model, CubeGeometry, loadImage} from '@luma.gl/engine';
import {Matrix4} from '@math.gl/core';

const INFO_HTML = `\
Expand Down
12 changes: 4 additions & 8 deletions examples/tutorials/lighting/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {glsl, NumberArray, loadImage} from '@luma.gl/core';
import {
AnimationLoopTemplate,
AnimationProps,
Model,
CubeGeometry,
_ShaderInputs
} from '@luma.gl/engine';
import {glsl, NumberArray} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, Model, CubeGeometry} from '@luma.gl/engine';
import {_ShaderInputs, loadImage} from '@luma.gl/engine';
import {phongMaterial, lighting, ShaderModule} from '@luma.gl/shadertools';
import {Matrix4} from '@math.gl/core';

Expand Down
5 changes: 3 additions & 2 deletions examples/webgpu/textured-cube/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Buffer, Texture, loadImageBitmap, glsl} from '@luma.gl/core';
import {Model, CubeGeometry, AnimationLoopTemplate, AnimationProps} from '@luma.gl/engine';
import {Buffer, Texture, glsl} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {Model, CubeGeometry, AnimationLoopTemplate, loadImageBitmap} from '@luma.gl/engine';
import {Matrix4} from '@math.gl/core';

export const title = 'Rotating Cube';
Expand Down
28 changes: 0 additions & 28 deletions modules/core/src/adapter-utils/get-attribute-from-layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,31 +230,3 @@ function getAttributeFromAttributesList(

return null;
}

/**
* Merges an provided shader layout into a base shader layout
* In WebGL, this allows the auto generated shader layout to be overridden by the application
* Typically to change the format of the vertex attributes (from float32x4 to uint8x4 etc).
* @todo Drop this? Aren't all use cases covered by mergeBufferLayout()?
*/
export function mergeShaderLayout(
baseLayout: ShaderLayout,
overrideLayout: ShaderLayout
): ShaderLayout {
// Deep clone the base layout
const mergedLayout: ShaderLayout = {
...baseLayout,
attributes: baseLayout.attributes.map(attribute => ({...attribute}))
};
// Merge the attributes
for (const attribute of overrideLayout?.attributes || []) {
const baseAttribute = mergedLayout.attributes.find(attr => attr.name === attribute.name);
if (!baseAttribute) {
log.warn(`shader layout attribute ${attribute.name} not present in shader`);
} else {
baseAttribute.type = attribute.type || baseAttribute.type;
baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
}
}
return mergedLayout;
}
22 changes: 0 additions & 22 deletions modules/core/src/adapter-utils/is-uniform-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {UniformValue} from '../adapter/types/types';
import type {Binding} from '../adapter/types/shader-layout';
import {isNumberArray} from '../utils/is-array';

export function isUniformValue(value: unknown): boolean {
return isNumberArray(value) !== null || typeof value === 'number' || typeof value === 'boolean';
}

type UniformsAndBindings = {
bindings: Record<string, Binding>;
uniforms: Record<string, UniformValue>;
};
export function splitUniformsAndBindings(
uniforms: Record<string, Binding | UniformValue>
): UniformsAndBindings {
const result: UniformsAndBindings = {bindings: {}, uniforms: {}};
Object.keys(uniforms).forEach(name => {
const uniform = uniforms[name];
if (isUniformValue(uniform)) {
result.uniforms[name] = uniform as UniformValue;
} else {
result.bindings[name] = uniform as Binding;
}
});

return result;
}
84 changes: 0 additions & 84 deletions modules/core/src/adapter/resources/framebuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,87 +161,3 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
}
}
}

// TODO - remove if not needed

// 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
// // }
// });
// }

// /** 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};
// }
8 changes: 6 additions & 2 deletions modules/core/src/adapter/resources/render-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export type RenderPassProps = ResourceProps & {
framebuffer?: Framebuffer | null;
/** Control viewport, scissor rect, blend constant and stencil ref */
parameters?: RenderPassParameters;

// TODO - API needs to be able to control multiple render targets

/** Clear value for color attachment, or `load` to preserve the previous value */
clearColor?: NumberArray | false;
/** Whether to disable / discard the output of the rasterizer */
discard?: boolean;

/** 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 */
Expand All @@ -28,8 +34,6 @@ export type RenderPassProps = ResourceProps & {
depthReadOnly?: boolean;
/** Indicates that the stencil component is read only. */
stencilReadOnly?: boolean;
/** Whether to disable / discard the output of the rasterizer */
discard?: boolean;

/** QuerySet to write begin/end timestamps to */
occlusionQuerySet?: QuerySet;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/adapter/resources/render-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

import type {Device} from '../device';
import type {UniformValue} from '../types/types';
import type {UniformValue} from '../types/uniforms';
import type {PrimitiveTopology, RenderPipelineParameters} from '../types/parameters';
import type {ShaderLayout, Binding} from '../types/shader-layout';
import type {BufferLayout} from '../types/buffer-layout';
Expand Down
5 changes: 4 additions & 1 deletion modules/core/src/adapter/resources/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ export abstract class Shader extends Resource<ShaderProps> {

// PRIVATE

/** In-browser UI logging of errors */
/**
* In-browser UI logging of errors
* TODO - this HTML formatting code should not be in Device, should be pluggable
*/
protected _displayShaderLog(messages: readonly CompilerMessage[]): void {
// Return if under Node.js / incomplete `document` polyfills
if (typeof document === 'undefined' || !document?.createElement) {
Expand Down

0 comments on commit db20629

Please sign in to comment.