gpu.js/bin/gpu-core.js

192 lines
5.3 KiB
JavaScript

/**
* gpu.js
* http://gpu.rocks/
*
* GPU Accelerated JavaScript
*
* @version 1.0.0
* @date Sat Feb 24 2018 19:31:19 GMT-0500 (EST)
*
* @license MIT
* The MIT License
*
* Copyright (c) 2018 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 && typeof webGlObj.getExtension === 'function';
}
}, {
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);
}
return canvasObj.getContext('webgl2', UtilsCore.initWebGlDefaultOptions());
}
}]);
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;
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]);