2626
2727package org .polyfrost .oneconfig .api .ui .v1 .internal .wrappers ;
2828
29+ import dev .deftu .omnicore .api .client .framebuffer .ManagedFramebuffer ;
30+ import dev .deftu .omnicore .api .client .framebuffer .OmniFramebuffer ;
2931import dev .deftu .omnicore .api .client .input .KeyboardModifiers ;
3032import dev .deftu .omnicore .api .client .input .OmniKey ;
3133import dev .deftu .omnicore .api .client .input .OmniKeys ;
3234import dev .deftu .omnicore .api .client .input .OmniMouseButton ;
3335import dev .deftu .omnicore .api .client .render .OmniRenderingContext ;
36+ import dev .deftu .omnicore .api .client .render .OmniResolution ;
3437import dev .deftu .omnicore .api .client .screen .KeyPressEvent ;
3538import dev .deftu .omnicore .api .client .screen .OmniScreen ;
3639import dev .deftu .textile .Text ;
40+ import dev .deftu .omnicore .api .client .textures .OmniTextureFormat ;
41+ import dev .deftu .omnicore .api .color .OmniColors ;
42+ import kotlin .Unit ;
3743import net .minecraft .client .Minecraft ;
3844import org .apache .logging .log4j .LogManager ;
3945import org .apache .logging .log4j .Logger ;
4046import org .jetbrains .annotations .MustBeInvokedByOverriders ;
4147import org .jetbrains .annotations .NotNull ;
42- import org .lwjgl .BufferUtils ;
4348import org .polyfrost .oneconfig .api .platform .v1 .Platform ;
4449import org .polyfrost .oneconfig .api .ui .v1 .Notifications ;
4550import org .polyfrost .oneconfig .api .ui .v1 .UIManager ;
4853import org .polyfrost .polyui .component .Drawable ;
4954import org .polyfrost .polyui .data .Cursor ;
5055
51- import java .nio .Buffer ;
52- import java .nio .IntBuffer ;
5356import java .util .function .Consumer ;
5457
55- import static org .lwjgl .opengl .GL11 .*;
5658import static org .polyfrost .oneconfig .api .ui .v1 .keybind .KeybindManager .translateKey ;
5759
5860@ SuppressWarnings ("unused" )
@@ -62,16 +64,11 @@ public class PolyUIScreen extends OmniScreen implements BlurScreen {
6264 @ NotNull
6365 public final PolyUI polyUI ;
6466
67+ private OmniFramebuffer framebuffer ;
68+
6569 private final float designedWidth , designedHeight , initialWidth , initialHeight ;
6670 private final boolean pauses , blurs ;
6771 private final Consumer <PolyUI > close ;
68- private final IntBuffer VIEWPORT = BufferUtils .createIntBuffer (
69- //#if MC >= 1.13
70- //$$ 4
71- //#else
72- 16
73- //#endif
74- );
7572
7673 //#if MC < 1.13
7774 private int mx , my ;
@@ -121,28 +118,42 @@ public void onRender(@NotNull OmniRenderingContext ctx, int mouseX, int mouseY,
121118 }
122119
123120 //#endif
124- if (polyUI == UIManager .INSTANCE .getDefaultInstance ()) {
121+ if (framebuffer == null || polyUI == UIManager .INSTANCE .getDefaultInstance ()) {
125122 return ;
126123 }
127124
125+ Drawable master = polyUI .getMaster ();
126+
128127 try {
129- ((Buffer ) VIEWPORT ).clear ();
130- //#if MC >= 1.13
131- //$$ glGetIntegerv(GL_VIEWPORT, VIEWPORT);
132- //#else
133- glGetInteger (GL_VIEWPORT , VIEWPORT );
134- //#endif
135- int w = (int ) polyUI .getMaster ().getWidth ();
136- int h = (int ) polyUI .getMaster ().getHeight ();
137- int x = Platform .screen ().windowWidth () / 2 - w / 2 ;
138- int y = Platform .screen ().windowHeight () / 2 - h / 2 ;
139- glViewport (x , y , w , h );
140- polyUI .render ();
141- glViewport (VIEWPORT .get (), VIEWPORT .get (), VIEWPORT .get (), VIEWPORT .get ());
128+ framebuffer .clearColor (0f , 0f , 0f , 0f ); // Clear to transparent black
129+ if (framebuffer instanceof ManagedFramebuffer ) {
130+ ((ManagedFramebuffer ) framebuffer ).clearDepthStencil (1.0 , 0 );
131+ }
132+
133+ framebuffer .usingToRender ((matrixStack , w , h ) -> {
134+ matrixStack .runReplacingGlobalState (polyUI ::render );
135+ return Unit .INSTANCE ;
136+ });
142137 } catch (Exception e ) {
143138 polyUI .getRenderer ().endFrame ();
144139 death (e );
145140 }
141+
142+ float ratio = Platform .screen ().pixelRatio ();
143+ float scalingFactor = 1f / (float ) OmniResolution .getScaleFactor ();
144+
145+ float scaledX = (Platform .screen ().viewportWidth () / 2f - master .getWidth () * ratio / 2f ) * scalingFactor ;
146+ float scaledY = (Platform .screen ().viewportHeight () / 2f - master .getHeight () * ratio / 2f ) * scalingFactor ;
147+ float scaledWidth = master .getWidth () * scalingFactor * ratio ;
148+ float scaledHeight = master .getHeight () * scalingFactor * ratio ;
149+
150+ framebuffer .drawColorTexture (
151+ UIManager .INSTANCE .getRenderPipeline (),
152+ ctx .pose (),
153+ scaledX , scaledY ,
154+ scaledWidth , scaledHeight ,
155+ OmniColors .WHITE
156+ );
146157 }
147158
148159 @ Override
@@ -272,6 +283,11 @@ public void onScreenClose() {
272283 }
273284
274285 protected final void adjustResolution (float w , float h , boolean force ) {
286+ if (this .framebuffer == null ) {
287+ int width = Platform .screen ().viewportWidth ();
288+ int height = Platform .screen ().viewportHeight ();
289+ this .framebuffer = new ManagedFramebuffer (width , height , OmniTextureFormat .RGBA8 , OmniTextureFormat .DEPTH24_STENCIL8 );
290+ }
275291
276292 // asm: normally, a polyui instance is as big as its window and that is it.
277293 // however, inside minecraft, the actual content is smaller than the window size, so resizing it directly would just fuck it up.
@@ -291,6 +307,7 @@ protected final void adjustResolution(float w, float h, boolean force) {
291307 // framebuffer should you know probably be the correct larger size because.. well yeah of course it does
292308 // didn't anyone think of that?
293309 polyUI .resize (initialWidth * sx , initialHeight * sy , force );
310+ framebuffer .resize ((int ) (polyUI .getMaster ().getWidth () * ratio ), (int ) (polyUI .getMaster ().getHeight () * ratio ));
294311 polyUI .getWindow ().setPixelRatio (ratio );
295312 } catch (Exception e ) {
296313 death (e );
0 commit comments