Skip to content

Commit

Permalink
Merge remote-tracking branch 'cj/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Mar 10, 2011
2 parents b30507b + 6bb434a commit c486bb1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion webgl-2d.js
Expand Up @@ -235,7 +235,8 @@
this.shaderProgram = undefined;
this.transform = new Transform();
this.shaderPool = [];

this.tex_max_size = undefined;

// Save a reference to the WebGL2D instance on the canvas object
canvas.gl2d = this;

Expand Down Expand Up @@ -271,6 +272,8 @@
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);

gl2d.tex_max_size = gl.getParameter(gl.MAX_TEXTURE_SIZE);

return gl;
} else {
return gl2d.canvas.$getContext(context);
Expand Down Expand Up @@ -851,6 +854,19 @@

imageCache.push(image);

// we may wish to consider tiling large images like this instead of scaling and
// adjust appropriately (flip to next texture source and tile offset) when drawing
if (image.width>gl2d.tex_max_size || image.height>gl2d.tex_max_size) {
var canvas = document.createElement("canvas");
canvas.width = (image.width>gl2d.tex_max_size)?gl2d.tex_max_size:image.width;
canvas.height = (image.height>gl2d.tex_max_size)?gl2d.tex_max_size:image.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(image,
0, 0, image.width, image.height,
0, 0, canvas.width, canvas.height);
image = canvas;
}

gl.bindTexture(gl.TEXTURE_2D, this.obj);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
Expand Down

0 comments on commit c486bb1

Please sign in to comment.