Skip to content

Commit

Permalink
refactor fill extrusion texture/fbo cache (#5328)
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner authored Sep 20, 2017
1 parent efd018f commit fbf6145
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
6 changes: 1 addition & 5 deletions src/render/draw_fill_extrusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function draw(painter: Painter, source: SourceCache, layer: FillExtrusionStyleLa
}

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

const gl = painter.gl;
Expand All @@ -56,10 +56,6 @@ function drawExtrusionTexture(painter, layer) {

renderedTexture.vao.bind(gl, program, renderedTexture.buffer);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

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

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

this.frameHistory = new FrameHistory();

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

for (const frame of this.viewportFrames) {
this.gl.deleteTexture(frame.texture);
this.gl.deleteFramebuffer(frame.fbo);
if (this.style) {
for (const layerId of this.style._order) {
this.style._layers[layerId].resize(gl);
}
}
this.viewportFrames = [];

if (this.depthRbo) {
this.gl.deleteRenderbuffer(this.depthRbo);
Expand Down Expand Up @@ -321,7 +317,8 @@ class Painter {

this._setup3DRenderbuffer();

const renderTarget = this.viewportFrames.pop() || new RenderTexture(this);
const renderTarget = layer.viewportFrame || new RenderTexture(this);
layer.viewportFrame = renderTarget;
renderTarget.bindWithDepth(this.depthRbo);

if (first) {
Expand All @@ -332,7 +329,6 @@ class Painter {
this.renderLayer(this, (sourceCache: any), layer, coords);

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

Expand Down
9 changes: 8 additions & 1 deletion src/style/style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Evented = require('../util/evented');
import type {Bucket, BucketParameters} from '../data/bucket';
import type Point from '@mapbox/point-geometry';
import type {Feature} from '../style-spec/function';
import type RenderTexture from '../render/render_texture';

export type GlobalProperties = {
zoom: number
Expand All @@ -36,6 +37,8 @@ class StyleLayer extends Evented {
paint: { [string]: any };
layout: { [string]: any };

viewportFrame: ?RenderTexture;

_paintSpecifications: any;
_layoutSpecifications: any;
_paintTransitions: {[string]: StyleTransition};
Expand Down Expand Up @@ -75,7 +78,7 @@ class StyleLayer extends Evented {
this._layoutSpecifications = styleSpec[`layout_${this.type}`];

this._paintTransitions = {}; // {[propertyName]: StyleTransition}
this._paintTransitionOptions = {}; //
this._paintTransitionOptions = {}; //
this._paintDeclarations = {}; // {[className]: {[propertyName]: StyleDeclaration}}
this._layoutDeclarations = {}; // {[propertyName]: StyleDeclaration}
this._layoutFunctions = {}; // {[propertyName]: Boolean}
Expand Down Expand Up @@ -386,6 +389,10 @@ class StyleLayer extends Evented {
has3DPass() {
return false;
}

resize(gl: WebGLRenderingContext) { // eslint-disable-line
// noop
}
}

module.exports = StyleLayer;
Expand Down
9 changes: 9 additions & 0 deletions src/style/style_layer/fill_extrusion_style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class FillExtrusionStyleLayer extends StyleLayer {
has3DPass() {
return this.paint['fill-extrusion-opacity'] !== 0 && this.layout['visibility'] !== 'none';
}

resize(gl: WebGLRenderingContext) {
if (this.viewportFrame) {
const {texture, fbo} = this.viewportFrame;
gl.deleteTexture(texture);
gl.deleteFramebuffer(fbo);
this.viewportFrame = null;
}
}
}

module.exports = FillExtrusionStyleLayer;

0 comments on commit fbf6145

Please sign in to comment.