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