diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index d99a9a5..b4361ac 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,7 +1,6 @@ import * as core from '../../core'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * Does nothing. Very handy. @@ -19,9 +18,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./void.frag') + readFileSync(join(__dirname, './void.frag'), 'utf8') ); this.glShaderKey = 'void'; diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index d99a9a5..b4361ac 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,7 +1,6 @@ import * as core from '../../core'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * Does nothing. Very handy. @@ -19,9 +18,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./void.frag') + readFileSync(join(__dirname, './void.frag'), 'utf8') ); this.glShaderKey = 'void'; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index ac9060c..2d637b1 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -46,8 +46,9 @@ let resolution = core.utils.getResolutionOfUrl(resource.url); const scale = resource.data.meta.scale; + // for now (to keep things compatible) resolution overrides scale // Support scale field on spritesheet - if (scale !== undefined && scale !== 1) + if (resolution === 1 && scale !== undefined && scale !== 1) { baseTexture.resolution = resolution = scale; baseTexture.update(); diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index d99a9a5..b4361ac 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,7 +1,6 @@ import * as core from '../../core'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * Does nothing. Very handy. @@ -19,9 +18,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./void.frag') + readFileSync(join(__dirname, './void.frag'), 'utf8') ); this.glShaderKey = 'void'; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index ac9060c..2d637b1 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -46,8 +46,9 @@ let resolution = core.utils.getResolutionOfUrl(resource.url); const scale = resource.data.meta.scale; + // for now (to keep things compatible) resolution overrides scale // Support scale field on spritesheet - if (scale !== undefined && scale !== 1) + if (resolution === 1 && scale !== undefined && scale !== 1) { baseTexture.resolution = resolution = scale; baseTexture.update(); diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index 7507de4..05e8f16 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -226,15 +226,6 @@ } /** - * Binds the buffers to the GPU - * - */ - bind() - { - this.vao.bind(); - } - - /** * Destroys the ParticleBuffer. * */ diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index d99a9a5..b4361ac 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,7 +1,6 @@ import * as core from '../../core'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * Does nothing. Very handy. @@ -19,9 +18,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./void.frag') + readFileSync(join(__dirname, './void.frag'), 'utf8') ); this.glShaderKey = 'void'; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index ac9060c..2d637b1 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -46,8 +46,9 @@ let resolution = core.utils.getResolutionOfUrl(resource.url); const scale = resource.data.meta.scale; + // for now (to keep things compatible) resolution overrides scale // Support scale field on spritesheet - if (scale !== undefined && scale !== 1) + if (resolution === 1 && scale !== undefined && scale !== 1) { baseTexture.resolution = resolution = scale; baseTexture.update(); diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index 7507de4..05e8f16 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -226,15 +226,6 @@ } /** - * Binds the buffers to the GPU - * - */ - bind() - { - this.vao.bind(); - } - - /** * Destroys the ParticleBuffer. * */ diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 4a18bde..ffce8ec 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -123,6 +123,7 @@ const children = container.children; const maxSize = container._maxSize; const batchSize = container._batchSize; + const renderer = this.renderer; let totalChildren = children.length; if (totalChildren === 0) @@ -134,21 +135,21 @@ totalChildren = maxSize; } - let buffers = container._glBuffers[this.renderer.CONTEXT_UID]; + let buffers = container._glBuffers[renderer.CONTEXT_UID]; if (!buffers) { - buffers = container._glBuffers[this.renderer.CONTEXT_UID] = this.generateBuffers(container); + buffers = container._glBuffers[renderer.CONTEXT_UID] = this.generateBuffers(container); } // if the uvs have not updated then no point rendering just yet! this.renderer.setBlendMode(container.blendMode); - const gl = this.renderer.gl; + const gl = renderer.gl; const m = container.worldTransform.copy(this.tempMatrix); - m.prepend(this.renderer._activeRenderTarget.projectionMatrix); + m.prepend(renderer._activeRenderTarget.projectionMatrix); this.shader.uniforms.projectionMatrix = m.toArray(true); this.shader.uniforms.uAlpha = container.worldAlpha; @@ -156,7 +157,7 @@ // make sure the texture is bound.. const baseTexture = children[0]._texture.baseTexture; - this.shader.uniforms.uSampler = this.renderer.bindTexture(baseTexture); + this.shader.uniforms.uSampler = renderer.bindTexture(baseTexture); // now lets upload and render the buffers.. for (let i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) @@ -181,13 +182,8 @@ } // bind the buffer - buffer.vao.bind() - .draw(gl.TRIANGLES, amount * 6) - .unbind(); - - // now draw those suckas! - // gl.drawElements(gl.TRIANGLES, amount * 6, gl.UNSIGNED_SHORT, 0); - // this.renderer.drawCount++; + renderer.bindVao(buffer.vao); + buffer.vao.draw(gl.TRIANGLES, amount * 6); } } diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index d99a9a5..b4361ac 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,7 +1,6 @@ import * as core from '../../core'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * Does nothing. Very handy. @@ -19,9 +18,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./void.frag') + readFileSync(join(__dirname, './void.frag'), 'utf8') ); this.glShaderKey = 'void'; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index ac9060c..2d637b1 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -46,8 +46,9 @@ let resolution = core.utils.getResolutionOfUrl(resource.url); const scale = resource.data.meta.scale; + // for now (to keep things compatible) resolution overrides scale // Support scale field on spritesheet - if (scale !== undefined && scale !== 1) + if (resolution === 1 && scale !== undefined && scale !== 1) { baseTexture.resolution = resolution = scale; baseTexture.update(); diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index 7507de4..05e8f16 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -226,15 +226,6 @@ } /** - * Binds the buffers to the GPU - * - */ - bind() - { - this.vao.bind(); - } - - /** * Destroys the ParticleBuffer. * */ diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 4a18bde..ffce8ec 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -123,6 +123,7 @@ const children = container.children; const maxSize = container._maxSize; const batchSize = container._batchSize; + const renderer = this.renderer; let totalChildren = children.length; if (totalChildren === 0) @@ -134,21 +135,21 @@ totalChildren = maxSize; } - let buffers = container._glBuffers[this.renderer.CONTEXT_UID]; + let buffers = container._glBuffers[renderer.CONTEXT_UID]; if (!buffers) { - buffers = container._glBuffers[this.renderer.CONTEXT_UID] = this.generateBuffers(container); + buffers = container._glBuffers[renderer.CONTEXT_UID] = this.generateBuffers(container); } // if the uvs have not updated then no point rendering just yet! this.renderer.setBlendMode(container.blendMode); - const gl = this.renderer.gl; + const gl = renderer.gl; const m = container.worldTransform.copy(this.tempMatrix); - m.prepend(this.renderer._activeRenderTarget.projectionMatrix); + m.prepend(renderer._activeRenderTarget.projectionMatrix); this.shader.uniforms.projectionMatrix = m.toArray(true); this.shader.uniforms.uAlpha = container.worldAlpha; @@ -156,7 +157,7 @@ // make sure the texture is bound.. const baseTexture = children[0]._texture.baseTexture; - this.shader.uniforms.uSampler = this.renderer.bindTexture(baseTexture); + this.shader.uniforms.uSampler = renderer.bindTexture(baseTexture); // now lets upload and render the buffers.. for (let i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) @@ -181,13 +182,8 @@ } // bind the buffer - buffer.vao.bind() - .draw(gl.TRIANGLES, amount * 6) - .unbind(); - - // now draw those suckas! - // gl.drawElements(gl.TRIANGLES, amount * 6, gl.UNSIGNED_SHORT, 0); - // this.renderer.drawCount++; + renderer.bindVao(buffer.vao); + buffer.vao.draw(gl.TRIANGLES, amount * 6); } } diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js index 4f10c10..ebf1195 100755 --- a/test/core/DisplayObject.js +++ b/test/core/DisplayObject.js @@ -16,13 +16,13 @@ it('should set the correct Transform', () => { - PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.DYNAMIC; + PIXI.settings.TRANSFORM_MODE = PIXI.TRANSFORM_MODE.DYNAMIC; const dynamicTransform = new PIXI.DisplayObject(); expect(dynamicTransform.transform).to.be.instanceof(PIXI.Transform); - PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.STATIC; + PIXI.settings.TRANSFORM_MODE = PIXI.TRANSFORM_MODE.STATIC; const staticTransform = new PIXI.DisplayObject(); diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index d99a9a5..b4361ac 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,7 +1,6 @@ import * as core from '../../core'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * Does nothing. Very handy. @@ -19,9 +18,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./void.frag') + readFileSync(join(__dirname, './void.frag'), 'utf8') ); this.glShaderKey = 'void'; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index ac9060c..2d637b1 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -46,8 +46,9 @@ let resolution = core.utils.getResolutionOfUrl(resource.url); const scale = resource.data.meta.scale; + // for now (to keep things compatible) resolution overrides scale // Support scale field on spritesheet - if (scale !== undefined && scale !== 1) + if (resolution === 1 && scale !== undefined && scale !== 1) { baseTexture.resolution = resolution = scale; baseTexture.update(); diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index 7507de4..05e8f16 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -226,15 +226,6 @@ } /** - * Binds the buffers to the GPU - * - */ - bind() - { - this.vao.bind(); - } - - /** * Destroys the ParticleBuffer. * */ diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 4a18bde..ffce8ec 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -123,6 +123,7 @@ const children = container.children; const maxSize = container._maxSize; const batchSize = container._batchSize; + const renderer = this.renderer; let totalChildren = children.length; if (totalChildren === 0) @@ -134,21 +135,21 @@ totalChildren = maxSize; } - let buffers = container._glBuffers[this.renderer.CONTEXT_UID]; + let buffers = container._glBuffers[renderer.CONTEXT_UID]; if (!buffers) { - buffers = container._glBuffers[this.renderer.CONTEXT_UID] = this.generateBuffers(container); + buffers = container._glBuffers[renderer.CONTEXT_UID] = this.generateBuffers(container); } // if the uvs have not updated then no point rendering just yet! this.renderer.setBlendMode(container.blendMode); - const gl = this.renderer.gl; + const gl = renderer.gl; const m = container.worldTransform.copy(this.tempMatrix); - m.prepend(this.renderer._activeRenderTarget.projectionMatrix); + m.prepend(renderer._activeRenderTarget.projectionMatrix); this.shader.uniforms.projectionMatrix = m.toArray(true); this.shader.uniforms.uAlpha = container.worldAlpha; @@ -156,7 +157,7 @@ // make sure the texture is bound.. const baseTexture = children[0]._texture.baseTexture; - this.shader.uniforms.uSampler = this.renderer.bindTexture(baseTexture); + this.shader.uniforms.uSampler = renderer.bindTexture(baseTexture); // now lets upload and render the buffers.. for (let i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) @@ -181,13 +182,8 @@ } // bind the buffer - buffer.vao.bind() - .draw(gl.TRIANGLES, amount * 6) - .unbind(); - - // now draw those suckas! - // gl.drawElements(gl.TRIANGLES, amount * 6, gl.UNSIGNED_SHORT, 0); - // this.renderer.drawCount++; + renderer.bindVao(buffer.vao); + buffer.vao.draw(gl.TRIANGLES, amount * 6); } } diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js index 4f10c10..ebf1195 100755 --- a/test/core/DisplayObject.js +++ b/test/core/DisplayObject.js @@ -16,13 +16,13 @@ it('should set the correct Transform', () => { - PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.DYNAMIC; + PIXI.settings.TRANSFORM_MODE = PIXI.TRANSFORM_MODE.DYNAMIC; const dynamicTransform = new PIXI.DisplayObject(); expect(dynamicTransform.transform).to.be.instanceof(PIXI.Transform); - PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.STATIC; + PIXI.settings.TRANSFORM_MODE = PIXI.TRANSFORM_MODE.STATIC; const staticTransform = new PIXI.DisplayObject(); diff --git a/test/core/TilingSprite.js b/test/core/TilingSprite.js index 17debe3..2e449a7 100644 --- a/test/core/TilingSprite.js +++ b/test/core/TilingSprite.js @@ -8,7 +8,7 @@ { const parent = new PIXI.Container(); const texture = new PIXI.Texture(new PIXI.BaseTexture()); - const tilingSprite = new PIXI.TilingSprite(texture, 200, 300); + const tilingSprite = new PIXI.extras.TilingSprite(texture, 200, 300); parent.addChild(tilingSprite); diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..402a0a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + presets: [ + ["es2015", { "loose": true }], + ], + plugins: [ + "static-fs", + "version-inline" + ] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index ff9ba60..cb6c09d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,12 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "globals": { - "global": false + "global": false, + "__VERSION__": false }, "parserOptions": { "ecmaVersion": 6, diff --git a/.gitignore b/.gitignore index 23731fd..1c378a5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ examples_old/ bin/ coverage/ +lib/ +dist/ # jetBrains IDE ignores .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a034c6e..3df8b22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,8 @@ - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - xvfb-maybe npm run coverage - npm run build + - xvfb-maybe npm run coverage - npm run docs deploy: @@ -39,7 +39,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=60" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true @@ -79,7 +79,7 @@ acl: public_read region: eu-west-1 cache_control: "max-age=2592000" - local_dir: bin + local_dir: dist upload-dir: "$TRAVIS_BRANCH" on: all_branches: true diff --git a/package.json b/package.json index 8ae4d07..c8c5220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.1.1", + "version": "4.2.1", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ @@ -9,7 +9,7 @@ "Chad Engler ", "Richard Davey " ], - "main": "./bin/pixi.min.js", + "main": "./lib/index.js", "homepage": "http://goodboydigital.com/", "bugs": "https://github.com/pixijs/pixi.js/issues", "license": "MIT", @@ -18,31 +18,34 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "clean": "rimraf bin && mkdirp bin", + "clean": "rimraf dist lib && mkdirp dist && mkdir lib", "prestart": "npm run clean", - "start": "parallelshell \"npm run watch:lint\" \"npm run watch\"", - "watch": "pixify -n PIXI -o pixi -w", + "start": "parallelshell \"npm run watch\" \"npm run watch:lint\" \"npm run watch:lib\"", + "watch": "npm run dist -- --watch", + "watch:lib": "npm run lib -- --watch", "watch:lint": "watch \"eslint scripts src test || exit 0\" src", "test": "floss --path test/index.js", "test:debug": "npm test -- --debug", "prerenders": "npm --prefix scripts/renders i scripts/renders", "renders": "electron scripts/renders", - "precoverage": "rimraf coverage && npm run build -- --noExternal", - "coverage": "npm test -- -c bin/pixi.js -s -h", + "precoverage": "rimraf coverage", + "coverage": "npm test -- -c dist/pixi.js -s -h", "lint": "eslint scripts src test --max-warnings 0", "lintfix": "npm run lint --fix", - "prebuild": "npm run lint && npm run clean", - "build": "pixify -n PIXI -o pixi", + "prebuild": "npm run lint", + "build": "npm run dist", + "dist": "pixify -d dist -n PIXI -o pixi", + "lib": "babel src --out-dir lib -s", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", "publish:patch": "npm version patch --no-git-tag-version && npm publish", "publish:minor": "npm version minor --no-git-tag-version && npm publish", "publish:major": "npm version major --no-git-tag-version && npm publish", - "postversion": "npm run build && npm test", + "postversion": "npm run clean && npm run build && npm run lib && npm test", "postpublish": "node scripts/release.js" }, "files": [ - "bin/", - "src/", + "dist/", + "lib/", "CONTRIBUTING.md", "LICENSE", "package.json", @@ -52,14 +55,15 @@ "bit-twiddle": "^1.0.2", "earcut": "^2.0.7", "eventemitter3": "^2.0.0", - "glslify": "^5.0.2", "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", - "resource-loader": "^1.8.0", - "browserify-versionify": "^1.0.6" + "resource-loader": "^1.8.0" }, "devDependencies": { + "babel-cli": "^6.18.0", + "babel-plugin-static-fs": "^1.1.0", + "babel-plugin-version-inline": "^1.0.0", "babel-preset-es2015": "^6.14.0", "babelify": "^7.3.0", "del": "^2.2.0", @@ -79,21 +83,7 @@ }, "browserify": { "transform": [ - [ - "babelify", - { - "presets": [ - [ - "es2015", - { - "loose": true - } - ] - ] - } - ], - "glslify", - "browserify-versionify" + "babelify" ] } } diff --git a/scripts/release.js b/scripts/release.js index 57d800a..c4c8e36 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -9,9 +9,10 @@ const options = { src: [ - 'bin/**/*', - 'scripts/**/*', + 'dist/**/*', + 'lib/**/*', 'src/**/*', + 'scripts/**/*', 'test/**/*', '*.json', '*.md', @@ -19,6 +20,7 @@ '.eslintrc', '.editorconfig', '.travis.yml', + '.babelrc', ], dotfiles: true, branch: 'release', diff --git a/src/core/Shader.js b/src/core/Shader.js new file mode 100644 index 0000000..81e076b --- /dev/null +++ b/src/core/Shader.js @@ -0,0 +1,47 @@ +import { GLShader } from 'pixi-gl-core'; +import settings from './settings'; + +const { PRECISION } = settings; + +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0, 9) !== 'precision') + { + const copy = src.slice(0); + + copy.unshift(`precision ${PRECISION} float;`); + + return copy; + } + } + else if (src.substring(0, 9) !== 'precision') + { + return `precision ${PRECISION} float;\n${src}`; + } + + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. + * + * @class + * @extends GLShader + * @memberof PIXI + */ +export default class Shader extends GLShader +{ + /** + * + * @param {WebGLRenderingContext} gl - The current WebGL rendering context + * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. + * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. + */ + constructor(gl, vertexSrc, fragmentSrc) + { + super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); + } +} diff --git a/src/core/const.js b/src/core/const.js index c0a7efb..efccde4 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,4 +1,3 @@ -import maxRecommendedTextures from './utils/maxRecommendedTextures'; import canUploadSameBuffer from './utils/canUploadSameBuffer'; /** @@ -9,7 +8,7 @@ * @memberof PIXI * @type {string} */ -export const VERSION = '__VERSION__'; +export const VERSION = __VERSION__; /** * Two Pi. @@ -42,17 +41,6 @@ export const DEG_TO_RAD = Math.PI / 180; /** - * Target frames per millisecond. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 0.06 - */ -export const TARGET_FPMS = 0.06; - -/** * Constant to identify the Renderer Type. * * @static @@ -146,19 +134,17 @@ /** * The scale modes that are supported by pixi. * - * The DEFAULT scale mode affects the default scaling mode of future operations. + * The PIXI.settings.SCALE_MODE scale mode affects the default scaling mode of future operations. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. * * @static * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=LINEAR * @property {number} LINEAR Smooth scaling * @property {number} NEAREST Pixelating scaling */ export const SCALE_MODES = { - DEFAULT: 0, LINEAR: 0, NEAREST: 1, }; @@ -166,7 +152,7 @@ /** * The wrap modes that are supported by pixi. * - * The DEFAULT wrap mode affects the default wraping mode of future operations. + * The PIXI.settings.WRAP_MODE wrap mode affects the default wraping mode of future operations. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can * only use REPEAT if the texture is po2. @@ -177,13 +163,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=CLAMP * @property {number} CLAMP - The textures uvs are clamped * @property {number} REPEAT - The texture uvs tile and repeat * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring */ export const WRAP_MODES = { - DEFAULT: 0, CLAMP: 0, REPEAT: 1, MIRRORED_REPEAT: 2, @@ -192,8 +176,8 @@ /** * The gc modes that are supported by pixi. * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not + * The PIXI.settings.GC_MODE Garbage Collection mode for pixi textures is AUTO + * If set to GC_MODE, the renderer will occasianally check textures usage. If they are not * used for a specified period of time they will be removed from the GPU. They will of course * be uploaded again when they are required. This is a silent behind the scenes process that * should ensure that the GPU does not get filled up. @@ -205,89 +189,15 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=MANUAL * @property {number} AUTO - Garbage collection will happen periodically automatically * @property {number} MANUAL - Garbage collection will need to be called manually */ export const GC_MODES = { - DEFAULT: 0, AUTO: 0, MANUAL: 1, }; /** - * If set to true WebGL will attempt make textures mimpaped by default. - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * - * @static - * @constant - * @memberof PIXI - * @type {boolean} - */ -export const MIPMAP_TEXTURES = true; - -/** - * The prefix that denotes a URL is for a retina asset. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `@2x` - */ -export const RETINA_PREFIX = /@(.+)x/; - -/** - * Default resolution / device pixel ratio of the renderer. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const RESOLUTION = 1; - -/** - * Default filter resolution. - * - * @static - * @constant - * @type {number} - */ -export const FILTER_RESOLUTION = 1; - -/** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @memberof PIXI - * @type {object} - * @property {HTMLCanvasElement} view=null - * @property {number} resolution=1 - * @property {boolean} antialias=false - * @property {boolean} forceFXAA=false - * @property {boolean} autoResize=false - * @property {boolean} transparent=false - * @property {number} backgroundColor=0x000000 - * @property {boolean} clearBeforeRender=true - * @property {boolean} preserveDrawingBuffer=false - * @property {boolean} roundPixels=false - */ -export const DEFAULT_RENDER_OPTIONS = { - view: null, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false, -}; - -/** * Regexp for image type by extension. * * @static @@ -349,13 +259,11 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT='mediump' - * @property {number} LOW='lowp' - * @property {number} MEDIUM='mediump' - * @property {number} HIGH='highp' + * @property {string} LOW='lowp' + * @property {string} MEDIUM='mediump' + * @property {string} HIGH='highp' */ export const PRECISION = { - DEFAULT: 'mediump', LOW: 'lowp', MEDIUM: 'mediump', HIGH: 'highp', @@ -368,12 +276,10 @@ * @constant * @memberof PIXI * @type {object} - * @property {number} DEFAULT=STATIC * @property {number} STATIC * @property {number} DYNAMIC */ export const TRANSFORM_MODE = { - DEFAULT: 0, STATIC: 0, DYNAMIC: 1, }; @@ -397,29 +303,6 @@ // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The default sprite batch size. - * - * The default aims to balance desktop and mobile devices. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - * @default 4096 - */ -export const SPRITE_BATCH_SIZE = 4096; - -/** - * The maximum textures that this device supports. - * - * @static - * @constant - * @memberof PIXI - * @type {number} - */ -export const SPRITE_MAX_TEXTURES = maxRecommendedTextures(32); - -/** * Can we upload the same buffer in a single frame? * * @static diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index bd9ee2f..cf9e5e2 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,6 @@ import EventEmitter from 'eventemitter3'; import { TRANSFORM_MODE } from '../const'; +import settings from '../settings'; import TransformStatic from './TransformStatic'; import Transform from './Transform'; import Bounds from './Bounds'; @@ -24,7 +25,7 @@ { super(); - const TransformClass = TRANSFORM_MODE.DEFAULT === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + const TransformClass = settings.TRANSFORM_MODE === TRANSFORM_MODE.STATIC ? TransformStatic : Transform; this.tempDisplayObjectParent = null; diff --git a/src/core/index.js b/src/core/index.js index 6f6b9dc..3443149 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,10 +6,11 @@ import * as utils from './utils'; import * as ticker from './ticker'; +import settings from './settings'; import CanvasRenderer from './renderers/canvas/CanvasRenderer'; import WebGLRenderer from './renderers/webgl/WebGLRenderer'; -export { utils, ticker, CanvasRenderer, WebGLRenderer }; +export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; export { default as glCore } from 'pixi-gl-core'; @@ -49,6 +50,7 @@ * the browser then this function will return a canvas renderer * * @memberof PIXI + * @function autoDetectRenderer * @param {number} [width=800] - the width of the renderers view * @param {number} [height=600] - the height of the renderers view * @param {object} [options] - The optional renderer parameters diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index aed0e21..5e0a3ca 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,11 +1,13 @@ import { sayHello, hex2string, hex2rgb } from '../utils'; import { Matrix } from '../math'; -import { DEFAULT_RENDER_OPTIONS, RENDERER_TYPE, RESOLUTION } from '../const'; +import { RENDERER_TYPE } from '../const'; +import settings from '../settings'; import Container from '../display/Container'; import RenderTexture from '../textures/RenderTexture'; import EventEmitter from 'eventemitter3'; const tempMatrix = new Matrix(); +const { RESOLUTION, RENDER_OPTIONS } = settings; /** * The SystemRenderer is the base for a Pixi Renderer. It is extended by the {@link PIXI.CanvasRenderer} @@ -45,17 +47,17 @@ // prepare options if (options) { - for (const i in DEFAULT_RENDER_OPTIONS) + for (const i in RENDER_OPTIONS) { if (typeof options[i] === 'undefined') { - options[i] = DEFAULT_RENDER_OPTIONS[i]; + options[i] = RENDER_OPTIONS[i]; } } } else { - options = DEFAULT_RENDER_OPTIONS; + options = RENDER_OPTIONS; } /** diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 3b0410d..369b181 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -4,6 +4,7 @@ import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; import { pluginTarget } from '../../utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '../../const'; +import settings from '../../settings'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should @@ -263,7 +264,7 @@ // surely a browser bug?? Let pixi fix that for you.. if (this.smoothProperty) { - this.rootContext[this.smoothProperty] = (SCALE_MODES.DEFAULT === SCALE_MODES.LINEAR); + this.rootContext[this.smoothProperty] = (settings.SCALE_MODE === SCALE_MODES.LINEAR); } } } diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index f4aec6d..1f1496a 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,5 @@ -import { RESOLUTION } from '../../../const'; +import settings from '../../../settings'; +const { RESOLUTION } = settings; /** * Creates a Canvas element of the given size. diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index df4d930..7bf613b 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -5,6 +5,8 @@ * Maps blend combinations to Canvas. * * @memberof PIXI + * @function mapCanvasBlendModesToPixi + * @private * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. */ diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index f4a2d2d..ce67a2b 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,5 @@ import { GC_MODES } from '../../const'; +import settings from '../../settings'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged @@ -21,7 +22,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.mode = GC_MODES.DEFAULT; + this.mode = settings.GC_MODE; } /** diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 5b45807..1e86c68 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,7 @@ import Filter from '../Filter'; import { Matrix } from '../../../../math'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The SpriteMaskFilter class @@ -21,8 +20,8 @@ const maskMatrix = new Matrix(); super( - glslify('./spriteMaskFilter.vert'), - glslify('./spriteMaskFilter.frag') + readFileSync(join(__dirname, './spriteMaskFilter.vert'), 'utf8'), + readFileSync(join(__dirname, './spriteMaskFilter.frag'), 'utf8') ); sprite.renderable = false; diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 1f605e7..7c1556f 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -323,14 +323,14 @@ { if (uniformData[i].type === 'sampler2D' && uniforms[i] !== 0) { - shader.uniforms[i] = textureCount; - if (uniforms[i].baseTexture) { - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); } else { + shader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 0286f60..1bfc4b6 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,7 +1,10 @@ import { Rectangle, Matrix } from '../../../math'; -import { RESOLUTION, SCALE_MODES } from '../../../const'; +import { SCALE_MODES } from '../../../const'; +import settings from '../../../settings'; import { GLFramebuffer } from 'pixi-gl-core'; +const { RESOLUTION, SCALE_MODE } = settings; + /** * @class * @memberof PIXI @@ -12,7 +15,7 @@ * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {number} [width=0] - the horizontal range of the filter * @param {number} [height=0] - the vertical range of the filter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The current resolution / device pixel ratio * @param {boolean} [root=false] - Whether this object is the root element or not */ @@ -120,10 +123,10 @@ * The scale mode. * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Whether this object is the root element or not diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index 221fd09..53e2111 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -4,6 +4,8 @@ * Maps gl blend combinations to WebGL. * * @memberof PIXI + * @function mapWebGLBlendModesToPixi + * @private * @param {WebGLRenderingContext} gl - The rendering context. * @param {string[]} [array=[]] - The array to output into. * @return {string[]} Mapped modes. diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index a2e6165..6d878a1 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -3,8 +3,9 @@ /** * Generic Mask Stack data structure. * - * @class * @memberof PIXI + * @function mapWebGLDrawModesToPixi + * @private * @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {object} [object={}] - The object to map into * @return {object} The mapped draw modes. diff --git a/src/core/settings.js b/src/core/settings.js new file mode 100644 index 0000000..4d4c3a0 --- /dev/null +++ b/src/core/settings.js @@ -0,0 +1,163 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; + +/** + * @namespace PIXI.settings + */ +export default { + + /** + * Target frames per millisecond. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 0.06 + */ + TARGET_FPMS: 0.06, + + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @memberof PIXI.settings + * @type {boolean} + * @default true + */ + MIPMAP_TEXTURES: true, + + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + RESOLUTION: 1, + + /** + * Default filter resolution. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 1 + */ + FILTER_RESOLUTION: 1, + + /** + * The maximum textures that this device supports. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 32 + */ + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32), + + /** + * The default sprite batch size. + * + * The default aims to balance desktop and mobile devices. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default 4096 + */ + SPRITE_BATCH_SIZE: 4096, + + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @memberof PIXI.settings + * @type {RegExp|string} + * @example `@2x` + * @default /@(.+)x/ + */ + RETINA_PREFIX: /@(.+)x/, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @memberof PIXI.settings + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + RENDER_OPTIONS: { + view: null, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false, + }, + + /** + * Default transform type. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.TRANSFORM_MODE.STATIC + */ + TRANSFORM_MODE: 0, + + /** + * Default Garbage Collection mode. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.GC_MODES.AUTO + */ + GC_MODE: 0, + + /** + * Default wrap modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.WRAP_MODES.CLAMP + */ + WRAP_MODE: 0, + + /** + * The scale modes that are supported by pixi. + * + * @static + * @memberof PIXI.settings + * @type {number} + * @default PIXI.SCALE_MODES.LINEAR + */ + SCALE_MODE: 0, + + /** + * Default specify float precision in shaders. + * + * @static + * @memberof PIXI.settings + * @type {string} + * @default PIXI.PRECISION.MEDIUM + */ + PRECISION: 'mediump', + +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 180a355..3e58a00 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -453,7 +453,7 @@ * @static * @param {string} imageId - The image url of the texture * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id */ diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9e9fe09..bcb273a 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -4,10 +4,13 @@ import generateMultiTextureShader from './generateMultiTextureShader'; import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; import Buffer from './BatchBuffer'; -import { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES, CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import { CAN_UPLOAD_SAME_BUFFER } from '../../const'; +import settings from '../../settings'; import glCore from 'pixi-gl-core'; import bitTwiddle from 'bit-twiddle'; +const { SPRITE_BATCH_SIZE, SPRITE_MAX_TEXTURES } = settings; + let TICK = 0; let TEXTURE_TICK = 0; diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index a0e2fe9..bf4e506 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ import { GLShader } from 'pixi-gl-core'; import { PRECISION } from '../../const'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const fragTemplate = [ 'varying vec2 vTextureCoord;', @@ -19,7 +19,7 @@ export default function generateMultiTextureShader(gl, maxTextures) { - const vertexSrc = glslify('./texture.vert'); + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 79d1e15..7bdd125 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -3,9 +3,12 @@ import Texture from '../textures/Texture'; import { Rectangle } from '../math'; import { sign } from '../utils'; -import { TEXT_GRADIENT, RESOLUTION } from '../const'; +import { TEXT_GRADIENT } from '../const'; +import settings from '../settings'; import TextStyle from './TextStyle'; +const { RESOLUTION } = settings; + const defaultDestroyOptions = { texture: true, children: false, diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 97c5d83..92b2eb9 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,7 @@ import BaseTexture from './BaseTexture'; -import { RESOLUTION, SCALE_MODES } from '../const'; +import settings from '../settings'; + +const { RESOLUTION, SCALE_MODE } = settings; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -46,7 +48,7 @@ /** * @param {number} [width=100] - The width of the base render texture * @param {number} [height=100] - The height of the base render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated */ constructor(width = 100, height = 100, scaleMode, resolution) @@ -61,7 +63,7 @@ this.realWidth = this.width * this.resolution; this.realHeight = this.height * this.resolution; - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; this.hasLoaded = true; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 05ae919..d83c447 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -2,11 +2,13 @@ uid, getUrlFileExtension, decomposeDataUri, getSvgSize, getResolutionOfUrl, BaseTextureCache, TextureCache, } from '../utils'; -import { RESOLUTION, SCALE_MODES, MIPMAP_TEXTURES, WRAP_MODES } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import determineCrossOrigin from '../utils/determineCrossOrigin'; import bitTwiddle from 'bit-twiddle'; +const { RESOLUTION, MIPMAP_TEXTURES, SCALE_MODE, WRAP_MODE } = settings; + /** * A texture stores the information that represents an image. All textures have a base texture. * @@ -18,7 +20,7 @@ { /** * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture */ constructor(source, scaleMode, resolution) @@ -74,10 +76,10 @@ * The scale mode to apply when scaling this texture * * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT + * @default PIXI.settings.SCALE_MODE * @see PIXI.SCALE_MODES */ - this.scaleMode = scaleMode || SCALE_MODES.DEFAULT; + this.scaleMode = scaleMode || SCALE_MODE; /** * Set to true once the base texture has successfully loaded. @@ -183,7 +185,7 @@ * @member {number} * @see PIXI.WRAP_MODES */ - this.wrapMode = WRAP_MODES.DEFAULT; + this.wrapMode = WRAP_MODE; /** * A map of renderer IDs to webgl textures @@ -627,7 +629,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images. * @return {PIXI.BaseTexture} The new base texture. */ diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6734033..1e0f270 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * * @param {number} [width=100] - The width of the render texture * @param {number} [height=100] - The height of the render texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated * @return {PIXI.RenderTexture} The new render texture */ diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0453902..b197e9c 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -279,7 +279,7 @@ * @static * @param {string} imageUrl - The image url of the texture * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images. * @return {PIXI.Texture} The newly created texture */ @@ -321,7 +321,7 @@ * * @static * @param {HTMLCanvasElement} canvas - The canvas element source of the texture - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromCanvas(canvas, scaleMode) @@ -334,7 +334,7 @@ * * @static * @param {HTMLVideoElement|string} video - The URL or actual element of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideo(video, scaleMode) @@ -352,7 +352,7 @@ * * @static * @param {string} videoUrl - URL of the video - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.Texture} The newly created texture */ static fromVideoUrl(videoUrl, scaleMode) diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index 0696e10..0098759 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -32,7 +32,7 @@ { /** * @param {HTMLVideoElement} source - Video source - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values */ constructor(source, scaleMode) { @@ -204,7 +204,7 @@ * * @static * @param {HTMLVideoElement} video - Video to create texture from - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - See {@link PIXI.SCALE_MODES} for possible values + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture */ static fromVideo(video, scaleMode) diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index fe839fe..6aec195 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,9 +1,11 @@ -import { TARGET_FPMS } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; // Internal event used by composed emitter const TICK = 'tick'; +const { TARGET_FPMS } = settings; + /** * A Ticker class that runs an update loop that other objects listen to. * This class is composed around an EventEmitter object to add listeners @@ -351,7 +353,7 @@ * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * * @memberof PIXI.ticker.Ticker# * @default 10 diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index 079de02..f35d9ad 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -1,8 +1,9 @@ /** * Generic Mask Stack data structure * - * @class * @memberof PIXI + * @function createIndicesForQuads + * @private * @param {number} size - Number of quads * @return {Uint16Array} indices */ diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 81a89e3..c82aaa4 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,4 +1,5 @@ -import { RETINA_PREFIX, DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import { DATA_URI, URL_FILE_EXTENSION, SVG_SIZE, VERSION } from '../const'; +import settings from '../settings'; import EventEmitter from 'eventemitter3'; import pluginTarget from './pluginTarget'; import * as isMobile from 'ismobilejs'; @@ -14,6 +15,7 @@ * @see {@link https://github.com/kaimallea/isMobile} * * @memberof PIXI.utils + * @function isMobile * @type {Object} */ isMobile, @@ -21,11 +23,13 @@ * @see {@link https://github.com/primus/eventemitter3} * * @memberof PIXI.utils + * @class EventEmitter * @type {EventEmitter} */ EventEmitter, /** * @memberof PIXI.utils + * @function pluginTarget * @type {mixin} */ pluginTarget, @@ -35,6 +39,7 @@ * Gets the next unique identifier * * @memberof PIXI.utils + * @function uid * @return {number} The next unique identifier to use. */ export function uid() @@ -46,6 +51,7 @@ * Converts a hex color number to an [R, G, B] array * * @memberof PIXI.utils + * @function hex2rgb * @param {number} hex - The number to convert * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one * @return {number[]} An array representing the [R, G, B] of the color. @@ -65,6 +71,7 @@ * Converts a hex color number to a string. * * @memberof PIXI.utils + * @function hex2string * @param {number} hex - Number in hex * @return {string} The string color. */ @@ -80,6 +87,7 @@ * Converts a color as an [R, G, B] array to a hex number * * @memberof PIXI.utils + * @function rgb2hex * @param {number[]} rgb - rgb array * @return {number} The color number */ @@ -93,12 +101,13 @@ * used by spritesheets and image urls * * @memberof PIXI.utils + * @function getResolutionOfUrl * @param {string} url - the image path * @return {number} resolution / device pixel ratio of an asset */ export function getResolutionOfUrl(url) { - const resolution = RETINA_PREFIX.exec(url); + const resolution = settings.RETINA_PREFIX.exec(url); if (resolution) { @@ -123,6 +132,7 @@ * parameter `dataUri` is not a valid data URI. * * @memberof PIXI.utils + * @function decomposeDataUri * @param {string} dataUri - the data URI to check * @return {DecomposedDataUri|undefined} The decomposed data uri or undefined */ @@ -147,6 +157,7 @@ * Get type of the image by regexp for extension. Returns undefined for unknown extensions. * * @memberof PIXI.utils + * @function getUrlFileExtension * @param {string} url - the image path * @return {string|undefined} image extension */ @@ -174,6 +185,7 @@ * Get size from an svg string using regexp. * * @memberof PIXI.utils + * @function getSvgSize * @param {string} svgString - a serialized svg element * @return {Size|undefined} image extension */ @@ -194,6 +206,7 @@ /** * Skips the hello message of renderers that are created after this is run. * + * @function skipHello * @memberof PIXI.utils */ export function skipHello() @@ -207,6 +220,7 @@ * creating your renderer. Keep in mind that doing that will forever makes you a jerk face. * * @static + * @function sayHello * @memberof PIXI.utils * @param {string} type - The string renderer type to log. */ @@ -246,6 +260,7 @@ * Helper for checking for webgl support * * @memberof PIXI.utils + * @function isWebGLSupported * @return {boolean} is webgl supported */ export function isWebGLSupported() @@ -288,6 +303,7 @@ * Returns sign of number * * @memberof PIXI.utils + * @function sign * @param {number} n - the number to check the sign of * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive */ @@ -302,6 +318,7 @@ * Remove a range of items from an array * * @memberof PIXI.utils + * @function removeItems * @param {Array<*>} arr The target array * @param {number} startIdx The index to begin removing from (inclusive) * @param {number} removeCount How many items to remove diff --git a/src/deprecation.js b/src/deprecation.js index 130c834..e52d60b 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -347,8 +347,216 @@ return core.TransformBase; }, }, + + /** + * @static + * @constant + * @name PIXI.TARGET_FPMS + * @see PIXI.settings.TARGET_FPMS + * @deprecated since version 4.2.0 + */ + TARGET_FPMS: { + enumerable: true, + get() + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + return core.settings.TARGET_FPMS; + }, + set(value) + { + warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS'); + + core.settings.TARGET_FPMS = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.FILTER_RESOLUTION + * @see PIXI.settings.FILTER_RESOLUTION + * @deprecated since version 4.2.0 + */ + FILTER_RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + return core.settings.FILTER_RESOLUTION; + }, + set(value) + { + warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION'); + + core.settings.FILTER_RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RESOLUTION + * @see PIXI.settings.RESOLUTION + * @deprecated since version 4.2.0 + */ + RESOLUTION: { + enumerable: true, + get() + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + return core.settings.RESOLUTION; + }, + set(value) + { + warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION'); + + core.settings.RESOLUTION = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.MIPMAP_TEXTURES + * @see PIXI.settings.MIPMAP_TEXTURES + * @deprecated since version 4.2.0 + */ + MIPMAP_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + return core.settings.MIPMAP_TEXTURES; + }, + set(value) + { + warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES'); + + core.settings.MIPMAP_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_BATCH_SIZE + * @see PIXI.settings.SPRITE_BATCH_SIZE + * @deprecated since version 4.2.0 + */ + SPRITE_BATCH_SIZE: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + return core.settings.SPRITE_BATCH_SIZE; + }, + set(value) + { + warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE'); + + core.settings.SPRITE_BATCH_SIZE = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.SPRITE_MAX_TEXTURES + * @see PIXI.settings.SPRITE_MAX_TEXTURES + * @deprecated since version 4.2.0 + */ + SPRITE_MAX_TEXTURES: { + enumerable: true, + get() + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + return core.settings.SPRITE_MAX_TEXTURES; + }, + set(value) + { + warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES'); + + core.settings.SPRITE_MAX_TEXTURES = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.RETINA_PREFIX + * @see PIXI.settings.RETINA_PREFIX + * @deprecated since version 4.2.0 + */ + RETINA_PREFIX: { + enumerable: true, + get() + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + return core.settings.RETINA_PREFIX; + }, + set(value) + { + warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX'); + + core.settings.RETINA_PREFIX = value; + }, + }, + + /** + * @static + * @constant + * @name PIXI.DEFAULT_RENDER_OPTIONS + * @see PIXI.settings.RENDER_OPTIONS + * @deprecated since version 4.2.0 + */ + DEFAULT_RENDER_OPTIONS: { + enumerable: true, + get() + { + warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS'); + + return core.settings.RENDER_OPTIONS; + }, + }, }); +// Move the default properties to settings +const defaults = [ + { parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, + { parent: 'GC_MODES', target: 'GC_MODE' }, + { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, + { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, + { parent: 'PRECISION', target: 'PRECISION' }, +]; + +for (let i = 0; i < defaults.length; i++) +{ + const deprecation = defaults[i]; + + Object.defineProperty(core[deprecation.parent], 'DEFAULT', { + enumerable: true, + get() + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + return core.settings[deprecation.target]; + }, + set(value) + { + warn(`PIXI.${deprecation.parent}.DEFAULT has been deprecated, please use PIXI.settings.${deprecation.target}`); + + core.settings[deprecation.target] = value; + }, + }); +} + Object.defineProperties(extras, { /** diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3bba625..b9352e6 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -369,7 +369,7 @@ * @param {number} width - the width of the tiling sprite * @param {number} height - the height of the tiling sprite * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter - * @param {number} [scaleMode=PIXI.SCALE_MODES.DEFAULT] - if you want to specify the scale mode, + * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode, * see {@link PIXI.SCALE_MODES} for possible values * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id */ diff --git a/src/extras/webgl/TilingSpriteRenderer.js b/src/extras/webgl/TilingSpriteRenderer.js index 29b446d..b782038 100644 --- a/src/extras/webgl/TilingSpriteRenderer.js +++ b/src/extras/webgl/TilingSpriteRenderer.js @@ -1,8 +1,8 @@ import * as core from '../../core'; import { WRAP_MODES } from '../../core/const'; import { GLShader } from 'pixi-gl-core'; - -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; const tempMat = new core.Matrix(); const tempArray = new Float32Array(4); @@ -36,12 +36,12 @@ const gl = this.renderer.gl; this.shader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite.frag'), 'utf8'), core.PRECISION.DEFAULT); this.simpleShader = new GLShader(gl, - glslify('./tilingSprite.vert'), - glslify('./tilingSprite_simple.frag'), + readFileSync(join(__dirname, './tilingSprite.vert'), 'utf8'), + readFileSync(join(__dirname, './tilingSprite_simple.frag'), 'utf8'), core.PRECISION.DEFAULT); this.renderer.bindVao(null); diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index dbaa861..36f51f6 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -25,9 +26,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./colorMatrix.frag') + readFileSync(join(__dirname, './colorMatrix.frag'), 'utf8') ); this.uniforms.m = [ diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index ac02c97..978c886 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * The DisplacementFilter class uses the pixel values from the specified texture @@ -26,9 +27,9 @@ super( // vertex shader - glslify('../fragments/default-filter-matrix.vert'), + readFileSync(join(__dirname, '../fragments/default-filter-matrix.vert'), 'utf8'), // fragment shader - glslify('./displacement.frag') + readFileSync(join(__dirname, './displacement.frag'), 'utf8') ); this.maskSprite = sprite; diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index f13a223..41a53d1 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @@ -24,9 +25,9 @@ // TODO - needs work super( // vertex shader - glslify('./fxaa.vert'), + readFileSync(join(__dirname, './fxaa.vert'), 'utf8'), // fragment shader - glslify('./fxaa.frag') + readFileSync(join(__dirname, './fxaa.frag'), 'utf8') ); } } diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 2f6d666..f5b7296 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,6 @@ import * as core from '../../core'; -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * @author Vico @vicocotea @@ -22,9 +23,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./noise.frag') + readFileSync(join(__dirname, './noise.frag'), 'utf8') ); this.noise = 0.5; diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index d99a9a5..b4361ac 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,7 +1,6 @@ import * as core from '../../core'; - -// @see https://github.com/substack/brfs/issues/25 -const glslify = require('glslify'); // eslint-disable-line no-undef +import { readFileSync } from 'fs'; +import { join } from 'path'; /** * Does nothing. Very handy. @@ -19,9 +18,9 @@ { super( // vertex shader - glslify('../fragments/default.vert'), + readFileSync(join(__dirname, '../fragments/default.vert'), 'utf8'), // fragment shader - glslify('./void.frag') + readFileSync(join(__dirname, './void.frag'), 'utf8') ); this.glShaderKey = 'void'; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index ac9060c..2d637b1 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -46,8 +46,9 @@ let resolution = core.utils.getResolutionOfUrl(resource.url); const scale = resource.data.meta.scale; + // for now (to keep things compatible) resolution overrides scale // Support scale field on spritesheet - if (scale !== undefined && scale !== 1) + if (resolution === 1 && scale !== undefined && scale !== 1) { baseTexture.resolution = resolution = scale; baseTexture.update(); diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index 7507de4..05e8f16 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -226,15 +226,6 @@ } /** - * Binds the buffers to the GPU - * - */ - bind() - { - this.vao.bind(); - } - - /** * Destroys the ParticleBuffer. * */ diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 4a18bde..ffce8ec 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -123,6 +123,7 @@ const children = container.children; const maxSize = container._maxSize; const batchSize = container._batchSize; + const renderer = this.renderer; let totalChildren = children.length; if (totalChildren === 0) @@ -134,21 +135,21 @@ totalChildren = maxSize; } - let buffers = container._glBuffers[this.renderer.CONTEXT_UID]; + let buffers = container._glBuffers[renderer.CONTEXT_UID]; if (!buffers) { - buffers = container._glBuffers[this.renderer.CONTEXT_UID] = this.generateBuffers(container); + buffers = container._glBuffers[renderer.CONTEXT_UID] = this.generateBuffers(container); } // if the uvs have not updated then no point rendering just yet! this.renderer.setBlendMode(container.blendMode); - const gl = this.renderer.gl; + const gl = renderer.gl; const m = container.worldTransform.copy(this.tempMatrix); - m.prepend(this.renderer._activeRenderTarget.projectionMatrix); + m.prepend(renderer._activeRenderTarget.projectionMatrix); this.shader.uniforms.projectionMatrix = m.toArray(true); this.shader.uniforms.uAlpha = container.worldAlpha; @@ -156,7 +157,7 @@ // make sure the texture is bound.. const baseTexture = children[0]._texture.baseTexture; - this.shader.uniforms.uSampler = this.renderer.bindTexture(baseTexture); + this.shader.uniforms.uSampler = renderer.bindTexture(baseTexture); // now lets upload and render the buffers.. for (let i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) @@ -181,13 +182,8 @@ } // bind the buffer - buffer.vao.bind() - .draw(gl.TRIANGLES, amount * 6) - .unbind(); - - // now draw those suckas! - // gl.drawElements(gl.TRIANGLES, amount * 6, gl.UNSIGNED_SHORT, 0); - // this.renderer.drawCount++; + renderer.bindVao(buffer.vao); + buffer.vao.draw(gl.TRIANGLES, amount * 6); } } diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js index 4f10c10..ebf1195 100755 --- a/test/core/DisplayObject.js +++ b/test/core/DisplayObject.js @@ -16,13 +16,13 @@ it('should set the correct Transform', () => { - PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.DYNAMIC; + PIXI.settings.TRANSFORM_MODE = PIXI.TRANSFORM_MODE.DYNAMIC; const dynamicTransform = new PIXI.DisplayObject(); expect(dynamicTransform.transform).to.be.instanceof(PIXI.Transform); - PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.STATIC; + PIXI.settings.TRANSFORM_MODE = PIXI.TRANSFORM_MODE.STATIC; const staticTransform = new PIXI.DisplayObject(); diff --git a/test/core/TilingSprite.js b/test/core/TilingSprite.js index 17debe3..2e449a7 100644 --- a/test/core/TilingSprite.js +++ b/test/core/TilingSprite.js @@ -8,7 +8,7 @@ { const parent = new PIXI.Container(); const texture = new PIXI.Texture(new PIXI.BaseTexture()); - const tilingSprite = new PIXI.TilingSprite(texture, 200, 300); + const tilingSprite = new PIXI.extras.TilingSprite(texture, 200, 300); parent.addChild(tilingSprite); diff --git a/test/index.js b/test/index.js index bf50692..50a85da 100755 --- a/test/index.js +++ b/test/index.js @@ -1,7 +1,7 @@ 'use strict'; /* eslint-disable global-require */ -require('../bin/pixi'); +require('../dist/pixi'); PIXI.utils.skipHello(); // hide banner