UNPKG

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.18 kB
{"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,8BACZ,CAAA,OAAA,EACA,EACA,EAAA,cAAA,GAAiB,KAErB,EAAA;AACI,EAAA,MAAM,aAAsD,EAAC,CAAA;AAE7D,EAAA,MAAM,eAAkB,GAAA,EAAA,CAAG,mBAAoB,CAAA,OAAA,EAAS,GAAG,iBAAiB,CAAA,CAAA;AAE5E,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,eAAA,EAAiB,CACrC,EAAA,EAAA;AACI,IAAA,MAAM,UAAa,GAAA,EAAA,CAAG,eAAgB,CAAA,OAAA,EAAS,CAAC,CAAA,CAAA;AAGhD,IAAA,IAAI,UAAW,CAAA,IAAA,CAAK,UAAW,CAAA,KAAK,CACpC,EAAA;AACI,MAAA,SAAA;AAAA,KACJ;AAEA,IAAA,MAAM,MAAS,GAAA,mBAAA,CAAoB,EAAI,EAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAEtD,IAAW,UAAA,CAAA,UAAA,CAAW,IAAI,CAAI,GAAA;AAAA,MAC1B,QAAU,EAAA,CAAA;AAAA;AAAA,MACV,MAAA;AAAA,MACA,MAAA,EAAQ,0BAA2B,CAAA,MAAM,CAAE,CAAA,MAAA;AAAA,MAC3C,MAAQ,EAAA,CAAA;AAAA,MACR,QAAU,EAAA,KAAA;AAAA,MACV,KAAO,EAAA,CAAA;AAAA,KACX,CAAA;AAAA,GACJ;AAEA,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,IAAA,CAAK,UAAU,CAAA,CAAA;AAEnC,EAAA,IAAI,cACJ,EAAA;AACI,IAAA,IAAA,CAAK,KAAK,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