settings.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*!
  2. * @pixi/settings - v6.5.10
  3. * Compiled Thu, 06 Jul 2023 15:25:11 UTC
  4. *
  5. * @pixi/settings is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. this.PIXI = this.PIXI || {};
  9. var _pixi_settings = (function (exports, constants) {
  10. 'use strict';
  11. var BrowserAdapter = {
  12. /**
  13. * Creates a canvas element of the given size.
  14. * This canvas is created using the browser's native canvas element.
  15. * @param width - width of the canvas
  16. * @param height - height of the canvas
  17. */
  18. createCanvas: function (width, height) {
  19. var canvas = document.createElement('canvas');
  20. canvas.width = width;
  21. canvas.height = height;
  22. return canvas;
  23. },
  24. getWebGLRenderingContext: function () { return WebGLRenderingContext; },
  25. getNavigator: function () { return navigator; },
  26. getBaseUrl: function () { var _a; return ((_a = document.baseURI) !== null && _a !== void 0 ? _a : window.location.href); },
  27. fetch: function (url, options) { return fetch(url, options); },
  28. };
  29. var appleIphone = /iPhone/i;
  30. var appleIpod = /iPod/i;
  31. var appleTablet = /iPad/i;
  32. var appleUniversal = /\biOS-universal(?:.+)Mac\b/i;
  33. var androidPhone = /\bAndroid(?:.+)Mobile\b/i;
  34. var androidTablet = /Android/i;
  35. var amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i;
  36. var amazonTablet = /Silk/i;
  37. var windowsPhone = /Windows Phone/i;
  38. var windowsTablet = /\bWindows(?:.+)ARM\b/i;
  39. var otherBlackBerry = /BlackBerry/i;
  40. var otherBlackBerry10 = /BB10/i;
  41. var otherOpera = /Opera Mini/i;
  42. var otherChrome = /\b(CriOS|Chrome)(?:.+)Mobile/i;
  43. var otherFirefox = /Mobile(?:.+)Firefox\b/i;
  44. var isAppleTabletOnIos13 = function (navigator) {
  45. return (typeof navigator !== 'undefined' &&
  46. navigator.platform === 'MacIntel' &&
  47. typeof navigator.maxTouchPoints === 'number' &&
  48. navigator.maxTouchPoints > 1 &&
  49. typeof MSStream === 'undefined');
  50. };
  51. function createMatch(userAgent) {
  52. return function (regex) { return regex.test(userAgent); };
  53. }
  54. function isMobile$1(param) {
  55. var nav = {
  56. userAgent: '',
  57. platform: '',
  58. maxTouchPoints: 0
  59. };
  60. if (!param && typeof navigator !== 'undefined') {
  61. nav = {
  62. userAgent: navigator.userAgent,
  63. platform: navigator.platform,
  64. maxTouchPoints: navigator.maxTouchPoints || 0
  65. };
  66. }
  67. else if (typeof param === 'string') {
  68. nav.userAgent = param;
  69. }
  70. else if (param && param.userAgent) {
  71. nav = {
  72. userAgent: param.userAgent,
  73. platform: param.platform,
  74. maxTouchPoints: param.maxTouchPoints || 0
  75. };
  76. }
  77. var userAgent = nav.userAgent;
  78. var tmp = userAgent.split('[FBAN');
  79. if (typeof tmp[1] !== 'undefined') {
  80. userAgent = tmp[0];
  81. }
  82. tmp = userAgent.split('Twitter');
  83. if (typeof tmp[1] !== 'undefined') {
  84. userAgent = tmp[0];
  85. }
  86. var match = createMatch(userAgent);
  87. var result = {
  88. apple: {
  89. phone: match(appleIphone) && !match(windowsPhone),
  90. ipod: match(appleIpod),
  91. tablet: !match(appleIphone) &&
  92. (match(appleTablet) || isAppleTabletOnIos13(nav)) &&
  93. !match(windowsPhone),
  94. universal: match(appleUniversal),
  95. device: (match(appleIphone) ||
  96. match(appleIpod) ||
  97. match(appleTablet) ||
  98. match(appleUniversal) ||
  99. isAppleTabletOnIos13(nav)) &&
  100. !match(windowsPhone)
  101. },
  102. amazon: {
  103. phone: match(amazonPhone),
  104. tablet: !match(amazonPhone) && match(amazonTablet),
  105. device: match(amazonPhone) || match(amazonTablet)
  106. },
  107. android: {
  108. phone: (!match(windowsPhone) && match(amazonPhone)) ||
  109. (!match(windowsPhone) && match(androidPhone)),
  110. tablet: !match(windowsPhone) &&
  111. !match(amazonPhone) &&
  112. !match(androidPhone) &&
  113. (match(amazonTablet) || match(androidTablet)),
  114. device: (!match(windowsPhone) &&
  115. (match(amazonPhone) ||
  116. match(amazonTablet) ||
  117. match(androidPhone) ||
  118. match(androidTablet))) ||
  119. match(/\bokhttp\b/i)
  120. },
  121. windows: {
  122. phone: match(windowsPhone),
  123. tablet: match(windowsTablet),
  124. device: match(windowsPhone) || match(windowsTablet)
  125. },
  126. other: {
  127. blackberry: match(otherBlackBerry),
  128. blackberry10: match(otherBlackBerry10),
  129. opera: match(otherOpera),
  130. firefox: match(otherFirefox),
  131. chrome: match(otherChrome),
  132. device: match(otherBlackBerry) ||
  133. match(otherBlackBerry10) ||
  134. match(otherOpera) ||
  135. match(otherFirefox) ||
  136. match(otherChrome)
  137. },
  138. any: false,
  139. phone: false,
  140. tablet: false
  141. };
  142. result.any =
  143. result.apple.device ||
  144. result.android.device ||
  145. result.windows.device ||
  146. result.other.device;
  147. result.phone =
  148. result.apple.phone || result.android.phone || result.windows.phone;
  149. result.tablet =
  150. result.apple.tablet || result.android.tablet || result.windows.tablet;
  151. return result;
  152. }
  153. var isMobile = isMobile$1(globalThis.navigator);
  154. /**
  155. * Uploading the same buffer multiple times in a single frame can cause performance issues.
  156. * Apparent on iOS so only check for that at the moment
  157. * This check may become more complex if this issue pops up elsewhere.
  158. * @private
  159. * @returns {boolean} `true` if the same buffer may be uploaded more than once.
  160. */
  161. function canUploadSameBuffer() {
  162. return !isMobile.apple.device;
  163. }
  164. /**
  165. * The maximum recommended texture units to use.
  166. * In theory the bigger the better, and for desktop we'll use as many as we can.
  167. * But some mobile devices slow down if there is to many branches in the shader.
  168. * So in practice there seems to be a sweet spot size that varies depending on the device.
  169. *
  170. * In v4, all mobile devices were limited to 4 texture units because for this.
  171. * In v5, we allow all texture units to be used on modern Apple or Android devices.
  172. * @private
  173. * @param {number} max
  174. * @returns {number} The maximum recommended texture units to use.
  175. */
  176. function maxRecommendedTextures(max) {
  177. var allowMax = true;
  178. if (isMobile.tablet || isMobile.phone) {
  179. if (isMobile.apple.device) {
  180. var match = (navigator.userAgent).match(/OS (\d+)_(\d+)?/);
  181. if (match) {
  182. var majorVersion = parseInt(match[1], 10);
  183. // Limit texture units on devices below iOS 11, which will be older hardware
  184. if (majorVersion < 11) {
  185. allowMax = false;
  186. }
  187. }
  188. }
  189. if (isMobile.android.device) {
  190. var match = (navigator.userAgent).match(/Android\s([0-9.]*)/);
  191. if (match) {
  192. var majorVersion = parseInt(match[1], 10);
  193. // Limit texture units on devices below Android 7 (Nougat), which will be older hardware
  194. if (majorVersion < 7) {
  195. allowMax = false;
  196. }
  197. }
  198. }
  199. }
  200. return allowMax ? max : 4;
  201. }
  202. /**
  203. * User's customizable globals for overriding the default PIXI settings, such
  204. * as a renderer's default resolution, framerate, float precision, etc.
  205. * @example
  206. * // Use the native window resolution as the default resolution
  207. * // will support high-density displays when rendering
  208. * PIXI.settings.RESOLUTION = window.devicePixelRatio;
  209. *
  210. * // Disable interpolation when scaling, will make texture be pixelated
  211. * PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
  212. * @namespace PIXI.settings
  213. */
  214. var settings = {
  215. /**
  216. * This adapter is used to call methods that are platform dependent.
  217. * For example `document.createElement` only runs on the web but fails in node environments.
  218. * This allows us to support more platforms by abstracting away specific implementations per platform.
  219. *
  220. * By default the adapter is set to work in the browser. However you can create your own
  221. * by implementing the `IAdapter` interface. See `IAdapter` for more information.
  222. * @name ADAPTER
  223. * @memberof PIXI.settings
  224. * @type {PIXI.IAdapter}
  225. * @default PIXI.BrowserAdapter
  226. */
  227. ADAPTER: BrowserAdapter,
  228. /**
  229. * If set to true WebGL will attempt make textures mimpaped by default.
  230. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions.
  231. * @static
  232. * @name MIPMAP_TEXTURES
  233. * @memberof PIXI.settings
  234. * @type {PIXI.MIPMAP_MODES}
  235. * @default PIXI.MIPMAP_MODES.POW2
  236. */
  237. MIPMAP_TEXTURES: constants.MIPMAP_MODES.POW2,
  238. /**
  239. * Default anisotropic filtering level of textures.
  240. * Usually from 0 to 16
  241. * @static
  242. * @name ANISOTROPIC_LEVEL
  243. * @memberof PIXI.settings
  244. * @type {number}
  245. * @default 0
  246. */
  247. ANISOTROPIC_LEVEL: 0,
  248. /**
  249. * Default resolution / device pixel ratio of the renderer.
  250. * @static
  251. * @name RESOLUTION
  252. * @memberof PIXI.settings
  253. * @type {number}
  254. * @default 1
  255. */
  256. RESOLUTION: 1,
  257. /**
  258. * Default filter resolution.
  259. * @static
  260. * @name FILTER_RESOLUTION
  261. * @memberof PIXI.settings
  262. * @type {number}
  263. * @default 1
  264. */
  265. FILTER_RESOLUTION: 1,
  266. /**
  267. * Default filter samples.
  268. * @static
  269. * @name FILTER_MULTISAMPLE
  270. * @memberof PIXI.settings
  271. * @type {PIXI.MSAA_QUALITY}
  272. * @default PIXI.MSAA_QUALITY.NONE
  273. */
  274. FILTER_MULTISAMPLE: constants.MSAA_QUALITY.NONE,
  275. /**
  276. * The maximum textures that this device supports.
  277. * @static
  278. * @name SPRITE_MAX_TEXTURES
  279. * @memberof PIXI.settings
  280. * @type {number}
  281. * @default 32
  282. */
  283. SPRITE_MAX_TEXTURES: maxRecommendedTextures(32),
  284. // TODO: maybe change to SPRITE.BATCH_SIZE: 2000
  285. // TODO: maybe add PARTICLE.BATCH_SIZE: 15000
  286. /**
  287. * The default sprite batch size.
  288. *
  289. * The default aims to balance desktop and mobile devices.
  290. * @static
  291. * @name SPRITE_BATCH_SIZE
  292. * @memberof PIXI.settings
  293. * @type {number}
  294. * @default 4096
  295. */
  296. SPRITE_BATCH_SIZE: 4096,
  297. /**
  298. * The default render options if none are supplied to {@link PIXI.Renderer}
  299. * or {@link PIXI.CanvasRenderer}.
  300. * @static
  301. * @name RENDER_OPTIONS
  302. * @memberof PIXI.settings
  303. * @type {object}
  304. * @property {boolean} [antialias=false] - {@link PIXI.IRendererOptions.antialias}
  305. * @property {boolean} [autoDensity=false] - {@link PIXI.IRendererOptions.autoDensity}
  306. * @property {number} [backgroundAlpha=1] - {@link PIXI.IRendererOptions.backgroundAlpha}
  307. * @property {number} [backgroundColor=0x000000] - {@link PIXI.IRendererOptions.backgroundColor}
  308. * @property {boolean} [clearBeforeRender=true] - {@link PIXI.IRendererOptions.clearBeforeRender}
  309. * @property {number} [height=600] - {@link PIXI.IRendererOptions.height}
  310. * @property {boolean} [preserveDrawingBuffer=false] - {@link PIXI.IRendererOptions.preserveDrawingBuffer}
  311. * @property {boolean|'notMultiplied'} [useContextAlpha=true] - {@link PIXI.IRendererOptions.useContextAlpha}
  312. * @property {HTMLCanvasElement} [view=null] - {@link PIXI.IRendererOptions.view}
  313. * @property {number} [width=800] - {@link PIXI.IRendererOptions.width}
  314. */
  315. RENDER_OPTIONS: {
  316. view: null,
  317. width: 800,
  318. height: 600,
  319. autoDensity: false,
  320. backgroundColor: 0x000000,
  321. backgroundAlpha: 1,
  322. useContextAlpha: true,
  323. clearBeforeRender: true,
  324. antialias: false,
  325. preserveDrawingBuffer: false,
  326. },
  327. /**
  328. * Default Garbage Collection mode.
  329. * @static
  330. * @name GC_MODE
  331. * @memberof PIXI.settings
  332. * @type {PIXI.GC_MODES}
  333. * @default PIXI.GC_MODES.AUTO
  334. */
  335. GC_MODE: constants.GC_MODES.AUTO,
  336. /**
  337. * Default Garbage Collection max idle.
  338. * @static
  339. * @name GC_MAX_IDLE
  340. * @memberof PIXI.settings
  341. * @type {number}
  342. * @default 3600
  343. */
  344. GC_MAX_IDLE: 60 * 60,
  345. /**
  346. * Default Garbage Collection maximum check count.
  347. * @static
  348. * @name GC_MAX_CHECK_COUNT
  349. * @memberof PIXI.settings
  350. * @type {number}
  351. * @default 600
  352. */
  353. GC_MAX_CHECK_COUNT: 60 * 10,
  354. /**
  355. * Default wrap modes that are supported by pixi.
  356. * @static
  357. * @name WRAP_MODE
  358. * @memberof PIXI.settings
  359. * @type {PIXI.WRAP_MODES}
  360. * @default PIXI.WRAP_MODES.CLAMP
  361. */
  362. WRAP_MODE: constants.WRAP_MODES.CLAMP,
  363. /**
  364. * Default scale mode for textures.
  365. * @static
  366. * @name SCALE_MODE
  367. * @memberof PIXI.settings
  368. * @type {PIXI.SCALE_MODES}
  369. * @default PIXI.SCALE_MODES.LINEAR
  370. */
  371. SCALE_MODE: constants.SCALE_MODES.LINEAR,
  372. /**
  373. * Default specify float precision in vertex shader.
  374. * @static
  375. * @name PRECISION_VERTEX
  376. * @memberof PIXI.settings
  377. * @type {PIXI.PRECISION}
  378. * @default PIXI.PRECISION.HIGH
  379. */
  380. PRECISION_VERTEX: constants.PRECISION.HIGH,
  381. /**
  382. * Default specify float precision in fragment shader.
  383. * iOS is best set at highp due to https://github.com/pixijs/pixi.js/issues/3742
  384. * @static
  385. * @name PRECISION_FRAGMENT
  386. * @memberof PIXI.settings
  387. * @type {PIXI.PRECISION}
  388. * @default PIXI.PRECISION.MEDIUM
  389. */
  390. PRECISION_FRAGMENT: isMobile.apple.device ? constants.PRECISION.HIGH : constants.PRECISION.MEDIUM,
  391. /**
  392. * Can we upload the same buffer in a single frame?
  393. * @static
  394. * @name CAN_UPLOAD_SAME_BUFFER
  395. * @memberof PIXI.settings
  396. * @type {boolean}
  397. */
  398. CAN_UPLOAD_SAME_BUFFER: canUploadSameBuffer(),
  399. /**
  400. * Enables bitmap creation before image load. This feature is experimental.
  401. * @static
  402. * @name CREATE_IMAGE_BITMAP
  403. * @memberof PIXI.settings
  404. * @type {boolean}
  405. * @default false
  406. */
  407. CREATE_IMAGE_BITMAP: false,
  408. /**
  409. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  410. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  411. * The main disadvantage is movement of objects may appear less smooth.
  412. * @static
  413. * @constant
  414. * @memberof PIXI.settings
  415. * @type {boolean}
  416. * @default false
  417. */
  418. ROUND_PIXELS: false,
  419. };
  420. exports.BrowserAdapter = BrowserAdapter;
  421. exports.isMobile = isMobile;
  422. exports.settings = settings;
  423. Object.defineProperty(exports, '__esModule', { value: true });
  424. return exports;
  425. })({}, PIXI);
  426. Object.assign(this.PIXI, _pixi_settings);
  427. //# sourceMappingURL=settings.js.map