VulkanShader_1.21.10-0.0.4-alpha.jar

Download file
    package net.vulkanmod.vulkan.shader.layout;

import java.util.function.Supplier;
import net.vulkanmod.vulkan.shader.Uniforms;
import net.vulkanmod.vulkan.util.MappedBuffer;
import org.lwjgl.system.MemoryUtil;

public class Uniform {
   protected Supplier<MappedBuffer> values;
   Info info;
   protected long offset;
   protected int size;

   Uniform(Info info) {
      this.info = info;
      this.offset = (long)info.offset * 4L;
      this.size = info.size * 4;
      this.setupSupplier();
   }

   protected void setupSupplier() {
      this.values = this.info.bufferSupplier;
   }

   public void setSupplier(Supplier<MappedBuffer> supplier) {
      this.values = supplier;
   }

   public String getName() {
      return this.info.name;
   }

   void update(long ptr) {
      if (this.values != null) {
         MappedBuffer src = (MappedBuffer)this.values.get();
         MemoryUtil.memCopy(src.ptr, ptr + this.offset, (long)this.size);
      }
   }

   public static Uniform createField(Info info) {
      Object var10000;
      switch (info.type) {
         case "mat4":
         case "vec3":
         case "vec4":
         case "vec2":
         case "ivec3":
         case "ivec2":
            var10000 = new Uniform(info);
            break;
         case "mat3":
            var10000 = new Mat3(info);
            break;
         case "float":
            var10000 = new Vec1f(info);
            break;
         case "int":
            var10000 = new Vec1i(info);
            break;
         default:
            throw new RuntimeException("not admitted type: " + info.type);
      }

      return (Uniform)var10000;
   }

   public int getOffset() {
      return this.info.offset;
   }

   public int getSize() {
      return this.info.size;
   }

   public Info getInfo() {
      return this.info;
   }

   public String toString() {
      return String.format("%s: %s offset: %d", this.info.type, this.info.name, this.info.offset);
   }

   public static Info createUniformInfo(String type, String name, int count) {
      Info var10000;
      switch (type) {
         case "matrix4x4":
            var10000 = new Info("mat4", name, 4, 16);
            return var10000;
         case "float":
            switch (count) {
               case 1:
                  var10000 = new Info("float", name, 1, 1);
                  return var10000;
               case 2:
                  var10000 = new Info("vec2", name, 2, 2);
                  return var10000;
               case 3:
                  var10000 = new Info("vec3", name, 4, 3);
                  return var10000;
               case 4:
                  var10000 = new Info("vec4", name, 4, 4);
                  return var10000;
               default:
                  throw new IllegalStateException("Unexpected value: " + count);
            }
         case "int":
            switch (count) {
               case 1:
                  var10000 = new Info("int", name, 1, 1);
                  return var10000;
               case 2:
                  var10000 = new Info("ivec2", name, 2, 2);
                  return var10000;
               case 3:
                  var10000 = new Info("ivec3", name, 4, 3);
                  return var10000;
               case 4:
                  var10000 = new Info("ivec4", name, 4, 4);
                  return var10000;
               default:
                  throw new IllegalStateException("Unexpected value: " + count);
            }
         default:
            throw new RuntimeException("not admitted type..");
      }
   }

   public static Info createUniformInfo(String type, String name) {
      Info var10000;
      switch (type) {
         case "mat4":
            var10000 = new Info(type, name, 4, 16);
            break;
         case "mat3":
            var10000 = new Info(type, name, 4, 9);
            break;
         case "vec4":
            var10000 = new Info(type, name, 4, 4);
            break;
         case "vec3":
         case "ivec3":
            var10000 = new Info(type, name, 4, 3);
            break;
         case "vec2":
         case "ivec2":
            var10000 = new Info(type, name, 2, 2);
            break;
         case "float":
         case "int":
            var10000 = new Info(type, name, 1, 1);
            break;
         default:
            throw new RuntimeException("not admitted type: " + type);
      }

      return var10000;
   }

   public static class Info {
      public final String type;
      public final String name;
      public final int align;
      public final int size;
      int offset;
      Supplier<MappedBuffer> bufferSupplier;
      Supplier<Integer> intSupplier;
      Supplier<Float> floatSupplier;

      Info(String type, String name, int align, int size) {
         this.type = type;
         this.name = name;
         this.align = align;
         this.size = size;
      }

      int getSizeBytes() {
         return 4 * this.size;
      }

      int computeAlignmentOffset(int builderOffset) {
         return this.offset = builderOffset + (this.align - builderOffset % this.align) % this.align;
      }

      public void setupSupplier() {
         switch (this.type) {
            case "float" -> this.floatSupplier = (Supplier)Uniforms.vec1f_uniformMap.get(this.name);
            case "int" -> this.intSupplier = (Supplier)Uniforms.vec1i_uniformMap.get(this.name);
            default -> this.bufferSupplier = Uniforms.getUniformSupplier(this.type, this.name);
         }

      }

      public boolean hasSupplier() {
         boolean var10000;
         switch (this.type) {
            case "float" -> var10000 = this.floatSupplier != null || this.bufferSupplier != null;
            case "int" -> var10000 = this.intSupplier != null || this.bufferSupplier != null;
            default -> var10000 = this.bufferSupplier != null;
         }

         return var10000;
      }

      public void setBufferSupplier(Supplier<MappedBuffer> supplier) {
         this.bufferSupplier = supplier;
      }
   }
}
    
Download file