Skip to content
Merged
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
38 changes: 36 additions & 2 deletions src/main/kotlin/gg/essential/universal/render/URenderPipeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ import net.minecraft.client.renderer.WorldVertexBufferUploader
//$$ import net.minecraft.client.render.Shader
//$$ import java.util.function.Supplier
//#endif
//#if MC<12100
//$$ import net.minecraft.client.gl.GlBlendState
//$$ import java.lang.invoke.MethodHandles
//#endif
//#else
import gg.essential.universal.shader.GlShader
import net.minecraft.client.renderer.vertex.VertexFormatElement
Expand Down Expand Up @@ -129,9 +133,23 @@ class URenderPipeline private constructor(
// (On 1.21+, MC's `GlBlendState` is still broken, but `ShaderProgram` no longer applies it)
//#if MC>=11700 && MC<12100
//$$ RenderSystem.getShader()?.let { shaderProgram ->
//$$ // Capture actual desired blend state to restore afterwards
//$$ val prevBlendState = BlendState.active()
//$$ shaderProgram.bind()
//$$ shaderProgram.unbind()
//$$ // This seemingly pointless change of active blend state here is necessary because of another bug in
//$$ // GlBlendState: It'll only update its global `activeBlendState` when the blend state is enabled or disabled
//$$ // but not when merely the blend function or one of its parameters is changed. So we need to make sure
//$$ // we enable a blend state which is the opposite of the blend state of the shader before we enable that one.
//$$ // We need to do two calls because we don't know the state of the current `activeBlendState`.
//$$ if (shaderProgram.glBlendState.isBlendDisabled) {
//$$ BlendState.DISABLED.mc.enable()
//$$ BlendState.ALPHA.mc.enable()
//$$ } else {
//$$ BlendState.ALPHA.mc.enable()
//$$ BlendState.DISABLED.mc.enable()
//$$ }
//$$ // Enable shader's GlBlendState so it becomes the `GlBlendState.activeBlendState`
//$$ shaderProgram.glBlendState.enable()
//$$ // Restore desired blend state
//$$ prevBlendState.activateWithoutChangingMcBlendState()
//$$ }
//#endif
Expand Down Expand Up @@ -522,6 +540,22 @@ class URenderPipeline private constructor(
val isRequired = false
//#endif

//#if MC>=11700 && MC<12100
//$$ private val Shader_glBlendState: (Shader) -> GlBlendState by lazy {
//$$ try {
//$$ val field = Shader::class.java.declaredFields
//$$ .first { it.type == GlBlendState::class.java }
//$$ field.isAccessible = true
//$$ val handle = MethodHandles.lookup().unreflectGetter(field)
//$$ return@lazy { shader: Shader -> handle.invoke(shader) as GlBlendState }
//$$ } catch (e: Exception) {
//$$ e.printStackTrace()
//$$ return@lazy { GlBlendState() }
//$$ }
//$$ }
//$$ private val Shader.glBlendState: GlBlendState get() = Shader_glBlendState(this)
//#endif

//#if !STANDALONE
//#if MC>=12105
//$$ @JvmStatic
Expand Down
Loading