Skip to content

Commit 00d7026

Browse files
karimnaajimourner
andauthored
Prevent creation of unused depth renderbuffer attachments (#9377)
* Remove unused depth renderbuffer Should save width * height * 2 bytes of uncompressed buffer memory * Prevent creation of unused depth renderbuffers Add option to allow not creating extra renderbuffers Refer https://www.khronos.org/registry/webgl/specs/latest/1.0/\#6.8 for supported attachment variants Should save the hillshade offscreen buffer width * height * 2 bytes of uncompressed gpu memory * Fix lint * Update src/gl/framebuffer.js Co-Authored-By: Vladimir Agafonkin <agafonkin@gmail.com> Co-authored-by: Vladimir Agafonkin <agafonkin@gmail.com>
1 parent 320755a commit 00d7026

File tree

5 files changed

+14
-28
lines changed

5 files changed

+14
-28
lines changed

src/gl/context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ class Context {
203203
return rbo;
204204
}
205205

206-
createFramebuffer(width: number, height: number) {
207-
return new Framebuffer(this, width, height);
206+
createFramebuffer(width: number, height: number, hasDepth: boolean) {
207+
return new Framebuffer(this, width, height, hasDepth);
208208
}
209209

210210
clear({color, depth}: ClearArgs) {

src/gl/framebuffer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22
import {ColorAttachment, DepthAttachment} from './value';
3+
import assert from 'assert';
34

45
import type Context from './context';
56

@@ -11,15 +12,18 @@ class Framebuffer {
1112
colorAttachment: ColorAttachment;
1213
depthAttachment: DepthAttachment;
1314

14-
constructor(context: Context, width: number, height: number) {
15+
constructor(context: Context, width: number, height: number, hasDepth: boolean) {
1516
this.context = context;
1617
this.width = width;
1718
this.height = height;
1819
const gl = context.gl;
1920
const fbo = this.framebuffer = gl.createFramebuffer();
2021

2122
this.colorAttachment = new ColorAttachment(context, fbo);
22-
this.depthAttachment = new DepthAttachment(context, fbo);
23+
if (hasDepth) {
24+
this.depthAttachment = new DepthAttachment(context, fbo);
25+
}
26+
assert(gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);
2327
}
2428

2529
destroy() {
@@ -28,8 +32,10 @@ class Framebuffer {
2832
const texture = this.colorAttachment.get();
2933
if (texture) gl.deleteTexture(texture);
3034

31-
const renderbuffer = this.depthAttachment.get();
32-
if (renderbuffer) gl.deleteRenderbuffer(renderbuffer);
35+
if (this.depthAttachment) {
36+
const renderbuffer = this.depthAttachment.get();
37+
if (renderbuffer) gl.deleteRenderbuffer(renderbuffer);
38+
}
3339

3440
gl.deleteFramebuffer(this.framebuffer);
3541
}

src/render/draw_heatmap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function bindFramebuffer(context, painter, layer) {
8787
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
8888
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
8989

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

9292
bindTextureToFramebuffer(context, painter, texture, fbo);
9393

src/render/draw_hillshade.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function prepareHillshade(painter, tile, layer, sourceMaxZoom, depthMode, stenci
9090
const renderTexture = new Texture(context, {width: tileSize, height: tileSize, data: null}, gl.RGBA);
9191
renderTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
9292

93-
fbo = tile.fbo = context.createFramebuffer(tileSize, tileSize);
93+
fbo = tile.fbo = context.createFramebuffer(tileSize, tileSize, true);
9494
fbo.colorAttachment.set(renderTexture.texture);
9595
}
9696

src/render/painter.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class Painter {
9292
emptyProgramConfiguration: ProgramConfiguration;
9393
width: number;
9494
height: number;
95-
depthRbo: WebGLRenderbuffer;
96-
depthRboNeedsClear: boolean;
9795
tileExtentBuffer: VertexBuffer;
9896
tileExtentSegments: SegmentVector;
9997
debugBuffer: VertexBuffer;
@@ -136,8 +134,6 @@ class Painter {
136134
this.numSublayers = SourceCache.maxUnderzooming + SourceCache.maxOverzooming + 1;
137135
this.depthEpsilon = 1 / Math.pow(2, 16);
138136

139-
this.depthRboNeedsClear = true;
140-
141137
this.crossTileSymbolIndex = new CrossTileSymbolIndex();
142138

143139
this.gpuTimers = {};
@@ -148,8 +144,6 @@ class Painter {
148144
* for a new width and height value.
149145
*/
150146
resize(width: number, height: number) {
151-
const gl = this.context.gl;
152-
153147
this.width = width * browser.devicePixelRatio;
154148
this.height = height * browser.devicePixelRatio;
155149
this.context.viewport.set([0, 0, this.width, this.height]);
@@ -159,11 +153,6 @@ class Painter {
159153
this.style._layers[layerId].resize();
160154
}
161155
}
162-
163-
if (this.depthRbo) {
164-
gl.deleteRenderbuffer(this.depthRbo);
165-
this.depthRbo = null;
166-
}
167156
}
168157

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

407395
for (const layerId of layerIds) {
408396
const layer = this.style._layers[layerId];
@@ -483,14 +471,6 @@ class Painter {
483471
this.context.setDefault();
484472
}
485473

486-
setupOffscreenDepthRenderbuffer(): void {
487-
const context = this.context;
488-
// All of the 3D textures will use the same depth renderbuffer.
489-
if (!this.depthRbo) {
490-
this.depthRbo = context.createRenderbuffer(context.gl.DEPTH_COMPONENT16, this.width, this.height);
491-
}
492-
}
493-
494474
renderLayer(painter: Painter, sourceCache: SourceCache, layer: StyleLayer, coords: Array<OverscaledTileID>) {
495475
if (layer.isHidden(this.transform.zoom)) return;
496476
if (layer.type !== 'background' && layer.type !== 'custom' && !coords.length) return;

0 commit comments

Comments
 (0)