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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 this.value = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]; | 330 this.value = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]; |
331 }; | 331 }; |
332 o3d.inherit('ParamMatrix4', 'Param'); | 332 o3d.inherit('ParamMatrix4', 'Param'); |
333 | 333 |
334 | 334 |
335 /** | 335 /** |
336 * @constructor | 336 * @constructor |
337 */ | 337 */ |
338 o3d.ParamParamArray = function() { | 338 o3d.ParamParamArray = function() { |
339 o3d.Param.call(this); | 339 o3d.Param.call(this); |
340 this.value = []; | 340 this.value = null; |
341 }; | 341 }; |
342 o3d.inherit('ParamParamArray', 'Param'); | 342 o3d.inherit('ParamParamArray', 'Param'); |
343 | 343 |
344 | 344 |
345 /** | 345 /** |
346 * @constructor | 346 * @constructor |
347 */ | 347 */ |
348 o3d.ParamRenderSurface = function() { | 348 o3d.ParamRenderSurface = function() { |
349 o3d.Param.call(this); | 349 o3d.Param.call(this); |
350 this.value = null; | 350 this.value = null; |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 * @param {WebGLContext} gl The current context. | 827 * @param {WebGLContext} gl The current context. |
828 * @param {WebGLUniformLocation} location The location to which to apply. | 828 * @param {WebGLUniformLocation} location The location to which to apply. |
829 */ | 829 */ |
830 o3d.ParamMatrix4.prototype.applyToLocation = function(gl, location) { | 830 o3d.ParamMatrix4.prototype.applyToLocation = function(gl, location) { |
831 gl.uniformMatrix4fv(location, | 831 gl.uniformMatrix4fv(location, |
832 false, | 832 false, |
833 o3d.Transform.flattenMatrix4(this.value)); | 833 o3d.Transform.flattenMatrix4(this.value)); |
834 }; | 834 }; |
835 | 835 |
836 /** | 836 /** |
| 837 * Called to specify the values of a uniform array. |
| 838 * @param {WebGLContext} gl The current context. |
| 839 * @param {!Array.<!WebGLUniformLocation>} locationArray An array of locations |
| 840 * to which to apply the values. |
| 841 */ |
| 842 o3d.ParamParamArray.prototype.applyToLocations = function(gl, locationArray) { |
| 843 if (locationArray.length != this.value.length) { |
| 844 gl.client.error_callback( |
| 845 'Invalid uniform param array: incorrect number of elements.'); |
| 846 } |
| 847 for (var i = 0; i < this.value.length; i++) { |
| 848 // Cannot have a ParamArray of ParamArrays, so safe to call applyToLocation |
| 849 this.value.getParam(i).applyToLocation(gl, locationArray[i]); |
| 850 } |
| 851 }; |
| 852 |
| 853 /** |
837 * A counter to ensure each texture sampler gets a unqiue id. | 854 * A counter to ensure each texture sampler gets a unqiue id. |
838 * @private | 855 * @private |
839 */ | 856 */ |
840 o3d.Param.texture_index_ = 0; | 857 o3d.Param.texture_index_ = 0; |
841 | 858 |
842 /** | 859 /** |
843 * Called to specify the value of a uniform variable. | 860 * Called to specify the value of a uniform variable. |
844 * @param {WebGLContext} gl The current context. | 861 * @param {WebGLContext} gl The current context. |
845 * @param {WebGLUniformLocation} location The location to which to apply. | 862 * @param {WebGLUniformLocation} location The location to which to apply. |
846 */ | 863 */ |
847 o3d.ParamSampler.prototype.applyToLocation = function(gl, location) { | 864 o3d.ParamSampler.prototype.applyToLocation = function(gl, location) { |
848 // When before the effect object assigns values to parameters, | 865 // When before the effect object assigns values to parameters, |
849 // it sets this variable to 0. | 866 // it sets this variable to 0. |
850 var i = o3d.Param.texture_index_; | 867 var i = o3d.Param.texture_index_; |
851 gl.activeTexture(gl.TEXTURE0 + i); | 868 gl.activeTexture(gl.TEXTURE0 + i); |
852 | 869 |
853 var value = null; | 870 var value = null; |
854 var target = 0; | 871 var target = 0; |
| 872 var sampler = null; |
855 | 873 |
856 if (this.value) { | 874 if (this.value) { |
857 this.value.bindAndSetParameters_(); | 875 sampler = this.value; |
858 gl.uniform1i(location, i); | 876 } else { |
859 o3d.Param.texture_index_++; | 877 o3d.Sampler.defaultSampler_.gl = gl; |
| 878 sampler = o3d.Sampler.defaultSampler_; |
| 879 if (gl.client.reportErrors_()) { |
| 880 gl.client.error_callback("Missing Sampler for ParamSampler " + this.name); |
| 881 } |
860 } | 882 } |
| 883 |
| 884 sampler.bindAndSetParameters_(); |
| 885 gl.uniform1i(location, i); |
| 886 o3d.Param.texture_index_++; |
861 }; | 887 }; |
862 | 888 |
| 889 /** |
| 890 * A default ParamSampler to be used if client does not assign one. |
| 891 * |
| 892 * @type {!o3d.ParamSampler} |
| 893 * @private |
| 894 */ |
| 895 o3d.ParamSampler.defaultParamSampler_ = new o3d.ParamSampler(); |
863 | 896 |
864 /** | 897 /** |
865 * Object to compute all combinations of world/view/projection | 898 * Object to compute all combinations of world/view/projection |
866 * inverse/transpose matrices and provide them as parameters. | 899 * inverse/transpose matrices and provide them as parameters. |
867 * | 900 * |
868 * @type {o3d.ParamObject} | 901 * @type {o3d.ParamObject} |
869 */ | 902 */ |
870 o3d.Param.SAS = new o3d.ParamObject; | 903 o3d.Param.SAS = new o3d.ParamObject; |
871 | 904 |
872 /** | 905 /** |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 o3d.Param.SAS.setViewProjection = function(viewProjection) { | 970 o3d.Param.SAS.setViewProjection = function(viewProjection) { |
938 this['viewProjection'] = viewProjection; | 971 this['viewProjection'] = viewProjection; |
939 }; | 972 }; |
940 | 973 |
941 /** | 974 /** |
942 * Sets the worldViewProjection matrix. | 975 * Sets the worldViewProjection matrix. |
943 */ | 976 */ |
944 o3d.Param.SAS.setWorldViewProjection = function(worldViewProjection) { | 977 o3d.Param.SAS.setWorldViewProjection = function(worldViewProjection) { |
945 this['worldViewProjection'] = worldViewProjection; | 978 this['worldViewProjection'] = worldViewProjection; |
946 }; | 979 }; |
OLD | NEW |