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 ;
3129import dev .deftu .omnicore .api .client .input .KeyboardModifiers ;
3230import dev .deftu .omnicore .api .client .input .OmniKey ;
3331import dev .deftu .omnicore .api .client .input .OmniKeys ;
3432import dev .deftu .omnicore .api .client .input .OmniMouseButton ;
3533import dev .deftu .omnicore .api .client .render .OmniRenderingContext ;
36- import dev .deftu .omnicore .api .client .render .OmniResolution ;
3734import dev .deftu .omnicore .api .client .screen .KeyPressEvent ;
3835import dev .deftu .omnicore .api .client .screen .OmniScreen ;
3936import 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 ;
4337import net .minecraft .client .Minecraft ;
4438import org .apache .logging .log4j .LogManager ;
4539import org .apache .logging .log4j .Logger ;
4640import org .jetbrains .annotations .MustBeInvokedByOverriders ;
4741import org .jetbrains .annotations .NotNull ;
42+ import org .lwjgl .BufferUtils ;
4843import org .polyfrost .oneconfig .api .platform .v1 .Platform ;
4944import org .polyfrost .oneconfig .api .ui .v1 .Notifications ;
5045import org .polyfrost .oneconfig .api .ui .v1 .UIManager ;
5348import org .polyfrost .polyui .component .Drawable ;
5449import org .polyfrost .polyui .data .Cursor ;
5550
51+ import java .nio .Buffer ;
52+ import java .nio .IntBuffer ;
5653import java .util .function .Consumer ;
5754
55+ import static org .lwjgl .opengl .GL11 .*;
5856import static org .polyfrost .oneconfig .api .ui .v1 .keybind .KeybindManager .translateKey ;
5957
6058@ SuppressWarnings ("unused" )
@@ -64,11 +62,16 @@ public class PolyUIScreen extends OmniScreen implements BlurScreen {
6462 @ NotNull
6563 public final PolyUI polyUI ;
6664
67- private OmniFramebuffer framebuffer ;
68-
6965 private final float designedWidth , designedHeight , initialWidth , initialHeight ;
7066 private final boolean pauses , blurs ;
7167 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+ );
7275
7376 //#if MC < 1.13
7477 private int mx , my ;
@@ -118,42 +121,28 @@ public void onRender(@NotNull OmniRenderingContext ctx, int mouseX, int mouseY,
118121 }
119122
120123 //#endif
121- if (framebuffer == null || polyUI == UIManager .INSTANCE .getDefaultInstance ()) {
124+ if (polyUI == UIManager .INSTANCE .getDefaultInstance ()) {
122125 return ;
123126 }
124127
125- Drawable master = polyUI .getMaster ();
126-
127128 try {
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- });
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 ());
137142 } catch (Exception e ) {
138143 polyUI .getRenderer ().endFrame ();
139144 death (e );
140145 }
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- );
157146 }
158147
159148 @ Override
@@ -283,11 +272,6 @@ public void onScreenClose() {
283272 }
284273
285274 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- }
291275
292276 // asm: normally, a polyui instance is as big as its window and that is it.
293277 // however, inside minecraft, the actual content is smaller than the window size, so resizing it directly would just fuck it up.
@@ -307,7 +291,6 @@ protected final void adjustResolution(float w, float h, boolean force) {
307291 // framebuffer should you know probably be the correct larger size because.. well yeah of course it does
308292 // didn't anyone think of that?
309293 polyUI .resize (initialWidth * sx , initialHeight * sy , force );
310- framebuffer .resize ((int ) (polyUI .getMaster ().getWidth () * ratio ), (int ) (polyUI .getMaster ().getHeight () * ratio ));
311294 polyUI .getWindow ().setPixelRatio (ratio );
312295 } catch (Exception e ) {
313296 death (e );
0 commit comments