LateInit 纹理上传
基本信息
| 属性 | 值 |
|---|---|
| 类 | alexiil.mods.load.imgur.LateInitDynamicTexture |
| 父类 | net.minecraft.client.renderer.texture.AbstractTexture |
| 使用方 | ImgurCacheManager 异步缓存填充 |
设计动机
原版 DynamicTexture 在构造时立即分配 GL 纹理并上传像素。但 BetterLoadingScreen 启动阶段主 OpenGL 上下文不在缓存线程里,因此需要一种"延迟上传"包装:
- 构造:只缓存
int[] dynamicTextureData、width、height,不分配 GL 纹理。 loadTexture(IResourceManager):在主线程拥有 OpenGL 上下文时才上传;上传后dynamicTextureData=null,避免重复上传。
实现
public LateInitDynamicTexture(BufferedImage image, int width, int height) {
this.width = width;
this.height = height;
this.dynamicTextureData = new int[width * height];
image.getRGB(0, 0, width, height, this.dynamicTextureData, 0, width);
}
public void loadTexture(IResourceManager rs) {
if (this.dynamicTextureData == null) return;
SplashTextureManager.upload(this.getGlTextureId(), this.dynamicTextureData, this.width, this.height, false, false);
this.dynamicTextureData = null;
}
注:
SplashTextureManager.upload(int, int[], int, int, boolean, boolean)是静态工具方法,直接调 GL API 上传像素,不走 GL_TEXTURE_MIN_FILTER 调整(参数blur=false, clamp=false)。
数值
| 字段 | 默认 |
|---|---|
| 像素 blur | false(最近邻) |
| 像素 clamp | false(repeat wrap) |
使用场景
ImgurCacheManager在 disk/memory 解码后构造LateInitDynamicTexture,把ResourceLocation推给MinecraftDisplayer,主线程下一帧渲染前调loadTexture完成上传。
相关条目
- Imgur 集成 - LateInit 是 Imgur 异步缓存的纹理抽象
- Splash 纹理管理 - 上传静态工具方法