settings.mjs 14 KB

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