1+ /**
2+ * gpu.js
3+ * http://gpu.rocks/
4+ *
5+ * GPU Accelerated JavaScript
6+ *
7+ * @version 0.0.0
8+ * @date Tue Jul 18 2017 17:43:25 GMT+0530 (IST)
9+ *
10+ * @license MIT
11+ * The MIT License
12+ *
13+ * Copyright (c) 2017 gpu.js Team
14+ */
15+ "use strict" ;
16+
17+ var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
18+
19+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
20+
21+ ( function e ( t , n , r ) {
22+ function s ( o , u ) {
23+ if ( ! n [ o ] ) {
24+ if ( ! t [ o ] ) {
25+ var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f ;
26+ } var l = n [ o ] = { exports : { } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) {
27+ var n = t [ o ] [ 1 ] [ e ] ; return s ( n ? n : e ) ;
28+ } , l , l . exports , e , t , n , r ) ;
29+ } return n [ o ] . exports ;
30+ } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) {
31+ s ( r [ o ] ) ;
32+ } return s ;
33+ } ) ( { 1 : [ function ( require , module , exports ) {
34+ 'use strict' ;
35+
36+ var UtilsCore = require ( "./utils-core" ) ;
37+
38+ module . exports = function ( ) {
39+ function GPUCore ( ) {
40+ _classCallCheck ( this , GPUCore ) ;
41+ }
42+
43+ _createClass ( GPUCore , null , [ {
44+ key : "validateKernelObj" ,
45+ value : function validateKernelObj ( kernelObj ) {
46+
47+ if ( kernelObj == null ) {
48+ throw "KernelObj being validated is NULL" ;
49+ }
50+
51+ if ( typeof kernelObj === "string" ) {
52+ try {
53+ kernelObj = JSON . parse ( kernelObj ) ;
54+ } catch ( e ) {
55+ console . error ( e ) ;
56+ throw "Failed to convert KernelObj from JSON string" ;
57+ }
58+
59+ if ( kernelObj == null ) {
60+ throw "Invalid (NULL) KernelObj JSON string representation" ;
61+ }
62+ }
63+
64+ if ( kernelObj . isKernelObj != true ) {
65+ throw "Failed missing isKernelObj flag check" ;
66+ }
67+
68+ return kernelObj ;
69+ }
70+ } , {
71+ key : "loadKernelObj" ,
72+ value : function loadKernelObj ( kernelObj , inOpt ) {
73+
74+ kernelObj = validateKernelObj ( kernelObj ) ;
75+ }
76+ } ] ) ;
77+
78+ return GPUCore ;
79+ } ( ) ;
80+ } , { "./utils-core" : 2 } ] , 2 : [ function ( require , module , exports ) {
81+ 'use strict' ;
82+
83+ var UtilsCore = function ( ) {
84+ function UtilsCore ( ) {
85+ _classCallCheck ( this , UtilsCore ) ;
86+ }
87+
88+ _createClass ( UtilsCore , null , [ {
89+ key : "isCanvas" ,
90+ value : function isCanvas ( canvasObj ) {
91+ return canvasObj !== null && canvasObj . nodeName && canvasObj . getContext && canvasObj . nodeName . toUpperCase ( ) === 'CANVAS' ;
92+ }
93+ } , {
94+ key : "isCanvasSupported" ,
95+ value : function isCanvasSupported ( ) {
96+ return _isCanvasSupported ;
97+ }
98+ } , {
99+ key : "initCanvas" ,
100+ value : function initCanvas ( ) {
101+ if ( ! _isCanvasSupported ) {
102+ return null ;
103+ }
104+
105+ var canvas = document . createElement ( 'canvas' ) ;
106+
107+ canvas . width = 2 ;
108+ canvas . height = 2 ;
109+
110+ return canvas ;
111+ }
112+ } , {
113+ key : "isWebGl" ,
114+ value : function isWebGl ( webGlObj ) {
115+ return webGlObj !== null && ( webGlObj . __proto__ && webGlObj . __proto__ . hasOwnProperty ( 'getExtension' ) || webGlObj . prototype && webGlObj . prototype . hasOwnProperty ( 'getExtension' ) ) ;
116+ }
117+ } , {
118+ key : "isWebGlSupported" ,
119+ value : function isWebGlSupported ( ) {
120+ return _isWebGlSupported ;
121+ }
122+ } , {
123+ key : "isWebGlDrawBuffersSupported" ,
124+ value : function isWebGlDrawBuffersSupported ( ) {
125+ return _isWebGlDrawBuffersSupported ;
126+ }
127+ } , {
128+ key : "initWebGlDefaultOptions" ,
129+ value : function initWebGlDefaultOptions ( ) {
130+ return {
131+ alpha : false ,
132+ depth : false ,
133+ antialias : false
134+ } ;
135+ }
136+ } , {
137+ key : "initWebGl" ,
138+ value : function initWebGl ( canvasObj ) {
139+
140+ if ( typeof _isCanvasSupported !== 'undefined' || canvasObj === null ) {
141+ if ( ! _isCanvasSupported ) {
142+ return null ;
143+ }
144+ }
145+
146+ if ( ! UtilsCore . isCanvas ( canvasObj ) ) {
147+ throw new Error ( 'Invalid canvas object - ' + canvasObj ) ;
148+ }
149+
150+ var webGl = canvasObj . getContext ( 'experimental-webgl' , UtilsCore . initWebGlDefaultOptions ( ) ) || canvasObj . getContext ( 'webgl' , UtilsCore . initWebGlDefaultOptions ( ) ) ;
151+
152+ webGl . OES_texture_float = webGl . getExtension ( 'OES_texture_float' ) ;
153+ webGl . OES_texture_float_linear = webGl . getExtension ( 'OES_texture_float_linear' ) ;
154+ webGl . OES_element_index_uint = webGl . getExtension ( 'OES_element_index_uint' ) ;
155+
156+ return webGl ;
157+ }
158+ } ] ) ;
159+
160+ return UtilsCore ;
161+ } ( ) ;
162+
163+ var _isCanvasSupported = typeof document !== 'undefined' ? UtilsCore . isCanvas ( document . createElement ( 'canvas' ) ) : false ;
164+ var _testingWebGl = UtilsCore . initWebGl ( UtilsCore . initCanvas ( ) ) ;
165+ var _isWebGlSupported = UtilsCore . isWebGl ( _testingWebGl ) ;
166+ var _isWebGlDrawBuffersSupported = _isWebGlSupported && Boolean ( _testingWebGl . getExtension ( 'WEBGL_draw_buffers' ) ) ;
167+
168+ if ( _isWebGlSupported ) {
169+ UtilsCore . OES_texture_float = _testingWebGl . OES_texture_float ;
170+ UtilsCore . OES_texture_float_linear = _testingWebGl . OES_texture_float_linear ;
171+ UtilsCore . OES_element_index_uint = _testingWebGl . OES_element_index_uint ;
172+ } else {
173+ UtilsCore . OES_texture_float = false ;
174+ UtilsCore . OES_texture_float_linear = false ;
175+ UtilsCore . OES_element_index_uint = false ;
176+ }
177+
178+ module . exports = UtilsCore ;
179+ } , { } ] , 3 : [ function ( require , module , exports ) {
180+ 'use strict' ;
181+
182+ var GPUCore = require ( "./core/gpu-core" ) ;
183+ if ( typeof module !== 'undefined' ) {
184+ module . exports = GPUCore ;
185+ }
186+ if ( typeof window !== 'undefined' ) {
187+ window . GPUCore = GPUCore ;
188+ if ( window . GPU === null ) {
189+ window . GPU = GPUCore ;
190+ }
191+ }
192+ } , { "./core/gpu-core" : 1 } ] } , { } , [ 3 ] ) ;
0 commit comments