SdlDebug .java

com.mojang.blaze3d.platform.SdlDebug (class): members: CALLBACK, HEX_FORMAT, init, LOGGER. strings: "ASSERT", "RENDER", "SYSTEM", "AUDIO", "INPUT", "TEST".

com.mojang.blaze3d.platformclass65 linesclient1.8 KB

API Surface (1)

void init()

Fields & Constants (3)

LOGGER
HEX_FORMAT
CALLBACK

String literals (9)

"Unknown (0x"
"APPLICATION"
"ASSERT"
"SYSTEM"
"AUDIO"
"VIDEO"
"RENDER"
"INPUT"
"TEST"

Full Source

SdlDebug.java65 lines · Minecraft 26.3 · verbatim
1
package com.mojang.blaze3d.platform;
2
3
import com.mojang.logging.LogUtils;
4
import java.util.HexFormat;
5
import net.fabricmc.api.EnvType;
6
import net.fabricmc.api.Environment;
7
import org.lwjgl.sdl.SDLLog;
8
import org.lwjgl.sdl.SDL_LogOutputFunction;
9
import org.lwjgl.system.MemoryUtil;
10
import org.slf4j.Logger;
11
12
@Environment(EnvType.CLIENT)
13
public class SdlDebug {
14
	private static final Logger LOGGER = LogUtils.getLogger();
15
	private static final HexFormat HEX_FORMAT = HexFormat.of().withUpperCase();
16
	private static final SDL_LogOutputFunction CALLBACK = SDL_LogOutputFunction.create(SdlDebug::onLogMessage);
17
18
	private SdlDebug() {
19
	}
20
21
	public static void init() {
22
		SDLLog.SDL_SetLogOutputFunction(CALLBACK, 0L);
23
		SDLLog.SDL_SetLogPriorities(LOGGER.isDebugEnabled() ? 3 : 4);
24
	}
25
26
	private static String printUnknownToken(final int token) {
27
		return "Unknown (0x" + HEX_FORMAT.toHexDigits(token) + ")";
28
	}
29
30
	private static String categoryToString(final int category) {
31
		return switch (category) {
32
			case 0 -> "APPLICATION";
33
			case 1 -> "ERROR";
34
			case 2 -> "ASSERT";
35
			case 3 -> "SYSTEM";
36
			case 4 -> "AUDIO";
37
			case 5 -> "VIDEO";
38
			case 6 -> "RENDER";
39
			case 7 -> "INPUT";
40
			case 8 -> "TEST";
41
			case 9 -> "GPU";
42
			default -> printUnknownToken(category);
43
		};
44
	}
45
46
	private static void onLogMessage(final long userData, final int category, final int priority, final long message) {
47
		String text = message == 0L ? "" : MemoryUtil.memUTF8(message);
48
		String categoryName = categoryToString(category);
49
		switch (priority) {
50
			case 2:
51
			case 3:
52
				LOGGER.debug("SDL [{}]: {}", categoryName, text);
53
				break;
54
			case 4:
55
				LOGGER.info("SDL [{}]: {}", categoryName, text);
56
				break;
57
			case 5:
58
				LOGGER.warn("SDL [{}]: {}", categoryName, text);
59
				break;
60
			default:
61
				LOGGER.error("SDL [{}]: {}", categoryName, text);
62
		}
63
	}
64
}
65

Decompiled Minecraft 26.3 source of SdlDebug (com/mojang/blaze3d/platform/SdlDebug.java) with Mojang official mappings, stored verbatim on the site.