From 80b815221af02ec5aa12502a81514851e3dfbcad Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Mon, 28 Oct 2013 15:50:58 -0400 Subject: [PATCH] Fix issue with canvas parameters --- src/wrappers/CanvasRenderingContext2D.js | 3 ++- src/wrappers/WebGLRenderingContext.js | 6 +++--- test/js/HTMLCanvasElement.js | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/wrappers/CanvasRenderingContext2D.js b/src/wrappers/CanvasRenderingContext2D.js index 7aaf236..0b5c31d 100644 --- a/src/wrappers/CanvasRenderingContext2D.js +++ b/src/wrappers/CanvasRenderingContext2D.js @@ -8,6 +8,7 @@ var mixin = scope.mixin; var registerWrapper = scope.registerWrapper; var unwrap = scope.unwrap; + var unwrapIfNeeded = scope.unwrapIfNeeded; var wrap = scope.wrap; var OriginalCanvasRenderingContext2D = window.CanvasRenderingContext2D; @@ -22,7 +23,7 @@ }, drawImage: function() { - arguments[0] = unwrap(arguments[0]); + arguments[0] = unwrapIfNeeded(arguments[0]); this.impl.drawImage.apply(this.impl, arguments); }, diff --git a/src/wrappers/WebGLRenderingContext.js b/src/wrappers/WebGLRenderingContext.js index 74de34f..6180284 100644 --- a/src/wrappers/WebGLRenderingContext.js +++ b/src/wrappers/WebGLRenderingContext.js @@ -7,7 +7,7 @@ var mixin = scope.mixin; var registerWrapper = scope.registerWrapper; - var unwrap = scope.unwrap; + var unwrapIfNeeded = scope.unwrapIfNeeded; var wrap = scope.wrap; var OriginalWebGLRenderingContext = window.WebGLRenderingContext; @@ -26,12 +26,12 @@ }, texImage2D: function() { - arguments[5] = unwrap(arguments[5]); + arguments[5] = unwrapIfNeeded(arguments[5]); this.impl.texImage2D.apply(this.impl, arguments); }, texSubImage2D: function() { - arguments[6] = unwrap(arguments[6]); + arguments[6] = unwrapIfNeeded(arguments[6]); this.impl.texSubImage2D.apply(this.impl, arguments); } }); diff --git a/test/js/HTMLCanvasElement.js b/test/js/HTMLCanvasElement.js index 89f82c3..e0c6482 100644 --- a/test/js/HTMLCanvasElement.js +++ b/test/js/HTMLCanvasElement.js @@ -93,11 +93,21 @@ suite('HTMLCanvasElement', function() { return; } + var imageData = document.createElement('canvas').getContext('2d'). + createImageData(16, 16); + var arrayBufferView = new Uint8Array(16 * 16 * 4); + var img = document.createElement('img'); img.onload = function() { var texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, + imageData); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, + 16, 16, 0, + gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView); + done(); }; img.src = iconUrl; @@ -118,11 +128,16 @@ suite('HTMLCanvasElement', function() { return; } + var arrayBufferView = new Uint8Array(16 * 16 * 4); + var img = document.createElement('img'); img.onload = function() { var texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture); gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, img); + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, + 16, 16, + gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView); done(); }; img.src = iconUrl;