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

Fix flicker when rendering image source #3522

Merged
merged 3 commits into from
Nov 3, 2016
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
2 changes: 1 addition & 1 deletion js/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ class Painter {
let j;
let coords = [];
if (sourceCache) {
if (sourceCache.prepare) sourceCache.prepare();
coords = sourceCache.getVisibleCoordinates();
for (j = 0; j < coords.length; j++) {
coords[j].posMatrix = this.transform.calculatePosMatrix(coords[j], sourceCache.getSource().maxzoom);
}
this.clearStencil();
if (sourceCache.prepare) sourceCache.prepare();
if (sourceCache.getSource().isTileClipped) {
this._renderTileClippingMasks(coords);
}
Expand Down
12 changes: 5 additions & 7 deletions js/source/image_source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('../util/util');
const window = require('../util/window');
const TileCoord = require('./tile_coord');
const LngLat = require('../geo/lng_lat');
const Point = require('point-geometry');
Expand Down Expand Up @@ -66,7 +67,6 @@ class ImageSource extends Evented {
if (err) return this.fire('error', {error: err});

this.image = image;
this._loaded = true;

this._finishLoading();
});
Expand Down Expand Up @@ -127,7 +127,6 @@ class ImageSource extends Evented {
}

_setTile(tile) {
this._prepared = false;
this.tile = tile;
const maxInt16 = 32767;
const array = new RasterBoundsArray();
Expand All @@ -140,25 +139,24 @@ class ImageSource extends Evented {

this.tile.boundsBuffer = Buffer.fromStructArray(array, Buffer.BufferType.VERTEX);
this.tile.boundsVAO = new VertexArrayObject();
this.tile.state = 'loaded';
}

prepare() {
if (!this.tile || !this._loaded || !this.image || !this.image.complete) return;
if (!this.tile || !this.image || !this.image.complete) return;
this._prepareImage(this.map.painter.gl, this.image);
}

_prepareImage(gl, image) {
if (!this._prepared) {
this._prepared = true;
if (this.tile.state !== 'loaded') {
this.tile.state = 'loaded';
this.tile.texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, this.tile.texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
} else {
} else if (image instanceof window.HTMLVideoElement) {
gl.bindTexture(gl.TEXTURE_2D, this.tile.texture);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
Expand Down