Better typing, fewer arrays
This commit is contained in:
@@ -23,6 +23,12 @@ ol.render.webgl.ImageReplay = function(tolerance) {
|
|||||||
*/
|
*/
|
||||||
this.extent_ = ol.extent.createEmpty();
|
this.extent_ = ol.extent.createEmpty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Array.<number>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.groupIndices_ = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number|undefined}
|
* @type {number|undefined}
|
||||||
* @private
|
* @private
|
||||||
@@ -30,7 +36,7 @@ ol.render.webgl.ImageReplay = function(tolerance) {
|
|||||||
this.height_ = undefined;
|
this.height_ = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array.<Array.<*>>}
|
* @type {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.images_ = [];
|
this.images_ = [];
|
||||||
@@ -71,6 +77,12 @@ ol.render.webgl.ImageReplay = function(tolerance) {
|
|||||||
*/
|
*/
|
||||||
this.originY_ = undefined;
|
this.originY_ = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Array.<WebGLTexture>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.textures_ = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array.<number>}
|
* @type {Array.<number>}
|
||||||
* @private
|
* @private
|
||||||
@@ -89,12 +101,6 @@ ol.render.webgl.ImageReplay = function(tolerance) {
|
|||||||
*/
|
*/
|
||||||
this.width_ = undefined;
|
this.width_ = undefined;
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {Array.<Array.<*>>}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
this.textures_ = [];
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -261,10 +267,8 @@ ol.render.webgl.ImageReplay.prototype.drawText = goog.abstractMethod;
|
|||||||
ol.render.webgl.ImageReplay.prototype.finish = function(context) {
|
ol.render.webgl.ImageReplay.prototype.finish = function(context) {
|
||||||
var gl = context.getGL();
|
var gl = context.getGL();
|
||||||
|
|
||||||
goog.asserts.assert(this.images_.length > 0);
|
this.groupIndices_.push(this.indices_.length);
|
||||||
var current = this.images_[this.images_.length - 1];
|
goog.asserts.assert(this.images_.length == this.groupIndices_.length);
|
||||||
goog.asserts.assert(!goog.isDef(current[1]));
|
|
||||||
current[1] = this.indices_.length;
|
|
||||||
|
|
||||||
this.verticesBuffer_ = gl.createBuffer();
|
this.verticesBuffer_ = gl.createBuffer();
|
||||||
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, this.verticesBuffer_);
|
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, this.verticesBuffer_);
|
||||||
@@ -281,10 +285,7 @@ ol.render.webgl.ImageReplay.prototype.finish = function(context) {
|
|||||||
var ii = this.images_.length;
|
var ii = this.images_.length;
|
||||||
var texture;
|
var texture;
|
||||||
for (i = 0; i < ii; ++i) {
|
for (i = 0; i < ii; ++i) {
|
||||||
var image =
|
var image = this.images_[i];
|
||||||
/** @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} */
|
|
||||||
(this.images_[i][0]);
|
|
||||||
current = this.images_[i];
|
|
||||||
texture = gl.createTexture();
|
texture = gl.createTexture();
|
||||||
gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
|
gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
|
||||||
gl.texParameteri(goog.webgl.TEXTURE_2D,
|
gl.texParameteri(goog.webgl.TEXTURE_2D,
|
||||||
@@ -297,15 +298,19 @@ ol.render.webgl.ImageReplay.prototype.finish = function(context) {
|
|||||||
goog.webgl.TEXTURE_MAG_FILTER, goog.webgl.NEAREST);
|
goog.webgl.TEXTURE_MAG_FILTER, goog.webgl.NEAREST);
|
||||||
gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA, goog.webgl.RGBA,
|
gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA, goog.webgl.RGBA,
|
||||||
goog.webgl.UNSIGNED_BYTE, image);
|
goog.webgl.UNSIGNED_BYTE, image);
|
||||||
this.textures_[i] = [texture, this.images_[i][1]];
|
this.textures_[i] = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goog.asserts.assert(this.textures_.length == this.groupIndices_.length);
|
||||||
|
|
||||||
this.height_ = undefined;
|
this.height_ = undefined;
|
||||||
this.images_.length = 0;
|
this.images_ = null;
|
||||||
this.imageHeight_ = undefined;
|
this.imageHeight_ = undefined;
|
||||||
this.imageWidth_ = undefined;
|
this.imageWidth_ = undefined;
|
||||||
|
this.indices_ = null;
|
||||||
this.originX_ = undefined;
|
this.originX_ = undefined;
|
||||||
this.originY_ = undefined;
|
this.originY_ = undefined;
|
||||||
|
this.vertices_ = null;
|
||||||
this.width_ = undefined;
|
this.width_ = undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -359,14 +364,13 @@ ol.render.webgl.ImageReplay.prototype.replay = function(context,
|
|||||||
|
|
||||||
gl.bindBuffer(goog.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer_);
|
gl.bindBuffer(goog.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer_);
|
||||||
|
|
||||||
|
goog.asserts.assert(this.textures_.length == this.groupIndices_.length);
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
var ii = this.textures_.length;
|
var ii = this.textures_.length;
|
||||||
var texture;
|
|
||||||
for (i = 0; i < ii; ++i) {
|
for (i = 0; i < ii; ++i) {
|
||||||
texture = this.textures_[i];
|
gl.bindTexture(goog.webgl.TEXTURE_2D, this.textures_[i]);
|
||||||
gl.bindTexture(goog.webgl.TEXTURE_2D,
|
gl.drawElements(goog.webgl.TRIANGLES, this.groupIndices_[i],
|
||||||
/** @type {WebGLTexture} */ (texture[0]));
|
|
||||||
gl.drawElements(goog.webgl.TRIANGLES, /** @type {number} */ (texture[1]),
|
|
||||||
goog.webgl.UNSIGNED_SHORT, 0);
|
goog.webgl.UNSIGNED_SHORT, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -393,16 +397,13 @@ ol.render.webgl.ImageReplay.prototype.setImageStyle = function(imageStyle) {
|
|||||||
goog.asserts.assert(!goog.isNull(size));
|
goog.asserts.assert(!goog.isNull(size));
|
||||||
|
|
||||||
if (this.images_.length === 0) {
|
if (this.images_.length === 0) {
|
||||||
this.images_.push([image, undefined]);
|
this.images_.push(image);
|
||||||
} else {
|
} else {
|
||||||
var current = this.images_[this.images_.length - 1];
|
var currentImage = this.images_[this.images_.length - 1];
|
||||||
var currentImage =
|
|
||||||
/** @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} */
|
|
||||||
(current[0]);
|
|
||||||
goog.asserts.assert(!goog.isDef(current[1]));
|
|
||||||
if (goog.getUid(currentImage) != goog.getUid(image)) {
|
if (goog.getUid(currentImage) != goog.getUid(image)) {
|
||||||
current[1] = this.indices_.length;
|
this.groupIndices_.push(this.indices_.length);
|
||||||
this.images_.push([image, undefined]);
|
goog.asserts.assert(this.groupIndices_.length == this.images_.length);
|
||||||
|
this.images_.push(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user