Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fill extrusion texture/fbo cache #5328

Merged
merged 1 commit into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -63,8 +63,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 @@ -95,8 +93,6 @@ class Painter {
this.gl = gl;
this.transform = transform;
this._tileTextures = {};
this.prerenderedFrames = {};
this.viewportFrames = [];

this.frameHistory = new FrameHistory();

Expand Down Expand Up @@ -124,11 +120,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 @@ -312,7 +308,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 @@ -323,7 +320,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;