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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: samples/o3d-webgl/texture.js
===================================================================
--- samples/o3d-webgl/texture.js (revision 45777)
+++ samples/o3d-webgl/texture.js (working copy)
@@ -281,6 +281,7 @@
0, // Level.
bitmap.canvas_,
bitmap.defer_flip_vertically_to_texture_);
+ this.setupRepeatModes_(bitmap.canvas_.width, bitmap.canvas_.height);
if (bitmap.defer_mipmaps_to_texture_) {
this.generateMips();
}
@@ -288,6 +289,39 @@
/**
+ * Sets up the repeat modes for the given width and height.
+ * Assumes the texture is already bound to the TEXTURE_2D binding point.
+ * @private
+ */
+o3d.Texture2D.prototype.setupRepeatModes_ = function(width, height) {
+ // OpenGL ES 2.0 and consequently WebGL don't support anything but
+ // CLAMP_TO_EDGE for NPOT textures.
+ if (o3d.Texture2D.isPowerOfTwo_(width) &&
+ o3d.Texture2D.isPowerOfTwo_(height)) {
+ this.gl.texParameteri(this.gl.TEXTURE_2D,
+ this.gl.TEXTURE_WRAP_S, this.gl.REPEAT);
+ this.gl.texParameteri(this.gl.TEXTURE_2D,
+ this.gl.TEXTURE_WRAP_T, this.gl.REPEAT);
+ } else {
+ this.gl.texParameteri(this.gl.TEXTURE_2D,
+ this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
+ this.gl.texParameteri(this.gl.TEXTURE_2D,
+ this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
+ }
+};
+
+/**
+ * Indicates whether the given number is a power of two.
+ * @private
+ */
+o3d.Texture2D.isPowerOfTwo_ = function(value) {
+ if (value == undefined)
+ return false;
+ return (value & (value - 1)) == 0;
+};
+
+
+/**
* Copy pixels from source bitmap to certain mip level.
* Scales if the width and height of source and dest do not match.
* TODO(petersont): Takes optional arguments.

Powered by Google App Engine
This is Rietveld 408576698