UNPKG

7.15 kBSource Map (JSON)View Raw
1{"version":3,"file":"Program.js","sources":["../../src/shader/Program.ts"],"sourcesContent":["import { PRECISION } from '@pixi/constants';\nimport { isMobile, ProgramCache } from '@pixi/utils';\nimport defaultFragment from './defaultProgram.frag';\nimport defaultVertex from './defaultProgram.vert';\nimport { getMaxFragmentPrecision, setPrecision } from './utils';\n\nimport type { GLProgram } from './GLProgram';\n\nlet UID = 0;\n\nconst nameCache: { [key: string]: number } = {};\n\nexport interface IAttributeData\n{\n type: string;\n size: number;\n location: number;\n name: string;\n}\n\nexport interface IUniformData\n{\n index: number;\n type: string;\n size: number;\n isArray: boolean;\n value: any;\n name: string;\n}\n\nexport interface IProgramExtraData\n{\n transformFeedbackVaryings?: {\n names: string[],\n bufferMode: 'separate' | 'interleaved'\n }\n}\n\n/**\n * Helper class to create a shader program.\n * @memberof PIXI\n */\nexport class Program\n{\n /**\n * Default specify float precision in vertex shader.\n * @static\n * @type {PIXI.PRECISION}\n * @default PIXI.PRECISION.HIGH\n */\n public static defaultVertexPrecision: PRECISION = PRECISION.HIGH;\n\n /**\n * Default specify float precision in fragment shader.\n * iOS is best set at highp due to https://github.com/pixijs/pixijs/issues/3742\n * @static\n * @type {PIXI.PRECISION}\n * @default PIXI.PRECISION.MEDIUM\n */\n public static defaultFragmentPrecision: PRECISION = isMobile.apple.device\n ? PRECISION.HIGH\n : PRECISION.MEDIUM;\n\n public id: number;\n\n /** Source code for the vertex shader. */\n public vertexSrc: string;\n\n /** Source code for the fragment shader. */\n public fragmentSrc: string;\n\n nameCache: any;\n glPrograms: { [ key: number ]: GLProgram};\n syncUniforms: any;\n\n /** Assigned when a program is first bound to the shader system. */\n attributeData: { [key: string]: IAttributeData};\n\n /** Assigned when a program is first bound to the shader system. */\n uniformData: {[key: string]: IUniformData};\n\n extra: IProgramExtraData = {};\n\n /**\n * @param vertexSrc - The source of the vertex shader.\n * @param fragmentSrc - The source of the fragment shader.\n * @param name - Name for shader\n * @param extra - Extra data for shader\n */\n constructor(vertexSrc?: string, fragmentSrc?: string, name = 'pixi-shader', extra: IProgramExtraData = {})\n {\n this.id = UID++;\n this.vertexSrc = vertexSrc || Program.defaultVertexSrc;\n this.fragmentSrc = fragmentSrc || Program.defaultFragmentSrc;\n\n this.vertexSrc = this.vertexSrc.trim();\n this.fragmentSrc = this.fragmentSrc.trim();\n\n this.extra = extra;\n\n if (this.vertexSrc.substring(0, 8) !== '#version')\n {\n name = name.replace(/\\s+/g, '-');\n\n if (nameCache[name])\n {\n nameCache[name]++;\n name += `-${nameCache[name]}`;\n }\n else\n {\n nameCache[name] = 1;\n }\n\n this.vertexSrc = `#define SHADER_NAME ${name}\\n${this.vertexSrc}`;\n this.fragmentSrc = `#define SHADER_NAME ${name}\\n${this.fragmentSrc}`;\n\n this.vertexSrc = setPrecision(\n this.vertexSrc,\n Program.defaultVertexPrecision,\n PRECISION.HIGH\n );\n this.fragmentSrc = setPrecision(\n this.fragmentSrc,\n Program.defaultFragmentPrecision,\n getMaxFragmentPrecision()\n );\n }\n\n // currently this does not extract structs only default types\n // this is where we store shader references..\n this.glPrograms = {};\n\n this.syncUniforms = null;\n }\n\n /**\n * The default vertex shader source.\n * @readonly\n */\n static get defaultVertexSrc(): string\n {\n return defaultVertex;\n }\n\n /**\n * The default fragment shader source.\n * @readonly\n */\n static get defaultFragmentSrc(): string\n {\n return defaultFragment;\n }\n\n /**\n * A short hand function to create a program based of a vertex and fragment shader.\n *\n * This method will also check to see if there is a cached program.\n * @param vertexSrc - The source of the vertex shader.\n * @param fragmentSrc - The source of the fragment shader.\n * @param name - Name for shader\n * @returns A shiny new PixiJS shader program!\n */\n static from(vertexSrc?: string, fragmentSrc?: string, name?: string): Program\n {\n const key = vertexSrc + fragmentSrc;\n\n let program = ProgramCache[key];\n\n if (!program)\n {\n ProgramCache[key] = program = new Program(vertexSrc, fragmentSrc, name);\n }\n\n return program;\n }\n}\n"],"names":["setPrecision","PRECISION","getMaxFragmentPrecision","defaultVertex","defaultFragment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