11///
22/// Class: GPUCore
33///
4+ /// Represents the "private/protected" namespace of the GPU class
5+ ///
46/// *GPUCore.js* internal functions namespace
57/// *gpu.js* PUBLIC function namespace
68///
@@ -27,104 +29,12 @@ var GPUCore = (function() {
2729 this . functionBuilder = new functionBuilder ( this ) ;
2830 this . functionBuilder . polyfillStandardFunctions ( ) ;
2931 }
30-
31- GPUCore . prototype . getWebgl = function ( ) {
32+
33+ // Legacy method to get webgl : Preseved for backwards compatibility
34+ GPUCore . prototype . getGl = function ( ) {
3235 return this . webgl ;
3336 } ;
3437
35- GPUCore . prototype . getCanvas = function ( mode ) {
36- if ( mode == "cpu" ) {
37- return null ;
38- }
39-
40- return this . canvas ;
41- } ;
42-
43- ///
44- /// Function: createKernel
45- ///
46- /// The core GPU.js function
47- ///
48- /// The parameter object contains the following sub parameters
49- ///
50- /// |---------------|---------------|---------------------------------------------------------------------------|
51- /// | Name | Default value | Description |
52- /// |---------------|---------------|---------------------------------------------------------------------------|
53- /// | dimensions | [1024] | Thread dimension array |
54- /// | mode | null | CPU / GPU configuration mode, "auto" / null. Has the following modes. |
55- /// | | | + null / "auto" : Attempts to build GPU mode, else fallbacks |
56- /// | | | + "gpu" : Attempts to build GPU mode, else fallbacks |
57- /// | | | + "cpu" : Forces JS fallback mode only |
58- /// |---------------|---------------|---------------------------------------------------------------------------|
59- ///
60- /// Parameters:
61- /// inputFunction {JS Function} The calling to perform the conversion
62- /// paramObj {Object} The parameter configuration object
63- ///
64- /// Returns:
65- /// callable function to run
66- ///
67- function createKernel ( kernel , paramObj ) {
68- //
69- // basic parameters safety checks
70- //
71- if ( kernel === undefined ) {
72- throw "Missing kernel parameter" ;
73- }
74- if ( ! ( kernel instanceof Function ) ) {
75- throw "kernel parameter not a function" ;
76- }
77- if ( paramObj === undefined ) {
78- paramObj = { } ;
79- }
80-
81- //
82- // Get theconfig, fallbacks to default value if not set
83- //
84- paramObj . dimensions = paramObj . dimensions || [ ] ;
85- var mode = paramObj . mode && paramObj . mode . toLowerCase ( ) ;
86-
87- if ( mode == "cpu" ) {
88- return this . _mode_cpu ( kernel , paramObj ) ;
89- }
90-
91- //
92- // Attempts to do the glsl conversion
93- //
94- try {
95- return this . _mode_gpu ( kernel , paramObj ) ;
96- } catch ( e ) {
97- if ( mode != "gpu" ) {
98- console . warning ( "Falling back to CPU!" ) ;
99- return this . _mode_cpu ( kernel , paramObj ) ;
100- } else {
101- throw e ;
102- }
103- }
104- } ;
105- GPUCore . prototype . createKernel = createKernel ;
106-
107- ///
108- /// Function: addFunction
109- ///
110- /// Adds additional functions, that the kernel may call.
111- ///
112- /// Parameters:
113- /// jsFunction - {JS Function} JS Function to do conversion
114- /// paramTypeArray - {[String,...]} Parameter type array, assumes all parameters are "float" if null
115- /// returnType - {String} The return type, assumes "float" if null
116- ///
117- /// Retuns:
118- /// {GPU} returns itself
119- ///
120- function addFunction ( jsFunction , paramTypeArray , returnType ) {
121- this . functionBuilder . addFunction ( null , jsFunction , paramTypeArray , returnType ) ;
122- return this ;
123- }
124- GPUCore . prototype . addFunction = addFunction ;
125-
126-
127-
12838 GPUCore . prototype . textureToArray = function ( texture ) {
12939 var copy = this . createKernel ( function ( x ) {
13040 return x [ this . thread . z ] [ this . thread . y ] [ this . thread . x ] ;
0 commit comments