Skip to content

Commit

Permalink
chore(gltools): Move legacy code from @luma.gl/engine to gltools (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Jan 23, 2022
1 parent 729878e commit ced963a
Show file tree
Hide file tree
Showing 67 changed files with 195 additions and 128 deletions.
5 changes: 2 additions & 3 deletions examples/api/animation/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RenderLoop, AnimationProps, CubeGeometry, Timeline, KeyFrames, ClassicModel as Model} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps, CubeGeometry, Timeline, KeyFrames} from '@luma.gl/engine';
import {clear, ClassicModel as Model} from '@luma.gl/gltools';
import {dirlight} from '@luma.gl/shadertools';
import {Matrix4, radians} from '@math.gl/core';

Expand Down Expand Up @@ -59,7 +59,6 @@ export default class AppRenderLoop extends RenderLoop {
model: Model
}[];

// @ts-expect-error animationLoop
constructor({device, aspect, animationLoop}: AnimationProps) {
super();

Expand Down
4 changes: 2 additions & 2 deletions examples/api/cubemap/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Device, loadImage} from '@luma.gl/api';
import {RenderLoop, ClassicModel as Model, ClassicModelProps as ModelProps, CubeGeometry, AnimationProps} from '@luma.gl/engine';
import {RenderLoop, CubeGeometry, AnimationProps} from '@luma.gl/engine';
import {clear, ClassicModel as Model, ClassicModelProps as ModelProps} from '@luma.gl/gltools';
import GL from '@luma.gl/constants';
import {clear} from '@luma.gl/gltools';
import {Matrix4, radians} from '@math.gl/core';

const INFO_HTML = `
Expand Down
3 changes: 2 additions & 1 deletion examples/api/program-management/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {getRandom} from '@luma.gl/api';
import {dirlight as dirlightBase} from '@luma.gl/shadertools';
import {RenderLoop, ClassicModel as Model, ProgramManager, AnimationProps, CubeGeometry} from '@luma.gl/engine';
import {RenderLoop, AnimationProps, CubeGeometry} from '@luma.gl/engine';
import {ClassicModel as Model, ProgramManager} from '@luma.gl/gltools';
import {clear} from '@luma.gl/gltools';
import {Matrix4, radians} from '@math.gl/core';

Expand Down
4 changes: 2 additions & 2 deletions examples/api/texture-3d/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

import {getRandom} from '@luma.gl/api';
import {RenderLoop, AnimationProps, ClassicModel as Model} from '@luma.gl/engine';
import {RenderLoop, AnimationProps} from '@luma.gl/engine';
import GL from '@luma.gl/constants';
import {setParameters, clear} from '@luma.gl/gltools';
import {setParameters, clear, ClassicModel as Model} from '@luma.gl/gltools';
import {Matrix4, radians} from '@math.gl/core';
import {perlin, lerp, shuffle, range} from './perlin';

Expand Down
4 changes: 2 additions & 2 deletions examples/getting-started/hello-cube/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RenderLoop, AnimationProps, ClassicModel as Model, CubeGeometry} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps, CubeGeometry} from '@luma.gl/engine';
import {clear, ClassicModel as Model} from '@luma.gl/gltools';
import {Matrix4} from '@math.gl/core';

const INFO_HTML = `
Expand Down
6 changes: 2 additions & 4 deletions examples/getting-started/hello-instancing/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Buffer} from '@luma.gl/api';
import {RenderLoop, AnimationProps, ClassicModel as Model} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps} from '@luma.gl/engine';
import {clear, ClassicModel as Model} from '@luma.gl/gltools';

const INFO_HTML = `
Instanced triangles using luma.gl's high-level API
Expand Down Expand Up @@ -58,9 +58,7 @@ export default class AppRenderLoop extends RenderLoop {
modules: [colorShaderModule],
attributes: {
position: this.positionBuffer,
// @ts-expect-error
color: [this.colorBuffer, {divisor: 1}],
// @ts-expect-error
offset: [this.offsetBuffer, {divisor: 1}]
},
vertexCount: 3,
Expand Down
4 changes: 2 additions & 2 deletions examples/getting-started/hello-triangle/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import type {Buffer} from '@luma.gl/api';
import {RenderLoop, AnimationProps, ClassicModel as Model} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps} from '@luma.gl/engine';
import {clear, ClassicModel as Model} from '@luma.gl/gltools';

const INFO_HTML = `
Have to start somewhere...
Expand Down
4 changes: 2 additions & 2 deletions examples/getting-started/instanced-transform/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RenderLoop, AnimationProps, ClassicModel as Model, Transform, CubeGeometry} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps, CubeGeometry} from '@luma.gl/engine';
import {clear, ClassicModel as Model, Transform} from '@luma.gl/gltools';
import {phongLighting} from '@luma.gl/shadertools';
import {Matrix4} from '@math.gl/core';

Expand Down
6 changes: 3 additions & 3 deletions examples/getting-started/lighting/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RenderLoop, AnimationProps, Model, CubeGeometry} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps, CubeGeometry} from '@luma.gl/engine';
import {clear, ClassicModel as Model} from '@luma.gl/gltools';
import {phongLighting} from '@luma.gl/shadertools';
import {Matrix4} from '@math.gl/core';

Expand Down Expand Up @@ -57,7 +57,7 @@ export default class AppRenderLoop extends RenderLoop {
viewMatrix = new Matrix4().lookAt({eye: eyePosition});
mvpMatrix = new Matrix4();

constructor({device, gl}: AnimationProps) {
constructor({device}: AnimationProps) {
super();

const texture = device.createTexture({data: 'vis-logo.png'});
Expand Down
4 changes: 2 additions & 2 deletions examples/getting-started/shader-hooks/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Buffer} from '@luma.gl/api';
import {RenderLoop, AnimationProps, ClassicModel as Model, ProgramManager} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps} from '@luma.gl/engine';
import {clear, ClassicModel as Model, ProgramManager} from '@luma.gl/gltools';

const INFO_HTML = `
Modifying shader behavior with shader hooks
Expand Down
4 changes: 2 additions & 2 deletions examples/getting-started/shader-modules/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Buffer} from '@luma.gl/api';
import {RenderLoop, AnimationProps, ClassicModel as Model} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps} from '@luma.gl/engine';
import {clear, ClassicModel as Model} from '@luma.gl/gltools';

const INFO_HTML = `
Re-using shader code with shader modules
Expand Down
4 changes: 2 additions & 2 deletions examples/getting-started/transform-feedback/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RenderLoop, Transform, ClassicModel as Model, AnimationProps} from '@luma.gl/engine';
import {clear} from '@luma.gl/gltools';
import {RenderLoop, AnimationProps} from '@luma.gl/engine';
import {clear, Transform, ClassicModel as Model} from '@luma.gl/gltools';

const INFO_HTML = `
Animation via transform feedback.
Expand Down
30 changes: 19 additions & 11 deletions examples/performance/stress-test/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Device, getRandom} from '@luma.gl/api';
import {RenderLoop, AnimationProps, Model, ModelProps, CubeGeometry} from '@luma.gl/engine';
import {RenderLoop, AnimationProps, CubeGeometry} from '@luma.gl/engine';
import {dirlight} from '@luma.gl/shadertools';
import GL from '@luma.gl/constants';
import {clear, Texture2D, Buffer, withParameters, isWebGL2} from '@luma.gl/webgl';
import {clear, withParameters, Model, ModelProps} from '@luma.gl/gltools';
import {Matrix4, radians} from '@math.gl/core';
import {StatsWidget} from '@probe.gl/stats-widget';

Expand Down Expand Up @@ -81,6 +81,7 @@ class InstancedCube extends Model {
uniforms: props.uniforms,
attributes: {
offset: {
// @ts-expect-error
buffer: offsetBuffer,
size: 3,
divisor: 1
Expand All @@ -104,21 +105,26 @@ export default class AppRenderLoop extends RenderLoop {

rotationAngle = 0;

constructor({device, gl}: AnimationProps) {
constructor({device}: AnimationProps) {
super();
if (!isWebGL2(gl)) {

if (device.info.type !== 'webgl2') {
throw new Error(ALT_TEXT);
}

// @ts-expect-error
const {gl} = device;

const projectionMatrix = new Matrix4();
const viewMatrix = new Matrix4().lookAt({eye: [0, 0, 8]});

const texture = device.createTexture({
data: 'vis-logo.png',
mipmaps: true,
parameters: {
[gl.TEXTURE_MAG_FILTER]: gl.LINEAR,
[gl.TEXTURE_MIN_FILTER]: gl.LINEAR_MIPMAP_NEAREST
sampler: {
magFilter: 'linear',
minFilter: 'linear',
mipmapFilter: 'nearest'
}
});

Expand Down Expand Up @@ -159,7 +165,7 @@ export default class AppRenderLoop extends RenderLoop {
this.transparentCubes.forEach((c) => c.delete());
}

onRender({gl, aspect, tick}: AnimationProps) {
onRender({device, aspect, tick}: AnimationProps) {
this.rotationAngle += 0.01;
this.statsWidget.update();

Expand All @@ -179,10 +185,11 @@ export default class AppRenderLoop extends RenderLoop {
up: [0, 1, 0]
});

clear(gl, {color: [0, 0, 0, 1], depth: true});
clear(device, {color: [0, 0, 0, 1], depth: true});

withParameters(
gl,
// @ts-expect-error
device.gl,
{depthTest: true, depthMask: true, depthFunc: GL.LEQUAL, cull: true, blend: false},
() => {
for (let i = 0; i < OPAQUE_DRAWCALLS; ++i) {
Expand All @@ -197,7 +204,8 @@ export default class AppRenderLoop extends RenderLoop {
);

withParameters(
gl,
// @ts-expect-error
device.gl,
{
depthTest: true,
depthMask: false,
Expand Down
6 changes: 3 additions & 3 deletions examples/showcase/geospatial/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mapboxgl from 'mapbox-gl';
import {Buffer} from '@luma.gl/gltools';
// import {instrumentGLContext} from '@luma.gl/webgl';
import {AnimationLoop, AnimationProps, Model} from '@luma.gl/engine';
import {AnimationProps} from '@luma.gl/engine';
import {Buffer, ClassicModel as Model, ClassicAnimationLoop as AnimationLoop} from '@luma.gl/gltools';
// import {instrumentGLContext} from '@luma.gl/gltools';

const INFO_HTML = `
<p>A triangle connecting Times Square, Rockefeller Center, and Columbus Circle in Manhattan, NYC on a <a class="external-link" href="https://www.mapbox.com/">Mapbox</a> basemap using the
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/gltf/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default class AppRenderLoop extends RenderLoop {

device: Device;

constructor({animationLoop, device, gl, canvas}: AnimationProps) {
constructor({animationLoop, device, canvas}: AnimationProps) {
super();

this.device = device; // for onDrop
Expand Down
14 changes: 6 additions & 8 deletions examples/showcase/instancing/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Device, getRandom} from '@luma.gl/api';
import {RenderLoop, AnimationProps, CubeGeometry, Timeline, ClassicModel as Model, ClassicModelProps as ModelProps, ProgramManager} from '@luma.gl/engine';
import {RenderLoop, AnimationProps, CubeGeometry, Timeline} from '@luma.gl/engine';
import {ClassicModel as Model, ClassicModelProps as ModelProps, ProgramManager} from '@luma.gl/gltools';
import {picking as pickingBase, dirlight as dirlightBase} from '@luma.gl/shadertools';
import {readPixelsToArray} from '@luma.gl/gltools';
import {clear} from '@luma.gl/gltools';
Expand Down Expand Up @@ -126,11 +127,8 @@ class InstancedCube extends Model {
attributes: {
// @ts-expect-error
instanceSizes: new Float32Array([1]), // Constant attribute
// @ts-expect-error
instanceOffsets: [offsetsBuffer, {divisor: 1}],
// @ts-expect-error
instanceColors: [colorsBuffer, {divisor: 1}],
// @ts-expect-error
instancePickingColors: [pickingColorsBuffer, {divisor: 1}]
},
parameters: {
Expand All @@ -150,7 +148,6 @@ export default class AppRenderLoop extends RenderLoop {
timeline: Timeline;
timelineChannels: Record<string, number>;

// @ts-expect-error
constructor({device, animationLoop}: AnimationProps) {
super();

Expand All @@ -168,9 +165,10 @@ export default class AppRenderLoop extends RenderLoop {
this.cube = new InstancedCube(device);
}

onRender(animationProps) {
const {device, gl, aspect, tick} = animationProps;
const {framebuffer, _mousePosition} = animationProps;
onRender(animationProps: AnimationProps) {
const {device, aspect, tick} = animationProps;
// @ts-expect-error
const {gl, framebuffer, _mousePosition} = animationProps;
const {timeChannel, eyeXChannel, eyeYChannel, eyeZChannel} = this.timelineChannels;

if (_mousePosition) {
Expand Down
4 changes: 2 additions & 2 deletions examples/showcase/persistence/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getRandom} from '@luma.gl/api';
import {RenderLoop, ClassicModel as Model, Geometry, SphereGeometry, AnimationProps} from '@luma.gl/engine';
import {clear, Framebuffer, setParameters} from '@luma.gl/gltools';
import {RenderLoop, Geometry, SphereGeometry, AnimationProps} from '@luma.gl/engine';
import {clear, Framebuffer, setParameters, ClassicModel as Model} from '@luma.gl/gltools';
import {Matrix4, Vector3, radians} from '@math.gl/core';

const INFO_HTML = `
Expand Down
7 changes: 2 additions & 5 deletions examples/showcase/wandering/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-enable camelcase */
import {RenderLoop, AnimationProps, ClassicModel as Model, Transform} from '@luma.gl/engine';
import {RenderLoop, AnimationProps} from '@luma.gl/engine';
import {ClassicModel as Model, Transform} from '@luma.gl/gltools';
import {picking} from '@luma.gl/shadertools';
import {Buffer, readPixelsToArray, Framebuffer} from '@luma.gl/gltools';
import GL from '@luma.gl/constants';
Expand Down Expand Up @@ -207,13 +208,9 @@ export default class AppRenderLoop extends RenderLoop {
instanceCount: NUM_INSTANCES,
attributes: {
a_position: this.positionBuffer,
// @ts-expect-error
a_color: [this.colorBuffer, {divisor: 1}],
// @ts-expect-error
a_offset: [this.offsetBuffer, {divisor: 1}],
// @ts-expect-error
a_rotation: [this.rotationBuffer, {divisor: 1}],
// @ts-expect-error
instancePickingColors: [this.pickingColorBuffer, {divisor: 1}]
},
modules: [picking]
Expand Down
5 changes: 3 additions & 2 deletions examples/webgl/external-webgl-context/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AnimationLoop, AnimationProps, Model} from '@luma.gl/engine';
import {Buffer, clear} from '@luma.gl/webgl';
import {AnimationLoop, AnimationProps, Model} from '@luma.gl/gltools';
import {Buffer, clear} from '@luma.gl/gltools';
import {GLContextOptions, instrumentGLContext} from '@luma.gl/gltools';

const INFO_HTML = `
Expand All @@ -18,6 +18,7 @@ export default class AppAnimationLoop extends AnimationLoop {
return instrumentGLContext(gl);
}

//
onInitialize({gl}: AnimationProps) {
gl.clearColor(0, 0, 0, 1);

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl/hello-instancing-webgl/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DeviceProps} from '@luma.gl/api';
import {polyfillContext} from '@luma.gl/webgl';
import {ClassicAnimationLoop, ClassicAnimationProps} from '@luma.gl/engine';
import {ClassicAnimationLoop, ClassicAnimationProps} from '@luma.gl/gltools';

const INFO_HTML = `
Instanced triangles using luma.gl's low-level API
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl/shader-modules-webgl/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DeviceProps} from '@luma.gl/api';
import {ClassicAnimationLoop, ClassicAnimationProps} from '@luma.gl/engine';
import {ClassicAnimationLoop, ClassicAnimationProps} from '@luma.gl/gltools';
import {assembleShaders} from '@luma.gl/shadertools';

const INFO_HTML = `
Expand Down
7 changes: 4 additions & 3 deletions modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ export {log, assert, uid} from '@luma.gl/api';
// CORE MODULE EXPORTS FOR LUMA.GL

// ENGINE
export {Timeline} from '@luma.gl/engine';

export {
ClassicAnimationLoop as AnimationLoop,
ClassicModel as Model,
Transform,
ProgramManager,
Timeline
} from '@luma.gl/engine';
ClipSpace
} from '@luma.gl/gltools';

export {
Geometry,
ClipSpace,
ConeGeometry,
CubeGeometry,
CylinderGeometry,
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/src/geometries/cone-geometry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TruncatedConeGeometry} from './truncated-cone-geometry';
import {uid} from '@luma.gl/api';
import {TruncatedConeGeometry} from './truncated-cone-geometry';

export type ConeGeometryProps = {
id?: string;
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/src/geometries/cube-geometry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Geometry from '../geometry/geometry';
import {uid} from '@luma.gl/api';
import Geometry from '../geometry/geometry';

export type CubeGeometryProps = {
id?: string;
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/src/geometries/cylinder-geometry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TruncatedConeGeometry} from './truncated-cone-geometry';
import {uid} from '@luma.gl/api';
import {TruncatedConeGeometry} from './truncated-cone-geometry';

export type CylinderGeometryProps = {
id?: string;
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/src/geometries/ico-sphere-geometry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {uid} from '@luma.gl/api';
import {Vector3} from '@math.gl/core';
import Geometry from '../geometry/geometry';
import {uid} from '@luma.gl/api';

/* eslint-disable comma-spacing, max-statements, complexity */

Expand Down
Loading

0 comments on commit ced963a

Please sign in to comment.