VertexFormatElement.java

com.mojang.blaze3d.vertex.VertexFormatElement

信息

  • 全限定名:com.mojang.blaze3d.vertex.VertexFormatElement
  • 类型:public record
  • 包:com.mojang.blaze3d.vertex
  • 源码路径:src/main/java/com/mojang/blaze3d/vertex/VertexFormatElement.java
  • 起始行号:L11
  • 职责:

    TODO

字段/常量

  • MAX_COUNT

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L12
    • 说明:

      TODO

  • BY_ID

    • 类型: VertexFormatElement[]
    • 修饰符: private static final
    • 源码定位: L13
    • 说明:

      TODO

  • ELEMENTS

    • 类型: List<VertexFormatElement>
    • 修饰符: private static final
    • 源码定位: L14
    • 说明:

      TODO

  • POSITION

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L15
    • 说明:

      TODO

  • COLOR

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L16
    • 说明:

      TODO

  • UV0

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L17
    • 说明:

      TODO

  • UV

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L18
    • 说明:

      TODO

  • UV1

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L19
    • 说明:

      TODO

  • UV2

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L20
    • 说明:

      TODO

  • NORMAL

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L21
    • 说明:

      TODO

  • LINE_WIDTH

    • 类型: VertexFormatElement
    • 修饰符: public static final
    • 源码定位: L22
    • 说明:

      TODO

内部类/嵌套类型

  • com.mojang.blaze3d.vertex.VertexFormatElement.Type
    • 类型: enum
    • 修饰符: public static
    • 源码定位: L70
    • 说明:

      TODO

构造器

public VertexFormatElement(int id, int index, VertexFormatElement.Type type, boolean normalized, int count) @ L24

  • 构造器名:VertexFormatElement
  • 源码定位:L24
  • 修饰符:public

参数:

  • id: int
  • index: int
  • type: VertexFormatElement.Type
  • normalized: boolean
  • count: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

public static VertexFormatElement register(int id, int index, VertexFormatElement.Type type, boolean normalized, int count) @ L36

  • 方法名:register
  • 源码定位:L36
  • 返回类型:VertexFormatElement
  • 修饰符:public static

参数:

  • id: int
  • index: int
  • type: VertexFormatElement.Type
  • normalized: boolean
  • count: int

说明:

TODO

public String toString() @ L47

  • 方法名:toString
  • 源码定位:L47
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

public int mask() @ L53

  • 方法名:mask
  • 源码定位:L53
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public int byteSize() @ L57

  • 方法名:byteSize
  • 源码定位:L57
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public static VertexFormatElement byId(int id) @ L61

  • 方法名:byId
  • 源码定位:L61
  • 返回类型:VertexFormatElement
  • 修饰符:public static

参数:

  • id: int

说明:

TODO

public static Stream<VertexFormatElement> elementsFromMask(int mask) @ L65

  • 方法名:elementsFromMask
  • 源码定位:L65
  • 返回类型:Stream
  • 修饰符:public static

参数:

  • mask: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public record VertexFormatElement(int id, int index, VertexFormatElement.Type type, boolean normalized, int count) {
    public static final int MAX_COUNT = 32;
    private static final @Nullable VertexFormatElement[] BY_ID = new VertexFormatElement[32];
    private static final List<VertexFormatElement> ELEMENTS = new ArrayList<>(32);
    public static final VertexFormatElement POSITION = register(0, 0, VertexFormatElement.Type.FLOAT, false, 3);
    public static final VertexFormatElement COLOR = register(1, 0, VertexFormatElement.Type.UBYTE, true, 4);
    public static final VertexFormatElement UV0 = register(2, 0, VertexFormatElement.Type.FLOAT, false, 2);
    public static final VertexFormatElement UV = UV0;
    public static final VertexFormatElement UV1 = register(3, 1, VertexFormatElement.Type.SHORT, false, 2);
    public static final VertexFormatElement UV2 = register(4, 2, VertexFormatElement.Type.SHORT, false, 2);
    public static final VertexFormatElement NORMAL = register(5, 0, VertexFormatElement.Type.BYTE, true, 3);
    public static final VertexFormatElement LINE_WIDTH = register(6, 0, VertexFormatElement.Type.FLOAT, false, 1);
 
    public VertexFormatElement(int id, int index, VertexFormatElement.Type type, boolean normalized, int count) {
        if (id >= 0 && id < BY_ID.length) {
            this.id = id;
            this.index = index;
            this.type = type;
            this.normalized = normalized;
            this.count = count;
        } else {
            throw new IllegalArgumentException("Element ID must be in range [0; " + BY_ID.length + ")");
        }
    }
 
    public static VertexFormatElement register(int id, int index, VertexFormatElement.Type type, boolean normalized, int count) {
        VertexFormatElement element = new VertexFormatElement(id, index, type, normalized, count);
        if (BY_ID[id] != null) {
            throw new IllegalArgumentException("Duplicate element registration for: " + id);
        } else {
            BY_ID[id] = element;
            ELEMENTS.add(element);
            return element;
        }
    }
 
    @Override
    public String toString() {
        String string = this.count + "x" + this.type + " (" + this.id + ")";
        return this.normalized ? "normalized " + string : string;
    }
 
    public int mask() {
        return 1 << this.id;
    }
 
    public int byteSize() {
        return this.type.size() * this.count;
    }
 
    public static @Nullable VertexFormatElement byId(int id) {
        return BY_ID[id];
    }
 
    public static Stream<VertexFormatElement> elementsFromMask(int mask) {
        return ELEMENTS.stream().filter(element -> (mask & element.mask()) != 0);
    }
 
    @OnlyIn(Dist.CLIENT)
    public static enum Type {
        FLOAT(4, "Float"),
        UBYTE(1, "Unsigned Byte"),
        BYTE(1, "Byte"),
        USHORT(2, "Unsigned Short"),
        SHORT(2, "Short"),
        UINT(4, "Unsigned Int"),
        INT(4, "Int");
 
        private final int size;
        private final String name;
 
        private Type(int size, String name) {
            this.size = size;
            this.name = name;
        }
 
        public int size() {
            return this.size;
        }
 
        @Override
        public String toString() {
            return this.name;
        }
    }
}

引用的其他类