Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/UniversalCraft.api
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,18 @@ public final class gg/essential/universal/UGraphics$DrawMode : java/lang/Enum {
public static final field TRIANGLE_FAN Lgg/essential/universal/UGraphics$DrawMode;
public static final field TRIANGLE_STRIP Lgg/essential/universal/UGraphics$DrawMode;
public final field glMode I
@26.2-fabric
public final field mcMode Lcom/mojang/blaze3d/PrimitiveTopology;
@1.21.11-fabric,1.21.5-fabric,1.21.6-fabric,1.21.7-fabric,1.21.9-fabric
public final field mcMode Lcom/mojang/blaze3d/vertex/VertexFormat$DrawMode;
@1.17.1-forge,1.18.1-forge,1.19.2-forge,1.19.3-forge,1.19.4-forge,1.20.1-forge,1.20.2-forge,1.20.4-forge,1.20.4-neoforge,1.20.6-forge,1.20.6-neoforge,1.21-forge,1.21-neoforge,1.21.3-forge,1.21.3-neoforge,1.21.4-forge,1.21.4-neoforge,1.21.5-forge,1.21.5-neoforge,1.21.7-forge,1.21.7-neoforge,26.1-fabric,26.2-fabric
@1.17.1-forge,1.18.1-forge,1.19.2-forge,1.19.3-forge,1.19.4-forge,1.20.1-forge,1.20.2-forge,1.20.4-forge,1.20.4-neoforge,1.20.6-forge,1.20.6-neoforge,1.21-forge,1.21-neoforge,1.21.3-forge,1.21.3-neoforge,1.21.4-forge,1.21.4-neoforge,1.21.5-forge,1.21.5-neoforge,1.21.7-forge,1.21.7-neoforge,26.1-fabric
public final field mcMode Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;
@1.17.1-fabric,1.18.1-fabric,1.19-fabric,1.19.1-fabric,1.19.2-fabric,1.19.3-fabric,1.19.4-fabric,1.20-fabric,1.20.1-fabric,1.20.2-fabric,1.20.4-fabric,1.20.6-fabric,1.21-fabric,1.21.3-fabric,1.21.4-fabric
public final field mcMode Lnet/minecraft/client/render/VertexFormat$DrawMode;
@1.12.2-forge,1.16.2-fabric,1.16.2-forge,1.8.9-forge
public final field mcMode I
public static fun fromGl (I)Lgg/essential/universal/UGraphics$DrawMode;
@26.1-fabric,26.2-fabric
@26.1-fabric
public static fun fromRenderLayer (Lnet/minecraft/client/renderer/rendertype/RenderType;)Lgg/essential/universal/UGraphics$DrawMode;
@1.16.2-forge,1.17.1-forge,1.18.1-forge,1.19.2-forge,1.19.3-forge,1.19.4-forge,1.20.1-forge,1.20.2-forge,1.20.4-forge,1.20.4-neoforge,1.20.6-forge,1.20.6-neoforge,1.21-forge,1.21-neoforge,1.21.3-forge,1.21.3-neoforge,1.21.4-forge,1.21.4-neoforge,1.21.5-forge,1.21.5-neoforge,1.21.7-forge,1.21.7-neoforge
public static fun fromRenderLayer (Lnet/minecraft/client/renderer/RenderType;)Lgg/essential/universal/UGraphics$DrawMode;
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pluginManagement {
maven("https://repo.essential.gg/repository/maven-public")
}
plugins {
val egtVersion = "0.7.0"
val egtVersion = "0.7.1"
id("gg.essential.multi-version.root") version egtVersion
id("gg.essential.multi-version.api-validation") version egtVersion
}
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/gg/essential/universal/UGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;

//#if MC >= 26.2
//$$ import com.mojang.blaze3d.PrimitiveTopology;
//#else
import net.minecraft.client.renderer.Tessellator;
//#endif
Expand Down Expand Up @@ -744,7 +745,7 @@ public static void drawString(UMatrixStack stack, String text, float x, float y,
//$$ pipeline = drawable.getPipeline();
//$$ texture = drawable.textureView();
//#if MC >= 26.2
//$$ bufferBuilder = new BufferBuilder(ALLOCATOR, pipeline.getVertexFormatMode(), pipeline.getVertexFormat());
//$$ bufferBuilder = new BufferBuilder(ALLOCATOR, pipeline.getPrimitiveTopology(), pipeline.getVertexFormatBinding(0));
//#else
//$$ bufferBuilder = Tessellator.getInstance().begin(pipeline.getVertexFormatMode(), pipeline.getVertexFormat());
//#endif
Expand Down Expand Up @@ -1091,7 +1092,9 @@ public enum DrawMode {

public final int glMode;
//#if !STANDALONE
//#if MC>=11700
//#if MC >= 26.2
//$$ public final PrimitiveTopology mcMode;
//#elseif MC>=11700
//$$ public final VertexFormat.DrawMode mcMode;
//#else
public final int mcMode;
Expand All @@ -1109,7 +1112,20 @@ public enum DrawMode {
//#endif
}

//#if MC>=11700 && !STANDALONE
//#if STANDALONE
//#elseif MC >= 26.2
//$$ private static PrimitiveTopology glToMcDrawMode(int glMode) {
//$$ switch (glMode) {
//$$ case GL11.GL_LINES: return PrimitiveTopology.LINES;
//$$ case GL11.GL_LINE_STRIP: return PrimitiveTopology.DEBUG_LINE_STRIP;
//$$ case GL11.GL_TRIANGLES: return PrimitiveTopology.TRIANGLES;
//$$ case GL11.GL_TRIANGLE_STRIP: return PrimitiveTopology.TRIANGLE_STRIP;
//$$ case GL11.GL_TRIANGLE_FAN: return PrimitiveTopology.TRIANGLE_FAN;
//$$ case GL11.GL_QUADS: return PrimitiveTopology.QUADS;
//$$ default: throw new IllegalArgumentException("Unsupported draw mode " + glMode);
//$$ }
//$$ }
//#elseif MC >= 1.17
//$$ private static VertexFormat.DrawMode glToMcDrawMode(int glMode) {
//$$ switch (glMode) {
//$$ case GL11.GL_LINES: return VertexFormat.DrawMode.LINES;
Expand All @@ -1125,7 +1141,9 @@ public enum DrawMode {
//$$ default: throw new IllegalArgumentException("Unsupported draw mode " + glMode);
//$$ }
//$$ }
//$$
//#endif

//#if MC >= 1.17 && MC < 26.2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: what does this change accomplish? why can't it remain in the above elseif block?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's conceptually separate from the above preprocessor chain. I.e. the fact that this is < 26.2 and that the above uses a separate block for 26.2+ are merely coincidental. Note that there's no 26.2+ replacement for this method, while there is for the one above.

The above chain is for converting the int OpenGL constant to the MC type (because our constructor needs that). It changes with 26.2+ because VertexFormat.DrawMode became PrimitiveTopology.

This method is for converting from the MC type to our type (because our fromRenderLayer needs that). It is removed with 26.2+ because fromRenderLayer is removed because RenderType (aka RenderLayer) no longer exists the way it used to.

//$$ private static DrawMode fromMc(VertexFormat.DrawMode mcMode) {
//$$ switch (mcMode) {
//$$ case LINES: return DrawMode.LINES;
Expand Down Expand Up @@ -1155,7 +1173,7 @@ public static DrawMode fromGl(int glMode) {
}
}

//#if MC>=11600 && !STANDALONE
//#if MC>=11600 && MC < 26.2
//$$ public static DrawMode fromRenderLayer(RenderType renderLayer) {
//#if MC>=11700
//$$ return fromMc(renderLayer.getDrawMode());
Expand Down
20 changes: 17 additions & 3 deletions src/main/kotlin/gg/essential/universal/render/URenderPass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import kotlin.ranges.coerceIn
//$$ import gg.essential.universal.vertex.UBufferBuilder
//$$ import net.minecraft.client.MinecraftClient
//$$ import net.minecraft.client.texture.GlTexture
//#if MC >= 26.2
//$$ import java.util.Optional
//#else
//$$ import java.util.OptionalInt
//#endif
//$$ import java.util.OptionalDouble
//#endif
//#endif
Expand Down Expand Up @@ -129,12 +133,20 @@ internal class URenderPass : AutoCloseable {
//$$ { "Immediate draw for $pipeline" },
//#endif
//$$ outputColorTexture,
//$$ OptionalInt.empty(),
//#if MC >= 26.2
//$$ Optional.empty(),
//#else
//$$ OptionalInt.empty(),
//#endif
//$$ outputDepthTexture,
//$$ OptionalDouble.empty(),
//$$ )
//$$ }
//$$ mc.setVertexBuffer(0, vertexBuffer)
//#if MC >= 26.2
//$$ mc.setVertexBuffer(0, vertexBuffer.slice())
//#else
//$$ mc.setVertexBuffer(0, vertexBuffer)
//#endif
//$$ mc.setIndexBuffer(indexBuffer, indexType)
//#if MC>=12106
//$$ RenderSystem.bindDefaultUniforms(mc)
Expand Down Expand Up @@ -229,7 +241,9 @@ internal class URenderPass : AutoCloseable {
@Deprecated("Does not support Vulkan; uses hard-coded sampler on 1.21.11+, relies on texture configuration on older versions.")
override fun texture(name: String, textureGlId: Int): DrawCallBuilder = apply {
//#if MC>=12105 && !STANDALONE
//#if MC>=12106
//#if MC >= 26.2
//$$ val texture = object : GlTexture(USAGE_TEXTURE_BINDING, "", GpuFormat.RGBA8_UNORM, 0, 0, 0, 1, textureGlId, null) {
//#elseif MC>=12106
//$$ val texture = object : GlTexture(USAGE_TEXTURE_BINDING, "", TextureFormat.RGBA8, 0, 0, 0, 1, textureGlId) {
//#else
//$$ val texture = object : GlTexture("", TextureFormat.RGBA8, 0, 0, 0, textureGlId) {
Expand Down
34 changes: 29 additions & 5 deletions src/main/kotlin/gg/essential/universal/render/URenderPipeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import net.minecraft.client.renderer.vertex.VertexFormat
import net.minecraft.util.ResourceLocation

//#if MC >= 26.2
//$$ import com.mojang.blaze3d.GpuFormat
//$$ import com.mojang.blaze3d.pipeline.BindGroupLayout
//$$ import com.mojang.blaze3d.vertex.DefaultVertexFormat
//$$ import net.minecraft.client.renderer.BindGroupLayouts
//#endif

Expand Down Expand Up @@ -418,7 +420,12 @@ class URenderPipeline private constructor(
//$$ var shaderSourceGetter: ShaderSourceGetter? = null
//$$ var mcRenderPipeline = RenderPipeline.builder().apply {
//$$ withLocation(id)
//$$ withVertexFormat(format, drawMode.mcMode)
//#if MC >= 26.2
//$$ withPrimitiveTopology(drawMode.mcMode)
//$$ withVertexBinding(0, format)
//#else
//$$ withVertexFormat(format, drawMode.mcMode)
//#endif
//$$ when (shader) {
//$$ is ShaderSupplier.LegacySource -> {
//$$ val transformer = ShaderTransformer(format, 150)
Expand Down Expand Up @@ -452,6 +459,15 @@ class URenderPipeline private constructor(
//$$
//$$ // ShaderProgram calls glBindAttribLocation using the names in the VertexFormat so we need to
//$$ // construct a custom one based on the original but with our prefixed names
//#if MC >= 26.2
//$$ val builder = VertexFormat.builder(0)
//$$ format.elements.forEachIndexed { index, element ->
//$$ val name = transformer.attributes.getOrNull(index) ?: element.name
//$$ val nextOffset = format.elements.getOrNull(index + 1)?.offset ?: format.vertexSize
//$$ builder.addAttribute(name, nextOffset - element.offset, element.format)
//$$ }
//$$ withVertexBinding(0, builder.build())
//#else
//$$ val builder = VertexFormat.builder()
//$$ var expectedOffset = 0
//$$ format.elements.mapIndexed { index, element ->
Expand All @@ -466,6 +482,7 @@ class URenderPipeline private constructor(
//$$ builder.add(name, element)
//$$ }
//$$ withVertexFormat(builder.build(), drawMode.mcMode)
//#endif
//$$ }
//$$ is ShaderSupplier.Mc -> {
//$$ withVertexShader(shader.vert)
Expand Down Expand Up @@ -519,6 +536,9 @@ class URenderPipeline private constructor(
//$$ blendState.srcAlpha.mcSourceFactor,
//$$ blendState.dstAlpha.mcDestFactor,
//$$ ) else null),
//#if MC >= 26.2
//$$ GpuFormat.RGBA8_UNORM,
//#endif
//$$ colorMask.let { (colorMask, alphaMask) ->
//$$ var flags = 0
//$$ if (colorMask) flags += ColorTargetState.WRITE_COLOR
Expand Down Expand Up @@ -653,7 +673,11 @@ class URenderPipeline private constructor(
//#if MC>=12105
//$$ @JvmStatic
//$$ fun wrap(mc: RenderPipeline): URenderPipeline =
//$$ URenderPipeline(mc.location, mc.vertexFormat, null, mc)
//#if MC >= 26.2
//$$ URenderPipeline(mc.location, mc.vertexFormatBindings[0]!!, null, mc)
//#else
//$$ URenderPipeline(mc.location, mc.vertexFormat, null, mc)
//#endif
//#endif
//#if MC >= 26.2
//$$ fun builder(id: Identifier, drawMode: DrawMode, format: VertexFormat, vert: Identifier, frag: Identifier, bindGroupLayouts: List<BindGroupLayout>): Builder {
Expand Down Expand Up @@ -698,9 +722,9 @@ class URenderPipeline private constructor(
//#if MC >= 26.2
//$$ val bindGroupLayouts = buildList(4) {
//$$ add(BindGroupLayouts.MATRICES_PROJECTION)
//$$ if (format.mc.contains(VertexFormatElement.UV0)) add(BindGroupLayouts.SAMPLER0)
//$$ if (format.mc.contains(VertexFormatElement.UV1)) add(BindGroupLayouts.SAMPLER1)
//$$ if (format.mc.contains(VertexFormatElement.UV2)) add(BindGroupLayouts.SAMPLER2)
//$$ if (format.mc.contains(DefaultVertexFormat.UV0_SEMANTIC_NAME)) add(BindGroupLayouts.SAMPLER0)
//$$ if (format.mc.contains(DefaultVertexFormat.UV1_SEMANTIC_NAME)) add(BindGroupLayouts.SAMPLER1)
//$$ if (format.mc.contains(DefaultVertexFormat.UV2_SEMANTIC_NAME)) add(BindGroupLayouts.SAMPLER2)
//$$ }
//$$ return builder(mcId, drawMode, format.mc, shaderId, shaderId, bindGroupLayouts)
//#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ internal class ShaderTransformer(private val vertexFormat: VertexFormat?, privat

if (vertexFormat != null) {
//#if MC>=11700 && !STANDALONE
//$$ newAttributes.sortedBy { vertexFormat.shaderAttributes.indexOf(it.first.removePrefix("uc_")) }
//#if MC >= 26.2
//$$ fun orgIndexOfAttr(name: String) = vertexFormat.elements.indexOfFirst { it.name == name }
//#else
//$$ fun orgIndexOfAttr(name: String) = vertexFormat.shaderAttributes.indexOf(name)
//#endif
//$$ newAttributes.sortedBy { orgIndexOfAttr(it.first.removePrefix("uc_")) }
//$$ .forEach {
//$$ attributes.add(it.first)
//$$ transformed.add(it.second)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ internal class TemporaryTextureAllocator(
}

val device = RenderSystem.getDevice()
device.createCommandEncoder().clearColorAndDepthTextures(texture.texture, 0, texture.depthTexture, 1.0)
//#if MC >= 26.2
//$$ val clearColor = org.joml.Vector4f(0f)
//#else
val clearColor = 0
//#endif
device.createCommandEncoder().clearColorAndDepthTextures(texture.texture, clearColor, texture.depthTexture, 1.0)

usedAllocations.add(texture)

Expand Down
1 change: 1 addition & 0 deletions versions/26.2-26.1.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
com.mojang.blaze3d.GpuFormat com.mojang.blaze3d.textures.TextureFormat
com.mojang.blaze3d.GpuFormat RGBA8_UNORM:Lcom/mojang/blaze3d/GpuFormat; RGBA8
com.mojang.blaze3d.GpuFormat D32_FLOAT:Lcom/mojang/blaze3d/GpuFormat; DEPTH32
com.mojang.blaze3d.vertex.MeshData$DrawState primitiveTopology() mode()
2 changes: 1 addition & 1 deletion versions/26.2-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
essential.defaults.loom.minecraft=com.mojang:minecraft:26.2-snapshot-5
essential.defaults.loom.minecraft=com.mojang:minecraft:26.2-snapshot-6
Loading