FontTexture.java
net.minecraft.client.gui.font.FontTexture
信息
- 全限定名:net.minecraft.client.gui.font.FontTexture
- 类型:public class
- 包:net.minecraft.client.gui.font
- 源码路径:src/main/java/net/minecraft/client/gui/font/FontTexture.java
- 起始行号:L21
- 继承:AbstractTexture
- 实现:Dumpable
- 职责:
TODO
字段/常量
-
SIZE- 类型:
int - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
renderTypes- 类型:
GlyphRenderTypes - 修饰符:
private final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
colored- 类型:
boolean - 修饰符:
private final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
root- 类型:
FontTexture.Node - 修饰符:
private final - 源码定位:
L25 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.gui.font.FontTexture.Node- 类型:
class - 修饰符:
private static - 源码定位:
L75 - 说明:
TODO
- 类型:
构造器
public FontTexture(Supplier<String> label, GlyphRenderTypes renderTypes, boolean colored) @ L27
- 构造器名:FontTexture
- 源码定位:L27
- 修饰符:public
参数:
- label: Supplier
- renderTypes: GlyphRenderTypes
- colored: boolean
说明:
TODO
方法
下面的方法块按源码顺序生成。
public BakedSheetGlyph add(GlyphInfo info, GlyphBitmap glyph) @ L37
- 方法名:add
- 源码定位:L37
- 返回类型:BakedSheetGlyph
- 修饰符:public
参数:
- info: GlyphInfo
- glyph: GlyphBitmap
说明:
TODO
public void dumpContents(Identifier selfId, Path dir) @ L66
- 方法名:dumpContents
- 源码定位:L66
- 返回类型:void
- 修饰符:public
参数:
- selfId: Identifier
- dir: Path
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class FontTexture extends AbstractTexture implements Dumpable {
private static final int SIZE = 256;
private final GlyphRenderTypes renderTypes;
private final boolean colored;
private final FontTexture.Node root;
public FontTexture(Supplier<String> label, GlyphRenderTypes renderTypes, boolean colored) {
this.colored = colored;
this.root = new FontTexture.Node(0, 0, 256, 256);
GpuDevice device = RenderSystem.getDevice();
this.texture = device.createTexture(label, 7, colored ? TextureFormat.RGBA8 : TextureFormat.RED8, 256, 256, 1, 1);
this.sampler = RenderSystem.getSamplerCache().getRepeat(FilterMode.NEAREST);
this.textureView = device.createTextureView(this.texture);
this.renderTypes = renderTypes;
}
public @Nullable BakedSheetGlyph add(GlyphInfo info, GlyphBitmap glyph) {
if (glyph.isColored() != this.colored) {
return null;
} else {
FontTexture.Node node = this.root.insert(glyph);
if (node != null) {
glyph.upload(node.x, node.y, this.getTexture());
float width = 256.0F;
float height = 256.0F;
float nudge = 0.01F;
return new BakedSheetGlyph(
info,
this.renderTypes,
this.getTextureView(),
(node.x + 0.01F) / 256.0F,
(node.x - 0.01F + glyph.getPixelWidth()) / 256.0F,
(node.y + 0.01F) / 256.0F,
(node.y - 0.01F + glyph.getPixelHeight()) / 256.0F,
glyph.getLeft(),
glyph.getRight(),
glyph.getTop(),
glyph.getBottom()
);
} else {
return null;
}
}
}
@Override
public void dumpContents(Identifier selfId, Path dir) {
if (this.texture != null) {
String outputId = selfId.toDebugFileName();
TextureUtil.writeAsPNG(dir, outputId, this.texture, 0, argb -> (argb & 0xFF000000) == 0 ? -16777216 : argb);
}
}
@OnlyIn(Dist.CLIENT)
private static class Node {
private final int x;
private final int y;
private final int width;
private final int height;
private FontTexture.@Nullable Node left;
private FontTexture.@Nullable Node right;
private boolean occupied;
private Node(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
FontTexture.@Nullable Node insert(GlyphBitmap glyph) {
if (this.left != null && this.right != null) {
FontTexture.Node newNode = this.left.insert(glyph);
if (newNode == null) {
newNode = this.right.insert(glyph);
}
return newNode;
} else if (this.occupied) {
return null;
} else {
int glyphWidth = glyph.getPixelWidth();
int glyphHeight = glyph.getPixelHeight();
if (glyphWidth > this.width || glyphHeight > this.height) {
return null;
} else if (glyphWidth == this.width && glyphHeight == this.height) {
this.occupied = true;
return this;
} else {
int deltaWidth = this.width - glyphWidth;
int deltaHeight = this.height - glyphHeight;
if (deltaWidth > deltaHeight) {
this.left = new FontTexture.Node(this.x, this.y, glyphWidth, this.height);
this.right = new FontTexture.Node(this.x + glyphWidth + 1, this.y, this.width - glyphWidth - 1, this.height);
} else {
this.left = new FontTexture.Node(this.x, this.y, this.width, glyphHeight);
this.right = new FontTexture.Node(this.x, this.y + glyphHeight + 1, this.width, this.height - glyphHeight - 1);
}
return this.left.insert(glyph);
}
}
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TextureUtil.writeAsPNG()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RenderSystem.getDevice(), RenderSystem.getSamplerCache()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
构造调用/返回值 - 关联成员:
BakedSheetGlyph()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
实现
- 引用位置:
-
- 引用位置:
参数
- 引用位置: