Skip to content

Commit

Permalink
Clean up/simplify/name more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Aug 26, 2017
1 parent 0651dcf commit 677c261
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/render/draw_fill_extrusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function draw(painter: Painter, source: SourceCache, layer: FillExtrusionStyleLa
}

function drawExtrusionTexture(painter, layer) {
const renderedTexture = painter._prerenderedFrames[layer.id];
const renderedTexture = painter.prerenderedFrames[layer.id];
if (!renderedTexture) return;

const gl = painter.gl;
Expand All @@ -57,8 +57,8 @@ function drawExtrusionTexture(painter, layer) {
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

// Since this texture has been rendered, make it available for reuse in the next frame.
painter.viewportFbos.push(renderedTexture);
delete painter._prerenderedFrames[layer.id];
painter.viewportFrames.push(renderedTexture);
delete painter.prerenderedFrames[layer.id];
}

function drawExtrusion(painter, source, layer, coord) {
Expand Down
83 changes: 33 additions & 50 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ class Painter {
emptyProgramConfiguration: ProgramConfiguration;
width: number;
height: number;
viewportFbos: Array<RenderTexture>;
_prerenderedFrames: { [string]: ?RenderTexture };
viewportFrames: Array<RenderTexture>;
prerenderedFrames: { [string]: ?RenderTexture };
depthRbo: WebGLRenderbuffer;
depthRboAttached: boolean;
_depthMask: boolean;
tileExtentBuffer: Buffer;
tileExtentVAO: VertexArrayObject;
Expand Down Expand Up @@ -95,8 +96,8 @@ class Painter {
this.gl = gl;
this.transform = transform;
this._tileTextures = {};
this._prerenderedFrames = {};
this.viewportFbos = [];
this.prerenderedFrames = {};
this.viewportFrames = [];

this.frameHistory = new FrameHistory();

Expand Down Expand Up @@ -124,13 +125,13 @@ class Painter {
this.height = height * browser.devicePixelRatio;
gl.viewport(0, 0, this.width, this.height);

for (const frame of this.viewportFbos) {
for (const frame of this.viewportFrames) {
this.gl.deleteTexture(frame.texture);
// TODO instead of deleting FBO on resize/destroying whole object,
// should we keep it around and only create a new texture next time?
this.gl.deleteFramebuffer(frame.fbo);
}
this.viewportFbos = [];
this.viewportFrames = [];

if (this.depthRbo) {
this.gl.deleteRenderbuffer(this.depthRbo);
Expand Down Expand Up @@ -288,68 +289,48 @@ class Painter {
const gl = this.gl;
// We'll wait and only attach the depth renderbuffer if we think we're
// rendering something.
let rboAttached = false;
let first = true;

let sourceCache;
let coords = [];

for (let i = 0; i < layerIds.length; i++) {
const layer = this.style._layers[layerIds[i]];

if (!layer.has3DPass()) continue;

if (layer.paint['fill-extrusion-opacity'] === 0 || layer.isHidden(this.transform.zoom)) {
// Don't bother creating a texture if we're not going
// to render anything: emplace a null value as a marker
// for the regular translucent render pass.
this._prerenderedFrames[layer.id] = null;
} else {
if (layer.source !== (sourceCache && sourceCache.id)) {
sourceCache = this.style.sourceCaches[layer.source];
coords = [];

if (sourceCache) {
if (sourceCache.prepare) sourceCache.prepare();
this.clearStencil();
coords = sourceCache.getVisibleCoordinates();
}

coords.reverse();
}
if (!layer.has3DPass() || layer.isHidden(this.transform.zoom)) continue;

if (!coords.length) {
this._prerenderedFrames[layer.id] = null;
continue;
}
if (layer.source !== (sourceCache && sourceCache.id)) {
sourceCache = this.style.sourceCaches[layer.source];
coords = [];

if (!rboAttached) {
// This is the first 3D layer we're rendering: setup the
// depth renderbuffer now.
this._setup3DRenderbuffer();
// Wait to flip the boolean until after we attach the first
// frame and clear the depth buffer a few lines down.
if (sourceCache) {
if (sourceCache.prepare) sourceCache.prepare();
this.clearStencil();
coords = sourceCache.getVisibleCoordinates();
}

let renderTarget = this.viewportFbos.pop();
if (!renderTarget) {
renderTarget = new RenderTexture(this);
}
renderTarget.attachRenderbuffer(this.depthRbo);
coords.reverse();
}

if (!rboAttached) {
this.clearDepth();
rboAttached = true;
}
if (!coords.length) continue;

this.renderLayer(this, (sourceCache: any), layer, coords);
this._setup3DRenderbuffer();

renderTarget.detachRenderbuffer();
let renderTarget = this.viewportFrames.pop() || new RenderTexture(this);
renderTarget.attachRenderbuffer(this.depthRbo);

this._prerenderedFrames[layer.id] = renderTarget;
if (first) {
this.clearDepth();
first = false;
}

this.renderLayer(this, (sourceCache: any), layer, coords);

renderTarget.detachRenderbuffer();
this.prerenderedFrames[layer.id] = renderTarget;
}

if (rboAttached) gl.bindRenderbuffer(gl.RENDERBUFFER, null);
if (this.depthRboAttached) gl.bindRenderbuffer(gl.RENDERBUFFER, null);
}

// Clear buffers in preparation for drawing to the main framebuffer
Expand Down Expand Up @@ -446,6 +427,8 @@ class Painter {
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, this.width, this.height);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
}

this.depthRboAttached = true;
}

depthMask(mask: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion src/style/style_layer/fill_extrusion_style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FillExtrusionStyleLayer extends StyleLayer {
}

has3DPass() {
return true;
return this.paint['fill-extrusion-opacity'] !== 0 && this.layout['visibility'] !== 'none';
}
}

Expand Down

0 comments on commit 677c261

Please sign in to comment.