Skip to content

Commit

Permalink
Merge 05f7f0d into c2047d6
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Nov 26, 2019
2 parents c2047d6 + 05f7f0d commit 984798a
Show file tree
Hide file tree
Showing 100 changed files with 192 additions and 4,864 deletions.
7 changes: 1 addition & 6 deletions modules/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export {
isWebGL2,
lumaStats,
createGLContext,
destroyGLContext,
resizeGLContext,
setGLContextDefaults,
getContextInfo,
getGLContextInfo,
getContextLimits,
Expand All @@ -21,10 +19,7 @@ export {
getKeyValue,
getKey,
cssToDeviceRatio,
cssToDevicePixels,
// DEPRECATED
setGLContextDefaults as setContextDefaults,
getContextDebugInfo as glGetDebugInfo
cssToDevicePixels
} from '@luma.gl/webgl';

export {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'tape-catch';

import {createGLContext} from '@luma.gl/webgl';
import {createTestContext} from '@luma.gl/test-utils';
import {makeDebugContext} from '@luma.gl/debug';

function triggerGLError(gl) {
Expand All @@ -14,7 +14,7 @@ function triggerValidationError(gl) {
}

test('WebGL#makeDebugContext', t => {
const gl = createGLContext({debug: false});
const gl = createTestContext({debug: false});
t.doesNotThrow(() => triggerGLError(gl), 'The default context does not throw on GL error');
t.doesNotThrow(
() => triggerValidationError(gl),
Expand Down
29 changes: 25 additions & 4 deletions modules/engine/src/lib/animation-loop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global OffscreenCanvas */
/* global window, OffscreenCanvas */
import {
isWebGL,
createGLContext,
Expand All @@ -7,15 +7,17 @@ import {
resetParameters,
requestAnimationFrame,
cancelAnimationFrame,
getPageLoadPromise,
Query,
lumaStats,
// TODO - remove dependency on framebuffer (bundle size impact)
Framebuffer,
log,
assert
assert,
isBrowser
} from '@luma.gl/webgl';

const isPage = isBrowser && typeof document !== 'undefined';

let statIdCounter = 0;

export default class AnimationLoop {
Expand Down Expand Up @@ -88,6 +90,8 @@ export default class AnimationLoop {
this.start = this.start.bind(this);
this.stop = this.stop.bind(this);

this._pageLoadPromise = null;

this._onMousemove = this._onMousemove.bind(this);
this._onMouseleave = this._onMouseleave.bind(this);
}
Expand Down Expand Up @@ -125,7 +129,7 @@ export default class AnimationLoop {
this._running = true;
// console.debug(`Starting ${this.constructor.name}`);
// Wait for start promise before rendering frame
getPageLoadPromise()
this._getPageLoadPromise()
.then(() => {
if (!this._running || this._initialized) {
return null;
Expand Down Expand Up @@ -281,6 +285,23 @@ export default class AnimationLoop {

// PRIVATE METHODS

_getPageLoadPromise() {
if (!this._pageLoadPromise) {
this._pageLoadPromise = isPage
? new Promise((resolve, reject) => {
if (isPage && document.readyState === 'complete') {
resolve(document);
return;
}
window.onload = () => {
resolve(document);
};
})
: Promise.resolve({});
}
return this._pageLoadPromise;
}

_setDisplay(display) {
if (this.display) {
this.display.delete();
Expand Down
15 changes: 1 addition & 14 deletions modules/gltools/test/polyfill/setup.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
// Avoid generating a lot of big context divs
import '@luma.gl/debug';
import {setGLContextDefaults, createGLContext, makeDebugContext} from '@luma.gl/core';

setGLContextDefaults({
width: 1,
height: 1,
debug: true,
throwOnFailure: false,
throwOnError: false
});

export function createTestContext(opts = {}) {
return makeDebugContext(createGLContext(opts));
}
import {createTestContext} from '@luma.gl/test-utils';

export const fixture = {
gl: createTestContext({webgl2: false, webgl1: true, throwOnFailure: true, throwOnError: true}),
Expand Down
16 changes: 1 addition & 15 deletions modules/gltools/test/state-tracker/setup.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
// TEST SETUP

import {setGLContextDefaults, createGLContext} from '@luma.gl/core';
import {makeDebugContext} from '@luma.gl/debug';

// Avoid generating a lot of big context divs
setGLContextDefaults({
width: 1,
height: 1,
debug: true,
throwOnFailure: false,
throwOnError: false
});

export function createTestContext(opts = {}) {
return makeDebugContext(createGLContext(opts));
}
import {createTestContext} from '@luma.gl/test-utils';

export const fixture = {
gl: createTestContext({webgl2: false, webgl1: true, throwOnFailure: true, throwOnError: true}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {GL_PARAMETER_DEFAULTS as GL_PARAMETERS} from '@luma.gl/gltools/state-tra
import {ENUM_STYLE_SETTINGS_SET1} from '../data/sample-enum-settings';
import {FUNCTION_STYLE_SETTINGS_SET1} from '../data/sample-function-settings';

import {createTestContext} from '@luma.gl/test-utils';

function stringifyTypedArray(v) {
v = ArrayBuffer.isView(v) ? Array.apply([], v) : v;
return JSON.stringify(v);
}

import {createTestContext} from 'test/setup';
const fixture = {
gl: createTestContext(),
gl2: createTestContext({webgl2: true, webgl1: false})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'tape-catch';
import {createTestContext} from 'test/setup';
import {createTestContext} from '@luma.gl/test-utils';

import {
trackContextState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {setParameters, getParameters, resetParameters} from '@luma.gl/gltools';
import GL from '@luma.gl/constants';
import {Framebuffer, getKey} from '@luma.gl/webgl';

import {createTestContext} from 'test/setup';
import {createTestContext} from '@luma.gl/test-utils';

import {GL_PARAMETER_DEFAULTS} from '@luma.gl/gltools/state-tracker/webgl-parameter-tables';

Expand Down
5 changes: 3 additions & 2 deletions modules/shadertools/test/gpu-test-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable max-len, prefer-template, camelcase */
/* global console */
/* eslint-disable no-console */
import {createGLContext, setParameters} from '@luma.gl/core';
import {setParameters} from '@luma.gl/core';
import {createTestContext} from '@luma.gl/test-utils';

// Utilities functions that to be moved to a common place for future tests

Expand Down Expand Up @@ -37,7 +38,7 @@ function glErrorShouldBe(gl, glErrors, opt_msg) {
}

export function initializeGL(canvas) {
const gl = createGLContext(canvas);
const gl = createTestContext(canvas);
setParameters(gl, {
viewport: [0, 0, canvas.width, canvas.height],
clearColor: [0, 0, 0, 1],
Expand Down
4 changes: 2 additions & 2 deletions modules/shadertools/test/lib/assemble-shaders.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable camelcase */
import {createGLContext} from '@luma.gl/webgl';
import {createTestContext} from '@luma.gl/test-utils';
import {assembleShaders, picking, fp64} from '@luma.gl/shadertools';
import test from 'tape-catch';

const fixture = {
gl: createGLContext()
gl: createTestContext()
};

const VS_GLSL_300 = `\
Expand Down
4 changes: 2 additions & 2 deletions modules/shadertools/test/lib/inject-shader.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase, no-console, no-undef */
import {createGLContext} from '@luma.gl/webgl';
import {createTestContext} from '@luma.gl/test-utils';
import {assembleShaders} from '@luma.gl/shadertools';
import injectShader, {
combineInjects,
Expand All @@ -8,7 +8,7 @@ import injectShader, {
import test from 'tape-catch';

const fixture = {
gl: createGLContext()
gl: createTestContext()
};

const VS_GLSL_TEMPLATE = `\
Expand Down
2 changes: 1 addition & 1 deletion modules/shadertools/test/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import './fun-filters';
import './utils';
import './warp-filters';

import shaderModules from '@luma.gl/shadertools/modules';
import * as shaderModules from '@luma.gl/shadertools/modules';
import ShaderModule from '@luma.gl/shadertools/lib/shader-module';

import test from 'tape-catch';
Expand Down
6 changes: 4 additions & 2 deletions modules/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"probe.gl": "^3.1.1"
},
"peerDependencies": {
"@luma.gl/core": "^7.1.0",
"@luma.gl/gltools": "^7.1.0",
"@luma.gl/core": "8.0.0-alpha.5",
"@luma.gl/webgl": "8.0.0-alpha.5",
"@luma.gl/gltools": "8.0.0-alpha.5",
"@luma.gl/debug": "8.0.0-alpha.5",
"@probe.gl/test-utils": "^3.1.1"
},
"gitHead": "8deca643b658ddf6d8fb279df6417b8901a6fc93"
Expand Down
62 changes: 62 additions & 0 deletions modules/test-utils/src/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {createGLContext, instrumentGLContext, isBrowser} from '@luma.gl/webgl';
import '@luma.gl/debug';

const ERR_HEADLESSGL_NOT_AVAILABLE =
'Failed to create WebGL context in Node.js, headless gl not available';

const ERR_HEADLESSGL_FAILED =
'Failed to create WebGL context in Node.js, headless gl returned null';

const ERR_HEADLESSGL_LOAD = `\
luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
contexts can not be created. This may not be an error. For example, this is a \
typical configuration for isorender applications running on the server.`;

const CONTEXT_DEFAULTS = {
width: 1,
height: 1,
debug: true,
throwOnFailure: false,
throwOnError: false
};

export function createTestContext(opts = {}) {
opts = Object.assign({}, CONTEXT_DEFAULTS, opts);
const context = isBrowser
? createGLContext(opts)
: instrumentGLContext(createHeadlessContext(opts), opts);
return context;
}

// Create headless gl context (for running under Node.js)
export function createHeadlessContext(options) {
const {width, height, webgl1, webgl2} = options;

function onError(message) {
if (options.throwOnError) {
throw new Error(message);
}
return null;
}

if (webgl2 && !webgl1) {
return onError('headless-gl does not support WebGL2');
}
if (!headlessGL) {
return onError(ERR_HEADLESSGL_NOT_AVAILABLE);
}
const gl = headlessGL(width, height, options);
if (!gl) {
return onError(ERR_HEADLESSGL_FAILED);
}
return gl;
}

// Load headless gl dynamically, if available
function headlessGL(...args) {
const headless = module.require('gl');
if (!headless) {
throw new Error(ERR_HEADLESSGL_LOAD);
}
return headless(...args);
}
1 change: 1 addition & 0 deletions modules/test-utils/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export {default as SnapshotTestRunner} from './snapshot-test-runner';
export {default as PerformanceTestRunner} from './performance-test-runner';
export {createTestContext, createHeadlessContext} from './context';
2 changes: 1 addition & 1 deletion modules/webgl/src/classes/clear.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {withParameters} from '../context';
import {withParameters} from '@luma.gl/gltools';
import {assertWebGL2Context} from '../webgl-utils';
import {assert} from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion modules/webgl/src/classes/copy-and-blit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GL from '@luma.gl/constants';
import Buffer from './buffer';
import Framebuffer from './framebuffer';
import Texture from './texture';
import {withParameters} from '../context';
import {withParameters} from '@luma.gl/gltools';
import {assertWebGL2Context, flipRows, scalePixels} from '../webgl-utils';
import {getTypedArrayFromGLType, getGLTypeFromTypedArray} from '../webgl-utils/typed-array-utils';
import {glFormatToComponents, glTypeToBytes} from '../webgl-utils/format-utils';
Expand Down
2 changes: 1 addition & 1 deletion modules/webgl/src/classes/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {VertexShader, FragmentShader} from './shader';
import ProgramConfiguration from './program-configuration';
import {copyUniform, checkUniformValues} from './uniforms';

import {withParameters} from '../context';
import {withParameters} from '@luma.gl/gltools';
import {assertWebGL2Context, isWebGL2, getKey} from '../webgl-utils';
import {getPrimitiveDrawMode} from '../webgl-utils/attribute-utils';
import {log, uid, assert} from '../utils';
Expand Down
2 changes: 1 addition & 1 deletion modules/webgl/src/classes/texture-3d.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GL from '@luma.gl/constants';
import {withParameters} from '../context';
import {withParameters} from '@luma.gl/gltools';
import {isWebGL2, assertWebGL2Context} from '../webgl-utils';
import Texture from './texture';
import {DATA_FORMAT_CHANNELS, TYPE_SIZES} from './texture-formats';
Expand Down
5 changes: 3 additions & 2 deletions modules/webgl/src/classes/texture.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global WebGLBuffer */
import GL from '@luma.gl/constants';

import Resource from './resource';
Expand All @@ -10,8 +11,8 @@ import {
isLinearFilteringSupported
} from './texture-formats';

import {withParameters} from '../context';
import {isWebGL2, assertWebGL2Context, WebGLBuffer} from '../webgl-utils';
import {withParameters} from '@luma.gl/gltools';
import {isWebGL2, assertWebGL2Context} from '../webgl-utils';
import {log, uid, isPowerOfTwo, assert} from '../utils';

// Supported min filters for NPOT texture.
Expand Down
Loading

0 comments on commit 984798a

Please sign in to comment.