GlTexture .java

com.mojang.renderpearl.backend.opengl.GlTexture (class): members: removeViews, addViews, fboKeys, views, removeAssociatedFbo, addAssociatedFbo, glId.

com.mojang.renderpearl.backend.openglclass90 linesclientextends BaseGpuTexture1.9 KB

Implements

API Surface (8)

void close()
boolean isClosed()
int glId()
int fboMipLevel()
void addAssociatedFbo(final FrameBufferCache.CacheKey fboKey)
void removeAssociatedFbo(final FrameBufferCache.CacheKey fboKey)
void addViews()
void removeViews()

Fields & Constants (13)

EMPTY
id
frameBufferCache
fboKeys
closed
views
usage
label
format
width
height
depthOrLayers
mipLevels

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

GlTexture.java90 lines · Minecraft 26.3 · verbatim
1
package com.mojang.renderpearl.backend.opengl;
2
3
import com.mojang.renderpearl.api.GpuFormat;
4
import com.mojang.renderpearl.api.textures.GpuTexture;
5
import com.mojang.renderpearl.backend.common.BaseGpuTexture;
6
import java.util.ArrayList;
7
import java.util.List;
8
import net.fabricmc.api.EnvType;
9
import net.fabricmc.api.Environment;
10
11
@Environment(EnvType.CLIENT)
12
public class GlTexture extends BaseGpuTexture implements FrameBufferAttachment {
13
	private static final int EMPTY = -1;
14
	protected final int id;
15
	private final FrameBufferCache frameBufferCache;
16
	private final List<FrameBufferCache.CacheKey> fboKeys = new ArrayList<>();
17
	protected boolean closed;
18
	private int views;
19
20
	protected GlTexture(
21
		final @GpuTexture.Usage int usage,
22
		final String label,
23
		final GpuFormat format,
24
		final int width,
25
		final int height,
26
		final int depthOrLayers,
27
		final int mipLevels,
28
		final int id,
29
		final FrameBufferCache frameBufferCache
30
	) {
31
		super(usage, label, format, width, height, depthOrLayers, mipLevels);
32
		this.id = id;
33
		this.frameBufferCache = frameBufferCache;
34
	}
35
36
	@Override
37
	public void close() {
38
		if (!this.closed) {
39
			this.closed = true;
40
			if (this.views == 0) {
41
				this.destroyImmediately();
42
			}
43
		}
44
	}
45
46
	private void destroyImmediately() {
47
		while (!this.fboKeys.isEmpty()) {
48
			this.frameBufferCache.destroyFbo(this.fboKeys.getLast());
49
		}
50
51
		GlStateManager._deleteTexture(this.id);
52
	}
53
54
	@Override
55
	public boolean isClosed() {
56
		return this.closed;
57
	}
58
59
	@Override
60
	public int glId() {
61
		return this.id;
62
	}
63
64
	@Override
65
	public int fboMipLevel() {
66
		return 0;
67
	}
68
69
	@Override
70
	public void addAssociatedFbo(final FrameBufferCache.CacheKey fboKey) {
71
		this.fboKeys.add(fboKey);
72
	}
73
74
	@Override
75
	public void removeAssociatedFbo(final FrameBufferCache.CacheKey fboKey) {
76
		this.fboKeys.remove(fboKey);
77
	}
78
79
	public void addViews() {
80
		this.views++;
81
	}
82
83
	public void removeViews() {
84
		this.views--;
85
		if (this.closed && this.views == 0) {
86
			this.destroyImmediately();
87
		}
88
	}
89
}
90

Decompiled Minecraft 26.3 source of GlTexture (com/mojang/renderpearl/backend/opengl/GlTexture.java) with Mojang official mappings, stored verbatim on the site.