MCPcopy Create free account
hub / github.com/esengine/esengine / loadTexture

Method loadTexture

packages/fairygui/src/render/RenderBridge.ts:153–186  ·  view source on GitHub ↗

* Load or get cached texture * 加载或获取缓存的纹理

(
        url: string,
        source?: ImageBitmap | HTMLImageElement | HTMLCanvasElement | ImageData
    )

Source from the content-addressed store, hash-verified

151 * 加载或获取缓存的纹理
152 */
153 public async loadTexture(
154 url: string,
155 source?: ImageBitmap | HTMLImageElement | HTMLCanvasElement | ImageData
156 ): Promise<ITextureHandle | null> {
157 // Check cache first
158 const cached = this._textureCache.get(url);
159 if (cached) {
160 cached.lastUsedFrame = this._currentFrame;
161 cached.refCount++;
162 return cached.handle;
163 }
164
165 // Load or create texture
166 let textureSource = source;
167 if (!textureSource) {
168 try {
169 const response = await fetch(url);
170 const blob = await response.blob();
171 textureSource = await createImageBitmap(blob);
172 } catch (error) {
173 console.error(`Failed to load texture: ${url}`, error);
174 return null;
175 }
176 }
177
178 const handle = this._backend.createTexture(textureSource);
179 this._textureCache.set(url, {
180 handle,
181 lastUsedFrame: this._currentFrame,
182 refCount: 1
183 });
184
185 return handle;
186 }
187
188 /**
189 * Release a texture reference

Callers

nothing calls this directly

Calls 4

getMethod · 0.65
createTextureMethod · 0.65
setMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected