GlSurface .java

com.mojang.renderpearl.backend.opengl.GlSurface (class, 70 lines): members: SUPPORTED_PRESENT_MODES, windowHandle, swapchainHeight, swapchainWidth, device.

com.mojang.renderpearl.backend.openglclass70 linesclient2.2 KB

Implements

API Surface (7)

void configure(final GpuSurface.Configuration config)
boolean isSuboptimal()
void acquireNextTexture()
void blitFromTexture(final CommandEncoderBackend commandEncoder, final GpuTextureView textureView)
void present()
void close()
Collection<GpuSurface.PresentMode> supportedPresentModes()

Fields & Constants (6)

SUPPORTED_PRESENT_MODES
device
windowHandle
isIconified
swapchainWidth
swapchainHeight

String literals (1)

"Cannot acquire minimized window"

Code Graph: Dependencies (6)

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

Full Source

GlSurface.java70 lines · Minecraft 26.3 · verbatim
1
package com.mojang.renderpearl.backend.opengl;
2
3
import com.mojang.renderpearl.api.device.GpuSurface;
4
import com.mojang.renderpearl.api.device.SurfaceException;
5
import com.mojang.renderpearl.api.textures.GpuTextureView;
6
import com.mojang.renderpearl.backend.api.CommandEncoderBackend;
7
import com.mojang.renderpearl.backend.api.GpuSurfaceBackend;
8
import java.util.Collection;
9
import java.util.EnumSet;
10
import java.util.Set;
11
import java.util.function.BooleanSupplier;
12
import net.fabricmc.api.EnvType;
13
import net.fabricmc.api.Environment;
14
import org.lwjgl.sdl.SDLVideo;
15
16
@Environment(EnvType.CLIENT)
17
public class GlSurface implements GpuSurfaceBackend {
18
	private static final Set<GpuSurface.PresentMode> SUPPORTED_PRESENT_MODES = EnumSet.of(GpuSurface.PresentMode.FIFO, GpuSurface.PresentMode.IMMEDIATE);
19
	private final GlDevice device;
20
	private final long windowHandle;
21
	private final BooleanSupplier isIconified;
22
	private int swapchainWidth;
23
	private int swapchainHeight;
24
25
	GlSurface(final GlDevice device, final long windowHandle, final BooleanSupplier isIconified) {
26
		this.device = device;
27
		this.windowHandle = windowHandle;
28
		this.isIconified = isIconified;
29
	}
30
31
	@Override
32
	public void configure(final GpuSurface.Configuration config) throws SurfaceException {
33
		this.device.makeCurrent(this.windowHandle);
34
		SDLVideo.SDL_GL_SetSwapInterval(config.presentMode() == GpuSurface.PresentMode.FIFO ? 1 : 0);
35
		this.swapchainWidth = config.width();
36
		this.swapchainHeight = config.height();
37
	}
38
39
	@Override
40
	public boolean isSuboptimal() {
41
		return false;
42
	}
43
44
	@Override
45
	public void acquireNextTexture() throws SurfaceException {
46
		if (this.isIconified.getAsBoolean()) {
47
			throw new SurfaceException("Cannot acquire minimized window");
48
		}
49
	}
50
51
	@Override
52
	public void blitFromTexture(final CommandEncoderBackend commandEncoder, final GpuTextureView textureView) {
53
		((GlCommandEncoder)commandEncoder).presentTexture(this.windowHandle, textureView, this.swapchainWidth, this.swapchainHeight);
54
	}
55
56
	@Override
57
	public void present() {
58
		SDLVideo.SDL_GL_SwapWindow(this.windowHandle);
59
	}
60
61
	@Override
62
	public void close() {
63
	}
64
65
	@Override
66
	public Collection<GpuSurface.PresentMode> supportedPresentModes() {
67
		return SUPPORTED_PRESENT_MODES;
68
	}
69
}
70

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