Skip to content

Fix Uniform[Mat4] and other Uniform[T] params on shader entry points - #36

Merged
treeform merged 1 commit into
masterfrom
shady-bugs
Aug 26, 2026
Merged

treeform merged 1 commit into
masterfrom
shady-bugs

Conversation

@treeform

Copy link
Copy Markdown
Owner

Fixes #32.

toGLSL failed with [Shady] can't figure out type: Uniform[Mat4] on the README/triangle-example vertex shader. Two fixes in shared.nim:

  1. Type resolution: typeString only recognized Uniform[float32] and Uniform[int] as hardcoded string cases, so any other wrapped type (Uniform[Mat4], Uniform[Vec2], …) fell through to the error. Now it recurses into the inner type for Uniform, UniformWriteOnly, and Attribute wrappers.

  2. Emission: entry-point params wrapped in Uniform were emitted as plain in params (in mat4 MVP;). The examples bind these via glGetUniformLocation, so they are now emitted as uniform globals (uniform mat4 MVP;), reusing the ES3 highp sampler handling and array suffix logic from the global-var path.

The issue's shader now produces:

#version 410
precision highp float;

uniform mat4 MVP;
in vec3 vCol;
in vec3 vPos;
out vec3 vertColor;

void main() {
  gl_Position = MVP * vec4(vPos.x, vPos.y, 0.0, 1.0);
  vertColor = vCol;
}

Added two gold-master regression tests (the issue's vertex shader and a Uniform[float32] fragment param); the gold-master diff is purely additive. nimble test passes, and examples/triangle.nim (which uses this exact pattern and previously failed to compile) now builds.

🤖 Generated with Claude Code

…32)

typeString only knew Uniform[float32] and Uniform[int] as literal
strings, so any other wrapped type like Uniform[Mat4] hit the
"can't figure out type" error. Recurse into Uniform, UniformWriteOnly
and Attribute wrappers instead.

Entry-point params wrapped in Uniform were also emitted as plain
"in" params; emit them as uniform globals like the examples expect.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@treeform
treeform merged commit fc66679 into master Aug 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: [GLSL] can't figure out type: Uniform[Mat4]

1 participant