2025-11-24 22:52:51 +03:00

83 lines
2.3 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* it.unimi.dsi.fastutil.ints.Int2IntMap
* it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap
* it.unimi.dsi.fastutil.ints.IntIterator
* org.jspecify.annotations.Nullable
*/
package com.mojang.blaze3d.opengl;
import com.mojang.blaze3d.opengl.DirectStateAccess;
import com.mojang.blaze3d.opengl.GlStateManager;
import com.mojang.blaze3d.textures.GpuTexture;
import com.mojang.blaze3d.textures.TextureFormat;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntIterator;
import org.jspecify.annotations.Nullable;
public class GlTexture
extends GpuTexture {
protected final int id;
private final Int2IntMap fboCache = new Int2IntOpenHashMap();
protected boolean closed;
private int views;
protected GlTexture(@GpuTexture.Usage int usage, String label, TextureFormat format, int width, int height, int depthOrLayers, int mipLevels, int id) {
super(usage, label, format, width, height, depthOrLayers, mipLevels);
this.id = id;
}
@Override
public void close() {
if (this.closed) {
return;
}
this.closed = true;
if (this.views == 0) {
this.destroyImmediately();
}
}
private void destroyImmediately() {
GlStateManager._deleteTexture(this.id);
IntIterator intIterator = this.fboCache.values().iterator();
while (intIterator.hasNext()) {
int fbo = (Integer)intIterator.next();
GlStateManager._glDeleteFramebuffers(fbo);
}
}
@Override
public boolean isClosed() {
return this.closed;
}
public int getFbo(DirectStateAccess dsa, @Nullable GpuTexture depth) {
int depthid = depth == null ? 0 : ((GlTexture)depth).id;
return this.fboCache.computeIfAbsent(depthid, ignored -> {
int fbo = dsa.createFrameBufferObject();
dsa.bindFrameBufferTextures(fbo, this.id, depthid, 0, 0);
return fbo;
});
}
public int glId() {
return this.id;
}
public void addViews() {
++this.views;
}
public void removeViews() {
--this.views;
if (this.closed && this.views == 0) {
this.destroyImmediately();
}
}
}