{"version":3,"file":"glUploadCubeTextureResource.mjs","sources":["../../../../../../src/rendering/renderers/gl/texture/uploaders/glUploadCubeTextureResource.ts"],"sourcesContent":["import { GL_TARGETS } from '../const';\n\nimport type { CubeTextureSource } from '../../../shared/texture/sources/CubeTextureSource';\nimport type { GlRenderingContext } from '../../context/GlRenderingContext';\nimport type { GlTexture } from '../GlTexture';\nimport type { GLTextureUploader } from './GLTextureUploader';\n\nconst FACE_ORDER: (keyof CubeTextureSource['faces'])[] = ['right', 'left', 'top', 'bottom', 'front', 'back'];\n\n/**\n * Creates a cube uploader that delegates to the given uploader registry.\n * This keeps the uploader map owned by the texture system (better discoverability),\n * while allowing cube uploads to reuse the same 2D upload implementations.\n * @param uploaders - Uploader registry keyed by `uploadMethodId` (must include `image`).\n * @internal\n */\nexport function createGlUploadCubeTextureResource(\n    uploaders: Record<string, GLTextureUploader> & { image: GLTextureUploader }\n): GLTextureUploader\n{\n    return {\n        id: 'cube',\n        upload(source: CubeTextureSource, glTexture: GlTexture, gl: GlRenderingContext, webGLVersion: number)\n        {\n            const faces = source.faces;\n\n            // Upload each face by delegating to the standard 2D uploaders with a face-target override.\n            for (let faceIndex = 0; faceIndex < FACE_ORDER.length; faceIndex++)\n            {\n                const key = FACE_ORDER[faceIndex];\n                const face = faces[key];\n                const uploader = uploaders[face.uploadMethodId] || uploaders.image;\n\n                // Each cube face target must be initialized (texImage2D) at least once before using texSubImage2D.\n                // Tell 2D uploaders to force allocation for the first upload of each face.\n                uploader.upload(\n                    face,\n                    glTexture,\n                    gl,\n                    webGLVersion,\n                    // Use the face target for the current face. cube faces ids go up 1 so\n                    // GL_TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + i addresses the i'th face target.\n                    GL_TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex,\n                    // Force allocation for the first upload of each face.\n                    (glTexture._layerInitMask & (1 << faceIndex)) === 0\n                );\n\n                glTexture._layerInitMask |= (1 << faceIndex);\n            }\n\n            // Track size for GC / re-upload decisions.\n            glTexture.width = source.pixelWidth;\n            glTexture.height = source.pixelHeight;\n        }\n    };\n}\n"],"names":[],"mappings":";;;AAOA,MAAM,aAAmD,CAAC,OAAA,EAAS,QAAQ,KAAA,EAAO,QAAA,EAAU,SAAS,MAAM,CAAA;AASpG,SAAS,kCACZ,SAAA,EAEJ;AACI,EAAA,OAAO;AAAA,IACH,EAAA,EAAI,MAAA;AAAA,IACJ,MAAA,CAAO,MAAA,EAA2B,SAAA,EAAsB,EAAA,EAAwB,YAAA,EAChF;AACI,MAAA,MAAM,QAAQ,MAAA,CAAO,KAAA;AAGrB,MAAA,KAAA,IAAS,SAAA,GAAY,CAAA,EAAG,SAAA,GAAY,UAAA,CAAW,QAAQ,SAAA,EAAA,EACvD;AACI,QAAA,MAAM,GAAA,GAAM,WAAW,SAAS,CAAA;AAChC,QAAA,MAAM,IAAA,GAAO,MAAM,GAAG,CAAA;AACtB,QAAA,MAAM,QAAA,GAAW,SAAA,CAAU,IAAA,CAAK,cAAc,KAAK,SAAA,CAAU,KAAA;AAI7D,QAAA,QAAA,CAAS,MAAA;AAAA,UACL,IAAA;AAAA,UACA,SAAA;AAAA,UACA,EAAA;AAAA,UACA,YAAA;AAAA;AAAA;AAAA,UAGA,WAAW,2BAAA,GAA8B,SAAA;AAAA;AAAA,UAAA,CAExC,SAAA,CAAU,cAAA,GAAkB,CAAA,IAAK,SAAA,MAAgB;AAAA,SACtD;AAEA,QAAA,SAAA,CAAU,kBAAmB,CAAA,IAAK,SAAA;AAAA,MACtC;AAGA,MAAA,SAAA,CAAU,QAAQ,MAAA,CAAO,UAAA;AACzB,MAAA,SAAA,CAAU,SAAS,MAAA,CAAO,WAAA;AAAA,IAC9B;AAAA,GACJ;AACJ;;;;"}