GuiItemAtlas.java

net.minecraft.client.gui.render.GuiItemAtlas

信息

  • 全限定名:net.minecraft.client.gui.render.GuiItemAtlas
  • 类型:public class
  • 包:net.minecraft.client.gui.render
  • 源码路径:src/main/java/net/minecraft/client/gui/render/GuiItemAtlas.java
  • 起始行号:L27
  • 实现:AutoCloseable
  • 职责:

    TODO

字段/常量

  • MINIMUM_TEXTURE_SIZE

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

      TODO

  • MAXIMUM_TEXTURE_SIZE

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

      TODO

  • submitNodeCollector

    • 类型: SubmitNodeCollector
    • 修饰符: private final
    • 源码定位: L30
    • 说明:

      TODO

  • featureRenderDispatcher

    • 类型: FeatureRenderDispatcher
    • 修饰符: private final
    • 源码定位: L31
    • 说明:

      TODO

  • bufferSource

    • 类型: MultiBufferSource.BufferSource
    • 修饰符: private final
    • 源码定位: L32
    • 说明:

      TODO

  • textureSize

    • 类型: int
    • 修饰符: private final
    • 源码定位: L33
    • 说明:

      TODO

  • slotTextureSize

    • 类型: int
    • 修饰符: private final
    • 源码定位: L34
    • 说明:

      TODO

  • texture

    • 类型: GpuTexture
    • 修饰符: private final
    • 源码定位: L35
    • 说明:

      TODO

  • textureView

    • 类型: GpuTextureView
    • 修饰符: private final
    • 源码定位: L36
    • 说明:

      TODO

  • depthTexture

    • 类型: GpuTexture
    • 修饰符: private final
    • 源码定位: L37
    • 说明:

      TODO

  • depthTextureView

    • 类型: GpuTextureView
    • 修饰符: private final
    • 源码定位: L38
    • 说明:

      TODO

  • allocator

    • 类型: DynamicAtlasAllocator<Object>
    • 修饰符: private final
    • 源码定位: L39
    • 说明:

      TODO

  • poseStack

    • 类型: PoseStack
    • 修饰符: private final
    • 源码定位: L40
    • 说明:

      TODO

  • projection

    • 类型: Projection
    • 修饰符: private final
    • 源码定位: L41
    • 说明:

      TODO

  • projectionMatrixBuffer

    • 类型: ProjectionMatrixBuffer
    • 修饰符: private final
    • 源码定位: L42
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.render.GuiItemAtlas.SlotView
    • 类型: record
    • 修饰符: public
    • 源码定位: L146
    • 说明:

      TODO

构造器

public GuiItemAtlas(SubmitNodeCollector submitNodeCollector, FeatureRenderDispatcher featureRenderDispatcher, MultiBufferSource.BufferSource bufferSource, int textureSize, int slotTextureSize) @ L44

  • 构造器名:GuiItemAtlas
  • 源码定位:L44
  • 修饰符:public

参数:

  • submitNodeCollector: SubmitNodeCollector
  • featureRenderDispatcher: FeatureRenderDispatcher
  • bufferSource: MultiBufferSource.BufferSource
  • textureSize: int
  • slotTextureSize: int

说明:

TODO

方法

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

public static int computeTextureSizeFor(int slotTextureSize, int requiredSlotCount) @ L66

  • 方法名:computeTextureSizeFor
  • 源码定位:L66
  • 返回类型:int
  • 修饰符:public static

参数:

  • slotTextureSize: int
  • requiredSlotCount: int

说明:

TODO

public void endFrame() @ L72

  • 方法名:endFrame
  • 源码定位:L72
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public boolean tryPrepareFor(Set<Object> items) @ L76

  • 方法名:tryPrepareFor
  • 源码定位:L76
  • 返回类型:boolean
  • 修饰符:public

参数:

  • items: Set

    说明:

    TODO

    public GuiItemAtlas.SlotView getOrUpdate(TrackingItemStackRenderState item) @ L80

    • 方法名:getOrUpdate
    • 源码定位:L80
    • 返回类型:GuiItemAtlas.SlotView
    • 修饰符:public

    参数:

    • item: TrackingItemStackRenderState

    说明:

    TODO

    private void drawToSlot(int slotX, int slotY, boolean clear, ItemStackRenderState item) @ L101

    • 方法名:drawToSlot
    • 源码定位:L101
    • 返回类型:void
    • 修饰符:private

    参数:

    • slotX: int
    • slotY: int
    • clear: boolean
    • item: ItemStackRenderState

    说明:

    TODO

    public int textureSize() @ L132

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

    参数:

    说明:

    TODO

    public void close() @ L136

    • 方法名:close
    • 源码定位:L136
    • 返回类型:void
    • 修饰符:public

    参数:

    说明:

    TODO

    代码

    @OnlyIn(Dist.CLIENT)
    public class GuiItemAtlas implements AutoCloseable {
        private static final int MINIMUM_TEXTURE_SIZE = 512;
        private static final int MAXIMUM_TEXTURE_SIZE = RenderSystem.getDevice().getMaxTextureSize();
        private final SubmitNodeCollector submitNodeCollector;
        private final FeatureRenderDispatcher featureRenderDispatcher;
        private final MultiBufferSource.BufferSource bufferSource;
        private final int textureSize;
        private final int slotTextureSize;
        private final GpuTexture texture;
        private final GpuTextureView textureView;
        private final GpuTexture depthTexture;
        private final GpuTextureView depthTextureView;
        private final DynamicAtlasAllocator<Object> allocator;
        private final PoseStack poseStack = new PoseStack();
        private final Projection projection = new Projection();
        private final ProjectionMatrixBuffer projectionMatrixBuffer = new ProjectionMatrixBuffer("items");
     
        public GuiItemAtlas(
            SubmitNodeCollector submitNodeCollector,
            FeatureRenderDispatcher featureRenderDispatcher,
            MultiBufferSource.BufferSource bufferSource,
            int textureSize,
            int slotTextureSize
        ) {
            this.submitNodeCollector = submitNodeCollector;
            this.featureRenderDispatcher = featureRenderDispatcher;
            this.bufferSource = bufferSource;
            int storageSize = textureSize / slotTextureSize;
            this.textureSize = textureSize;
            this.slotTextureSize = slotTextureSize;
            GpuDevice device = RenderSystem.getDevice();
            this.texture = device.createTexture("UI items atlas", 13, TextureFormat.RGBA8, textureSize, textureSize, 1, 1);
            this.textureView = device.createTextureView(this.texture);
            this.depthTexture = device.createTexture("UI items atlas depth", 9, TextureFormat.DEPTH32, textureSize, textureSize, 1, 1);
            this.depthTextureView = device.createTextureView(this.depthTexture);
            this.allocator = new DynamicAtlasAllocator<>(storageSize, storageSize);
            device.createCommandEncoder().clearColorAndDepthTextures(this.texture, 0, this.depthTexture, 1.0);
        }
     
        public static int computeTextureSizeFor(int slotTextureSize, int requiredSlotCount) {
            int preferredSlotCount = requiredSlotCount + requiredSlotCount / 2;
            int atlasSize = Mth.smallestSquareSide(preferredSlotCount);
            return Math.clamp((long)Mth.smallestEncompassingPowerOfTwo(atlasSize * slotTextureSize), 512, MAXIMUM_TEXTURE_SIZE);
        }
     
        public void endFrame() {
            this.allocator.endFrame();
        }
     
        public boolean tryPrepareFor(Set<Object> items) {
            return this.allocator.hasSpaceForAll(items) ? true : this.allocator.reclaimSpaceFor(items);
        }
     
        public GuiItemAtlas.@Nullable SlotView getOrUpdate(TrackingItemStackRenderState item) {
            DynamicAtlasAllocator.Slot slot = this.allocator.getOrAllocate(item.getModelIdentity(), item.isAnimated());
            if (slot == null) {
                return null;
            } else {
                switch (slot.state()) {
                    case EMPTY:
                        this.drawToSlot(slot.x(), slot.y(), false, item);
                        break;
                    case STALE:
                        this.drawToSlot(slot.x(), slot.y(), true, item);
                    case READY:
                }
     
                float slotUvSize = (float)this.slotTextureSize / this.textureSize;
                float u0 = slot.x() * slotUvSize;
                float v0 = 1.0F - slot.y() * slotUvSize;
                return new GuiItemAtlas.SlotView(this.textureView, u0, v0, u0 + slotUvSize, v0 - slotUvSize);
            }
        }
     
        private void drawToSlot(int slotX, int slotY, boolean clear, ItemStackRenderState item) {
            int left = slotX * this.slotTextureSize;
            int top = slotY * this.slotTextureSize;
            int bottom = top + this.slotTextureSize;
            GpuDevice device = RenderSystem.getDevice();
            if (clear) {
                device.createCommandEncoder()
                    .clearColorAndDepthTextures(
                        this.texture, 0, this.depthTexture, 1.0, left, this.textureSize - bottom, this.slotTextureSize, this.slotTextureSize
                    );
            }
     
            this.poseStack.pushPose();
            this.poseStack.translate(left + this.slotTextureSize / 2.0F, top + this.slotTextureSize / 2.0F, 0.0F);
            this.poseStack.scale(this.slotTextureSize, -this.slotTextureSize, this.slotTextureSize);
            RenderSystem.outputColorTextureOverride = this.textureView;
            RenderSystem.outputDepthTextureOverride = this.depthTextureView;
            this.projection.setupOrtho(-1000.0F, 1000.0F, this.textureSize, this.textureSize, true);
            RenderSystem.setProjectionMatrix(this.projectionMatrixBuffer.getBuffer(this.projection), ProjectionType.ORTHOGRAPHIC);
            RenderSystem.enableScissorForRenderTypeDraws(left, this.textureSize - bottom, this.slotTextureSize, this.slotTextureSize);
            Lighting.Entry lighting = item.usesBlockLight() ? Lighting.Entry.ITEMS_3D : Lighting.Entry.ITEMS_FLAT;
            Minecraft.getInstance().gameRenderer.getLighting().setupFor(lighting);
            item.submit(this.poseStack, this.submitNodeCollector, 15728880, OverlayTexture.NO_OVERLAY, 0);
            this.featureRenderDispatcher.renderAllFeatures();
            this.bufferSource.endBatch();
            RenderSystem.disableScissorForRenderTypeDraws();
            RenderSystem.outputColorTextureOverride = null;
            RenderSystem.outputDepthTextureOverride = null;
            this.poseStack.popPose();
        }
     
        public int textureSize() {
            return this.textureSize;
        }
     
        @Override
        public void close() {
            this.texture.close();
            this.textureView.close();
            this.depthTexture.close();
            this.depthTextureView.close();
            this.projectionMatrixBuffer.close();
        }
     
        @OnlyIn(Dist.CLIENT)
        public record SlotView(GpuTextureView textureView, float u0, float v0, float u1, float v1) {
        }
    }

    引用的其他类