Skip to content

Commit

Permalink
chore(core): Remove assert, cast, stubProps, checkProps, ... (#2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Mar 6, 2024
1 parent 1f25795 commit f3284e1
Show file tree
Hide file tree
Showing 39 changed files with 104 additions and 384 deletions.
4 changes: 2 additions & 2 deletions modules/core-tests/test/adapter/resources/texture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import test from 'tape-promise/tape';
import {webglDevice, getTestDevices} from '@luma.gl/test-utils';

import {Device, Texture, TextureFormat, cast} from '@luma.gl/core';
import {Device, Texture, TextureFormat} from '@luma.gl/core';
import {GL} from '@luma.gl/constants';

// TODO(v9): Avoid import from `@luma.gl/webgl` in core tests.
Expand Down Expand Up @@ -638,7 +638,7 @@ test.skip('WebGL#Texture3D construct/delete', t => {
// HELPERS

function getParameter(texture: Texture, pname: number): any {
const webglTexture = cast<WEBGLTexture>(texture);
const webglTexture = texture as WEBGLTexture;
webglTexture.gl.bindTexture(webglTexture.target, webglTexture.handle);
const value = webglTexture.gl.getTexParameter(webglTexture.target, pname);
webglTexture.gl.bindTexture(webglTexture.target, null);
Expand Down
10 changes: 1 addition & 9 deletions modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,15 @@ export {
// GENERAL UTILS

export {StatsManager} from './utils/stats-manager';
export {assert} from './utils/assert';
export {cast} from './utils/cast';
export {log} from './utils/log';
export {uid, isObjectEmpty} from './utils/utils';
export {isUniformValue, splitUniformsAndBindings} from './lib/uniforms/uniform';
export {formatValue} from './utils/format-value';
export {stubRemovedMethods} from './utils/stub-methods';
export {checkProps} from './utils/check-props';
export {setPathPrefix, loadFile, loadImage, loadImageBitmap, loadScript} from './utils/load-file';
export {getScratchArrayBuffer, getScratchArray, fillArray} from './utils/array-utils-flat';
export {makeRandomNumberGenerator, random} from './utils/random';
export {deepEqual} from './utils/deep-equal';

// ENGINE - TODO/move to @luma.gl/engine once that module is webgl-independent?
export {requestAnimationFrame, cancelAnimationFrame} from './utils/request-animation-frame';

// SHADER HELPERS
// SHADER HELPERS../../engine/src/animation-loop/request-animation-frame

/**
* Marks GLSL shaders for syntax highlighting: glsl`...`
Expand Down
3 changes: 1 addition & 2 deletions modules/core/src/lib/luma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {Device} from '../adapter/device';
import {StatsManager} from '../utils/stats-manager';
import {lumaStats} from '../utils/stats-manager';
import {log} from '../utils/log';
import {assert} from '../utils/assert';

const deviceList = new Map<string, typeof Device>();

Expand All @@ -31,7 +30,7 @@ export class luma {

static registerDevices(deviceClasses: any[] /* : typeof Device */): void {
for (const deviceClass of deviceClasses) {
assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
// assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
deviceList.set(deviceClass.type, deviceClass);
}
}
Expand Down
11 changes: 0 additions & 11 deletions modules/core/src/utils/assert.ts

This file was deleted.

8 changes: 0 additions & 8 deletions modules/core/src/utils/cast.ts

This file was deleted.

82 changes: 0 additions & 82 deletions modules/core/src/utils/check-props.ts

This file was deleted.

47 changes: 0 additions & 47 deletions modules/core/src/utils/format-value.ts

This file was deleted.

29 changes: 0 additions & 29 deletions modules/core/src/utils/stub-methods.ts

This file was deleted.

1 change: 0 additions & 1 deletion modules/core/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// general utils
import './lib/utils/array-utils-flat.spec';
import './lib/utils/utils.spec';
import './lib/utils/format-value.spec';
import './lib/utils/deep-equal.spec';
import './lib/utils/uniform.spec';

Expand Down
66 changes: 0 additions & 66 deletions modules/core/test/lib/utils/format-value.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion modules/engine/src/animation-loop/animation-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

import {luma, Device} from '@luma.gl/core';
import {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/core';
import {requestAnimationFrame, cancelAnimationFrame} from './request-animation-frame';
import {Timeline} from '../animation/timeline';
import {AnimationProps} from './animation-props';
import {Stats, Stat} from '@probe.gl/stats';
Expand Down
17 changes: 10 additions & 7 deletions modules/engine/src/geometry/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

import type {PrimitiveTopology, TypedArray} from '@luma.gl/core';
import {uid, assert} from '@luma.gl/core';
import {uid} from '@luma.gl/core';

export type GeometryProps = {
id?: string;
Expand Down Expand Up @@ -71,18 +71,21 @@ export class Geometry {
? {value: attributeValue}
: attributeValue;

assert(
ArrayBuffer.isView(attribute.value),
`${this._print(attributeName)}: must be typed array or object with value as typed array`
);
if (!ArrayBuffer.isView(attribute.value)) {
throw new Error(
`${this._print(attributeName)}: must be typed array or object with value as typed array`
);
}

if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
attribute.size = 3;
}

// Move indices to separate field
if (attributeName === 'indices') {
assert(!this.indices);
if (this.indices) {
throw new Error('Multiple indices detected');
}
this.indices = attribute;
} else {
this.attributes[attributeName] = attribute;
Expand Down Expand Up @@ -142,7 +145,7 @@ export class Geometry {
}
}

assert(Number.isFinite(vertexCount));
// assert(Number.isFinite(vertexCount));
return vertexCount;
}
}
6 changes: 4 additions & 2 deletions modules/engine/src/geometry/gpu-geometry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';
import {Device, Buffer, uid, assert, getVertexFormatFromAttribute} from '@luma.gl/core';
import {Device, Buffer, uid, getVertexFormatFromAttribute} from '@luma.gl/core';
import type {Geometry} from '../geometry/geometry';

export type GPUGeometryProps = {
Expand Down Expand Up @@ -43,7 +43,9 @@ export class GPUGeometry {
this.bufferLayout = props.bufferLayout || [];

if (this.indices) {
assert(this.indices.usage === Buffer.INDEX);
if (!(this.indices.usage & Buffer.INDEX)) {
throw new Error('Index buffer must have INDEX usage');
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions modules/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ export type {ShaderModuleInputs} from './shader-inputs';
export {ShaderInputs as _ShaderInputs} from './shader-inputs';
export type {ComputationProps} from './computation';
export {Computation} from './computation';
export {
requestAnimationFrame,
cancelAnimationFrame
} from './animation-loop/request-animation-frame';
Loading

0 comments on commit f3284e1

Please sign in to comment.