Refactor createTexture
This commit is contained in:
@@ -13,6 +13,7 @@ goog.require('ol.render.webgl.imagereplay.shader.Color');
|
|||||||
goog.require('ol.render.webgl.imagereplay.shader.Default');
|
goog.require('ol.render.webgl.imagereplay.shader.Default');
|
||||||
goog.require('ol.vec.Mat4');
|
goog.require('ol.vec.Mat4');
|
||||||
goog.require('ol.webgl.Buffer');
|
goog.require('ol.webgl.Buffer');
|
||||||
|
goog.require('ol.webgl.Context');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -533,18 +534,8 @@ ol.render.webgl.ImageReplay.prototype.createTextures_ =
|
|||||||
if (goog.object.containsKey(texturePerImage, uid)) {
|
if (goog.object.containsKey(texturePerImage, uid)) {
|
||||||
texture = texturePerImage[uid];
|
texture = texturePerImage[uid];
|
||||||
} else {
|
} else {
|
||||||
texture = gl.createTexture();
|
texture = ol.webgl.Context.createTexture(
|
||||||
gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
|
gl, image, goog.webgl.CLAMP_TO_EDGE, goog.webgl.CLAMP_TO_EDGE);
|
||||||
gl.texParameteri(goog.webgl.TEXTURE_2D,
|
|
||||||
goog.webgl.TEXTURE_WRAP_S, goog.webgl.CLAMP_TO_EDGE);
|
|
||||||
gl.texParameteri(goog.webgl.TEXTURE_2D,
|
|
||||||
goog.webgl.TEXTURE_WRAP_T, goog.webgl.CLAMP_TO_EDGE);
|
|
||||||
gl.texParameteri(goog.webgl.TEXTURE_2D,
|
|
||||||
goog.webgl.TEXTURE_MIN_FILTER, goog.webgl.LINEAR);
|
|
||||||
gl.texParameteri(goog.webgl.TEXTURE_2D,
|
|
||||||
goog.webgl.TEXTURE_MAG_FILTER, goog.webgl.LINEAR);
|
|
||||||
gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA, goog.webgl.RGBA,
|
|
||||||
goog.webgl.UNSIGNED_BYTE, image);
|
|
||||||
texturePerImage[uid] = texture;
|
texturePerImage[uid] = texture;
|
||||||
}
|
}
|
||||||
textures[i] = texture;
|
textures[i] = texture;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ goog.require('ol.extent');
|
|||||||
goog.require('ol.layer.Image');
|
goog.require('ol.layer.Image');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.renderer.webgl.Layer');
|
goog.require('ol.renderer.webgl.Layer');
|
||||||
|
goog.require('ol.webgl.Context');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -52,24 +53,8 @@ ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
|
|||||||
var imageElement = image.getImage();
|
var imageElement = image.getImage();
|
||||||
var gl = this.getWebGLMapRenderer().getGL();
|
var gl = this.getWebGLMapRenderer().getGL();
|
||||||
|
|
||||||
var texture = gl.createTexture();
|
return ol.webgl.Context.createTexture(
|
||||||
|
gl, imageElement, goog.webgl.CLAMP_TO_EDGE, goog.webgl.CLAMP_TO_EDGE);
|
||||||
gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
|
|
||||||
gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA,
|
|
||||||
goog.webgl.RGBA, goog.webgl.UNSIGNED_BYTE, imageElement);
|
|
||||||
|
|
||||||
gl.texParameteri(
|
|
||||||
goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_WRAP_S,
|
|
||||||
goog.webgl.CLAMP_TO_EDGE);
|
|
||||||
gl.texParameteri(
|
|
||||||
goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_WRAP_T,
|
|
||||||
goog.webgl.CLAMP_TO_EDGE);
|
|
||||||
gl.texParameteri(
|
|
||||||
goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MIN_FILTER, goog.webgl.LINEAR);
|
|
||||||
gl.texParameteri(
|
|
||||||
goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MAG_FILTER, goog.webgl.LINEAR);
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ goog.require('ol.renderer.Layer');
|
|||||||
goog.require('ol.renderer.webgl.map.shader.Color');
|
goog.require('ol.renderer.webgl.map.shader.Color');
|
||||||
goog.require('ol.renderer.webgl.map.shader.Default');
|
goog.require('ol.renderer.webgl.map.shader.Default');
|
||||||
goog.require('ol.webgl.Buffer');
|
goog.require('ol.webgl.Buffer');
|
||||||
|
goog.require('ol.webgl.Context');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -115,15 +116,8 @@ ol.renderer.webgl.Layer.prototype.bindFramebuffer =
|
|||||||
}
|
}
|
||||||
}, gl, this.framebuffer, this.texture));
|
}, gl, this.framebuffer, this.texture));
|
||||||
|
|
||||||
var texture = gl.createTexture();
|
var texture = ol.webgl.Context.createEmptyTexture(
|
||||||
gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
|
gl, framebufferDimension, framebufferDimension);
|
||||||
gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA,
|
|
||||||
framebufferDimension, framebufferDimension, 0, goog.webgl.RGBA,
|
|
||||||
goog.webgl.UNSIGNED_BYTE, null);
|
|
||||||
gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MAG_FILTER,
|
|
||||||
goog.webgl.LINEAR);
|
|
||||||
gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MIN_FILTER,
|
|
||||||
goog.webgl.LINEAR);
|
|
||||||
|
|
||||||
var framebuffer = gl.createFramebuffer();
|
var framebuffer = gl.createFramebuffer();
|
||||||
gl.bindFramebuffer(goog.webgl.FRAMEBUFFER, framebuffer);
|
gl.bindFramebuffer(goog.webgl.FRAMEBUFFER, framebuffer);
|
||||||
|
|||||||
@@ -303,13 +303,7 @@ ol.webgl.Context.prototype.initHitDetectionFramebuffer_ = function() {
|
|||||||
var framebuffer = gl.createFramebuffer();
|
var framebuffer = gl.createFramebuffer();
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
||||||
|
|
||||||
var texture = gl.createTexture();
|
var texture = ol.webgl.Context.createEmptyTexture(gl, 1, 1);
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
||||||
gl.texImage2D(
|
|
||||||
gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
||||||
|
|
||||||
var renderbuffer = gl.createRenderbuffer();
|
var renderbuffer = gl.createRenderbuffer();
|
||||||
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
|
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
|
||||||
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 1, 1);
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 1, 1);
|
||||||
@@ -353,3 +347,64 @@ ol.webgl.Context.prototype.useProgram = function(program) {
|
|||||||
* @type {goog.log.Logger}
|
* @type {goog.log.Logger}
|
||||||
*/
|
*/
|
||||||
ol.webgl.Context.prototype.logger_ = goog.log.getLogger('ol.webgl.Context');
|
ol.webgl.Context.prototype.logger_ = goog.log.getLogger('ol.webgl.Context');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {WebGLRenderingContext} gl WebGL rendering context.
|
||||||
|
* @param {number=} opt_wrapS wrapS.
|
||||||
|
* @param {number=} opt_wrapT wrapT.
|
||||||
|
* @return {WebGLTexture}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.webgl.Context.createTexture_ = function(gl, opt_wrapS, opt_wrapT) {
|
||||||
|
var texture = gl.createTexture();
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||||
|
|
||||||
|
if (goog.isDef(opt_wrapS)) {
|
||||||
|
gl.texParameteri(
|
||||||
|
goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_WRAP_S, opt_wrapS);
|
||||||
|
}
|
||||||
|
if (goog.isDef(opt_wrapT)) {
|
||||||
|
gl.texParameteri(
|
||||||
|
goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_WRAP_T, opt_wrapT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {WebGLRenderingContext} gl WebGL rendering context.
|
||||||
|
* @param {number} width Width.
|
||||||
|
* @param {number} height Height.
|
||||||
|
* @param {number=} opt_wrapS wrapS.
|
||||||
|
* @param {number=} opt_wrapT wrapT.
|
||||||
|
* @return {WebGLTexture}
|
||||||
|
*/
|
||||||
|
ol.webgl.Context.createEmptyTexture = function(
|
||||||
|
gl, width, height, opt_wrapS, opt_wrapT) {
|
||||||
|
var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT);
|
||||||
|
gl.texImage2D(
|
||||||
|
gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE,
|
||||||
|
null);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {WebGLRenderingContext} gl WebGL rendering context.
|
||||||
|
* @param {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} image Image.
|
||||||
|
* @param {number=} opt_wrapS wrapS.
|
||||||
|
* @param {number=} opt_wrapT wrapT.
|
||||||
|
* @return {WebGLTexture}
|
||||||
|
*/
|
||||||
|
ol.webgl.Context.createTexture = function(gl, image, opt_wrapS, opt_wrapT) {
|
||||||
|
var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT);
|
||||||
|
gl.texImage2D(
|
||||||
|
gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user