Skip to content

Commit

Permalink
Optimizations (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Oct 17, 2019
1 parent 4483858 commit 9baad74
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 844 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -9,6 +9,7 @@ module.exports = {
'no-inline-comments': 0,
camelcase: 0,
'max-statements': 0,
'max-depth': 0,
'luma-gl-custom-rules/check-log-call': 1,
'import/no-unresolved': ['error'],
'import/no-extraneous-dependencies': [
Expand Down
1 change: 1 addition & 0 deletions docs/api-reference/webgl/program.md
Expand Up @@ -159,6 +159,7 @@ Notes:
* Indexed rendering uses the element buffer (`GL.ELEMENT_ARRAY_BUFFER`), make sure your attributes or `VertexArray` contains one.
* If a `TransformFeedback` object is supplied, `transformFeedback.begin()` and `transformFeedback.end()` will be called before and after the draw call.
* A `Sampler` will only be bound if there is a matching Texture with the same key in the supplied `uniforms` object.
* Once a uniform is set, it's size should not be changed. This is only a concern for array uniforms.

The following WebGL APIs are called in this function:

Expand Down
1 change: 1 addition & 0 deletions docs/upgrade-guide.md
Expand Up @@ -6,6 +6,7 @@
- `BaseModel` and `Model` have been consolidated in `Model`. `Model` be used as a substitute for `BaseModel` where necessary.
- `AmbientLight`, `DirectionalLight`, `PointLight`, `PhongMaterial`, `PBRMaterial`, `CameraNode` have been removed from @luma.gl/core. These were either empty classes or simple data objects and so can be replaced by plain JavaScript objects in most cases.
- `ShaderCache` has been removed and superseded by `ProgramManager`.
- `VertexArray.getDrawParams` no longer takes overrides as an argument. The calling function can manually override values as needed.
- @luma.gl/glfx has been renamed to @luma.gl/effects.
- @luma.gl/main has been removed. Use individual modules instead.
- `Multipass` classes have been removed.
Expand Down
7 changes: 6 additions & 1 deletion examples/performance/stress-test/app.js
Expand Up @@ -165,11 +165,16 @@ export default class AppAnimationLoop extends AnimationLoop {
opaqueCubes,
transparentCubes,
angle,
statsWidget
statsWidget,
tick
} = props;

statsWidget.update();

if (tick % 600 === 0) {
this.stats.reset();
}

const camX = Math.cos(angle);
const camZ = Math.sin(angle);
const camRadius = 800;
Expand Down
31 changes: 23 additions & 8 deletions modules/core/src/lib/model.js
Expand Up @@ -17,6 +17,9 @@ const LOG_DRAW_TIMEOUT = 10000;

const ERR_MODEL_PARAMS = 'Model needs drawMode and vertexCount';

const NOOP = () => {};
const DRAW_PARAMS = {};

export default class Model {
constructor(gl, props = {}) {
// Deduce a helpful id
Expand All @@ -25,6 +28,7 @@ export default class Model {
this.id = id;
this.gl = gl;
this.id = props.id || uid('Model');
this.debug = props.debug || false;
this.lastLogTime = 0; // TODO - move to probe.gl
this.initialize(props);
}
Expand Down Expand Up @@ -236,25 +240,34 @@ export default class Model {
this.updateModuleSettings(moduleSettings);
this.setUniforms(uniforms);

const logPriority = this._logDrawCallStart(2);
let logPriority;

if (this.debug) {
logPriority = this._logDrawCallStart(2);
}

const drawParams = this.vertexArray.getDrawParams();
const {
isIndexed = drawParams.isIndexed,
indexType = drawParams.indexType,
indexOffset = drawParams.indexOffset,
vertexArrayInstanced = drawParams.isInstanced
} = this.props;

const drawParams = this.vertexArray.getDrawParams(this.props);
if (drawParams.isInstanced && !this.isInstanced) {
if (vertexArrayInstanced && !this.isInstanced) {
log.warn('Found instanced attributes on non-instanced model', this.id)();
}

const {isIndexed, indexType, indexOffset} = drawParams;
const {isInstanced, instanceCount} = this;

const noop = () => {};
const {onBeforeRender = noop, onAfterRender = noop} = this.props;
const {onBeforeRender = NOOP, onAfterRender = NOOP} = this.props;

onBeforeRender();

this.program.setUniforms(this.uniforms);

const didDraw = this.program.draw(
Object.assign({}, opts, {
Object.assign(DRAW_PARAMS, opts, {
logPriority,
uniforms: null, // Already set (may contain "function values" not understood by Program)
framebuffer,
Expand All @@ -273,7 +286,9 @@ export default class Model {

onAfterRender();

this._logDrawCallEnd(logPriority, vertexArray, framebuffer);
if (this.debug) {
this._logDrawCallEnd(logPriority, vertexArray, framebuffer);
}

return didDraw;
}
Expand Down
5 changes: 0 additions & 5 deletions modules/debug/src/index.js
Expand Up @@ -15,11 +15,6 @@ export {makeDebugContext} from './webgl-api-tracing/webgl-debug-context';
import {makeDebugContext} from './webgl-api-tracing/webgl-debug-context';
global.makeDebugContext = makeDebugContext;

// Install additional parameter definitions on luma.gl classes
// TODO: This needs a bit more plumbing
// import {installParameterDefinitions} from './webgl-api-tracing/parameter-definitions';
// installParameterDefinitions();

// Since debug support has been explicitly installed, no qualms about printing to console
// TODO - That said: We could import probe.gl from luma.gl
log.info('@luma.gl/debug: WebGL debug support installed'); // eslint-disable-line

0 comments on commit 9baad74

Please sign in to comment.