babylon.engine.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.Engine = function (canvas, antialias, options) {
  5. var that = this;
  6. this._renderingCanvas = canvas;
  7. options = options || {};
  8. options.antialias = antialias;
  9. // GL
  10. try {
  11. this._gl = canvas.getContext("webgl", options) || canvas.getContext("experimental-webgl", options);
  12. } catch (e) {
  13. throw new Error("WebGL not supported");
  14. }
  15. if (!this._gl) {
  16. throw new Error("WebGL not supported");
  17. }
  18. this._windowIsBackground = false;
  19. this._onBlur = function () {
  20. that._windowIsBackground = true;
  21. };
  22. this._onFocus = function () {
  23. that._windowIsBackground = false;
  24. };
  25. window.addEventListener("blur", this._onBlur);
  26. window.addEventListener("focus", this._onFocus);
  27. // Options
  28. this.forceWireframe = false;
  29. this.cullBackFaces = true;
  30. this.renderEvenInBackground = true;
  31. // Scenes
  32. this.scenes = [];
  33. // Textures
  34. this._workingCanvas = document.createElement("canvas");
  35. this._workingContext = this._workingCanvas.getContext("2d");
  36. // Viewport
  37. this._hardwareScalingLevel = 1.0 / (window.devicePixelRatio || 1.0);
  38. this.resize();
  39. // Caps
  40. this._caps = {};
  41. this._caps.maxTexturesImageUnits = this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS);
  42. this._caps.maxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);
  43. this._caps.maxCubemapTextureSize = this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE);
  44. this._caps.maxRenderTextureSize = this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE);
  45. // Extensions
  46. this._caps.standardDerivatives = (this._gl.getExtension('OES_standard_derivatives') !== null);
  47. this._caps.s3tc = this._gl.getExtension('WEBGL_compressed_texture_s3tc');
  48. this._caps.textureFloat = (this._gl.getExtension('OES_texture_float') !== null);
  49. this._caps.textureAnisotropicFilterExtension = this._gl.getExtension('EXT_texture_filter_anisotropic') || this._gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || this._gl.getExtension('MOZ_EXT_texture_filter_anisotropic');
  50. this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0;
  51. // Cache
  52. this._loadedTexturesCache = [];
  53. this._activeTexturesCache = [];
  54. this._currentEffect = null;
  55. this._currentState = {
  56. culling: null
  57. };
  58. this._compiledEffects = {};
  59. this._gl.enable(this._gl.DEPTH_TEST);
  60. this._gl.depthFunc(this._gl.LEQUAL);
  61. // Fullscreen
  62. this.isFullscreen = false;
  63. this._onFullscreenChange = function () {
  64. if (document.fullscreen !== undefined) {
  65. that.isFullscreen = document.fullscreen;
  66. } else if (document.mozFullScreen !== undefined) {
  67. that.isFullscreen = document.mozFullScreen;
  68. } else if (document.webkitIsFullScreen !== undefined) {
  69. that.isFullscreen = document.webkitIsFullScreen;
  70. } else if (document.msIsFullScreen !== undefined) {
  71. that.isFullscreen = document.msIsFullScreen;
  72. }
  73. // Pointer lock
  74. if (that.isFullscreen && that._pointerLockRequested) {
  75. canvas.requestPointerLock = canvas.requestPointerLock ||
  76. canvas.msRequestPointerLock ||
  77. canvas.mozRequestPointerLock ||
  78. canvas.webkitRequestPointerLock;
  79. if (canvas.requestPointerLock) {
  80. canvas.requestPointerLock();
  81. }
  82. }
  83. };
  84. document.addEventListener("fullscreenchange", this._onFullscreenChange, false);
  85. document.addEventListener("mozfullscreenchange", this._onFullscreenChange, false);
  86. document.addEventListener("webkitfullscreenchange", this._onFullscreenChange, false);
  87. document.addEventListener("msfullscreenchange", this._onFullscreenChange, false);
  88. // Pointer lock
  89. this.isPointerLock = false;
  90. this._onPointerLockChange = function () {
  91. that.isPointerLock = (document.mozPointerLockElement === canvas ||
  92. document.webkitPointerLockElement === canvas ||
  93. document.msPointerLockElement === canvas ||
  94. document.pointerLockElement === canvas
  95. );
  96. };
  97. document.addEventListener("pointerlockchange", this._onPointerLockChange, false);
  98. document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
  99. document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
  100. document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
  101. };
  102. // Properties
  103. BABYLON.Engine.prototype.getAspectRatio = function (camera) {
  104. var viewport = camera.viewport;
  105. return (this._renderingCanvas.width * viewport.width) / (this._renderingCanvas.height * viewport.height);
  106. };
  107. BABYLON.Engine.prototype.getRenderWidth = function () {
  108. return this._renderingCanvas.width;
  109. };
  110. BABYLON.Engine.prototype.getRenderHeight = function () {
  111. return this._renderingCanvas.height;
  112. };
  113. BABYLON.Engine.prototype.getRenderingCanvas = function () {
  114. return this._renderingCanvas;
  115. };
  116. BABYLON.Engine.prototype.setHardwareScalingLevel = function (level) {
  117. this._hardwareScalingLevel = level;
  118. this.resize();
  119. };
  120. BABYLON.Engine.prototype.getHardwareScalingLevel = function () {
  121. return this._hardwareScalingLevel;
  122. };
  123. BABYLON.Engine.prototype.getLoadedTexturesCache = function () {
  124. return this._loadedTexturesCache;
  125. };
  126. BABYLON.Engine.prototype.getCaps = function () {
  127. return this._caps;
  128. };
  129. // Methods
  130. BABYLON.Engine.prototype.stopRenderLoop = function () {
  131. this._renderFunction = null;
  132. this._runningLoop = false;
  133. };
  134. BABYLON.Engine.prototype._renderLoop = function () {
  135. var shouldRender = true;
  136. if (!this.renderEvenInBackground && this._windowIsBackground) {
  137. shouldRender = false;
  138. }
  139. if (shouldRender) {
  140. // Start new frame
  141. this.beginFrame();
  142. if (this._renderFunction) {
  143. this._renderFunction();
  144. }
  145. // Present
  146. this.endFrame();
  147. }
  148. if (this._runningLoop) {
  149. // Register new frame
  150. var that = this;
  151. BABYLON.Tools.QueueNewFrame(function () {
  152. that._renderLoop();
  153. });
  154. }
  155. };
  156. BABYLON.Engine.prototype.runRenderLoop = function (renderFunction) {
  157. this._runningLoop = true;
  158. this._renderFunction = renderFunction;
  159. var that = this;
  160. BABYLON.Tools.QueueNewFrame(function () {
  161. that._renderLoop();
  162. });
  163. };
  164. BABYLON.Engine.prototype.switchFullscreen = function (requestPointerLock) {
  165. if (this.isFullscreen) {
  166. BABYLON.Tools.ExitFullscreen();
  167. } else {
  168. this._pointerLockRequested = requestPointerLock;
  169. BABYLON.Tools.RequestFullscreen(this._renderingCanvas);
  170. }
  171. };
  172. BABYLON.Engine.prototype.clear = function (color, backBuffer, depthStencil) {
  173. this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
  174. this._gl.clearDepth(1.0);
  175. var mode = 0;
  176. if (backBuffer)
  177. mode |= this._gl.COLOR_BUFFER_BIT;
  178. if (depthStencil)
  179. mode |= this._gl.DEPTH_BUFFER_BIT;
  180. this._gl.clear(mode);
  181. };
  182. BABYLON.Engine.prototype.setViewport = function (viewport, requiredWidth, requiredHeight) {
  183. var width = requiredWidth || this._renderingCanvas.width;
  184. var height = requiredHeight || this._renderingCanvas.height;
  185. var x = viewport.x || 0;
  186. var y = viewport.y || 0;
  187. this._cachedViewport = viewport;
  188. this._gl.viewport(x * width, y * height, width * viewport.width, height * viewport.height);
  189. };
  190. BABYLON.Engine.prototype.setDirectViewport = function (x, y, width, height) {
  191. this._cachedViewport = null;
  192. this._gl.viewport(x, y, width, height);
  193. };
  194. BABYLON.Engine.prototype.beginFrame = function () {
  195. BABYLON.Tools._MeasureFps();
  196. };
  197. BABYLON.Engine.prototype.endFrame = function () {
  198. this.flushFramebuffer();
  199. };
  200. BABYLON.Engine.prototype.resize = function () {
  201. this._renderingCanvas.width = this._renderingCanvas.clientWidth / this._hardwareScalingLevel;
  202. this._renderingCanvas.height = this._renderingCanvas.clientHeight / this._hardwareScalingLevel;
  203. };
  204. BABYLON.Engine.prototype.bindFramebuffer = function (texture) {
  205. var gl = this._gl;
  206. gl.bindFramebuffer(gl.FRAMEBUFFER, texture._framebuffer);
  207. this._gl.viewport(0, 0, texture._width, texture._height);
  208. this.wipeCaches();
  209. };
  210. BABYLON.Engine.prototype.unBindFramebuffer = function (texture) {
  211. if (texture.generateMipMaps) {
  212. var gl = this._gl;
  213. gl.bindTexture(gl.TEXTURE_2D, texture);
  214. gl.generateMipmap(gl.TEXTURE_2D);
  215. gl.bindTexture(gl.TEXTURE_2D, null);
  216. }
  217. };
  218. BABYLON.Engine.prototype.flushFramebuffer = function () {
  219. this._gl.flush();
  220. };
  221. BABYLON.Engine.prototype.restoreDefaultFramebuffer = function () {
  222. this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
  223. this.setViewport(this._cachedViewport);
  224. this.wipeCaches();
  225. };
  226. // VBOs
  227. BABYLON.Engine.prototype.createVertexBuffer = function (vertices) {
  228. var vbo = this._gl.createBuffer();
  229. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vbo);
  230. this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(vertices), this._gl.STATIC_DRAW);
  231. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, null);
  232. vbo.references = 1;
  233. return vbo;
  234. };
  235. BABYLON.Engine.prototype.createDynamicVertexBuffer = function (capacity) {
  236. var vbo = this._gl.createBuffer();
  237. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vbo);
  238. this._gl.bufferData(this._gl.ARRAY_BUFFER, capacity, this._gl.DYNAMIC_DRAW);
  239. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, null);
  240. vbo.references = 1;
  241. return vbo;
  242. };
  243. BABYLON.Engine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, vertices, length) {
  244. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vertexBuffer);
  245. // Should be (vertices instanceof Float32Array ? vertices : new Float32Array(vertices)) but Chrome raises an Exception in this case :(
  246. if (length) {
  247. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(vertices, 0, length));
  248. } else {
  249. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(vertices));
  250. }
  251. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, null);
  252. };
  253. BABYLON.Engine.prototype.createIndexBuffer = function (indices) {
  254. var vbo = this._gl.createBuffer();
  255. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, vbo);
  256. this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), this._gl.STATIC_DRAW);
  257. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, null);
  258. vbo.references = 1;
  259. return vbo;
  260. };
  261. BABYLON.Engine.prototype.bindBuffers = function (vertexBuffer, indexBuffer, vertexDeclaration, vertexStrideSize, effect) {
  262. if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {
  263. this._cachedVertexBuffers = vertexBuffer;
  264. this._cachedEffectForVertexBuffers = effect;
  265. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vertexBuffer);
  266. var offset = 0;
  267. for (var index = 0; index < vertexDeclaration.length; index++) {
  268. var order = effect.getAttribute(index);
  269. if (order >= 0) {
  270. this._gl.vertexAttribPointer(order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
  271. }
  272. offset += vertexDeclaration[index] * 4;
  273. }
  274. }
  275. if (this._cachedIndexBuffer !== indexBuffer) {
  276. this._cachedIndexBuffer = indexBuffer;
  277. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
  278. }
  279. };
  280. BABYLON.Engine.prototype.bindMultiBuffers = function (vertexBuffers, indexBuffer, effect) {
  281. if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
  282. this._cachedVertexBuffers = vertexBuffers;
  283. this._cachedEffectForVertexBuffers = effect;
  284. var attributes = effect.getAttributesNames();
  285. for (var index = 0; index < attributes.length; index++) {
  286. var order = effect.getAttribute(index);
  287. if (order >= 0) {
  288. var vertexBuffer = vertexBuffers[attributes[index]];
  289. var stride = vertexBuffer.getStrideSize();
  290. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vertexBuffer._buffer);
  291. this._gl.vertexAttribPointer(order, stride, this._gl.FLOAT, false, stride * 4, 0);
  292. }
  293. }
  294. }
  295. if (this._cachedIndexBuffer !== indexBuffer) {
  296. this._cachedIndexBuffer = indexBuffer;
  297. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
  298. }
  299. };
  300. BABYLON.Engine.prototype._releaseBuffer = function (buffer) {
  301. buffer.references--;
  302. if (buffer.references === 0) {
  303. this._gl.deleteBuffer(buffer);
  304. }
  305. };
  306. BABYLON.Engine.prototype.draw = function (useTriangles, indexStart, indexCount) {
  307. this._gl.drawElements(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, this._gl.UNSIGNED_SHORT, indexStart * 2);
  308. };
  309. // Shaders
  310. BABYLON.Engine.prototype.createEffect = function (baseName, attributesNames, uniformsNames, samplers, defines, optionalDefines) {
  311. var vertex = baseName.vertexElement || baseName.vertex || baseName;
  312. var fragment = baseName.fragmentElement || baseName.fragment || baseName;
  313. var name = vertex + "+" + fragment + "@" + defines;
  314. if (this._compiledEffects[name]) {
  315. return this._compiledEffects[name];
  316. }
  317. var effect = new BABYLON.Effect(baseName, attributesNames, uniformsNames, samplers, this, defines, optionalDefines);
  318. this._compiledEffects[name] = effect;
  319. return effect;
  320. };
  321. var compileShader = function (gl, source, type, defines) {
  322. var shader = gl.createShader(type === "vertex" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);
  323. gl.shaderSource(shader, (defines ? defines + "\n" : "") + source);
  324. gl.compileShader(shader);
  325. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  326. throw new Error(gl.getShaderInfoLog(shader));
  327. }
  328. return shader;
  329. };
  330. BABYLON.Engine.prototype.createShaderProgram = function (vertexCode, fragmentCode, defines) {
  331. var vertexShader = compileShader(this._gl, vertexCode, "vertex", defines);
  332. var fragmentShader = compileShader(this._gl, fragmentCode, "fragment", defines);
  333. var shaderProgram = this._gl.createProgram();
  334. this._gl.attachShader(shaderProgram, vertexShader);
  335. this._gl.attachShader(shaderProgram, fragmentShader);
  336. this._gl.linkProgram(shaderProgram);
  337. var error = this._gl.getProgramInfoLog(shaderProgram);
  338. if (error) {
  339. throw new Error(error);
  340. }
  341. this._gl.deleteShader(vertexShader);
  342. this._gl.deleteShader(fragmentShader);
  343. return shaderProgram;
  344. };
  345. BABYLON.Engine.prototype.getUniforms = function (shaderProgram, uniformsNames) {
  346. var results = [];
  347. for (var index = 0; index < uniformsNames.length; index++) {
  348. results.push(this._gl.getUniformLocation(shaderProgram, uniformsNames[index]));
  349. }
  350. return results;
  351. };
  352. BABYLON.Engine.prototype.getAttributes = function (shaderProgram, attributesNames) {
  353. var results = [];
  354. for (var index = 0; index < attributesNames.length; index++) {
  355. try {
  356. results.push(this._gl.getAttribLocation(shaderProgram, attributesNames[index]));
  357. } catch (e) {
  358. results.push(-1);
  359. }
  360. }
  361. return results;
  362. };
  363. BABYLON.Engine.prototype.enableEffect = function (effect) {
  364. if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
  365. return;
  366. }
  367. // Use program
  368. this._gl.useProgram(effect.getProgram());
  369. for (var index = 0; index < effect.getAttributesCount() ; index++) {
  370. // Attributes
  371. var order = effect.getAttribute(index);
  372. if (order >= 0) {
  373. this._gl.enableVertexAttribArray(effect.getAttribute(index));
  374. }
  375. }
  376. this._currentEffect = effect;
  377. };
  378. BABYLON.Engine.prototype.setArray = function (uniform, array) {
  379. if (!uniform)
  380. return;
  381. this._gl.uniform1fv(uniform, array);
  382. };
  383. BABYLON.Engine.prototype.setMatrices = function (uniform, matrices) {
  384. if (!uniform)
  385. return;
  386. this._gl.uniformMatrix4fv(uniform, false, matrices);
  387. };
  388. BABYLON.Engine.prototype.setMatrix = function (uniform, matrix) {
  389. if (!uniform)
  390. return;
  391. this._gl.uniformMatrix4fv(uniform, false, matrix.toArray());
  392. };
  393. BABYLON.Engine.prototype.setFloat = function (uniform, value) {
  394. if (!uniform)
  395. return;
  396. this._gl.uniform1f(uniform, value);
  397. };
  398. BABYLON.Engine.prototype.setFloat2 = function (uniform, x, y) {
  399. if (!uniform)
  400. return;
  401. this._gl.uniform2f(uniform, x, y);
  402. };
  403. BABYLON.Engine.prototype.setFloat3 = function (uniform, x, y, z) {
  404. if (!uniform)
  405. return;
  406. this._gl.uniform3f(uniform, x, y, z);
  407. };
  408. BABYLON.Engine.prototype.setBool = function (uniform, bool) {
  409. if (!uniform)
  410. return;
  411. this._gl.uniform1i(uniform, bool);
  412. };
  413. BABYLON.Engine.prototype.setFloat4 = function (uniform, x, y, z, w) {
  414. if (!uniform)
  415. return;
  416. this._gl.uniform4f(uniform, x, y, z, w);
  417. };
  418. BABYLON.Engine.prototype.setColor3 = function (uniform, color3) {
  419. if (!uniform)
  420. return;
  421. this._gl.uniform3f(uniform, color3.r, color3.g, color3.b);
  422. };
  423. BABYLON.Engine.prototype.setColor4 = function (uniform, color3, alpha) {
  424. if (!uniform)
  425. return;
  426. this._gl.uniform4f(uniform, color3.r, color3.g, color3.b, alpha);
  427. };
  428. // States
  429. BABYLON.Engine.prototype.setState = function (culling) {
  430. // Culling
  431. if (this._currentState.culling !== culling) {
  432. if (culling) {
  433. this._gl.cullFace(this.cullBackFaces ? this._gl.BACK : this._gl.FRONT);
  434. this._gl.enable(this._gl.CULL_FACE);
  435. } else {
  436. this._gl.disable(this._gl.CULL_FACE);
  437. }
  438. this._currentState.culling = culling;
  439. }
  440. };
  441. BABYLON.Engine.prototype.setDepthBuffer = function (enable) {
  442. if (enable) {
  443. this._gl.enable(this._gl.DEPTH_TEST);
  444. } else {
  445. this._gl.disable(this._gl.DEPTH_TEST);
  446. }
  447. };
  448. BABYLON.Engine.prototype.setDepthWrite = function (enable) {
  449. this._gl.depthMask(enable);
  450. };
  451. BABYLON.Engine.prototype.setColorWrite = function (enable) {
  452. this._gl.colorMask(enable, enable, enable, enable);
  453. };
  454. BABYLON.Engine.prototype.setAlphaMode = function (mode) {
  455. switch (mode) {
  456. case BABYLON.Engine.ALPHA_DISABLE:
  457. this.setDepthWrite(true);
  458. this._gl.disable(this._gl.BLEND);
  459. break;
  460. case BABYLON.Engine.ALPHA_COMBINE:
  461. this.setDepthWrite(false);
  462. this._gl.blendFuncSeparate(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);
  463. this._gl.enable(this._gl.BLEND);
  464. break;
  465. case BABYLON.Engine.ALPHA_ADD:
  466. this.setDepthWrite(false);
  467. this._gl.blendFuncSeparate(this._gl.ONE, this._gl.ONE, this._gl.ZERO, this._gl.ONE);
  468. this._gl.enable(this._gl.BLEND);
  469. break;
  470. }
  471. };
  472. BABYLON.Engine.prototype.setAlphaTesting = function (enable) {
  473. this._alphaTest = enable;
  474. };
  475. BABYLON.Engine.prototype.getAlphaTesting = function () {
  476. return this._alphaTest;
  477. };
  478. // Textures
  479. BABYLON.Engine.prototype.wipeCaches = function () {
  480. this._activeTexturesCache = [];
  481. this._currentEffect = null;
  482. this._currentState = {
  483. culling: null
  484. };
  485. this._cachedVertexBuffers = null;
  486. this._cachedVertexBuffers = null;
  487. this._cachedEffectForVertexBuffers = null;
  488. };
  489. var getExponantOfTwo = function (value, max) {
  490. var count = 1;
  491. do {
  492. count *= 2;
  493. } while (count < value);
  494. if (count > max)
  495. count = max;
  496. return count;
  497. };
  498. var prepareWebGLTexture = function (texture, scene, width, height, invertY, noMipmap, processFunction) {
  499. var engine = scene.getEngine();
  500. var potWidth = getExponantOfTwo(width, engine._caps.maxTextureSize);
  501. var potHeight = getExponantOfTwo(height, engine._caps.maxTextureSize);
  502. engine._gl.bindTexture(engine._gl.TEXTURE_2D, texture);
  503. engine._gl.pixelStorei(engine._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? true : invertY);
  504. processFunction(potWidth, potHeight);
  505. engine._gl.texParameteri(engine._gl.TEXTURE_2D, engine._gl.TEXTURE_MAG_FILTER, engine._gl.LINEAR);
  506. if (noMipmap) {
  507. engine._gl.texParameteri(engine._gl.TEXTURE_2D, engine._gl.TEXTURE_MIN_FILTER, engine._gl.LINEAR);
  508. } else {
  509. engine._gl.texParameteri(engine._gl.TEXTURE_2D, engine._gl.TEXTURE_MIN_FILTER, engine._gl.LINEAR_MIPMAP_LINEAR);
  510. engine._gl.generateMipmap(engine._gl.TEXTURE_2D);
  511. }
  512. engine._gl.bindTexture(engine._gl.TEXTURE_2D, null);
  513. engine._activeTexturesCache = [];
  514. texture._baseWidth = width;
  515. texture._baseHeight = height;
  516. texture._width = potWidth;
  517. texture._height = potHeight;
  518. texture.isReady = true;
  519. scene._removePendingData(texture);
  520. };
  521. BABYLON.Engine.prototype.createTexture = function (url, noMipmap, invertY, scene) {
  522. var texture = this._gl.createTexture();
  523. var that = this;
  524. var isDDS = this.getCaps().s3tc && (url.substr(url.length - 4, 4).toLowerCase() === ".dds");
  525. scene._addPendingData(texture);
  526. texture.url = url;
  527. texture.noMipmap = noMipmap;
  528. texture.references = 1;
  529. this._loadedTexturesCache.push(texture);
  530. if (isDDS) {
  531. BABYLON.Tools.LoadFile(url, function (data) {
  532. var info = BABYLON.Tools.GetDDSInfo(data);
  533. var loadMipmap = info.mipmapCount > 1 && !noMipmap;
  534. prepareWebGLTexture(texture, scene, info.width, info.height, invertY, !loadMipmap, function (potWidth, potHeight) {
  535. BABYLON.Tools.UploadDDSLevels(that._gl, that.getCaps().s3tc, data, loadMipmap);
  536. });
  537. }, null, scene.database, true);
  538. } else {
  539. var onload = function(img) {
  540. prepareWebGLTexture(texture, scene, img.width, img.height, invertY, noMipmap, function (potWidth, potHeight) {
  541. var isPot = (img.width == potWidth && img.height == potHeight);
  542. if (!isPot) {
  543. that._workingCanvas.width = potWidth;
  544. that._workingCanvas.height = potHeight;
  545. that._workingContext.drawImage(img, 0, 0, img.width, img.height, 0, 0, potWidth, potHeight);
  546. }
  547. that._gl.texImage2D(that._gl.TEXTURE_2D, 0, that._gl.RGBA, that._gl.RGBA, that._gl.UNSIGNED_BYTE, isPot ? img : that._workingCanvas);
  548. });
  549. };
  550. var onerror = function() {
  551. scene._removePendingData(texture);
  552. };
  553. BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
  554. }
  555. return texture;
  556. };
  557. BABYLON.Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps) {
  558. var texture = this._gl.createTexture();
  559. width = getExponantOfTwo(width, this._caps.maxTextureSize);
  560. height = getExponantOfTwo(height, this._caps.maxTextureSize);
  561. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  562. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.LINEAR);
  563. if (!generateMipMaps) {
  564. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR);
  565. } else {
  566. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR_MIPMAP_LINEAR);
  567. }
  568. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  569. this._activeTexturesCache = [];
  570. texture._baseWidth = width;
  571. texture._baseHeight = height;
  572. texture._width = width;
  573. texture._height = height;
  574. texture.isReady = false;
  575. texture.generateMipMaps = generateMipMaps;
  576. texture.references = 1;
  577. this._loadedTexturesCache.push(texture);
  578. return texture;
  579. };
  580. BABYLON.Engine.prototype.updateDynamicTexture = function (texture, canvas, invertY) {
  581. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  582. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY);
  583. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, canvas);
  584. if (texture.generateMipMaps) {
  585. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  586. }
  587. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  588. this._activeTexturesCache = [];
  589. texture.isReady = true;
  590. };
  591. BABYLON.Engine.prototype.updateVideoTexture = function (texture, video, invertY) {
  592. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  593. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? false : true); // Video are upside down by default
  594. // Scale the video if it is a NPOT
  595. if (video.videoWidth !== texture._width || video.videoHeight !== texture._height) {
  596. if (!texture._workingCanvas) {
  597. texture._workingCanvas = document.createElement("canvas");
  598. texture._workingContext = texture._workingCanvas.getContext("2d");
  599. texture._workingCanvas.width = texture._width;
  600. texture._workingCanvas.height = texture._height;
  601. }
  602. texture._workingContext.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture._width, texture._height);
  603. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, texture._workingCanvas);
  604. } else {
  605. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, video);
  606. }
  607. if (texture.generateMipMaps) {
  608. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  609. }
  610. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  611. this._activeTexturesCache = [];
  612. texture.isReady = true;
  613. };
  614. BABYLON.Engine.prototype.createRenderTargetTexture = function (size, options) {
  615. // old version had a "generateMipMaps" arg instead of options.
  616. // if options.generateMipMaps is undefined, consider that options itself if the generateMipmaps value
  617. // in the same way, generateDepthBuffer is defaulted to true
  618. var generateMipMaps = false;
  619. var generateDepthBuffer = true;
  620. var samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  621. if (options !== undefined) {
  622. generateMipMaps = options.generateMipMaps === undefined ? options : options.generateMipmaps;
  623. generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
  624. if (options.samplingMode !== undefined) {
  625. samplingMode = options.samplingMode;
  626. }
  627. }
  628. var gl = this._gl;
  629. var texture = gl.createTexture();
  630. gl.bindTexture(gl.TEXTURE_2D, texture);
  631. var width = size.width || size;
  632. var height = size.height || size;
  633. var magFilter = gl.NEAREST;
  634. var minFilter = gl.NEAREST;
  635. if (samplingMode === BABYLON.Texture.BILINEAR_SAMPLINGMODE) {
  636. magFilter = gl.LINEAR;
  637. if (generateMipMaps) {
  638. minFilter = gl.LINEAR_MIPMAP_NEAREST;
  639. } else {
  640. minFilter = gl.LINEAR;
  641. }
  642. } else if (samplingMode === BABYLON.Texture.TRILINEAR_SAMPLINGMODE) {
  643. magFilter = gl.LINEAR;
  644. if (generateMipMaps) {
  645. minFilter = gl.LINEAR_MIPMAP_LINEAR;
  646. } else {
  647. minFilter = gl.LINEAR;
  648. }
  649. }
  650. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
  651. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
  652. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  653. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  654. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  655. var depthBuffer;
  656. // Create the depth buffer
  657. if (generateDepthBuffer) {
  658. depthBuffer = gl.createRenderbuffer();
  659. gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer);
  660. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
  661. }
  662. // Create the framebuffer
  663. var framebuffer = gl.createFramebuffer();
  664. gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
  665. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
  666. if (generateDepthBuffer) {
  667. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
  668. }
  669. // Unbind
  670. gl.bindTexture(gl.TEXTURE_2D, null);
  671. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  672. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  673. texture._framebuffer = framebuffer;
  674. if (generateDepthBuffer) {
  675. texture._depthBuffer = depthBuffer;
  676. }
  677. texture._width = width;
  678. texture._height = height;
  679. texture.isReady = true;
  680. texture.generateMipMaps = generateMipMaps;
  681. texture.references = 1;
  682. this._activeTexturesCache = [];
  683. this._loadedTexturesCache.push(texture);
  684. return texture;
  685. };
  686. var cascadeLoad = function (rootUrl, index, loadedImages, scene, onfinish, extensions) {
  687. var img;
  688. var onload = function () {
  689. loadedImages.push(img);
  690. scene._removePendingData(img);
  691. if (index != extensions.length - 1) {
  692. cascadeLoad(rootUrl, index + 1, loadedImages, scene, onfinish, extensions);
  693. } else {
  694. onfinish(loadedImages);
  695. }
  696. };
  697. var onerror = function () {
  698. scene._removePendingData(img);
  699. };
  700. img = BABYLON.Tools.LoadImage(rootUrl + extensions[index], onload, onerror, scene.database);
  701. scene._addPendingData(img);
  702. };
  703. BABYLON.Engine.prototype.createCubeTexture = function (rootUrl, scene, extensions, noMipmap) {
  704. var gl = this._gl;
  705. var texture = gl.createTexture();
  706. texture.isCube = true;
  707. texture.url = rootUrl;
  708. texture.references = 1;
  709. this._loadedTexturesCache.push(texture);
  710. var that = this;
  711. cascadeLoad(rootUrl, 0, [], scene, function (imgs) {
  712. var width = getExponantOfTwo(imgs[0].width, that._caps.maxCubemapTextureSize);
  713. var height = width;
  714. that._workingCanvas.width = width;
  715. that._workingCanvas.height = height;
  716. var faces = [
  717. gl.TEXTURE_CUBE_MAP_POSITIVE_X, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
  718. gl.TEXTURE_CUBE_MAP_NEGATIVE_X, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
  719. ];
  720. gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
  721. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
  722. for (var index = 0; index < faces.length; index++) {
  723. that._workingContext.drawImage(imgs[index], 0, 0, imgs[index].width, imgs[index].height, 0, 0, width, height);
  724. gl.texImage2D(faces[index], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, that._workingCanvas);
  725. }
  726. if (!noMipmap) {
  727. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  728. }
  729. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  730. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, noMipmap ? gl.LINEAR : gl.LINEAR_MIPMAP_LINEAR);
  731. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  732. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  733. gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
  734. that._activeTexturesCache = [];
  735. texture._width = width;
  736. texture._height = height;
  737. texture.isReady = true;
  738. }, extensions);
  739. return texture;
  740. };
  741. BABYLON.Engine.prototype._releaseTexture = function (texture) {
  742. var gl = this._gl;
  743. if (texture._framebuffer) {
  744. gl.deleteFramebuffer(texture._framebuffer);
  745. }
  746. if (texture._depthBuffer) {
  747. gl.deleteRenderbuffer(texture._depthBuffer);
  748. }
  749. gl.deleteTexture(texture);
  750. // Unbind channels
  751. for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
  752. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  753. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  754. this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
  755. this._activeTexturesCache[channel] = null;
  756. }
  757. var index = this._loadedTexturesCache.indexOf(texture);
  758. if (index !== -1) {
  759. this._loadedTexturesCache.splice(index, 1);
  760. }
  761. };
  762. BABYLON.Engine.prototype.bindSamplers = function (effect) {
  763. this._gl.useProgram(effect.getProgram());
  764. var samplers = effect.getSamplers();
  765. for (var index = 0; index < samplers.length; index++) {
  766. var uniform = effect.getUniform(samplers[index]);
  767. this._gl.uniform1i(uniform, index);
  768. }
  769. this._currentEffect = null;
  770. };
  771. BABYLON.Engine.prototype._bindTexture = function (channel, texture) {
  772. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  773. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  774. this._activeTexturesCache[channel] = null;
  775. };
  776. BABYLON.Engine.prototype.setTextureFromPostProcess = function (channel, postProcess) {
  777. this._bindTexture(channel, postProcess._textures.data[postProcess._currentRenderTextureInd]);
  778. };
  779. BABYLON.Engine.prototype.setTexture = function (channel, texture) {
  780. if (channel < 0) {
  781. return;
  782. }
  783. // Not ready?
  784. if (!texture || !texture.isReady()) {
  785. if (this._activeTexturesCache[channel] != null) {
  786. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  787. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  788. this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
  789. this._activeTexturesCache[channel] = null;
  790. }
  791. return;
  792. }
  793. // Video
  794. if (texture instanceof BABYLON.VideoTexture) {
  795. if (texture._update()) {
  796. this._activeTexturesCache[channel] = null;
  797. }
  798. } else if (texture.delayLoadState == BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) { // Delay loading
  799. texture.delayLoad();
  800. return;
  801. }
  802. if (this._activeTexturesCache[channel] == texture) {
  803. return;
  804. }
  805. this._activeTexturesCache[channel] = texture;
  806. var internalTexture = texture.getInternalTexture();
  807. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  808. if (internalTexture.isCube) {
  809. this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, internalTexture);
  810. if (internalTexture._cachedCoordinatesMode !== texture.coordinatesMode) {
  811. internalTexture._cachedCoordinatesMode = texture.coordinatesMode;
  812. this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_S, texture.coordinatesMode !== BABYLON.CubeTexture.CUBIC_MODE ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE);
  813. this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_T, texture.coordinatesMode !== BABYLON.CubeTexture.CUBIC_MODE ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE);
  814. }
  815. this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP, texture);
  816. } else {
  817. this._gl.bindTexture(this._gl.TEXTURE_2D, internalTexture);
  818. if (internalTexture._cachedWrapU !== texture.wrapU) {
  819. internalTexture._cachedWrapU = texture.wrapU;
  820. switch (texture.wrapU) {
  821. case BABYLON.Texture.WRAP_ADDRESSMODE:
  822. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.REPEAT);
  823. break;
  824. case BABYLON.Texture.CLAMP_ADDRESSMODE:
  825. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
  826. break;
  827. case BABYLON.Texture.MIRROR_ADDRESSMODE:
  828. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.MIRRORED_REPEAT);
  829. break;
  830. }
  831. }
  832. if (internalTexture._cachedWrapV !== texture.wrapV) {
  833. internalTexture._cachedWrapV = texture.wrapV;
  834. switch (texture.wrapV) {
  835. case BABYLON.Texture.WRAP_ADDRESSMODE:
  836. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.REPEAT);
  837. break;
  838. case BABYLON.Texture.CLAMP_ADDRESSMODE:
  839. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);
  840. break;
  841. case BABYLON.Texture.MIRROR_ADDRESSMODE:
  842. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.MIRRORED_REPEAT);
  843. break;
  844. }
  845. }
  846. this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
  847. }
  848. };
  849. BABYLON.Engine.prototype._setAnisotropicLevel = function (key, texture) {
  850. var anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;
  851. if (anisotropicFilterExtension && texture._cachedAnisotropicFilteringLevel !== texture.anisotropicFilteringLevel) {
  852. this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropicFilteringLevel, this._caps.maxAnisotropy));
  853. texture._cachedAnisotropicFilteringLevel = texture.anisotropicFilteringLevel;
  854. }
  855. };
  856. // Dispose
  857. BABYLON.Engine.prototype.dispose = function () {
  858. // Release scenes
  859. while (this.scenes.length) {
  860. this.scenes[0].dispose();
  861. }
  862. // Release effects
  863. for (var name in this._compiledEffects.length) {
  864. this._gl.deleteProgram(this._compiledEffects[name]._program);
  865. }
  866. // Events
  867. window.removeEventListener("blur", this._onBlur);
  868. window.removeEventListener("focus", this._onFocus);
  869. document.removeEventListener("fullscreenchange", this._onFullscreenChange);
  870. document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
  871. document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
  872. document.removeEventListener("msfullscreenchange", this._onFullscreenChange);
  873. document.removeEventListener("pointerlockchange", this._onPointerLockChange);
  874. document.removeEventListener("mspointerlockchange", this._onPointerLockChange);
  875. document.removeEventListener("mozpointerlockchange", this._onPointerLockChange);
  876. document.removeEventListener("webkitpointerlockchange", this._onPointerLockChange);
  877. };
  878. // Statics
  879. BABYLON.Engine.ShadersRepository = "Babylon/Shaders/";
  880. BABYLON.Engine.ALPHA_DISABLE = 0;
  881. BABYLON.Engine.ALPHA_ADD = 1;
  882. BABYLON.Engine.ALPHA_COMBINE = 2;
  883. // Statics
  884. BABYLON.Engine.DELAYLOADSTATE_NONE = 0;
  885. BABYLON.Engine.DELAYLOADSTATE_LOADED = 1;
  886. BABYLON.Engine.DELAYLOADSTATE_LOADING = 2;
  887. BABYLON.Engine.DELAYLOADSTATE_NOTLOADED = 4;
  888. BABYLON.Engine.epsilon = 0.001;
  889. BABYLON.Engine.collisionsEpsilon = 0.001;
  890. BABYLON.Engine.isSupported = function () {
  891. try {
  892. var tempcanvas = document.createElement("canvas");
  893. var gl = tempcanvas.getContext("webgl") || tempcanvas.getContext("experimental-webgl");
  894. return gl != null && !!window.WebGLRenderingContext;
  895. } catch (e) {
  896. return false;
  897. }
  898. };
  899. })();