UNPKG

laya-coreui-es

Version:

laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改

133 lines (132 loc) 5.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Render = void 0; const ILaya_1 = require("./../../ILaya"); const Config_1 = require("./../../Config"); const LayaGL_1 = require("../layagl/LayaGL"); const Context_1 = require("../resource/Context"); const WebGL_1 = require("../webgl/WebGL"); const WebGLContext_1 = require("../webgl/WebGLContext"); const BlendMode_1 = require("../webgl/canvas/BlendMode"); const Shader2D_1 = require("../webgl/shader/d2/Shader2D"); const ShaderDefines2D_1 = require("../webgl/shader/d2/ShaderDefines2D"); const Value2D_1 = require("../webgl/shader/d2/value/Value2D"); const Buffer2D_1 = require("../webgl/utils/Buffer2D"); const SubmitBase_1 = require("../webgl/submit/SubmitBase"); const LayaGPU_1 = require("../webgl/LayaGPU"); const Browser_1 = require("../utils/Browser"); const RenderInfo_1 = require("./RenderInfo"); class Render { constructor(width, height, mainCanv) { this._timeId = 0; Render._mainCanvas = mainCanv; let source = Render._mainCanvas.source; source.id = "layaCanvas"; source.width = width; source.height = height; if (Render.isConchApp) { document.body.appendChild(source); } this.initRender(Render._mainCanvas, width, height); window.requestAnimationFrame(loop); function loop(stamp) { ILaya_1.ILaya.stage._loop(); window.requestAnimationFrame(loop); } ILaya_1.ILaya.stage.on("visibilitychange", this, this._onVisibilitychange); } _onVisibilitychange() { if (!ILaya_1.ILaya.stage.isVisibility) { this._timeId = window.setInterval(this._enterFrame, 1000); } else if (this._timeId != 0) { window.clearInterval(this._timeId); } } initRender(canvas, w, h) { function getWebGLContext(canvas) { var gl; var names = ["webgl2", "webgl", "experimental-webgl", "webkit-3d", "moz-webgl"]; if (!Config_1.Config.useWebGL2 || Browser_1.Browser.onBDMiniGame) { names.shift(); } for (var i = 0; i < names.length; i++) { try { gl = canvas.getContext(names[i], { stencil: Config_1.Config.isStencil, alpha: Config_1.Config.isAlpha, antialias: Config_1.Config.isAntialias, premultipliedAlpha: Config_1.Config.premultipliedAlpha, preserveDrawingBuffer: Config_1.Config.preserveDrawingBuffer }); } catch (e) { } if (gl) { (names[i] === 'webgl2') && (WebGL_1.WebGL._isWebGL2 = true); new LayaGL_1.LayaGL(); return gl; } } return null; } var gl = LayaGL_1.LayaGL.instance = WebGLContext_1.WebGLContext.mainContext = getWebGLContext(Render._mainCanvas.source); if (Config_1.Config.printWebglOrder) this._replaceWebglcall(gl); if (!gl) return false; LayaGL_1.LayaGL.instance = gl; LayaGL_1.LayaGL.layaGPUInstance = new LayaGPU_1.LayaGPU(gl, WebGL_1.WebGL._isWebGL2); canvas.size(w, h); Context_1.Context.__init__(); SubmitBase_1.SubmitBase.__init__(); var ctx = new Context_1.Context(); ctx.isMain = true; Render._context = ctx; canvas._setContext(ctx); ShaderDefines2D_1.ShaderDefines2D.__init__(); Value2D_1.Value2D.__init__(); Shader2D_1.Shader2D.__init__(); Buffer2D_1.Buffer2D.__int__(gl); BlendMode_1.BlendMode._init_(gl); return true; } _replaceWebglcall(gl) { var tempgl = {}; for (const key in gl) { if (typeof gl[key] == "function" && key != "getError" && key != "__SPECTOR_Origin_getError" && key != "__proto__") { tempgl[key] = gl[key]; gl[key] = function () { let arr = []; for (let i = 0; i < arguments.length; i++) { arr.push(arguments[i]); } let result = tempgl[key].apply(gl, arr); console.log(RenderInfo_1.RenderInfo.loopCount + ":gl." + key + ":" + arr); let err = gl.getError(); if (err) { console.log(err); debugger; } return result; }; } } } _enterFrame(e = null) { ILaya_1.ILaya.stage._loop(); } static get context() { return Render._context; } static get canvas() { return Render._mainCanvas.source; } } exports.Render = Render; Render.supportWebGLPlusAnimation = false; Render.supportWebGLPlusRendering = false; Render.isConchApp = false; { Render.isConchApp = (window.conch != null); if (Render.isConchApp) { Render.supportWebGLPlusRendering = false; } else if (window.qq != null && window.qq.webglPlus != null) { Render.supportWebGLPlusRendering = false; } }