UNPKG

5.67 kBSource Map (JSON)View Raw
1{"version":3,"file":"generateProgram.js","sources":["../../../src/shader/utils/generateProgram.ts"],"sourcesContent":["import { GLProgram } from '../GLProgram';\nimport { compileShader } from './compileShader';\nimport { defaultValue } from './defaultValue';\nimport { getAttributeData } from './getAttributeData';\nimport { getUniformData } from './getUniformData';\nimport { logProgramError } from './logProgramError';\n\nimport type { IRenderingContext } from '../../IRenderer';\nimport type { IGLUniformData } from '../GLProgram';\nimport type { Program } from '../Program';\n\n/**\n * generates a WebGL Program object from a high level Pixi Program.\n * @param gl - a rendering context on which to generate the program\n * @param program - the high level Pixi Program.\n */\nexport function generateProgram(gl: IRenderingContext, program: Program): GLProgram\n{\n const glVertShader = compileShader(gl, gl.VERTEX_SHADER, program.vertexSrc);\n const glFragShader = compileShader(gl, gl.FRAGMENT_SHADER, program.fragmentSrc);\n\n const webGLProgram = gl.createProgram();\n\n gl.attachShader(webGLProgram, glVertShader);\n gl.attachShader(webGLProgram, glFragShader);\n\n const transformFeedbackVaryings = program.extra?.transformFeedbackVaryings;\n\n if (transformFeedbackVaryings)\n {\n if (typeof gl.transformFeedbackVaryings !== 'function')\n {\n // #if _DEBUG\n console.warn(`TransformFeedback is not supported but TransformFeedbackVaryings are given.`);\n // #endif\n }\n else\n {\n gl.transformFeedbackVaryings(\n webGLProgram,\n transformFeedbackVaryings.names,\n transformFeedbackVaryings.bufferMode === 'separate'\n ? gl.SEPARATE_ATTRIBS\n : gl.INTERLEAVED_ATTRIBS\n );\n }\n }\n\n gl.linkProgram(webGLProgram);\n\n if (!gl.getProgramParameter(webGLProgram, gl.LINK_STATUS))\n {\n logProgramError(gl, webGLProgram, glVertShader, glFragShader);\n }\n\n program.attributeData = getAttributeData(webGLProgram, gl);\n program.uniformData = getUniformData(webGLProgram, gl);\n\n // GLSL 1.00: bind attributes sorted by name in ascending order\n // GLSL 3.00: don't change the attribute locations that where chosen by the compiler\n // or assigned by the layout specifier in the shader source code\n if (!(/^[ \\t]*#[ \\t]*version[ \\t]+300[ \\t]+es[ \\t]*$/m).test(program.vertexSrc))\n {\n const keys = Object.keys(program.attributeData);\n\n keys.sort((a, b) => (a > b) ? 1 : -1); // eslint-disable-line no-confusing-arrow\n\n for (let i = 0; i < keys.length; i++)\n {\n program.attributeData[keys[i]].location = i;\n\n gl.bindAttribLocation(webGLProgram, i, keys[i]);\n }\n\n gl.linkProgram(webGLProgram);\n }\n\n gl.deleteShader(glVertShader);\n gl.deleteShader(glFragShader);\n\n const uniformData: {[key: string]: IGLUniformData} = {};\n\n for (const i in program.uniformData)\n {\n const data = program.uniformData[i];\n\n uniformData[i] = {\n location: gl.getUniformLocation(webGLProgram, i),\n value: defaultValue(data.type, data.size),\n };\n }\n\n const glProgram = new GLProgram(webGLProgram, uniformData);\n\n return glProgram;\n}\n"],"names":["compileShader","logProgramError","getAttributeData","getUniformData","defaultValue","GLProgram"],"mappings":";;;;;;;;;;;AAgBO,SAAA,eAAA,CAAyB,IAAuB,OACvD,EAAA;AACI,EAAA,MAAM,eAAeA,2BAAc,CAAA,EAAA,EAAI,EAAG,CAAA,aAAA,EAAe,QAAQ,SAAS,CAAA,CAAA;AAC1E,EAAA,MAAM,eAAeA,2BAAc,CAAA,EAAA,EAAI,EAAG,CAAA,eAAA,EAAiB,QAAQ,WAAW,CAAA,CAAA;AAE9E,EAAM,MAAA,YAAA,GAAe,GAAG,aAAc,EAAA,CAAA;AAEtC,EAAG,EAAA,CAAA,YAAA,CAAa,cAAc,YAAY,CAAA,CAAA;AAC1C,EAAG,EAAA,CAAA,YAAA,CAAa,cAAc,YAAY,CAAA,CAAA;AAE1C,EAAM,MAAA,yBAAA,GAA4B,QAAQ,KAAO,EAAA,yBAAA,CAAA;AAEjD,EAAA,IAAI,yBACJ,EAAA;AACI,IAAI,IAAA,OAAO,EAAG,CAAA,yBAAA,KAA8B,UAC5C,EAAA;AAEI,MAAA,OAAA,CAAQ,KAAK,CAA6E,2EAAA,CAAA,CAAA,CAAA;AAAA,KAI9F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