Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Mar 7, 2024
1 parent 5603f69 commit d59dd56
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 132 deletions.
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;
}
28 changes: 28 additions & 0 deletions modules/core/src/adapter-utils/split-uniforms-and-bindings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// luma.gl
// 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 {isUniformValue} from './is-uniform-value';

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};
// }
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
3 changes: 1 addition & 2 deletions modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ export {uid} from './utils/uid';

export type {AttributeInfo} from './adapter-utils/get-attribute-from-layouts';
export {getAttributeInfosFromLayouts} from './adapter-utils/get-attribute-from-layouts';
export {mergeShaderLayout} from './adapter-utils/get-attribute-from-layouts';
export {splitUniformsAndBindings} from './adapter-utils/is-uniform-value';
export {splitUniformsAndBindings} from './adapter-utils/split-uniforms-and-bindings';

export type {
CopyBufferToBufferOptions,
Expand Down
15 changes: 0 additions & 15 deletions modules/core/src/utils/is-object-empty.ts

This file was deleted.

28 changes: 26 additions & 2 deletions modules/webgl/src/adapter/resources/webgl-render-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type {UniformValue, RenderPipelineProps, Binding} from '@luma.gl/core';
import type {ShaderLayout} from '@luma.gl/core';
import type {RenderPass, VertexArray} from '@luma.gl/core';
import {RenderPipeline, splitUniformsAndBindings, log} from '@luma.gl/core';
import {mergeShaderLayout} from '@luma.gl/core';
// import {mergeShaderLayout, getAttributeInfosFromLayouts} from '@luma.gl/core';
// import {getAttributeInfosFromLayouts} from '@luma.gl/core';
import {GL} from '@luma.gl/constants';

import {getShaderLayout} from '../helpers/get-shader-layout';
Expand Down Expand Up @@ -502,3 +501,28 @@ export class WEBGLRenderPipeline extends RenderPipeline {
}
}
}

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

0 comments on commit d59dd56

Please sign in to comment.