Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(784)

Side by Side Diff: samples/o3d-webgl/texture.js

Issue 1687019: Fixed samples to work with resizing code introduced yesterday. Now the... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/o3d/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 * 274 *
275 * @param {o3d.Bitmap} bitmap The bitmap to copy data from. 275 * @param {o3d.Bitmap} bitmap The bitmap to copy data from.
276 */ 276 */
277 o3d.Texture2D.prototype.setFromBitmap = 277 o3d.Texture2D.prototype.setFromBitmap =
278 function(bitmap) { 278 function(bitmap) {
279 this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture_); 279 this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture_);
280 this.gl.texImage2D(this.gl.TEXTURE_2D, 280 this.gl.texImage2D(this.gl.TEXTURE_2D,
281 0, // Level. 281 0, // Level.
282 bitmap.canvas_, 282 bitmap.canvas_,
283 bitmap.defer_flip_vertically_to_texture_); 283 bitmap.defer_flip_vertically_to_texture_);
284 this.setupRepeatModes_(bitmap.canvas_.width, bitmap.canvas_.height);
284 if (bitmap.defer_mipmaps_to_texture_) { 285 if (bitmap.defer_mipmaps_to_texture_) {
285 this.generateMips(); 286 this.generateMips();
286 } 287 }
287 }; 288 };
288 289
289 290
290 /** 291 /**
292 * Sets up the repeat modes for the given width and height.
293 * Assumes the texture is already bound to the TEXTURE_2D binding point.
294 * @private
295 */
296 o3d.Texture2D.prototype.setupRepeatModes_ = function(width, height) {
297 // OpenGL ES 2.0 and consequently WebGL don't support anything but
298 // CLAMP_TO_EDGE for NPOT textures.
299 if (o3d.Texture2D.isPowerOfTwo_(width) &&
300 o3d.Texture2D.isPowerOfTwo_(height)) {
301 this.gl.texParameteri(this.gl.TEXTURE_2D,
302 this.gl.TEXTURE_WRAP_S, this.gl.REPEAT);
303 this.gl.texParameteri(this.gl.TEXTURE_2D,
304 this.gl.TEXTURE_WRAP_T, this.gl.REPEAT);
305 } else {
306 this.gl.texParameteri(this.gl.TEXTURE_2D,
307 this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
308 this.gl.texParameteri(this.gl.TEXTURE_2D,
309 this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
310 }
311 };
312
313 /**
314 * Indicates whether the given number is a power of two.
315 * @private
316 */
317 o3d.Texture2D.isPowerOfTwo_ = function(value) {
318 if (value == undefined)
319 return false;
320 return (value & (value - 1)) == 0;
321 };
322
323
324 /**
291 * Copy pixels from source bitmap to certain mip level. 325 * Copy pixels from source bitmap to certain mip level.
292 * Scales if the width and height of source and dest do not match. 326 * Scales if the width and height of source and dest do not match.
293 * TODO(petersont): Takes optional arguments. 327 * TODO(petersont): Takes optional arguments.
294 * 328 *
295 * @param {o3d.Bitmap} source_img The source bitmap. 329 * @param {o3d.Bitmap} source_img The source bitmap.
296 * @param {number} source_mip which mip from the source to copy from. 330 * @param {number} source_mip which mip from the source to copy from.
297 * @param {number} source_x x-coordinate of the starting pixel in the 331 * @param {number} source_x x-coordinate of the starting pixel in the
298 * source image. 332 * source image.
299 * @param {number} source_y y-coordinate of the starting pixel in the 333 * @param {number} source_y y-coordinate of the starting pixel in the
300 * source image. 334 * source image.
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 * @param {number} dest_height height of the destination image. 538 * @param {number} dest_height height of the destination image.
505 */ 539 */
506 o3d.TextureCUBE.prototype.drawImage = 540 o3d.TextureCUBE.prototype.drawImage =
507 function(source_img, source_mip, source_x, source_y, source_width, 541 function(source_img, source_mip, source_x, source_y, source_width,
508 source_height, face, dest_mip, dest_x, dest_y, dest_width, 542 source_height, face, dest_mip, dest_x, dest_y, dest_width,
509 dest_height) { 543 dest_height) {
510 o3d.notImplemented(); 544 o3d.notImplemented();
511 }; 545 };
512 546
513 547
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698