Skip to content

Commit 4fd7050

Browse files
authored
URenderPipeline: Use transformed attribute names in VertexFormat for RenderPipeline
Pretty much the same issue as d6937c4 but in the code for 1.21.5+ which no longer supports MCShader uses the new vanilla RenderPipeline mechanism instead. This fixes draws with custom shader on graphics drivers which do not order attributes by default by their order in the shader source code (mainly MacOS). Linear: EM-3161 GitHub: #114
1 parent 72de1e3 commit 4fd7050

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/main/kotlin/gg/essential/universal/render/URenderPipeline.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,23 @@ class URenderPipeline private constructor(
351351
//$$
352352
//$$ transformer.samplers.forEach { withSampler(it) }
353353
//$$ transformer.uniforms.forEach { withUniform(it.key, it.value.mc) }
354+
//$$
355+
//$$ // ShaderProgram calls glBindAttribLocation using the names in the VertexFormat so we need to
356+
//$$ // construct a custom one based on the original but with our prefixed names
357+
//$$ val builder = VertexFormat.builder()
358+
//$$ var expectedOffset = 0
359+
//$$ format.elements.mapIndexed { index, element ->
360+
//$$ val offset = format.getOffset(element)
361+
//$$ val padding = offset - expectedOffset
362+
//$$ if (padding > 0) {
363+
//$$ expectedOffset += padding
364+
//$$ builder.padding(padding)
365+
//$$ }
366+
//$$ expectedOffset += element.byteSize()
367+
//$$ val name = transformer.attributes.getOrNull(index) ?: format.getElementName(element)
368+
//$$ builder.add(name, element)
369+
//$$ }
370+
//$$ withVertexFormat(builder.build(), drawMode.mcMode)
354371
//$$ }
355372
//$$ is ShaderSupplier.Mc -> {
356373
//$$ withVertexShader(shader.vert)

0 commit comments

Comments
 (0)