summaryrefslogtreecommitdiffstats
path: root/o3d/samples
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 01:23:17 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 01:23:17 +0000
commit73c59792bc9d2462b71aeafa22fd26ee8d5c37ac (patch)
tree239aceebc768398f1a3c4b0cdb917296d36aefcb /o3d/samples
parent6b376c380840ea0ecc82e0705c31be0116d2804a (diff)
downloadchromium_src-73c59792bc9d2462b71aeafa22fd26ee8d5c37ac.zip
chromium_src-73c59792bc9d2462b71aeafa22fd26ee8d5c37ac.tar.gz
chromium_src-73c59792bc9d2462b71aeafa22fd26ee8d5c37ac.tar.bz2
Review URL: http://codereview.chromium.org/1798009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples')
-rw-r--r--o3d/samples/o3d-webgl/texture.js115
1 files changed, 79 insertions, 36 deletions
diff --git a/o3d/samples/o3d-webgl/texture.js b/o3d/samples/o3d-webgl/texture.js
index 68d6a4f..7cc7927 100644
--- a/o3d/samples/o3d-webgl/texture.js
+++ b/o3d/samples/o3d-webgl/texture.js
@@ -69,6 +69,13 @@ o3d.Texture = function() {
* @private
*/
this.texture_target_ = 0;
+
+ /**
+ * When texParameters get set, this keeps track of what they are so we don't
+ * set them again next time if we don't have to.
+ * @private
+ */
+ this.parameter_cache_ = {};
};
o3d.inherit('Texture', 'ParamObject');
@@ -89,30 +96,30 @@ o3d.Texture.Format = goog.typedef;
* DXT1
* DXT3
* DXT5
- *
+ *
* The in-memory format of the texture bitmap.
- *
+ *
* NOTE: The R32F format is different on GL vs D3D. If you use it in a shader
* you must only use the red channel. The green, blue and alpha channels are
* undefined.
- *
+ *
* For example:
- *
+ *
* ...
- *
+ *
* sampler texSampler0;
- *
+ *
* ...
- *
+ *
* struct PixelShaderInput {
* float4 position : POSITION;
- * float2 texcoord : TEXCOORD0;
+ * float2 texcoord : TEXCOORD0;
* };
- *
+ *
* float4 pixelShaderFunction(PixelShaderInput input): COLOR {
* return tex2D(texSampler0, input.texcoord).rrrr;
* }
- *
+ *
* @param {number} levels The number of mip levels in this texture.
*/
o3d.Texture.UNKNOWN_FORMAT = 0;
@@ -141,7 +148,7 @@ o3d.Texture.prototype.generateMips =
/**
* A class for 2D textures that defines the interface for getting
* the dimensions of the texture, its memory format and number of mipmap levels.
- *
+ *
* @param {number} opt_width The width of this texture in pixels.
* @param {number} opt_height The height of this texture in pixels.
* @constructor
@@ -174,7 +181,7 @@ o3d.ParamObject.setUpO3DParam_(o3d.Texture2D, 'height', 'ParamInteger');
/**
* Returns a RenderSurface object associated with a mip_level of a texture.
- *
+ *
* @param {number} mip_level The mip-level of the surface to be returned.
* @return {o3d.RenderSurface} The RenderSurface object.
*/
@@ -193,16 +200,16 @@ o3d.Texture2D.prototype.getRenderSurface =
/**
* Sets the values of the data stored in the texture.
- *
+ *
* It is not recommend that you call this for large textures but it is useful
* for making simple ramps or noise textures for shaders.
- *
+ *
* NOTE: the number of values must equal the size of the texture * the number
* of elements. In other words, for a XRGB8 texture there must be
* width * height * 3 values. For an ARGB8, ABGR16F or ABGR32F texture there
* must be width * height * 4 values. For an R32F texture there must be
* width * height values.
- *
+ *
* NOTE: the order of channels is R G B for XRGB8 textures and R G B A
* for ARGB8, ABGR16F and ABGR32F textures so for example for XRGB8 textures\n
* \n
@@ -214,7 +221,7 @@ o3d.Texture2D.prototype.getRenderSurface =
* [1, 0, 0, 0] = a red pixel with zero alpha\n
* [1, 0, 0, 1] = a red pixel with one alpha\n
* [0, 0, 1, 1] = a blue pixel with one alpha\n
- *
+ *
* @param {number} level the mip level to update.
* @param {number} values Values to be stored in the buffer.
*/
@@ -226,14 +233,14 @@ o3d.Texture2D.prototype.set =
/**
* Sets a rectangular area of values in a texture.
- *
+ *
* Does clipping. In other words if you pass in a 10x10 pixel array
* and give it destination of (-5, -5) it will only use the bottom 5x5
* pixels of the array you passed in to set the top 5x5 pixels of the
* texture.
- *
+ *
* See o3d.Texture2D.set for details on formats.
- *
+ *
* @param {number} level the mip level to update.
* @param {number} destination_x The x coordinate of the area in the texture
* to affect.
@@ -251,10 +258,10 @@ o3d.Texture2D.prototype.setRect =
/**
* Gets a rectangular area of values from a texture.
- *
+ *
* See o3d.Texture2D.set for details on formats.
* Can not be used for compressed textures.
- *
+ *
* @param {number} level the mip level to get.
* @param {number} x The x coordinate of the area in the texture to retrieve.
* @param {number} y The y coordinate of the area in the texture to retrieve.
@@ -271,7 +278,7 @@ o3d.Texture2D.prototype.getRect =
/**
* Sets the content of the texture to the content of the bitmap. The texture
* and the bitmap must be the same dimensions and the same format.
- *
+ *
* @param {o3d.Bitmap} bitmap The bitmap to copy data from.
*/
o3d.Texture2D.prototype.setFromBitmap =
@@ -325,7 +332,7 @@ o3d.Texture2D.isPowerOfTwo_ = function(value) {
* 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.
- *
+ *
* @param {o3d.Bitmap} source_img The source bitmap.
* @param {number} source_mip which mip from the source to copy from.
* @param {number} source_x x-coordinate of the starting pixel in the
@@ -368,7 +375,7 @@ o3d.Texture2D.prototype.drawImage =
* TextureCUBE is a class for textures used for cube mapping. A cube texture
* stores bitmaps for the 6 faces of a cube and is addressed via three texture
* coordinates.
- *
+ *
* @param {number} edgeLength The length of any edge of this texture
* @constructor
*/
@@ -398,7 +405,7 @@ o3d.TextureCUBE.CubeFace = goog.typedef;
* FACE_NEGATIVE_Y
* FACE_POSITIVE_Z
* FACE_NEGATIVE_Z
- *
+ *
* The names of each of the six faces of a cube map texture.
*/
o3d.TextureCUBE.FACE_POSITIVE_X = 0;
@@ -414,7 +421,7 @@ o3d.ParamObject.setUpO3DParam_(o3d.TextureCUBE, 'edgeLength', 'ParamInteger');
/**
* Returns a RenderSurface object associated with a given cube face and
* mip_level of a texture.
- *
+ *
* @param {o3d.TextureCUBE.CubeFace} face The cube face from which to extract
* the surface.
* @param {o3d.Pack} pack This parameter is no longer used. The surface exists
@@ -430,12 +437,12 @@ o3d.TextureCUBE.prototype.getRenderSurface =
/**
* Sets the values of the data stored in the texture.
- *
+ *
* It is not recommend that you call this for large textures but it is useful
* for making simple ramps or noise textures for shaders.
- *
+ *
* See o3d.Texture2D.set for details on formats.
- *
+ *
* @param {o3d.TextureCUBE.CubeFace} face the face to update.
* @param {number} level the mip level to update.
* @param {number} values Values to be stored in the buffer.
@@ -448,14 +455,14 @@ o3d.TextureCUBE.prototype.set =
/**
* Sets a rectangular area of values in a texture.
- *
+ *
* Does clipping. In other words if you pass in a 10x10 pixel array
* and give it destination of (-5, -5) it will only use the bottom 5x5
* pixels of the array you passed in to set the top 5x5 pixels of the
* texture.
- *
+ *
* See o3d.Texture2D.set for details on formats.
- *
+ *
* @param {o3d.TextureCUBE.CubeFace} face the face to update.
* @param {number} level the mip level to update.
* @param {number} destination_x The x coordinate of the area in the texture
@@ -474,10 +481,10 @@ o3d.TextureCUBE.prototype.setRect =
/**
* Gets a rectangular area of values from a texture.
- *
+ *
* See o3d.Texture2D.set for details on formats.
* Can not be used for compressed textures.
- *
+ *
* @param {o3d.TextureCUBE.CubeFace} face the face to get.
* @param {number} level the mip level to get.
* @param {number} x The x coordinate of the area in the texture to retrieve.
@@ -495,7 +502,7 @@ o3d.TextureCUBE.prototype.getRect =
/**
* Sets the content of a face of the texture to the content of the bitmap. The
* texture and the bitmap must be the same dimensions and the same format.
- *
+ *
* @param {o3d.TextureCUBE.CubeFace} face The face to set.
* @param {o3d.Bitmap} bitmap The bitmap to copy data from.
*/
@@ -519,7 +526,7 @@ o3d.TextureCUBE.prototype.setFromBitmap =
* Copy pixels from source bitmap to certain face and mip level.
* Scales if the width and height of source and dest do not match.
* TODO(petersont): Should take optional arguments.
- *
+ *
* @param {o3d.Bitmap} source_img The source bitmap.
* @param {number} source_mip which mip of the source to copy from.
* @param {number} source_x x-coordinate of the starting pixel in the
@@ -545,3 +552,39 @@ o3d.TextureCUBE.prototype.drawImage =
};
+/**
+ * Makes this texture currrent, and sets various texParameters provided they
+ * have changed since the last time bindAndSetParameters_ was called for this
+ * texture.
+ * @param {number} addressModeU The address mode in the U coordinate.
+ * @param {number} addressModeV The address mode in the V coordinate.
+ * @param {number} minFilter The type of the min filter.
+ * @param {number} magFilter The type of the mag filter.
+ */
+o3d.Texture.prototype.bindAndSetParameters_ =
+ function(addressModeU, addressModeV, minFilter, magFilter) {
+ var target = this.texture_target_;
+ this.gl.bindTexture(target, this.texture_);
+
+ if (this.parameter_cache_.addressModeU != addressModeU) {
+ this.gl.texParameteri(target, this.gl.TEXTURE_WRAP_S, addressModeU);
+ this.parameter_cache_.addressModeU = addressModeU;
+ }
+
+ if (this.parameter_cache_.addressModeV != addressModeV) {
+ this.gl.texParameteri(target, this.gl.TEXTURE_WRAP_T, addressModeV);
+ this.parameter_cache_.addressModeV = addressModeV;
+ }
+
+ if (this.parameter_cache_.minFilter != minFilter) {
+ this.gl.texParameteri(target, this.gl.TEXTURE_MIN_FILTER, minFilter);
+ this.parameter_cache_.minFilter = minFilter;
+ }
+
+ if (this.parameter_cache_.magFilter != magFilter) {
+ this.gl.texParameteri(target, this.gl.TEXTURE_MAG_FILTER, magFilter);
+ this.parameter_cache_.magFilter = magFilter;
+ }
+};
+
+