diff options
author | petersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 01:02:30 +0000 |
---|---|---|
committer | petersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 01:02:30 +0000 |
commit | bb80cd0ebf646892cf0d4ae24f5ca701ab53c9d4 (patch) | |
tree | f79e89d96376f98e89be5e0f0ad3706798eee334 /o3d | |
parent | 87b4c791f0f5dfea6acf9f7ada069ee595535d31 (diff) | |
download | chromium_src-bb80cd0ebf646892cf0d4ae24f5ca701ab53c9d4.zip chromium_src-bb80cd0ebf646892cf0d4ae24f5ca701ab53c9d4.tar.gz chromium_src-bb80cd0ebf646892cf0d4ae24f5ca701ab53c9d4.tar.bz2 |
Fleshed out sampler implementation a bit.
Review URL: http://codereview.chromium.org/1759012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/samples/o3d-webgl/pack.js | 7 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl/param.js | 11 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl/sampler.js | 111 |
3 files changed, 115 insertions, 14 deletions
diff --git a/o3d/samples/o3d-webgl/pack.js b/o3d/samples/o3d-webgl/pack.js index 58abf20..1ce8a15 100644 --- a/o3d/samples/o3d-webgl/pack.js +++ b/o3d/samples/o3d-webgl/pack.js @@ -211,15 +211,8 @@ o3d.Pack.prototype.createTexture2D = this.gl.bindTexture(this.gl.TEXTURE_2D, texture.texture_); this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, width, height, 0, this.gl.RGBA, this.gl.UNSIGNED_BYTE, null); - texture.setupRepeatModes_(width, height); } - this.gl.bindTexture(this.gl.TEXTURE_2D, texture.texture_); - this.gl.texParameteri(this.gl.TEXTURE_2D, - this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR); - this.gl.texParameteri(this.gl.TEXTURE_2D, - this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR); - return texture; }; diff --git a/o3d/samples/o3d-webgl/param.js b/o3d/samples/o3d-webgl/param.js index 731ae21..4a5ec63 100644 --- a/o3d/samples/o3d-webgl/param.js +++ b/o3d/samples/o3d-webgl/param.js @@ -822,14 +822,11 @@ o3d.ParamSampler.prototype.applyToLocation = function(gl, location) { var value = null; var target = 0; - if (this.value && this.value.texture && this.value.texture.texture_) { - value = this.value.texture.texture_; - target = this.value.texture.texture_target_; + if (this.value) { + this.value.bindAndSetParameters_(); + gl.uniform1i(location, i); + o3d.Param.texture_index_++; } - - gl.bindTexture(target, value); - gl.uniform1i(location, i); - o3d.Param.texture_index_++; }; diff --git a/o3d/samples/o3d-webgl/sampler.js b/o3d/samples/o3d-webgl/sampler.js index f126385..eb0a0e1 100644 --- a/o3d/samples/o3d-webgl/sampler.js +++ b/o3d/samples/o3d-webgl/sampler.js @@ -160,3 +160,114 @@ o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'borderColor', 'ParamFloat4'); o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'maxAnisotropy', 'ParamInteger'); o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'texture', 'ParamTexture'); + +/** + * Converts the addressing mode of the sampler from an o3d constant to a webgl + * constant. + * @param {!o3d.Sampler.AddressMode} o3d_mode, the O3D addressing mode. + * @return {number} The webgl mode. + */ +o3d.Sampler.prototype.convertAddressMode_ = function(o3d_mode) { + var gl_mode = this.gl.REPEAT; + switch (o3d_mode) { + case o3d.Sampler.WRAP: + gl_mode = this.gl.REPEAT; + break; + case o3d.Sampler.MIRROR: + gl_mode = this.gl.MIRRORED_REPEAT; + break; + case o3d.Sampler.CLAMP: + gl_mode = this.gl.CLAMP_TO_EDGE; + break; + case o3d.Sampler.BORDER: + gl_mode = this.gl.CLAMP_TO_BORDER; + break; + default: + this.gl.client.error_callback("Unknown Address mode"); + break; + } + return gl_mode; +} + + +/** + * Converts the min filter mode of the sampler from an o3d constant to a webgl + * constant. + * @param {!o3d.Sampler.FilterType} o3d_filter, the O3D filter. + * @param {!o3d.Sampler.FilterType} mip_filter, the O3D mip filter. + * @return {number} The webgl filter. + */ +o3d.Sampler.prototype.convertMinFilter_ = function(o3d_filter, mip_filter) { + switch (o3d_filter) { + case o3d.Sampler.NONE: + return this.gl.NEAREST; + case o3d.Sampler.POINT: + if (mip_filter == o3d.Sampler.NONE) { + return this.gl.NEAREST; + } else if (mip_filter == o3d.Sampler.POINT) { + return this.gl.NEAREST_MIPMAP_NEAREST; + } else if (mip_filter == o3d.Sampler.LINEAR) { + return this.gl.NEAREST_MIPMAP_LINEAR; + } else if (mip_filter == o3d.Sampler.ANISOTROPIC) { + return this.gl.NEAREST_MIPMAP_LINEAR; + } + case o3d.Sampler.ANISOTROPIC: + case o3d.Sampler.LINEAR: + if (mip_filter == o3d.Sampler.NONE) { + return this.gl.LINEAR; + } else if (mip_filter == o3d.Sampler.POINT) { + return this.gl.LINEAR_MIPMAP_NEAREST; + } else if (mip_filter == o3d.Sampler.LINEAR) { + return this.gl.LINEAR_MIPMAP_LINEAR; + } else if (mip_filter == o3d.Sampler.ANISOTROPIC) { + return this.gl.LINEAR_MIPMAP_LINEAR; + } + } + + this.gl.client.error_callback("Unknown filter."); + return this.gl.NONE; +} + + +/** + * Converts the mag filter mode of the sampler from an o3d constant to a webgl + * constant. + * @param {!o3d.Sampler.FilterType} o3d_filter, the O3D filter. + * @return {number} The webgl filter. + */ +o3d.Sampler.prototype.convertMagFilter_ = function(o3d_filter) { + switch (o3d_filter) { + case o3d.Sampler.NONE: + case o3d.Sampler.POINT: + return this.gl.NEAREST; + case o3d.Sampler.LINEAR: + case o3d.Sampler.ANISOTROPIC: + return this.gl.LINEAR; + } + this.gl.client.error_callback("Unknown filter."); + return this.gl.LINEAR; +} + + +/** + * Binds the texture for this sampler and sets texParameters according to the + * states of the sampler. + */ +o3d.Sampler.prototype.bindAndSetParameters_ = function() { + if (this.texture) { + var mip_filter = this.mipFilter; + if (this.texture.levels == 1) { + mip_filter = o3d.Sampler.NONE; + } + + this.texture.bindAndSetParameters_( + this.convertAddressMode_(this.addressModeU), + this.convertAddressMode_(this.addressModeV), + this.convertMinFilter_(this.minFilter, mip_filter), + this.convertMagFilter_(this.magFilter)); + } else { + this.gl.client.error_callback("Sampler used with no texture set."); + return; + } +} + |