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

Prevent creation of unused depth renderbuffer attachments #9377

Merged
merged 4 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/gl/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ class Context {
return rbo;
}

createFramebuffer(width: number, height: number) {
return new Framebuffer(this, width, height);
createFramebuffer(width: number, height: number, hasDepth: boolean) {
return new Framebuffer(this, width, height, hasDepth);
}

clear({color, depth}: ClearArgs) {
Expand Down
15 changes: 11 additions & 4 deletions src/gl/framebuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import {ColorAttachment, DepthAttachment} from './value';
import assert from 'assert';

import type Context from './context';

Expand All @@ -11,15 +12,19 @@ class Framebuffer {
colorAttachment: ColorAttachment;
depthAttachment: DepthAttachment;

constructor(context: Context, width: number, height: number) {
constructor(context: Context, width: number, height: number, hasDepth: boolean) {
this.context = context;
this.width = width;
this.height = height;
const gl = context.gl;
const fbo = this.framebuffer = gl.createFramebuffer();

this.colorAttachment = new ColorAttachment(context, fbo);
this.depthAttachment = new DepthAttachment(context, fbo);
if (hasDepth) {
this.depthAttachment = new DepthAttachment(context, fbo);
}
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
assert(status === gl.FRAMEBUFFER_COMPLETE);
karimnaaji marked this conversation as resolved.
Show resolved Hide resolved
}

destroy() {
Expand All @@ -28,8 +33,10 @@ class Framebuffer {
const texture = this.colorAttachment.get();
if (texture) gl.deleteTexture(texture);

const renderbuffer = this.depthAttachment.get();
if (renderbuffer) gl.deleteRenderbuffer(renderbuffer);
if (this.depthAttachment) {
const renderbuffer = this.depthAttachment.get();
if (renderbuffer) gl.deleteRenderbuffer(renderbuffer);
}

gl.deleteFramebuffer(this.framebuffer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/render/draw_heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function bindFramebuffer(context, painter, layer) {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);

fbo = layer.heatmapFbo = context.createFramebuffer(painter.width / 4, painter.height / 4);
fbo = layer.heatmapFbo = context.createFramebuffer(painter.width / 4, painter.height / 4, false);

bindTextureToFramebuffer(context, painter, texture, fbo);

Expand Down
2 changes: 1 addition & 1 deletion src/render/draw_hillshade.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function prepareHillshade(painter, tile, layer, sourceMaxZoom, depthMode, stenci
const renderTexture = new Texture(context, {width: tileSize, height: tileSize, data: null}, gl.RGBA);
renderTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);

fbo = tile.fbo = context.createFramebuffer(tileSize, tileSize);
fbo = tile.fbo = context.createFramebuffer(tileSize, tileSize, true);
fbo.colorAttachment.set(renderTexture.texture);
}

Expand Down
20 changes: 0 additions & 20 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class Painter {
emptyProgramConfiguration: ProgramConfiguration;
width: number;
height: number;
depthRbo: WebGLRenderbuffer;
depthRboNeedsClear: boolean;
tileExtentBuffer: VertexBuffer;
tileExtentSegments: SegmentVector;
debugBuffer: VertexBuffer;
Expand Down Expand Up @@ -136,8 +134,6 @@ class Painter {
this.numSublayers = SourceCache.maxUnderzooming + SourceCache.maxOverzooming + 1;
this.depthEpsilon = 1 / Math.pow(2, 16);

this.depthRboNeedsClear = true;

this.crossTileSymbolIndex = new CrossTileSymbolIndex();

this.gpuTimers = {};
Expand All @@ -148,8 +144,6 @@ class Painter {
* for a new width and height value.
*/
resize(width: number, height: number) {
const gl = this.context.gl;

this.width = width * browser.devicePixelRatio;
this.height = height * browser.devicePixelRatio;
this.context.viewport.set([0, 0, this.width, this.height]);
Expand All @@ -159,11 +153,6 @@ class Painter {
this.style._layers[layerId].resize();
}
}

if (this.depthRbo) {
gl.deleteRenderbuffer(this.depthRbo);
this.depthRbo = null;
}
}

setup() {
Expand Down Expand Up @@ -402,7 +391,6 @@ class Painter {
// framebuffer, and then save those for rendering back to the map
// later: in doing this we avoid doing expensive framebuffer restores.
this.renderPass = 'offscreen';
this.depthRboNeedsClear = true;

for (const layerId of layerIds) {
const layer = this.style._layers[layerId];
Expand Down Expand Up @@ -483,14 +471,6 @@ class Painter {
this.context.setDefault();
}

setupOffscreenDepthRenderbuffer(): void {
const context = this.context;
// All of the 3D textures will use the same depth renderbuffer.
if (!this.depthRbo) {
this.depthRbo = context.createRenderbuffer(context.gl.DEPTH_COMPONENT16, this.width, this.height);
}
}

renderLayer(painter: Painter, sourceCache: SourceCache, layer: StyleLayer, coords: Array<OverscaledTileID>) {
if (layer.isHidden(this.transform.zoom)) return;
if (layer.type !== 'background' && layer.type !== 'custom' && !coords.length) return;
Expand Down