1 | {"version":3,"file":"Shader.js","sources":["../../src/shader/Shader.ts"],"sourcesContent":["import { Runner } from '@pixi/runner';\nimport { Program } from './Program';\nimport { UniformGroup } from './UniformGroup';\n\nimport type { Dict } from '@pixi/utils';\n\n/**\n * A helper class for shaders.\n * @memberof PIXI\n */\nexport class Shader\n{\n /** Program that the shader uses. */\n public program: Program;\n public uniformGroup: UniformGroup;\n\n /**\n * Used internally to bind uniform buffer objects.\n * @ignore\n */\n uniformBindCount = 0;\n\n disposeRunner: Runner;\n\n /**\n * @param program - The program the shader will use.\n * @param uniforms - Custom uniforms to use to augment the built-in ones.\n */\n constructor(program: Program, uniforms?: Dict<any>)\n {\n this.program = program;\n\n // lets see whats been passed in\n // uniforms should be converted to a uniform group\n if (uniforms)\n {\n if (uniforms instanceof UniformGroup)\n {\n this.uniformGroup = uniforms;\n }\n else\n {\n this.uniformGroup = new UniformGroup(uniforms);\n }\n }\n else\n {\n this.uniformGroup = new UniformGroup({});\n }\n\n this.disposeRunner = new Runner('disposeShader');\n }\n\n // TODO move to shader system..\n checkUniformExists(name: string, group: UniformGroup): boolean\n {\n if (group.uniforms[name])\n {\n return true;\n }\n\n for (const i in group.uniforms)\n {\n const uniform = group.uniforms[i];\n\n if (uniform.group)\n {\n if (this.checkUniformExists(name, uniform))\n {\n return true;\n }\n }\n }\n\n return false;\n }\n\n destroy(): void\n {\n // usage count on programs?\n // remove if not used!\n this.uniformGroup = null;\n\n this.disposeRunner.emit(this);\n this.disposeRunner.destroy();\n }\n\n /**\n * Shader uniform values, shortcut for `uniformGroup.uniforms`.\n * @readonly\n */\n get uniforms(): Dict<any>\n {\n return this.uniformGroup.uniforms;\n }\n\n /**\n * A short hand function to create a shader based of a vertex and fragment shader.\n * @param vertexSrc - The source of the vertex shader.\n * @param fragmentSrc - The source of the fragment shader.\n * @param uniforms - Custom uniforms to use to augment the built-in ones.\n * @returns A shiny new PixiJS shader!\n */\n static from(vertexSrc?: string, fragmentSrc?: string, uniforms?: Dict<any>): Shader\n {\n const program = Program.from(vertexSrc, fragmentSrc);\n\n return new Shader(program, uniforms);\n }\n}\n"],"names":["UniformGroup","Runner","Program"],"mappings":";;;;;;;;AAUO,MAAM,MACb,CAAA;AAAA,EAiBI,WAAA,CAAY,SAAkB,QAC9B,EAAA;AATA,IAAmB,IAAA,CAAA,gBAAA,GAAA,CAAA,CAAA;AAUf,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AAIf,IAAA,IAAI,QACJ,EAAA;AACI,MAAA,IAAI,oBAAoBA,yBACxB,EAAA;AACI,QAAA,IAAA,CAAK,YAAe,GAAA,QAAA,CAAA;AAAA,OAGxB,MAAA;AACI,QAAK,IAAA,CAAA,YAAA,GAAe,IAAIA,yBAAA,CAAa,QAAQ,CAAA,CAAA;AAAA,OACjD;AAAA,KAGJ,MAAA;AACI,MAAA,IAAA,CAAK,YAAe,GAAA,IAAIA,yBAAa,CAAA,EAAE,CAAA,CAAA;AAAA,KAC3C;AAEA,IAAK,IAAA,CAAA,aAAA,GAAgB,IAAIC,aAAA,CAAO,eAAe,CAAA,CAAA;AAAA,GACnD;AAAA,EAGA,kBAAA,CAAmB,MAAc,KACjC,EAAA;AACI,IAAI,IAAA,KAAA,CAAM,SAAS,IACnB,CAAA,EAAA;AACI,MAAO,OAAA,IAAA,CAAA;AAAA,KACX;AAEA,IAAW,KAAA,MAAA,CAAA,IAAK,MAAM,QACtB,EAAA;AACI,MAAM,MAAA,OAAA,GAAU,MAAM,QAAS,CAAA,CAAA,CAAA,CAAA;AAE/B,MAAA,IAAI,QAAQ,KACZ,EAAA;AACI,QAAA,IAAI,IAAK,CAAA,kBAAA,CAAmB,IAAM,EAAA,OAAO,CACzC,EAAA;AACI,UAAO,OAAA,IAAA,CAAA;AAAA,SACX;AAAA,OACJ;AAAA,KACJ;AAEA,IAAO,OAAA,KAAA,CAAA;AAAA,GACX;AAAA,EAEA,OACA,GAAA;AAGI,IAAA,IAAA,CAAK,YAAe,GAAA,IAAA,CAAA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