Fixed MatrixStack leak on RenderScope 1.21.6 #59
This commit is contained in:
@@ -1,76 +1,44 @@
|
||||
package org.saturnclient.impl.ref;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
import org.joml.Matrix3x2fStack;
|
||||
import org.saturnclient.common.ref.render.MatrixStackRef;
|
||||
|
||||
public class Matrix3x2fStackRef implements MatrixStackRef {
|
||||
public final Matrix3x2fStack stack;
|
||||
|
||||
// Our custom stack stores the reverse transforms
|
||||
private final Deque<Transform> customStack = new ArrayDeque<>();
|
||||
|
||||
public Matrix3x2fStackRef(Matrix3x2fStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push() {
|
||||
// Push a new empty Transform
|
||||
customStack.push(new Transform());
|
||||
stack.pushMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pop() {
|
||||
if (customStack.isEmpty())
|
||||
return;
|
||||
|
||||
// Apply inverse transforms in reverse order
|
||||
Transform t = customStack.pop();
|
||||
if (t.scaleX != 1 || t.scaleY != 1)
|
||||
stack.scale(1f / t.scaleX, 1f / t.scaleY);
|
||||
stack.translate(-t.translateX, -t.translateY);
|
||||
stack.rotate(-t.rotation);
|
||||
stack.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scale(float x, float y) {
|
||||
stack.scale(x, y);
|
||||
if (!customStack.isEmpty()) {
|
||||
Transform t = customStack.peek();
|
||||
t.scaleX *= x;
|
||||
t.scaleY *= y;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(float x, float y) {
|
||||
stack.translate(x, y);
|
||||
if (!customStack.isEmpty()) {
|
||||
Transform t = customStack.peek();
|
||||
t.translateX += x;
|
||||
t.translateY += y;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle) {
|
||||
stack.rotate(angle);
|
||||
if (!customStack.isEmpty()) {
|
||||
Transform t = customStack.peek();
|
||||
t.rotation += angle;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle, float originX, float originY, float originZ) {
|
||||
}
|
||||
|
||||
private static class Transform {
|
||||
float scaleX = 1f, scaleY = 1f;
|
||||
float translateX = 0f, translateY = 0f;
|
||||
float rotation = 0f;
|
||||
translate(originX, originY);
|
||||
rotate(angle);
|
||||
translate(-originX, -originY);
|
||||
}
|
||||
}
|
||||
@@ -56,8 +56,8 @@ public class RenderScopeImpl implements RenderScope {
|
||||
}
|
||||
|
||||
public RenderScopeImpl(Matrix3x2fStack matrices, GuiRenderState state) {
|
||||
this.state = state;
|
||||
this.matrices = new Matrix3x2fStackRef(matrices);
|
||||
this.state = state;
|
||||
this.scissorStack = new ScissorStack();
|
||||
}
|
||||
|
||||
@@ -130,17 +130,21 @@ public class RenderScopeImpl implements RenderScope {
|
||||
int lineIndex = 0;
|
||||
for (String line : text.split("\n")) {
|
||||
int finalColor = getColor(color);
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(x, y + (lineIndex * Fonts.getHeight()));
|
||||
matrices.scale(scale, scale);
|
||||
|
||||
this.state.addText(
|
||||
new TextGuiElementRenderState(
|
||||
SaturnClient.client.textRenderer,
|
||||
((Text) Fonts.setFont(line, font)).asOrderedText(),
|
||||
new Matrix3x2f(this.matrices.stack),
|
||||
x, y,
|
||||
0, 0, // IMPORTANT
|
||||
finalColor, 0, false, this.scissorStack.peekLast()));
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(x, y + (lineIndex * Fonts.getHeight()));
|
||||
matrices.scale(scale, scale);
|
||||
matrices.pop();
|
||||
|
||||
lineIndex++;
|
||||
}
|
||||
}
|
||||
@@ -182,17 +186,19 @@ public class RenderScopeImpl implements RenderScope {
|
||||
return;
|
||||
radius = Math.min(radius, Math.min(width, height));
|
||||
|
||||
int cornerWidth = width / 2;
|
||||
int cornerHeight = height / 2;
|
||||
fill(x, y, x + width, y + height, color);
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(x, y);
|
||||
drawRoundedSide(cornerWidth, cornerHeight, radius, color);
|
||||
// int cornerWidth = width / 2;
|
||||
// int cornerHeight = height / 2;
|
||||
|
||||
matrices.translate(cornerWidth * 2, cornerHeight * 2);
|
||||
matrices.stack.rotate((float) Math.toRadians(90));
|
||||
drawRoundedSide(cornerWidth, cornerHeight, radius, color);
|
||||
matrices.pop();
|
||||
// matrices.push();
|
||||
// matrices.translate(x, y);
|
||||
// drawRoundedSide(cornerWidth, cornerHeight, radius, color);
|
||||
|
||||
// matrices.translate(cornerWidth * 2, cornerHeight * 2);
|
||||
// matrices.stack.rotate((float) Math.toRadians(90));
|
||||
// drawRoundedSide(cornerWidth, cornerHeight, radius, color);
|
||||
// matrices.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user