/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/rendering/renderers/gpu/texture/uploaders/gpuUploadImageSource.ts
50 строк
2 KB
Mat Groves
feat: add cube texture (#11800)
30 янв 2026, 13:29
Не верифицирован
30 янв 2026, 13:29
b794958
Код
Авторство
О чём код?
import { DOMAdapter } from '../../../../../environment/adapter'; import { warn } from '../../../../../utils/logging/warn'; import type { TextureSource } from '../../../shared/texture/sources/TextureSource'; import type { GPU } from '../../GpuDeviceSystem'; import type { GpuTextureUploader } from './GpuTextureUploader'; /** @internal */ export const gpuUploadImageResource = { type: 'image', upload(source: TextureSource, gpuTexture: GPUTexture, gpu: GPU, originZOverride = 0) { const resource = source.resource as ImageBitmap | HTMLCanvasElement | OffscreenCanvas | HTMLImageElement; if (!resource) return; // WebGPU does not support HTMLImageElement // so we need to convert it to a canvas if (globalThis.HTMLImageElement && resource instanceof HTMLImageElement) { const canvas = DOMAdapter.get().createCanvas(resource.width, resource.height); const context = canvas.getContext('2d'); context.drawImage(resource, 0, 0, resource.width, resource.height); // replace with the canvas - for future uploads source.resource = canvas; // #if _DEBUG warn('ImageSource: Image element passed, converting to canvas and replacing resource.'); // #endif } const width = Math.min(gpuTexture.width, source.resourceWidth || source.pixelWidth); const height = Math.min(gpuTexture.height, source.resourceHeight || source.pixelHeight); const premultipliedAlpha = source.alphaMode === 'premultiply-alpha-on-upload'; gpu.device.queue.copyExternalImageToTexture( { source: resource }, { texture: gpuTexture, origin: { x: 0, y: 0, z: originZOverride }, premultipliedAlpha }, { width, height, } ); } } as GpuTextureUploader<TextureSource>;