Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCShader: use transformed attribute names in VertexFormat for Shader #62

Merged
merged 1 commit into from
Oct 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,17 @@ internal class MCShader(
//#endif
}

val shaderVertexFormat = vertexFormat?.mc
val shaderVertexFormat = if (vertexFormat != null) {
// Shader calls glBindAttribLocation using the names in the VertexFormat, not the shader json...
// Easiest way to work around this is to construct a custom VertexFormat with our prefixed names.
VertexFormat(ImmutableMap.copyOf(
transformer.attributes.withIndex()
.associate { it.value to vertexFormat.mc.elements[it.index] }))
} else {
// Legacy fallback: The actual element doesn't matter here, Shader only cares about the names
?: VertexFormat(ImmutableMap.copyOf(transformer.attributes.associateWith { VertexFormats.POSITION_ELEMENT }))
VertexFormat(ImmutableMap.copyOf(transformer.attributes.associateWith { VertexFormats.POSITION_ELEMENT }))
}


val name = DigestUtils.sha1Hex(json).lowercase()
return MCShader(Shader(factory, name, shaderVertexFormat), blendState)
Expand Down