"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var stardust_core_1 = require("stardust-core"); var webgl_1 = require("./webgl"); var helpers_1 = require("./helpers"); var WebGLCanvasPlatform2D = /** @class */ (function (_super) { __extends(WebGLCanvasPlatform2D, _super); function WebGLCanvasPlatform2D(canvas, width, height) { if (width === void 0) { width = 600; } if (height === void 0) { height = 400; } var _this = this; var GL = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); try { GL.getExtension("OES_texture_float"); GL.getExtension("OES_texture_float_linear"); } catch (e) { } _this = _super.call(this, GL) || this; _this._canvas = canvas; GL.clearColor(1, 1, 1, 1); GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); GL.disable(GL.DEPTH_TEST); GL.enable(GL.BLEND); GL.disable(GL.CULL_FACE); GL.blendFuncSeparate(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA); _this._pixelRatio = helpers_1.getDefaultDevicePixelRatio(); _this.resize(width, height); return _this; } Object.defineProperty(WebGLCanvasPlatform2D.prototype, "pixelRatio", { get: function () { return this._pixelRatio; }, set: function (value) { this._pixelRatio = value; this.resize(this._width, this._height); }, enumerable: true, configurable: true }); WebGLCanvasPlatform2D.prototype.resize = function (width, height) { this._width = width; this._height = height; this._canvas.style.width = width + "px"; this._canvas.style.height = height + "px"; this._canvas.width = width * this._pixelRatio; this._canvas.height = height * this._pixelRatio; this.set2DView(width, height); this.setPose(new stardust_core_1.Pose()); this._GL.viewport(0, 0, this._canvas.width, this._canvas.height); }; WebGLCanvasPlatform2D.prototype.clear = function (color) { if (color) { this._GL.clearColor(color[0], color[1], color[2], color[3] != null ? color[3] : 1); } this._GL.clear(this._GL.COLOR_BUFFER_BIT | this._GL.DEPTH_BUFFER_BIT); }; return WebGLCanvasPlatform2D; }(webgl_1.WebGLPlatform)); exports.WebGLCanvasPlatform2D = WebGLCanvasPlatform2D; var WebGLCanvasPlatform3D = /** @class */ (function (_super) { __extends(WebGLCanvasPlatform3D, _super); function WebGLCanvasPlatform3D(canvas, width, height) { if (width === void 0) { width = 600; } if (height === void 0) { height = 400; } var _this = this; var GL = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); _this = _super.call(this, GL) || this; _this._canvas = canvas; GL.clearColor(1, 1, 1, 1); GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); GL.enable(GL.DEPTH_TEST); GL.enable(GL.BLEND); GL.disable(GL.CULL_FACE); GL.blendFuncSeparate(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA); _this._pixelRatio = 2; _super.prototype.set3DView.call(_this, Math.PI / 4, width / height, 0.1, 1000); _this.resize(width, height); return _this; } Object.defineProperty(WebGLCanvasPlatform3D.prototype, "pixelRatio", { get: function () { return this._pixelRatio; }, set: function (value) { this._pixelRatio = value; this.resize(this._width, this._height); }, enumerable: true, configurable: true }); WebGLCanvasPlatform3D.prototype.resize = function (width, height) { this._width = width; this._height = height; this._canvas.style.width = width + "px"; this._canvas.style.height = height + "px"; this._canvas.width = width * this._pixelRatio; this._canvas.height = height * this._pixelRatio; this._GL.viewport(0, 0, this._canvas.width, this._canvas.height); _super.prototype.set3DView.call(this, this._viewInfo.fovY, this._width / this._height, this._viewInfo.near, this._viewInfo.far); }; WebGLCanvasPlatform3D.prototype.set3DView = function (fovY, near, far) { if (near === void 0) { near = 0.1; } if (far === void 0) { far = 1000; } _super.prototype.set3DView.call(this, fovY, this._width / this._height, near, far); }; WebGLCanvasPlatform3D.prototype.setMVPMatrix = function (matrix) { throw new stardust_core_1.RuntimeError("not implemented"); }; WebGLCanvasPlatform3D.prototype.clear = function (color) { if (color) { this._GL.clearColor(color[0], color[1], color[2], color[3] != null ? color[3] : 1); } this._GL.clear(this._GL.COLOR_BUFFER_BIT | this._GL.DEPTH_BUFFER_BIT); }; return WebGLCanvasPlatform3D; }(webgl_1.WebGLPlatform)); exports.WebGLCanvasPlatform3D = WebGLCanvasPlatform3D; var WebGLCanvasPlatformWebVR = /** @class */ (function (_super) { __extends(WebGLCanvasPlatformWebVR, _super); function WebGLCanvasPlatformWebVR(canvas, width, height) { if (width === void 0) { width = 600; } if (height === void 0) { height = 400; } var _this = this; var GL = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); _this = _super.call(this, GL) || this; _this._canvas = canvas; GL.clearColor(1, 1, 1, 1); GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); GL.enable(GL.DEPTH_TEST); GL.enable(GL.BLEND); GL.disable(GL.CULL_FACE); GL.blendFuncSeparate(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA); _this._pixelRatio = helpers_1.getDefaultDevicePixelRatio(); _this.resize(width, height); _this.setWebVRView([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); return _this; } Object.defineProperty(WebGLCanvasPlatformWebVR.prototype, "pixelRatio", { get: function () { return this._pixelRatio; }, set: function (value) { this._pixelRatio = value; this.resize(this._width, this._height); }, enumerable: true, configurable: true }); WebGLCanvasPlatformWebVR.prototype.resize = function (width, height) { this._width = width; this._height = height; this._canvas.width = width * this._pixelRatio; this._canvas.height = height * this._pixelRatio; }; WebGLCanvasPlatformWebVR.prototype.set3DView = function (fovY, near, far) { if (near === void 0) { near = 0.1; } if (far === void 0) { far = 1000; } _super.prototype.set3DView.call(this, fovY, this._width / this._height, near, far); }; WebGLCanvasPlatformWebVR.prototype.setWebVRView = function (viewMatrix, projectionMatrix) { _super.prototype.setWebVRView.call(this, viewMatrix, projectionMatrix); }; WebGLCanvasPlatformWebVR.prototype.clear = function (color) { if (color) { this._GL.clearColor(color[0], color[1], color[2], color[3] != null ? color[3] : 1); } this._GL.clear(this._GL.COLOR_BUFFER_BIT | this._GL.DEPTH_BUFFER_BIT); }; return WebGLCanvasPlatformWebVR; }(webgl_1.WebGLPlatform)); exports.WebGLCanvasPlatformWebVR = WebGLCanvasPlatformWebVR; //# sourceMappingURL=platforms.js.map