| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 * | 277 * |
| 278 * @param {o3d.Bitmap} bitmap The bitmap to copy data from. | 278 * @param {o3d.Bitmap} bitmap The bitmap to copy data from. |
| 279 */ | 279 */ |
| 280 o3d.Texture2D.prototype.setFromBitmap = | 280 o3d.Texture2D.prototype.setFromBitmap = |
| 281 function(bitmap) { | 281 function(bitmap) { |
| 282 this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture_); | 282 this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture_); |
| 283 this.gl.texImage2D(this.gl.TEXTURE_2D, | 283 this.gl.texImage2D(this.gl.TEXTURE_2D, |
| 284 0, // Level. | 284 0, // Level. |
| 285 bitmap.canvas_, | 285 bitmap.canvas_, |
| 286 bitmap.defer_flip_verically_to_texture_); | 286 bitmap.defer_flip_verically_to_texture_); |
| 287 | |
| 288 this.gl.texParameteri(this.gl.TEXTURE_2D, | |
| 289 this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR); | |
| 290 this.gl.texParameteri(this.gl.TEXTURE_2D, | |
| 291 this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR); | |
| 292 this.gl.texParameteri(this.gl.TEXTURE_2D, | |
| 293 this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE); | |
| 294 this.gl.texParameteri(this.gl.TEXTURE_2D, | |
| 295 this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE); | |
| 296 | |
| 297 if (bitmap.defer_mipmaps_to_texture_) { | 287 if (bitmap.defer_mipmaps_to_texture_) { |
| 298 this.generateMips(); | 288 this.generateMips(); |
| 299 } | 289 } |
| 300 }; | 290 }; |
| 301 | 291 |
| 302 | 292 |
| 303 /** | 293 /** |
| 304 * Copy pixels from source bitmap to certain mip level. | 294 * Copy pixels from source bitmap to certain mip level. |
| 305 * Scales if the width and height of source and dest do not match. | 295 * Scales if the width and height of source and dest do not match. |
| 306 * TODO(petersont): Takes optional arguments. | 296 * TODO(petersont): Takes optional arguments. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 318 * destination texture. | 308 * destination texture. |
| 319 * @param {number} dest_y y-coordinate of the starting pixel in the | 309 * @param {number} dest_y y-coordinate of the starting pixel in the |
| 320 * destination texture. | 310 * destination texture. |
| 321 * @param {number} dest_width width of the dest image. | 311 * @param {number} dest_width width of the dest image. |
| 322 * @param {number} dest_height height of the dest image. | 312 * @param {number} dest_height height of the dest image. |
| 323 */ | 313 */ |
| 324 o3d.Texture2D.prototype.drawImage = | 314 o3d.Texture2D.prototype.drawImage = |
| 325 function(source_img, source_mip, source_x, source_y, source_width, | 315 function(source_img, source_mip, source_x, source_y, source_width, |
| 326 source_height, dest_mip, dest_x, dest_y, dest_width, | 316 source_height, dest_mip, dest_x, dest_y, dest_width, |
| 327 dest_height) { | 317 dest_height) { |
| 328 o3d.notImplemented(); | 318 var canvas = o3d.Bitmap.getScratchCanvas_(); |
| 319 canvas.width = dest_width; |
| 320 canvas.height = dest_height; |
| 321 |
| 322 var context = canvas.getContext('2d'); |
| 323 |
| 324 context.translate(-source_x, -source_y); |
| 325 context.scale(dest_width / source_width, |
| 326 dest_height / source_height); |
| 327 |
| 328 context.drawImage(source_img.canvas_, |
| 329 0, 0, source_img.canvas_.width, source_img.canvas_.height); |
| 330 |
| 331 this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture_); |
| 332 this.gl.texSubImage2D(this.gl.TEXTURE_2D, 0, 0, 0, canvas); |
| 329 }; | 333 }; |
| 330 | 334 |
| 331 | 335 |
| 332 /** | 336 /** |
| 333 * TextureCUBE is a class for textures used for cube mapping. A cube texture | 337 * TextureCUBE is a class for textures used for cube mapping. A cube texture |
| 334 * stores bitmaps for the 6 faces of a cube and is addressed via three texture | 338 * stores bitmaps for the 6 faces of a cube and is addressed via three texture |
| 335 * coordinates. | 339 * coordinates. |
| 336 * | 340 * |
| 337 * @param {number} edgeLength The length of any edge of this texture | 341 * @param {number} edgeLength The length of any edge of this texture |
| 338 * @constructor | 342 * @constructor |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 * @param {number} dest_height height of the destination image. | 496 * @param {number} dest_height height of the destination image. |
| 493 */ | 497 */ |
| 494 o3d.TextureCUBE.prototype.drawImage = | 498 o3d.TextureCUBE.prototype.drawImage = |
| 495 function(source_img, source_mip, source_x, source_y, source_width, | 499 function(source_img, source_mip, source_x, source_y, source_width, |
| 496 source_height, face, dest_mip, dest_x, dest_y, dest_width, | 500 source_height, face, dest_mip, dest_x, dest_y, dest_width, |
| 497 dest_height) { | 501 dest_height) { |
| 498 o3d.notImplemented(); | 502 o3d.notImplemented(); |
| 499 }; | 503 }; |
| 500 | 504 |
| 501 | 505 |
| OLD | NEW |