Skip to content

Commit

Permalink
Update per mdn webgl recommendations (#9474)
Browse files Browse the repository at this point in the history
* Update per mdn webgl recommendations
- Delete shader handles after succesfull compilation
- Query render to half float texture instead of calling checkFramebufferStatus, potentially involving flush + round-trip on first frame

* Add heatmap layer to release testing
  • Loading branch information
karimnaaji committed Apr 1, 2020
1 parent 928f3dd commit 0a7ecc5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/gl/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Context {
extTextureFilterAnisotropic: any;
extTextureFilterAnisotropicMax: any;
extTextureHalfFloat: any;
extRenderToTextureHalfFloat: any;
extTimerQuery: any;

constructor(gl: WebGLRenderingContext) {
Expand Down Expand Up @@ -113,6 +114,7 @@ class Context {
this.extTextureHalfFloat = gl.getExtension('OES_texture_half_float');
if (this.extTextureHalfFloat) {
gl.getExtension('OES_texture_half_float_linear');
this.extRenderToTextureHalfFloat = gl.getExtension('EXT_color_buffer_half_float');
}

this.extTimerQuery = gl.getExtension('EXT_disjoint_timer_query');
Expand Down
13 changes: 3 additions & 10 deletions src/render/draw_heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,10 @@ function bindFramebuffer(context, painter, layer) {
function bindTextureToFramebuffer(context, painter, texture, fbo) {
const gl = context.gl;
// Use the higher precision half-float texture where available (producing much smoother looking heatmaps);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, painter.width / 4, painter.height / 4, 0, gl.RGBA,
context.extTextureHalfFloat ? context.extTextureHalfFloat.HALF_FLOAT_OES : gl.UNSIGNED_BYTE, null);

// Otherwise, fall back to a low precision texture
const internalFormat = context.extRenderToTextureHalfFloat ? context.extTextureHalfFloat.HALF_FLOAT_OES : gl.UNSIGNED_BYTE;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, painter.width / 4, painter.height / 4, 0, gl.RGBA, internalFormat, null);
fbo.colorAttachment.set(texture);

// If using half-float texture as a render target is not supported, fall back to a low precision texture
if (context.extTextureHalfFloat && gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
context.extTextureHalfFloat = null;
fbo.colorAttachment.setDirty();
bindTextureToFramebuffer(context, painter, texture, fbo);
}
}

function renderTextureToMap(painter, layer) {
Expand Down
3 changes: 3 additions & 0 deletions src/render/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class Program<Us: UniformBindings> {
gl.linkProgram(this.program);
assert(gl.getProgramParameter(this.program, gl.LINK_STATUS), (gl.getProgramInfoLog(this.program): any));

gl.deleteShader(vertexShader);
gl.deleteShader(fragmentShader);

this.numAttributes = gl.getProgramParameter(this.program, gl.ACTIVE_ATTRIBUTES);

this.attributes = {};
Expand Down
3 changes: 3 additions & 0 deletions test/release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const pages = {
},
"mapbox-gl-rtl-text": {
"title": "Add support for right-to-left scripts"
},
"heatmap-layer": {
"title": "Add a heatmap layer"
}
};

Expand Down

0 comments on commit 0a7ecc5

Please sign in to comment.