| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 * size. | 218 * size. |
| 219 * @param {HTMLCanvas} canvas The canvas to load into the texture. | 219 * @param {HTMLCanvas} canvas The canvas to load into the texture. |
| 220 * @param {boolean} resize_to_pot Whether or not to resize to a power of two | 220 * @param {boolean} resize_to_pot Whether or not to resize to a power of two |
| 221 * size. | 221 * size. |
| 222 * @param {boolean} generate_mips Whether or not to generate mips. | 222 * @param {boolean} generate_mips Whether or not to generate mips. |
| 223 * | 223 * |
| 224 * @private | 224 * @private |
| 225 */ | 225 */ |
| 226 o3d.Texture.prototype.setFromCanvas_ = | 226 o3d.Texture.prototype.setFromCanvas_ = |
| 227 function(canvas, resize_to_pot, flip, generate_mips, face) { | 227 function(canvas, resize_to_pot, flip, generate_mips, face) { |
| 228 this.gl.bindTexture(this.texture_target_, this.texture_); | 228 var gl = this.gl; |
| 229 gl.bindTexture(this.texture_target_, this.texture_); |
| 229 | 230 |
| 230 if (resize_to_pot && (!o3d.Texture.isPowerOfTwo_(canvas.width) || | 231 if (resize_to_pot && (!o3d.Texture.isPowerOfTwo_(canvas.width) || |
| 231 !o3d.Texture.isPowerOfTwo_(canvas.height))) { | 232 !o3d.Texture.isPowerOfTwo_(canvas.height))) { |
| 232 // Get a scratch canvas. | 233 // Get a scratch canvas. |
| 233 var scratch = o3d.Bitmap.getScratchCanvas_(); | 234 var scratch = o3d.Bitmap.getScratchCanvas_(); |
| 234 // Set the size of the canvas to the power-of-two size. | 235 // Set the size of the canvas to the power-of-two size. |
| 235 scratch.width = o3d.Texture.nextHighestPowerOfTwo_(canvas.width); | 236 scratch.width = o3d.Texture.nextHighestPowerOfTwo_(canvas.width); |
| 236 scratch.height = o3d.Texture.nextHighestPowerOfTwo_(canvas.height); | 237 scratch.height = o3d.Texture.nextHighestPowerOfTwo_(canvas.height); |
| 237 // Draw the given canvas into that scratch canvas. | 238 // Draw the given canvas into that scratch canvas. |
| 238 scratch.getContext("2d").drawImage(canvas, | 239 scratch.getContext("2d").drawImage(canvas, |
| 239 0, 0, canvas.width, canvas.height, | 240 0, 0, canvas.width, canvas.height, |
| 240 0, 0, scratch.width, scratch.height); | 241 0, 0, scratch.width, scratch.height); |
| 241 canvas = scratch; | 242 canvas = scratch; |
| 242 } | 243 } |
| 243 | 244 |
| 244 var target = this.texture_target_; | 245 var target = this.texture_target_; |
| 245 if (target == this.gl.TEXTURE_CUBE_MAP) { | 246 if (target == this.gl.TEXTURE_CUBE_MAP) { |
| 246 target = this.gl.TEXTURE_CUBE_MAP_POSITIVE_X + face; | 247 target = this.gl.TEXTURE_CUBE_MAP_POSITIVE_X + face; |
| 247 } | 248 } |
| 248 | 249 |
| 249 this.gl.texImage2D(target, 0 /*level*/, canvas, flip); | 250 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flip); |
| 251 gl.texImage2D( |
| 252 target, 0 /*level*/, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas); |
| 253 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0); |
| 250 this.texture_width_ = canvas.width; | 254 this.texture_width_ = canvas.width; |
| 251 this.texture_height_ = canvas.height; | 255 this.texture_height_ = canvas.height; |
| 252 | 256 |
| 253 if (generate_mips) { | 257 if (generate_mips) { |
| 254 // The texture target is already bound so why bind it again by calling | 258 // The texture target is already bound so why bind it again by calling |
| 255 // this.generateMip. | 259 // this.generateMip. |
| 256 this.gl.generateMipmap(this.texture_target_); | 260 this.gl.generateMipmap(this.texture_target_); |
| 257 } | 261 } |
| 258 }; | 262 }; |
| 259 | 263 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 | 495 |
| 492 var context = canvas.getContext('2d'); | 496 var context = canvas.getContext('2d'); |
| 493 | 497 |
| 494 context.translate(-source_x, -source_y); | 498 context.translate(-source_x, -source_y); |
| 495 context.scale(dest_width / source_width, | 499 context.scale(dest_width / source_width, |
| 496 dest_height / source_height); | 500 dest_height / source_height); |
| 497 | 501 |
| 498 context.drawImage(source_img.canvas_, | 502 context.drawImage(source_img.canvas_, |
| 499 0, 0, source_img.canvas_.width, source_img.canvas_.height); | 503 0, 0, source_img.canvas_.width, source_img.canvas_.height); |
| 500 | 504 |
| 501 this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture_); | 505 var gl = this.gl; |
| 506 gl.bindTexture(gl.TEXTURE_2D, this.texture_); |
| 502 // TODO(petersont): replace this with a call to texSubImage2D once | 507 // TODO(petersont): replace this with a call to texSubImage2D once |
| 503 // Firefox supports it. | 508 // Firefox supports it. |
| 504 this.gl.texImage2D(this.gl.TEXTURE_2D, 0, canvas); | 509 gl.texImage2D( |
| 510 gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas); |
| 505 // this.gl.texSubImage2D(this.gl.TEXTURE_2D, 0, 0, 0, canvas); | 511 // this.gl.texSubImage2D(this.gl.TEXTURE_2D, 0, 0, 0, canvas); |
| 506 this.texture_width_ = canvas.width; | 512 this.texture_width_ = canvas.width; |
| 507 this.texture_height_ = canvas.height; | 513 this.texture_height_ = canvas.height; |
| 508 }; | 514 }; |
| 509 | 515 |
| 510 | 516 |
| 511 /** | 517 /** |
| 512 * TextureCUBE is a class for textures used for cube mapping. A cube texture | 518 * TextureCUBE is a class for textures used for cube mapping. A cube texture |
| 513 * stores bitmaps for the 6 faces of a cube and is addressed via three texture | 519 * stores bitmaps for the 6 faces of a cube and is addressed via three texture |
| 514 * coordinates. | 520 * coordinates. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 this.parameter_cache_.minFilter = minFilter; | 783 this.parameter_cache_.minFilter = minFilter; |
| 778 } | 784 } |
| 779 | 785 |
| 780 if (this.parameter_cache_.magFilter != magFilter) { | 786 if (this.parameter_cache_.magFilter != magFilter) { |
| 781 this.gl.texParameteri(target, this.gl.TEXTURE_MAG_FILTER, magFilter); | 787 this.gl.texParameteri(target, this.gl.TEXTURE_MAG_FILTER, magFilter); |
| 782 this.parameter_cache_.magFilter = magFilter; | 788 this.parameter_cache_.magFilter = magFilter; |
| 783 } | 789 } |
| 784 }; | 790 }; |
| 785 | 791 |
| 786 | 792 |
| OLD | NEW |