| 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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 /** | 742 /** |
| 743 * Called to specify the value of a uniform variable. | 743 * Called to specify the value of a uniform variable. |
| 744 */ | 744 */ |
| 745 o3d.ParamMatrix4.prototype.applyToLocation = function(gl, location) { | 745 o3d.ParamMatrix4.prototype.applyToLocation = function(gl, location) { |
| 746 gl.uniformMatrix4fv(location, | 746 gl.uniformMatrix4fv(location, |
| 747 false, | 747 false, |
| 748 o3d.Transform.flattenMatrix4(this.value)); | 748 o3d.Transform.flattenMatrix4(this.value)); |
| 749 }; | 749 }; |
| 750 | 750 |
| 751 /** | 751 /** |
| 752 * A counter to ensure each texture sampler gets a unqiue id. |
| 753 * @private |
| 754 */ |
| 755 o3d.Param.texture_index_ = 0; |
| 756 |
| 757 /** |
| 752 * Called to specify the value of a uniform variable. | 758 * Called to specify the value of a uniform variable. |
| 753 */ | 759 */ |
| 754 o3d.ParamSampler.prototype.applyToLocation = function(gl, location) { | 760 o3d.ParamSampler.prototype.applyToLocation = function(gl, location) { |
| 755 var i = 0; | 761 // When before the effect object assigns values to parameters, |
| 762 // it sets this variable to 0. |
| 763 var i = o3d.Param.texture_index_; |
| 756 gl.activeTexture(gl.TEXTURE0 + i); | 764 gl.activeTexture(gl.TEXTURE0 + i); |
| 757 if (!this.value || !this.value.texture || !this.value.texture.texture_) { | 765 |
| 758 throw ('Attempt to use texture parameter before texture value set.'); | 766 var value = null; |
| 767 |
| 768 if (this.value && this.value.texture && this.value.texture.texture_) { |
| 769 value = this.value.texture.texture_; |
| 759 } | 770 } |
| 760 gl.bindTexture(gl.TEXTURE_2D, this.value.texture.texture_); | 771 |
| 772 gl.bindTexture(gl.TEXTURE_2D, value); |
| 761 gl.uniform1i(location, i); | 773 gl.uniform1i(location, i); |
| 774 o3d.Param.texture_index_++; |
| 762 }; | 775 }; |
| 763 | 776 |
| 764 | 777 |
| 765 /** | 778 /** |
| 766 * Object to compute all combinations of world/view/projection | 779 * Object to compute all combinations of world/view/projection |
| 767 * inverse/transpose matrices and provide them as parameters. | 780 * inverse/transpose matrices and provide them as parameters. |
| 768 * | 781 * |
| 769 * @type {o3d.ParamObject} | 782 * @type {o3d.ParamObject} |
| 770 */ | 783 */ |
| 771 o3d.Param.SAS = new o3d.ParamObject; | 784 o3d.Param.SAS = new o3d.ParamObject; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 */ | 857 */ |
| 845 o3d.Param.SAS.setProjection = function(projection) { | 858 o3d.Param.SAS.setProjection = function(projection) { |
| 846 var adjustedProjection = | 859 var adjustedProjection = |
| 847 [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 2, 0], [0, 0, -1, 1]]; | 860 [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 2, 0], [0, 0, -1, 1]]; |
| 848 o3d.Transform.compose( | 861 o3d.Transform.compose( |
| 849 adjustedProjection, projection, adjustedProjection); | 862 adjustedProjection, projection, adjustedProjection); |
| 850 this['projection'] = projection; | 863 this['projection'] = projection; |
| 851 }; | 864 }; |
| 852 | 865 |
| 853 | 866 |
| OLD | NEW |