/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/rendering/renderers/gl/GlLimitsSystem.ts
77 строк
3 KB
Ilia Malanin
fix: handle uniform buffer bindings check in WebGL1 gracefully (#11458) (#11608)
19 авг 2025, 10:36
Не верифицирован
19 авг 2025, 10:36
33bd721
Код
Авторство
О чём код?
import { ExtensionType } from '../../../extensions/Extensions'; import { checkMaxIfStatementsInShader } from '../../batcher/gl/utils/checkMaxIfStatementsInShader'; import { type System } from '../shared/system/System'; import type { WebGLRenderer } from './WebGLRenderer'; /** * The GpuLimitsSystem provides information about the capabilities and limitations of the underlying GPU. * These limits, such as the maximum number of textures that can be used in a shader * (`maxTextures`) or the maximum number of textures that can be batched together (`maxBatchableTextures`), * are determined by the specific graphics hardware and driver. * * The values for these limits are not available immediately upon instantiation of the class. * They are populated when the GL rendering context is successfully initialized and ready, * which occurs after the `renderer.init()` method has completed. * Attempting to access these properties before the context is ready will result in undefined or default values. * * This system allows the renderer to adapt its behavior and resource allocation strategies * to stay within the supported boundaries of the GPU, ensuring optimal performance and stability. * @example * ```ts * const renderer = new WebGlRenderer(); * await renderer.init(); * * console.log(renderer.limits.maxTextures); * ``` * @category rendering * @advanced */ export class GlLimitsSystem implements System { /** @ignore */ public static extension = { type: [ ExtensionType.WebGLSystem, ], name: 'limits', } as const; /** The maximum number of textures that can be used by a shader */ public maxTextures: number; /** The maximum number of batchable textures */ public maxBatchableTextures: number; /** The maximum number of uniform bindings */ public maxUniformBindings: number; private readonly _renderer: WebGLRenderer; constructor(renderer: WebGLRenderer) { this._renderer = renderer; } public contextChange(): void { const gl = this._renderer.gl; // step 1: first check max textures the GPU can handle. this.maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); // step 2: check the maximum number of if statements the shader can have too.. this.maxBatchableTextures = checkMaxIfStatementsInShader(this.maxTextures, gl); // step 3: check the limit of uniform buffer bindings. // UBs are available only in WebGL2 context, requesting within WebGL1 produces a warning. const isWebGl2 = this._renderer.context.webGLVersion === 2; this.maxUniformBindings = isWebGl2 ? gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS) : 0; } public destroy(): void { // boom! } }