Refactor createTexture
This commit is contained in:
@@ -303,13 +303,7 @@ ol.webgl.Context.prototype.initHitDetectionFramebuffer_ = function() {
|
||||
var framebuffer = gl.createFramebuffer();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
||||
|
||||
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);
|
||||
gl.texImage2D(
|
||||
gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
||||
|
||||
var texture = ol.webgl.Context.createEmptyTexture(gl, 1, 1);
|
||||
var renderbuffer = gl.createRenderbuffer();
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 1, 1);
|
||||
@@ -353,3 +347,64 @@ ol.webgl.Context.prototype.useProgram = function(program) {
|
||||
* @type {goog.log.Logger}
|
||||
*/
|
||||
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