Fix: Restore correct rounded-rect corners on 26.2

- V26_2TextureHelper.create now takes raw RGBA again, so V26_2ShapeCache's quarter-circle corner textures are uploaded intact instead of being read as one-byte coverage and appearing grey

- Add an explicit createFromCoverage entry point for font atlases, which still expands directly into the NativeImage buffer

- Point V26_2FontBackend at createFromCoverage so the font texture optimisation is kept
This commit is contained in:
xiaozhou233 committed 2026-11-08 01:55:41 +08:00
1 parent 6a045fd46f
commit 8183eae9d1
2 files changed
+39 -12

No files matched your search

@@ -30,7 +30,7 @@ public final class V26_2FontBackend implements FontBackend {
int height = atlas.getHeight(); int height = atlas.getHeight();
byte[] coverage = atlas.getPixels(); byte[] coverage = atlas.getPixels();
V26_2GpuTexture texture = V26_2TextureHelper.create( V26_2GpuTexture texture = V26_2TextureHelper.createFromCoverage(
loader, width, height, coverage); loader, width, height, coverage);
return new V26_2FontTexture(texture.texture, texture.textureView, return new V26_2FontTexture(texture.texture, texture.textureView,
texture.sampler, width, height); texture.sampler, width, height);
@@ -5,13 +5,43 @@ import java.nio.ByteBuffer;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
* Creates a {@code DynamicTexture} from an RGBA byte array without linking * Creates a {@code DynamicTexture} without linking against Mojang's classes.
* against Mojang's classes. *
* <p>Two input formats are supported so callers cannot mix them up: raw RGBA
* (shapes, sprites) and one-byte coverage/font atlases, which are expanded to
* white RGB + coverage alpha directly inside the {@code NativeImage} buffer.</p>
*/ */
final class V26_2TextureHelper { final class V26_2TextureHelper {
static V26_2GpuTexture create(ClassLoader loader, int width, int height, static V26_2GpuTexture create(ClassLoader loader, int width, int height,
byte[] coverage) { final byte[] rgba) {
return create(loader, width, height, new PixelWriter() {
@Override
public void write(ByteBuffer buffer) {
buffer.put(rgba);
}
});
}
static V26_2GpuTexture createFromCoverage(ClassLoader loader, int width,
int height, final byte[] coverage) {
return create(loader, width, height, new PixelWriter() {
@Override
public void write(ByteBuffer buffer) {
// Expand straight into the NativeImage buffer: avoids a second
// full-size RGBA array on top of the atlas and the image.
for (byte alpha : coverage) {
buffer.put((byte) 0xFF);
buffer.put((byte) 0xFF);
buffer.put((byte) 0xFF);
buffer.put(alpha);
}
}
});
}
private static V26_2GpuTexture create(ClassLoader loader, int width,
int height, PixelWriter writer) {
try { try {
Class<?> nativeImageClass = Class.forName( Class<?> nativeImageClass = Class.forName(
"com.mojang.blaze3d.platform.NativeImage", false, loader); "com.mojang.blaze3d.platform.NativeImage", false, loader);
@@ -19,16 +49,9 @@ final class V26_2TextureHelper {
.getDeclaredConstructor(int.class, int.class, boolean.class); .getDeclaredConstructor(int.class, int.class, boolean.class);
Object image = nativeImageConstructor.newInstance(width, height, false); Object image = nativeImageConstructor.newInstance(width, height, false);
// Expand straight into the NativeImage buffer: avoids a second
// full-size RGBA array on top of the atlas and the image.
ByteBuffer buffer = (ByteBuffer) nativeImageClass ByteBuffer buffer = (ByteBuffer) nativeImageClass
.getMethod("getPixelBytes").invoke(image); .getMethod("getPixelBytes").invoke(image);
for (byte alpha : coverage) { writer.write(buffer);
buffer.put((byte) 0xFF);
buffer.put((byte) 0xFF);
buffer.put((byte) 0xFF);
buffer.put(alpha);
}
Class<?> dynamicTextureClass = Class.forName( Class<?> dynamicTextureClass = Class.forName(
"net.minecraft.client.renderer.texture.DynamicTexture", false, loader); "net.minecraft.client.renderer.texture.DynamicTexture", false, loader);
@@ -53,6 +76,10 @@ final class V26_2TextureHelper {
} }
} }
private interface PixelWriter {
void write(ByteBuffer buffer);
}
private V26_2TextureHelper() { private V26_2TextureHelper() {
} }
} }