Skip to content

Commit 7ef695f

Browse files
committed
getting there!
1 parent c3d4efa commit 7ef695f

File tree

8 files changed

+67
-40
lines changed

8 files changed

+67
-40
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ kotlinx-coroutines = "1.10.2"
77
kotlinx-atomicfu = "0.29.0"
88
fabric-language-kotlin = "1.13.5+kotlin.2.2.10"
99
google-ksp = "2.2.10-2.0.2"
10-
polyui = "2.0.4"
10+
polyui = "2.0.5"
1111
annotations = "24.1.0"
1212
hypixel-modapi = "1.0.1"
1313
hypixel-data = "0.2.0" # Dep of hypixel-modapi

minecraft/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@
4747
import org.apache.logging.log4j.LogManager;
4848
import org.apache.logging.log4j.Logger;
4949
import org.jetbrains.annotations.NotNull;
50+
import org.jetbrains.annotations.Nullable;
5051
import org.polyfrost.oneconfig.api.ClassHasOverwrites;
51-
import org.polyfrost.oneconfig.api.ui.v1.api.NanoSvgApi;
52-
import org.polyfrost.oneconfig.api.ui.v1.api.NanoVgApi;
53-
import org.polyfrost.oneconfig.api.ui.v1.api.StbApi;
54-
import org.polyfrost.oneconfig.api.ui.v1.api.TinyFdApi;
52+
import org.polyfrost.oneconfig.api.ui.v1.api.*;
5553
import org.polyfrost.oneconfig.api.ui.v1.UIManager;
5654
import org.polyfrost.oneconfig.api.ui.v1.internal.wrappers.MCWindow;
5755
import org.polyfrost.oneconfig.api.ui.v1.internal.wrappers.PolyUIScreen;
@@ -134,6 +132,11 @@ public UIManagerImpl() throws Throwable {
134132
}
135133
}
136134

135+
@Override
136+
public @Nullable RendererExt getRendererExt() {
137+
return (renderer instanceof RendererExt ? (RendererExt) renderer : null);
138+
}
139+
137140
@Override
138141
public Renderer getRenderer() {
139142
return renderer;

minecraft/src/main/java/org/polyfrost/oneconfig/internal/OneConfig.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils;
5454
import org.polyfrost.oneconfig.api.platform.v1.Platform;
5555
import org.polyfrost.oneconfig.api.ui.v1.UIManager;
56+
import org.polyfrost.oneconfig.api.ui.v1.api.RendererExt;
5657
import org.polyfrost.oneconfig.api.ui.v1.internal.BlurHandler;
5758
import org.polyfrost.oneconfig.api.ui.v1.keybind.OCKeybindHelper;
5859
import org.polyfrost.oneconfig.internal.ui.OneConfigUI;
@@ -132,8 +133,8 @@ private void init() {
132133
if (Boolean.getBoolean("oneconfig.test")) {
133134
try {
134135
TestMod_Test.initialize();
135-
} catch (Throwable ignored) {
136-
ignored.printStackTrace();
136+
} catch (Throwable e) {
137+
e.printStackTrace();
137138
}
138139
}
139140

@@ -155,7 +156,7 @@ private void init() {
155156
LOGGER.info("OneConfig initialization took {}ms", (System.nanoTime() - t1) / 1_000_000.0);
156157
}
157158

158-
@SuppressWarnings({"unchecked", "rawtypes"})
159+
@SuppressWarnings({"unchecked", "rawtypes", "UnstableApiUsage"})
159160
private static void registerCommands() {
160161
ClientCommandInternals.initialize();
161162
// //#if MC > 1.16
@@ -201,7 +202,16 @@ private static void registerCommands() {
201202
return ctx.getSource().replyChat("OK");
202203
})
203204
)
204-
.build();
205+
.then(OmniClientCommands.literal("dumpAtlas")
206+
.executes((ctx) -> {
207+
RendererExt ext = UIManager.INSTANCE.getRendererExt();
208+
if (ext == null) {
209+
return ctx.getSource().replyChat("RendererExt is not available on this platform.");
210+
}
211+
ext.dumpAtlas();
212+
return ctx.getSource().replyChat("OK");
213+
})
214+
).build();
205215
OmniClientCommands.register(node);
206216
OmniClientCommands.register(OmniClientCommands.literal("ocfg").executes(executor).redirect(node));
207217
}

modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/UIManager.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
import org.polyfrost.oneconfig.api.event.v1.EventDelay;
4848
import org.polyfrost.oneconfig.api.event.v1.EventManager;
4949
import org.polyfrost.oneconfig.api.event.v1.events.HudRenderEvent;
50-
import org.polyfrost.oneconfig.api.event.v1.events.RenderEvent;
5150
import org.polyfrost.oneconfig.api.event.v1.events.ResizeEvent;
5251
import org.polyfrost.oneconfig.api.event.v1.events.WorldEvent;
5352
import org.polyfrost.oneconfig.api.platform.v1.Platform;
53+
import org.polyfrost.oneconfig.api.ui.v1.api.RendererExt;
5454
import org.polyfrost.oneconfig.api.ui.v1.api.TinyFdApi;
5555
import org.polyfrost.polyui.PolyUI;
5656
import org.polyfrost.polyui.Settings;
@@ -76,6 +76,12 @@ public interface UIManager {
7676
*/
7777
Renderer getRenderer();
7878

79+
/**
80+
* Return the renderer extension instance. This interface specifies additional (debug) operations for the renderer.
81+
*/
82+
@Nullable
83+
RendererExt getRendererExt();
84+
7985
/**
8086
* Return the TinyFD implementation instance. This interface specifies operations for opening native
8187
* file dialogs, and showing notifications.
@@ -157,9 +163,8 @@ default PolyUI createDefault() {
157163
});
158164
};
159165

160-
EventManager.register(RenderEvent.Post.class, event -> {
161-
renderer.accept(event.ctx);
162-
});
166+
// todo temporary reversion: on RenderEvent it just renders nothing (see #592, #579)
167+
EventManager.register(HudRenderEvent.class, event -> renderer.accept(event.ctx));
163168

164169
EventManager.register(ResizeEvent.class, event -> {
165170
float ratio = Platform.screen().pixelRatio();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.polyfrost.oneconfig.api.ui.v1.api;
2+
3+
public interface RendererExt {
4+
void dumpAtlas();
5+
}

modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/api/StbApi.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public interface StbApi {
1212

1313
void image_write_png(String filename, int w, int h, int comp, ByteBuffer data, int strideInBytes);
1414

15-
long createFontInfo();
15+
long font_CreateFontInfo();
1616

17-
long createPackRange();
17+
long font_CreatePackRange();
1818

19-
long createPackedCharArray(int capacity);
19+
long font_CreatePackedCharArray(int capacity);
2020

21-
long createPackContext();
21+
long font_CreatePackContext();
2222

23-
boolean initFont(long info, ByteBuffer data);
23+
boolean font_InitFont(long info, ByteBuffer data);
2424

2525
float font_ScaleForMappingEmToPixels(long info, float pixels);
2626

modules/ui/src/main/kotlin/org/polyfrost/oneconfig/api/ui/v1/internal/GLRendererImpl.kt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.lwjgl.opengl.GL14.*
99
import org.lwjgl.opengl.GL15.*
1010
import org.lwjgl.opengl.GL20.*
1111
import org.polyfrost.oneconfig.api.ui.v1.api.NanoSvgApi
12+
import org.polyfrost.oneconfig.api.ui.v1.api.RendererExt
1213
import org.polyfrost.oneconfig.api.ui.v1.api.StbApi
1314
import org.polyfrost.polyui.PolyUI
1415
import org.polyfrost.polyui.color.Color
@@ -42,10 +43,9 @@ private val EMPTY_ROW = floatArrayOf(0f, 0f, 0f, 0f)
4243
private val NO_UV = floatArrayOf(-1f, -1f, 1f, 1f)
4344

4445
@Suppress("UnstableApiUsage", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
45-
class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Renderer {
46+
class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Renderer, RendererExt {
4647

4748
private val buffer = BufferUtils.createFloatBuffer(MAX_BATCH * STRIDE)
48-
private val transformBuffer = BufferUtils.createFloatBuffer(9)
4949
private val scissorStack = IntArray(MAX_UI_DEPTH * 4)
5050
private val transformStack = ArrayList<FloatArray>(MAX_UI_DEPTH)
5151
private val fonts = HashMap<Font, FontAtlas>()
@@ -81,11 +81,6 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
8181
0f, 1f, 0f,
8282
0f, 0f, 1f
8383
)
84-
set(value) {
85-
field = value
86-
transformBuffer.clear()
87-
transformBuffer.put(value).flip()
88-
}
8984
private var viewportWidth = 0f
9085
private var viewportHeight = 0f
9186
private var pixelRatio = 1f
@@ -284,8 +279,8 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
284279

285280

286281
@Suppress("SameParameterValue")
287-
private fun glUniformMatrix3fv(location: Int, transpose: Boolean, buf: FloatBuffer) {
288-
ShaderInternals.uniformMatrix3(location, transpose, buf)
282+
private fun glUniformMatrix3fv(location: Int, transpose: Boolean, array: FloatArray) {
283+
ShaderInternals.uniformMatrix3(location, transpose, array)
289284
}
290285

291286
override fun init() {
@@ -387,7 +382,7 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
387382
val prevProg = glGetInteger(GL_CURRENT_PROGRAM)
388383
glUseProgram(program)
389384
glUniform2f(uWindow, width, height)
390-
glUniformMatrix3fv(uTransform, false, transformBuffer)
385+
glUniformMatrix3fv(uTransform, false, transform)
391386
glUseProgram(prevProg)
392387
glDisable(GL_SCISSOR_TEST)
393388
viewportWidth = width * pixelRatio
@@ -430,7 +425,7 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
430425
glUseProgram(program)
431426

432427
if (popFlushNeeded) {
433-
glUniformMatrix3fv(uTransform, false, transformBuffer)
428+
glUniformMatrix3fv(uTransform, false, transform)
434429
popFlushNeeded = false
435430
}
436431

@@ -851,19 +846,25 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
851846
}
852847
}
853848

849+
private var i = 0
854850
fun dumpTexture(texId: Int = atlas) {
855851
val buf = BufferUtils.createByteBuffer(ATLAS_SIZE * ATLAS_SIZE * 4)
856852
glBindTexture(GL_TEXTURE_2D, texId)
857853
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf)
858854
glBindTexture(GL_TEXTURE_2D, 0)
859855
stb.image_write_png(
860-
"debug_texture$texId.png",
856+
"debug_texture$texId($i).png",
861857
ATLAS_SIZE,
862858
ATLAS_SIZE,
863859
4,
864860
buf,
865861
ATLAS_SIZE * 4
866862
)
863+
i++
864+
}
865+
866+
override fun dumpAtlas() {
867+
dumpTexture(atlas)
867868
}
868869

869870
override fun cleanup() {
@@ -891,8 +892,9 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
891892
val lineGap: Float
892893

893894
init {
894-
val fontInfo = stb.createFontInfo()
895-
if (!stb.initFont(fontInfo, data)) {
895+
val stb = stb
896+
val fontInfo = stb.font_CreateFontInfo()
897+
if (!stb.font_InitFont(fontInfo, data)) {
896898
throw IllegalStateException("Failed to initialize font")
897899
}
898900
val scale = stb.font_ScaleForMappingEmToPixels(fontInfo, renderedSize)
@@ -906,15 +908,15 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
906908
descent = des[0] * scale
907909
lineGap = gap[0] * scale
908910

909-
val range = stb.createPackRange()
911+
val range = stb.font_CreatePackRange()
910912
stb.font_RangeSetFontSize(range, renderedSize)
911913
stb.font_RangeSetFirstUnicodeCodepointInRange(range, 32)
912914
stb.font_RangeSetNumChars(range, 95)
913-
val packed = stb.createPackedCharArray(95)
915+
val packed = stb.font_CreatePackedCharArray(95)
914916
stb.font_RangeSetChardata(range, packed)
915917

916918
val bitMap = BufferUtils.createByteBuffer(FONT_MAX_BITMAP_W * FONT_MAX_BITMAP_H)
917-
val pack = stb.createPackContext()
919+
val pack = stb.font_CreatePackContext()
918920
if (!stb.font_PackBegin(pack, bitMap, FONT_MAX_BITMAP_W, FONT_MAX_BITMAP_H, 0, 1, 0L)) {
919921
throw IllegalStateException("Failed to initialize font packer")
920922
}
@@ -974,6 +976,8 @@ class GLRendererImpl(private val nsvg: NanoSvgApi, private val stb: StbApi) : Re
974976
stb.free(packed)
975977
stb.free(range)
976978

979+
// dumpAtlas()
980+
977981
val prevTex = glGetInteger(GL_TEXTURE_BINDING_2D)
978982
glBindTexture(GL_TEXTURE_2D, atlas)
979983
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

modules/ui/src/main/kotlin/org/polyfrost/oneconfig/api/ui/v1/internal/StbImpl.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class StbImpl : StbApi {
2727
STBImageWrite.stbi_write_png(filename, w, h, comp, data, strideInBytes)
2828
}
2929

30-
override fun createFontInfo() = STBTTFontinfo.malloc().address()
30+
override fun font_CreateFontInfo() = STBTTFontinfo.malloc().address()
3131

32-
override fun createPackRange() = STBTTPackRange.malloc().address()
32+
override fun font_CreatePackRange() = STBTTPackRange.malloc().address()
3333

34-
override fun createPackedCharArray(capacity: Int) = STBTTPackedchar.malloc(capacity).address()
34+
override fun font_CreatePackedCharArray(capacity: Int) = STBTTPackedchar.malloc(capacity).address()
3535

36-
override fun createPackContext() = STBTTPackContext.malloc().address()
36+
override fun font_CreatePackContext() = STBTTPackContext.malloc().address()
3737

38-
override fun initFont(info: Long, data: ByteBuffer) = nstbtt_InitFont(info, MemoryUtil.memAddress(data), 0) != 0
38+
override fun font_InitFont(info: Long, data: ByteBuffer) = nstbtt_InitFont(info, MemoryUtil.memAddress(data), 0) != 0
3939

4040
override fun font_ScaleForMappingEmToPixels(info: Long, pixels: Float) =
4141
nstbtt_ScaleForMappingEmToPixels(info, pixels)

0 commit comments

Comments
 (0)