Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Fix issue with canvas parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Oct 28, 2013
1 parent 3888683 commit 80b8152
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/wrappers/CanvasRenderingContext2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +23,7 @@
},

drawImage: function() {
arguments[0] = unwrap(arguments[0]);
arguments[0] = unwrapIfNeeded(arguments[0]);
this.impl.drawImage.apply(this.impl, arguments);
},

Expand Down
6 changes: 3 additions & 3 deletions src/wrappers/WebGLRenderingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});
Expand Down
15 changes: 15 additions & 0 deletions test/js/HTMLCanvasElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 80b8152

Please sign in to comment.