pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
1 lines • 4.12 kB
Source Map (JSON)
{"version":3,"file":"extractAttributesFromGlProgram.mjs","sources":["../../../../../../src/rendering/renderers/gl/shader/program/extractAttributesFromGlProgram.ts"],"sourcesContent":["import { getAttributeInfoFromFormat } from '../../../shared/geometry/utils/getAttributeInfoFromFormat';\nimport { mapGlToVertexFormat } from './mapType';\n\nimport type { Attribute } from '../../../shared/geometry/Geometry';\n\n/**\n * This interface represents the extracted attribute data from a WebGL program.\n * It extends the `Attribute` interface but omits the `buffer` property.\n * It includes an optional `location` property that indicates where the shader location is for this attribute.\n * @category rendering\n * @advanced\n */\nexport interface ExtractedAttributeData extends Omit<Attribute, 'buffer'>\n{\n /** set where the shader location is for this attribute */\n location?: number;\n}\n\n/**\n * returns the attribute data from the program\n * @private\n * @param {WebGLProgram} [program] - the WebGL program\n * @param {WebGLRenderingContext} [gl] - the WebGL context\n * @param sortAttributes\n * @returns {object} the attribute data for this program\n */\nexport function extractAttributesFromGlProgram(\n program: WebGLProgram,\n gl: WebGLRenderingContextBase,\n sortAttributes = false\n): Record<string, ExtractedAttributeData>\n{\n const attributes: {[key: string]: ExtractedAttributeData} = {};\n\n const totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);\n\n for (let i = 0; i < totalAttributes; i++)\n {\n const attribData = gl.getActiveAttrib(program, i);\n\n // ignore the default ones!\n if (attribData.name.startsWith('gl_'))\n {\n continue;\n }\n\n const format = mapGlToVertexFormat(gl, attribData.type);\n\n attributes[attribData.name] = {\n location: 0, // set further down..\n format,\n stride: getAttributeInfoFromFormat(format).stride,\n offset: 0,\n instance: false,\n start: 0,\n };\n }\n\n const keys = Object.keys(attributes);\n\n if (sortAttributes)\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 attributes[keys[i]].location = i;\n\n gl.bindAttribLocation(program, i, keys[i]);\n }\n\n gl.linkProgram(program);\n }\n else\n {\n for (let i = 0; i < keys.length; i++)\n {\n attributes[keys[i]].location = gl.getAttribLocation(program, keys[i]);\n }\n }\n\n return attributes;\n}\n"],"names":[],"mappings":";;;;AA0BO,SAAS,8BAAA,CACZ,OAAA,EACA,EAAA,EACA,cAAA,GAAiB,KAAA,EAErB;AACI,EAAA,MAAM,aAAsD,EAAC;AAE7D,EAAA,MAAM,eAAA,GAAkB,EAAA,CAAG,mBAAA,CAAoB,OAAA,EAAS,GAAG,iBAAiB,CAAA;AAE5E,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,eAAA,EAAiB,CAAA,EAAA,EACrC;AACI,IAAA,MAAM,UAAA,GAAa,EAAA,CAAG,eAAA,CAAgB,OAAA,EAAS,CAAC,CAAA;AAGhD,IAAA,IAAI,UAAA,CAAW,IAAA,CAAK,UAAA,CAAW,KAAK,CAAA,EACpC;AACI,MAAA;AAAA,IACJ;AAEA,IAAA,MAAM,MAAA,GAAS,mBAAA,CAAoB,EAAA,EAAI,UAAA,CAAW,IAAI,CAAA;AAEtD,IAAA,UAAA,CAAW,UAAA,CAAW,IAAI,CAAA,GAAI;AAAA,MAC1B,QAAA,EAAU,CAAA;AAAA;AAAA,MACV,MAAA;AAAA,MACA,MAAA,EAAQ,0BAAA,CAA2B,MAAM,CAAA,CAAE,MAAA;AAAA,MAC3C,MAAA,EAAQ,CAAA;AAAA,MACR,QAAA,EAAU,KAAA;AAAA,MACV,KAAA,EAAO;AAAA,KACX;AAAA,EACJ;AAEA,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,IAAA,CAAK,UAAU,CAAA;AAEnC,EAAA,IAAI,cAAA,EACJ;AACI,IAAA,IAAA,CAAK,KAAK,CAAC,CAAA,EAAG,MAAO,CAAA,GAAI,CAAA,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