SamplerCache.java

com.mojang.blaze3d.systems.SamplerCache

信息

  • 全限定名:com.mojang.blaze3d.systems.SamplerCache
  • 类型:public class
  • 包:com.mojang.blaze3d.systems
  • 源码路径:src/main/java/com/mojang/blaze3d/systems/SamplerCache.java
  • 起始行号:L12
  • 职责:

    TODO

字段/常量

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

      TODO

内部类/嵌套类型

构造器

方法

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

public void initialize() @ L15

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

参数:

说明:

TODO

public GpuSampler getSampler(AddressMode addressModeU, AddressMode addressModeV, FilterMode minFilter, FilterMode magFilter, boolean useMipmaps) @ L36

  • 方法名:getSampler
  • 源码定位:L36
  • 返回类型:GpuSampler
  • 修饰符:public

参数:

  • addressModeU: AddressMode
  • addressModeV: AddressMode
  • minFilter: FilterMode
  • magFilter: FilterMode
  • useMipmaps: boolean

说明:

TODO

public GpuSampler getClampToEdge(FilterMode minMag) @ L40

  • 方法名:getClampToEdge
  • 源码定位:L40
  • 返回类型:GpuSampler
  • 修饰符:public

参数:

  • minMag: FilterMode

说明:

TODO

public GpuSampler getClampToEdge(FilterMode minMag, boolean mipmaps) @ L44

  • 方法名:getClampToEdge
  • 源码定位:L44
  • 返回类型:GpuSampler
  • 修饰符:public

参数:

  • minMag: FilterMode
  • mipmaps: boolean

说明:

TODO

public GpuSampler getRepeat(FilterMode minMag) @ L48

  • 方法名:getRepeat
  • 源码定位:L48
  • 返回类型:GpuSampler
  • 修饰符:public

参数:

  • minMag: FilterMode

说明:

TODO

public GpuSampler getRepeat(FilterMode minMag, boolean mipmaps) @ L52

  • 方法名:getRepeat
  • 源码定位:L52
  • 返回类型:GpuSampler
  • 修饰符:public

参数:

  • minMag: FilterMode
  • mipmaps: boolean

说明:

TODO

public void close() @ L56

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

参数:

说明:

TODO

static int encode(AddressMode addressModeU, AddressMode addressModeV, FilterMode minFilter, FilterMode magFilter, boolean useMipmaps) @ L62

  • 方法名:encode
  • 源码定位:L62
  • 返回类型:int
  • 修饰符:static

参数:

  • addressModeU: AddressMode
  • addressModeV: AddressMode
  • minFilter: FilterMode
  • magFilter: FilterMode
  • useMipmaps: boolean

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SamplerCache {
    private final GpuSampler[] samplers = new GpuSampler[32];
 
    public void initialize() {
        GpuDevice device = RenderSystem.getDevice();
        if (AddressMode.values().length == 2 && FilterMode.values().length == 2) {
            for (AddressMode addressModeU : AddressMode.values()) {
                for (AddressMode addressModeV : AddressMode.values()) {
                    for (FilterMode minFilter : FilterMode.values()) {
                        for (FilterMode magFilter : FilterMode.values()) {
                            for (boolean useMipmaps : new boolean[]{true, false}) {
                                this.samplers[encode(addressModeU, addressModeV, minFilter, magFilter, useMipmaps)] = device.createSampler(
                                    addressModeU, addressModeV, minFilter, magFilter, 1, useMipmaps ? OptionalDouble.empty() : OptionalDouble.of(0.0)
                                );
                            }
                        }
                    }
                }
            }
        } else {
            throw new IllegalStateException("AddressMode and FilterMode enum sizes must be 2 - if you expanded them, please update SamplerCache");
        }
    }
 
    public GpuSampler getSampler(AddressMode addressModeU, AddressMode addressModeV, FilterMode minFilter, FilterMode magFilter, boolean useMipmaps) {
        return this.samplers[encode(addressModeU, addressModeV, minFilter, magFilter, useMipmaps)];
    }
 
    public GpuSampler getClampToEdge(FilterMode minMag) {
        return this.getSampler(AddressMode.CLAMP_TO_EDGE, AddressMode.CLAMP_TO_EDGE, minMag, minMag, false);
    }
 
    public GpuSampler getClampToEdge(FilterMode minMag, boolean mipmaps) {
        return this.getSampler(AddressMode.CLAMP_TO_EDGE, AddressMode.CLAMP_TO_EDGE, minMag, minMag, mipmaps);
    }
 
    public GpuSampler getRepeat(FilterMode minMag) {
        return this.getSampler(AddressMode.REPEAT, AddressMode.REPEAT, minMag, minMag, false);
    }
 
    public GpuSampler getRepeat(FilterMode minMag, boolean mipmaps) {
        return this.getSampler(AddressMode.REPEAT, AddressMode.REPEAT, minMag, minMag, mipmaps);
    }
 
    public void close() {
        for (GpuSampler sampler : this.samplers) {
            sampler.close();
        }
    }
 
    @VisibleForTesting
    static int encode(AddressMode addressModeU, AddressMode addressModeV, FilterMode minFilter, FilterMode magFilter, boolean useMipmaps) {
        int result = 0;
        result |= addressModeU.ordinal() & 1;
        result |= (addressModeV.ordinal() & 1) << 1;
        result |= (minFilter.ordinal() & 1) << 2;
        result |= (magFilter.ordinal() & 1) << 3;
        if (useMipmaps) {
            result |= 16;
        }
 
        return result;
    }
}

引用的其他类

  • RenderSystem

    • 引用位置: 方法调用
    • 关联成员: RenderSystem.getDevice()
  • AddressMode

    • 引用位置: 参数/方法调用
    • 关联成员: AddressMode.values()
  • FilterMode

    • 引用位置: 参数/方法调用
    • 关联成员: FilterMode.values()
  • GpuSampler

    • 引用位置: 字段/返回值