/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/rendering/renderers/gl/shader/program/extractAttributesFromGlProgram.ts
83 строки
2 KB
Zyie
chore: add standard/advanced tags to documentation (#11448)
03 июн 2025, 10:12
Не верифицирован
03 июн 2025, 10:12
7d91234
Код
Авторство
О чём код?
import { getAttributeInfoFromFormat } from '../../../shared/geometry/utils/getAttributeInfoFromFormat'; import { mapGlToVertexFormat } from './mapType'; import type { Attribute } from '../../../shared/geometry/Geometry'; /** * This interface represents the extracted attribute data from a WebGL program. * It extends the `Attribute` interface but omits the `buffer` property. * It includes an optional `location` property that indicates where the shader location is for this attribute. * @category rendering * @advanced */ export interface ExtractedAttributeData extends Omit<Attribute, 'buffer'> { /** set where the shader location is for this attribute */ location?: number; } /** * returns the attribute data from the program * @private * @param {WebGLProgram} [program] - the WebGL program * @param {WebGLRenderingContext} [gl] - the WebGL context * @param sortAttributes * @returns {object} the attribute data for this program */ export function extractAttributesFromGlProgram( program: WebGLProgram, gl: WebGLRenderingContextBase, sortAttributes = false ): Record<string, ExtractedAttributeData> { const attributes: {[key: string]: ExtractedAttributeData} = {}; const totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES); for (let i = 0; i < totalAttributes; i++) { const attribData = gl.getActiveAttrib(program, i); // ignore the default ones! if (attribData.name.startsWith('gl_')) { continue; } const format = mapGlToVertexFormat(gl, attribData.type); attributes[attribData.name] = { location: 0, // set further down.. format, stride: getAttributeInfoFromFormat(format).stride, offset: 0, instance: false, start: 0, }; } const keys = Object.keys(attributes); if (sortAttributes) { keys.sort((a, b) => (a > b) ? 1 : -1); // eslint-disable-line no-confusing-arrow for (let i = 0; i < keys.length; i++) { attributes[keys[i]].location = i; gl.bindAttribLocation(program, i, keys[i]); } gl.linkProgram(program); } else { for (let i = 0; i < keys.length; i++) { attributes[keys[i]].location = gl.getAttribLocation(program, keys[i]); } } return attributes; }