DPI scaling fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#version 450 core
|
||||
|
||||
// ---------- Vertex attributes (used in both modes) ----------
|
||||
// ---------- Vertex attributes (used in all modes) ----------
|
||||
layout(location = 0) in vec2 v_position;
|
||||
layout(location = 1) in vec2 v_uv;
|
||||
layout(location = 2) in vec4 v_color;
|
||||
@@ -16,10 +16,18 @@ layout(location = 6) flat out vec4 f_uv_rect;
|
||||
layout(location = 7) flat out uvec4 f_effects;
|
||||
|
||||
// ---------- Uniforms (single block — avoids spirv-cross reordering on Metal) ----------
|
||||
// Mode values mirror Core_2D_Mode in core_2d.odin:
|
||||
// 0 = Tessellated v_position is in logical pixels; shader scales by dpi_scale.
|
||||
// 1 = SDF v_position is a unit-quad corner; world-space comes from
|
||||
// primitives[gl_InstanceIndex].bounds (logical px). Shader
|
||||
// scales by dpi_scale.
|
||||
// 2 = Text v_position is in *physical* pixels already (the CPU baked
|
||||
// the anchor snap and SDL_ttf glyph offsets, both physical).
|
||||
// Shader must NOT rescale.
|
||||
layout(set = 1, binding = 0) uniform Uniforms {
|
||||
mat4 projection;
|
||||
float dpi_scale;
|
||||
uint mode; // 0 = tessellated, 1 = SDF
|
||||
uint mode;
|
||||
};
|
||||
|
||||
// ---------- SDF primitive storage buffer ----------
|
||||
@@ -44,18 +52,7 @@ layout(std430, set = 0, binding = 0) readonly buffer Core_2D_Primitives {
|
||||
|
||||
// ---------- Entry point ----------
|
||||
void main() {
|
||||
if (mode == 0u) {
|
||||
// ---- Mode 0: Tessellated (used for text and arbitrary user geometry) ----
|
||||
f_color = v_color;
|
||||
f_local_or_uv = v_uv;
|
||||
f_params = vec4(0.0);
|
||||
f_params2 = vec4(0.0);
|
||||
f_flags = 0u;
|
||||
f_uv_rect = vec4(0.0);
|
||||
f_effects = uvec4(0);
|
||||
|
||||
gl_Position = projection * vec4(v_position * dpi_scale, 0.0, 1.0);
|
||||
} else {
|
||||
if (mode == 1u) {
|
||||
// ---- Mode 1: SDF instanced quads ----
|
||||
Core_2D_Primitive p = primitives[gl_InstanceIndex];
|
||||
|
||||
@@ -86,5 +83,25 @@ void main() {
|
||||
f_effects = p.effects;
|
||||
|
||||
gl_Position = projection * vec4(world_pos * dpi_scale, 0.0, 1.0);
|
||||
} else {
|
||||
// ---- Mode 0 (Tessellated) and Mode 2 (Text) ----
|
||||
// Both feed the raw-vertex pipeline (kind 0 in the fragment shader).
|
||||
// They differ only in what coord space `v_position` is in:
|
||||
// Mode 0 — logical pixels, scale here by dpi_scale.
|
||||
// Mode 2 — physical pixels (CPU pre-scaled and snapped to integer
|
||||
// physical pixels for atlas-aligned bilinear sampling).
|
||||
// Do NOT rescale.
|
||||
// `mode` is uniform across the workgroup, so the select compiles to a
|
||||
// uniform-controlled branch with no SIMT divergence cost.
|
||||
f_color = v_color;
|
||||
f_local_or_uv = v_uv;
|
||||
f_params = vec4(0.0);
|
||||
f_params2 = vec4(0.0);
|
||||
f_flags = 0u;
|
||||
f_uv_rect = vec4(0.0);
|
||||
f_effects = uvec4(0);
|
||||
|
||||
vec2 pos = (mode == 2u) ? v_position : (v_position * dpi_scale);
|
||||
gl_Position = projection * vec4(pos, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user