Skip to content

Commit c73fa83

Browse files
committed
fix: keep devtools and avoid font reload gl regressions
1 parent 59aa6be commit c73fa83

15 files changed

Lines changed: 162 additions & 364 deletions

File tree

src/main/java/top/fpsmaster/features/impl/render/DragonWings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private void renderWings(EntityPlayer player, float partialTicks) {
139139
}
140140
GL11.glCullFace(1029);
141141
GL11.glDisable(GL11.GL_CULL_FACE);
142-
GL11.glColor3f(1.0F, 1.0F, 1.0F);
142+
GL11.glColor3f(255F, 255F, 255F);
143143
GL11.glPopMatrix();
144144
}
145145

src/main/java/top/fpsmaster/features/impl/render/MotionBlur.java

Lines changed: 39 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -125,81 +125,55 @@ private boolean isUsingShader() {
125125
public void onDisable() {
126126
super.onDisable();
127127
Minecraft.getMinecraft().entityRenderer.stopUseShader();
128-
releaseBuffers();
129128
}
130129

131130
public static void blur(float multiplier) {
132131
if (OpenGlHelper.isFramebufferEnabled()) {
133132
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
134133
int width = Minecraft.getMinecraft().getFramebuffer().framebufferWidth;
135134
int height = Minecraft.getMinecraft().getFramebuffer().framebufferHeight;
136-
float scaledWidth = width / (float) sr.getScaleFactor();
137-
float scaledHeight = height / (float) sr.getScaleFactor();
138135

139136
GlStateManager.matrixMode(GL11.GL_PROJECTION);
140-
GL11.glPushMatrix();
137+
GlStateManager.loadIdentity();
138+
GlStateManager.ortho(0.0, (double) width / sr.getScaleFactor(), (double) height / sr.getScaleFactor(), 0.0, 2000.0, 4000.0);
141139
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
142-
GL11.glPushMatrix();
143-
try {
144-
GlStateManager.matrixMode(GL11.GL_PROJECTION);
145-
GlStateManager.loadIdentity();
146-
GlStateManager.ortho(0.0, scaledWidth, scaledHeight, 0.0, 2000.0, 4000.0);
147-
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
148-
GlStateManager.loadIdentity();
149-
GlStateManager.translate(0f, 0f, -2000f);
150-
151-
blurBufferMain = checkFramebufferSizes(blurBufferMain, width, height);
152-
blurBufferInto = checkFramebufferSizes(blurBufferInto, width, height);
153-
154-
blurBufferInto.framebufferClear();
155-
blurBufferInto.bindFramebuffer(true);
156-
157-
OpenGlHelper.glBlendFunc(770, 771, 0, 1);
158-
GlStateManager.disableLighting();
159-
GlStateManager.disableFog();
160-
GlStateManager.disableBlend();
161-
162-
Minecraft.getMinecraft().getFramebuffer().bindFramebufferTexture();
163-
GlStateManager.color(1f, 1f, 1f, 1f);
164-
drawTexturedRectNoBlend(0f, 0f, scaledWidth, scaledHeight, 0f, 1f, 0f, 1f, 9728);
165-
166-
GlStateManager.enableBlend();
167-
blurBufferMain.bindFramebufferTexture();
168-
GlStateManager.color(1f, 1f, 1f, multiplier / 10 - 0.1f);
169-
drawTexturedRectNoBlend(0f, 0f, scaledWidth, scaledHeight, 0f, 1f, 1f, 0f, 9728);
170-
171-
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true);
172-
blurBufferInto.bindFramebufferTexture();
173-
GlStateManager.color(1f, 1f, 1f, 1f);
174-
GlStateManager.enableBlend();
175-
OpenGlHelper.glBlendFunc(770, 771, 1, 771);
176-
drawTexturedRectNoBlend(0f, 0f, scaledWidth, scaledHeight, 0f, 1f, 0f, 1f, 9728);
177-
178-
Framebuffer tempBuff = blurBufferMain;
179-
blurBufferMain = blurBufferInto;
180-
blurBufferInto = tempBuff;
181-
} finally {
182-
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true);
183-
GlStateManager.color(1f, 1f, 1f, 1f);
184-
GlStateManager.enableTexture2D();
185-
GlStateManager.enableBlend();
186-
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
187-
GL11.glPopMatrix();
188-
GlStateManager.matrixMode(GL11.GL_PROJECTION);
189-
GL11.glPopMatrix();
190-
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
191-
}
192-
}
193-
}
194-
195-
private static void releaseBuffers() {
196-
if (blurBufferMain != null) {
197-
blurBufferMain.deleteFramebuffer();
198-
blurBufferMain = null;
199-
}
200-
if (blurBufferInto != null) {
201-
blurBufferInto.deleteFramebuffer();
202-
blurBufferInto = null;
140+
GlStateManager.loadIdentity();
141+
GlStateManager.translate(0f, 0f, -2000f);
142+
143+
blurBufferMain = checkFramebufferSizes(blurBufferMain, width, height);
144+
blurBufferInto = checkFramebufferSizes(blurBufferInto, width, height);
145+
146+
blurBufferInto.framebufferClear();
147+
blurBufferInto.bindFramebuffer(true);
148+
149+
OpenGlHelper.glBlendFunc(770, 771, 0, 1); // GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
150+
GlStateManager.disableLighting();
151+
GlStateManager.disableFog();
152+
GlStateManager.disableBlend();
153+
154+
Minecraft.getMinecraft().getFramebuffer().bindFramebufferTexture();
155+
GlStateManager.color(1f, 1f, 1f, 1f);
156+
drawTexturedRectNoBlend(0f, 0f, width / sr.getScaleFactor(), height / sr.getScaleFactor(),
157+
0f, 1f, 0f, 1f, 9728);
158+
159+
GlStateManager.enableBlend();
160+
blurBufferMain.bindFramebufferTexture();
161+
GlStateManager.color(1f, 1f, 1f, multiplier / 10 - 0.1f);
162+
drawTexturedRectNoBlend(0f, 0f, width / sr.getScaleFactor(), height / sr.getScaleFactor(),
163+
0f, 1f, 1f, 0f, 9728);
164+
165+
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true);
166+
blurBufferInto.bindFramebufferTexture();
167+
GlStateManager.color(1f, 1f, 1f, 1f);
168+
GlStateManager.enableBlend();
169+
OpenGlHelper.glBlendFunc(770, 771, 1, 771);
170+
171+
drawTexturedRectNoBlend(0f, 0f, width / sr.getScaleFactor(), height / sr.getScaleFactor(),
172+
0f, 1f, 0f, 1f, 9728);
173+
174+
Framebuffer tempBuff = blurBufferMain;
175+
blurBufferMain = blurBufferInto;
176+
blurBufferInto = tempBuff;
203177
}
204178
}
205179
}

src/main/java/top/fpsmaster/font/EnhancedFontRenderer.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public CachedString get(StringHash key) {
5959
public void cache(StringHash key, CachedString value) {
6060
int maxCacheSize = 5000;
6161
if (stringCache.size() >= maxCacheSize) {
62-
releaseCachedLists();
62+
stringCache.clear();
6363
}
6464
stringCache.put(key, value);
6565
}
@@ -69,25 +69,13 @@ public Map<String, Integer> getStringWidthCache() {
6969
}
7070

7171
public void invalidateAll() {
72-
releaseCachedLists();
7372
this.stringCache.clear();
7473
this.stringWidthCache.clear();
7574
this.obfuscated.clear();
7675
}
7776

7877
public void releaseAll() {
7978
invalidateAll();
80-
Integer listId;
81-
while ((listId = glRemoval.poll()) != null) {
82-
GLAllocation.deleteDisplayLists(listId);
83-
}
84-
}
85-
86-
private void releaseCachedLists() {
87-
for (CachedString cachedString : stringCache.values()) {
88-
GLAllocation.deleteDisplayLists(cachedString.getListId());
89-
}
90-
this.stringCache.clear();
9179
}
9280

9381
public List<StringHash> getObfuscated() {

src/main/java/top/fpsmaster/font/FontManager.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package top.fpsmaster.font;
22

3-
import top.fpsmaster.font.FontRendererHook;
43
import top.fpsmaster.font.impl.UFontRenderer;
54

65
import java.util.HashMap;
@@ -18,8 +17,6 @@ public class FontManager {
1817
public UFontRenderer s40;
1918

2019
public void load(){
21-
releaseFonts();
22-
fonts.clear();
2320
s14 = new UFontRenderer("NotoSansSC-Regular",14);
2421
s16 = new UFontRenderer("NotoSansSC-Regular",16);
2522
s18 = new UFontRenderer("NotoSansSC-Regular",18);
@@ -29,8 +26,6 @@ public void load(){
2926
s28 = new UFontRenderer("NotoSansSC-Regular",28);
3027
s36 = new UFontRenderer("NotoSansSC-Regular",36);
3128
s40 = new UFontRenderer("NotoSansSC-Regular",40);
32-
EnhancedFontRenderer.releaseAllInstances();
33-
FontRendererHook.forceRefresh = true;
3429
}
3530

3631
HashMap<Integer, UFontRenderer> fonts = new HashMap<>();
@@ -43,27 +38,6 @@ public UFontRenderer getFont(int size) {
4338
fonts.put(size, harmonyBold);
4439
return harmonyBold;
4540
}
46-
47-
private void releaseFonts() {
48-
destroyFont(s14);
49-
destroyFont(s16);
50-
destroyFont(s18);
51-
destroyFont(s20);
52-
destroyFont(s22);
53-
destroyFont(s24);
54-
destroyFont(s28);
55-
destroyFont(s36);
56-
destroyFont(s40);
57-
for (UFontRenderer font : fonts.values()) {
58-
destroyFont(font);
59-
}
60-
}
61-
62-
private void destroyFont(UFontRenderer font) {
63-
if (font != null) {
64-
font.destroy();
65-
}
66-
}
6741
}
6842

6943

src/main/java/top/fpsmaster/font/FontRendererHook.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ private void deleteTextureId() {
103103
}
104104
}
105105

106-
public void release() {
107-
deleteTextureId();
108-
enhancedFontRenderer.releaseAll();
109-
forceRefresh = true;
110-
}
111-
112106
public static String clearColorReset(String text) {
113107
int startIndex = 0;
114108
int endIndex = text.length();

src/main/java/top/fpsmaster/font/impl/GlyphCache.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,6 @@ private void allocateGlyphCacheTexture() {
589589
/* Initialize the background to all white but fully transparent. */
590590
glyphCacheGraphics.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
591591

592-
if (textureName != 0) {
593-
GL11.glDeleteTextures(textureName);
594-
textureName = 0;
595-
}
596-
597592
/* Allocate new OpenGL texure */
598593
singleIntBuffer.clear();
599594
GL11.glGenTextures(singleIntBuffer);
@@ -680,24 +675,6 @@ public int loadGlTexture(BufferedImage bufferedImage) {
680675
return textureId;
681676
}
682677

683-
void destroy() {
684-
if (stringGraphics != null) {
685-
stringGraphics.dispose();
686-
stringGraphics = null;
687-
}
688-
glyphCacheGraphics.dispose();
689-
glyphCache.clear();
690-
fontCache.clear();
691-
usedFonts.clear();
692-
cachePosX = GLYPH_BORDER;
693-
cachePosY = GLYPH_BORDER;
694-
cacheLineHeight = 0;
695-
if (textureName != 0) {
696-
GL11.glDeleteTextures(textureName);
697-
textureName = 0;
698-
}
699-
}
700-
701678
}
702679

703680

src/main/java/top/fpsmaster/font/impl/StringCache.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,6 @@ public void setDefaultFont(Font font, int fontSize, boolean antiAlias) {
388388
cacheDightGlyphs();
389389
}
390390

391-
public void destroy() {
392-
weakRefCache.clear();
393-
stringCache.clear();
394-
glyphCache.destroy();
395-
}
396-
397391
/**
398392
* Pre-cache the ASCII digits to allow for fast glyph substitution. Called once from the constructor and called any time the font selection
399393
* changes at runtime via setDefaultFont().

src/main/java/top/fpsmaster/font/impl/UFontRenderer.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,6 @@ public float drawStringCapableWithEmojiWithShadow(String text, float x, float y,
243243
}
244244
return drawStringWithShadow(text, x, y, color);
245245
}
246-
247-
public void destroy() {
248-
if (stringCache != null) {
249-
stringCache.destroy();
250-
stringCache = null;
251-
}
252-
}
253246
}
254247

255248

src/main/java/top/fpsmaster/forge/mixin/MixinFontRender.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.spongepowered.asm.mixin.injection.Inject;
1111
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1212
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13-
import top.fpsmaster.FPSMaster;
1413
import top.fpsmaster.features.impl.optimizes.Performance;
1514
import top.fpsmaster.font.FontRendererHook;
1615
import top.fpsmaster.modules.client.GlobalTextFilter;
@@ -76,11 +75,8 @@ public void getStringWidth(String text, CallbackInfoReturnable<Integer> cir) {
7675
}
7776

7877
@Inject(method = "onResourceManagerReload", at = @At("HEAD"))
79-
private void patcher$releaseFontCaches(CallbackInfo ci) {
80-
this.patcher$fontRendererHook.release();
81-
if (FPSMaster.fontManager != null) {
82-
FPSMaster.fontManager.load();
83-
}
78+
private void patcher$markFontRefresh(CallbackInfo ci) {
79+
FontRendererHook.forceRefresh = true;
8480
}
8581

8682
/**

0 commit comments

Comments
 (0)