修复文字显示bug

This commit is contained in:
ubuntu1804 2025-11-10 20:26:57 +08:00
parent 25e6159176
commit 96a744bde0
4 changed files with 158 additions and 145 deletions

View File

@ -7,24 +7,30 @@ layout(location = 2) in vec2 inTexCoord;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec2 fragTexCoord;
layout(binding = 0) uniform UniformBufferObject {
float time;
vec2 resolution;
float rotation;
float wavePhase;
// Use std140 layout and separate floats instead of vec2 to avoid alignment issues
layout(binding = 0, std140) uniform UniformBufferObject {
float time; // offset 0
float resX; // offset 4
float resY; // offset 8
float rotation; // offset 12
float wavePhase; // offset 16
float padding1; // offset 20
float padding2; // offset 24
} ubo;
void main() {
// Transform position from pixel coordinates to normalized device coordinates
// Input position is in pixel coordinates (0,0 = top-left)
vec2 pos = inPosition;
// Convert to NDC: (0, 0) to (width, height) -> (-1, -1) to (1, 1)
vec2 ndc = (pos / ubo.resolution) * 2.0 - 1.0;
// Note: Vulkan NDC has Y pointing down, but we want traditional Y-up
float ndcX = (pos.x / ubo.resX) * 2.0 - 1.0;
float ndcY = (pos.y / ubo.resY) * 2.0 - 1.0;
// Flip Y axis (Vulkan has Y down, we want Y up for easier math)
ndc.y = -ndc.y;
// NO Y-flip needed here - text coordinates are already in screen space
// where (0,0) is top-left, which matches Vulkan's framebuffer coordinates
gl_Position = vec4(ndcX, ndcY, 0.0, 1.0);
gl_Position = vec4(ndc, 0.0, 1.0);
fragColor = inColor;
fragTexCoord = inTexCoord;
}

Binary file not shown.

View File

@ -1,60 +1,67 @@
// Auto-generated from text.vert.spv
// Size: 1840 bytes (460 words)
0x07230203u, 0x00010000u, 0x0008000bu, 0x00000039u, 0x00000000u, 0x00020011u, 0x00000001u, 0x0006000bu,
// Size: 2080 bytes (520 words)
0x07230203u, 0x00010000u, 0x0008000bu, 0x0000003eu, 0x00000000u, 0x00020011u, 0x00000001u, 0x0006000bu,
0x00000001u, 0x4c534c47u, 0x6474732eu, 0x3035342eu, 0x00000000u, 0x0003000eu, 0x00000000u, 0x00000001u,
0x000b000fu, 0x00000000u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x0000000bu, 0x00000028u, 0x00000031u,
0x00000033u, 0x00000036u, 0x00000037u, 0x00030003u, 0x00000002u, 0x000001c2u, 0x00040005u, 0x00000004u,
0x000b000fu, 0x00000000u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x0000000bu, 0x0000002eu, 0x00000036u,
0x00000038u, 0x0000003bu, 0x0000003cu, 0x00030003u, 0x00000002u, 0x000001c2u, 0x00040005u, 0x00000004u,
0x6e69616du, 0x00000000u, 0x00030005u, 0x00000009u, 0x00736f70u, 0x00050005u, 0x0000000bu, 0x6f506e69u,
0x69746973u, 0x00006e6fu, 0x00030005u, 0x0000000du, 0x0063646eu, 0x00070005u, 0x0000000fu, 0x66696e55u,
0x426d726fu, 0x65666675u, 0x6a624f72u, 0x00746365u, 0x00050006u, 0x0000000fu, 0x00000000u, 0x656d6974u,
0x00000000u, 0x00060006u, 0x0000000fu, 0x00000001u, 0x6f736572u, 0x6974756cu, 0x00006e6fu, 0x00060006u,
0x0000000fu, 0x00000002u, 0x61746f72u, 0x6e6f6974u, 0x00000000u, 0x00060006u, 0x0000000fu, 0x00000003u,
0x65766177u, 0x73616850u, 0x00000065u, 0x00030005u, 0x00000011u, 0x006f6275u, 0x00060005u, 0x00000026u,
0x505f6c67u, 0x65567265u, 0x78657472u, 0x00000000u, 0x00060006u, 0x00000026u, 0x00000000u, 0x505f6c67u,
0x7469736fu, 0x006e6f69u, 0x00070006u, 0x00000026u, 0x00000001u, 0x505f6c67u, 0x746e696fu, 0x657a6953u,
0x00000000u, 0x00070006u, 0x00000026u, 0x00000002u, 0x435f6c67u, 0x4470696cu, 0x61747369u, 0x0065636eu,
0x00070006u, 0x00000026u, 0x00000003u, 0x435f6c67u, 0x446c6c75u, 0x61747369u, 0x0065636eu, 0x00030005u,
0x00000028u, 0x00000000u, 0x00050005u, 0x00000031u, 0x67617266u, 0x6f6c6f43u, 0x00000072u, 0x00040005u,
0x00000033u, 0x6f436e69u, 0x00726f6cu, 0x00060005u, 0x00000036u, 0x67617266u, 0x43786554u, 0x64726f6fu,
0x00000000u, 0x00050005u, 0x00000037u, 0x65546e69u, 0x6f6f4378u, 0x00006472u, 0x00040047u, 0x0000000bu,
0x0000001eu, 0x00000000u, 0x00050048u, 0x0000000fu, 0x00000000u, 0x00000023u, 0x00000000u, 0x00050048u,
0x0000000fu, 0x00000001u, 0x00000023u, 0x00000008u, 0x00050048u, 0x0000000fu, 0x00000002u, 0x00000023u,
0x00000010u, 0x00050048u, 0x0000000fu, 0x00000003u, 0x00000023u, 0x00000014u, 0x00030047u, 0x0000000fu,
0x00000002u, 0x00040047u, 0x00000011u, 0x00000022u, 0x00000000u, 0x00040047u, 0x00000011u, 0x00000021u,
0x00000000u, 0x00050048u, 0x00000026u, 0x00000000u, 0x0000000bu, 0x00000000u, 0x00050048u, 0x00000026u,
0x00000001u, 0x0000000bu, 0x00000001u, 0x00050048u, 0x00000026u, 0x00000002u, 0x0000000bu, 0x00000003u,
0x00050048u, 0x00000026u, 0x00000003u, 0x0000000bu, 0x00000004u, 0x00030047u, 0x00000026u, 0x00000002u,
0x00040047u, 0x00000031u, 0x0000001eu, 0x00000000u, 0x00040047u, 0x00000033u, 0x0000001eu, 0x00000001u,
0x00040047u, 0x00000036u, 0x0000001eu, 0x00000001u, 0x00040047u, 0x00000037u, 0x0000001eu, 0x00000002u,
0x00020013u, 0x00000002u, 0x00030021u, 0x00000003u, 0x00000002u, 0x00030016u, 0x00000006u, 0x00000020u,
0x00040017u, 0x00000007u, 0x00000006u, 0x00000002u, 0x00040020u, 0x00000008u, 0x00000007u, 0x00000007u,
0x00040020u, 0x0000000au, 0x00000001u, 0x00000007u, 0x0004003bu, 0x0000000au, 0x0000000bu, 0x00000001u,
0x0006001eu, 0x0000000fu, 0x00000006u, 0x00000007u, 0x00000006u, 0x00000006u, 0x00040020u, 0x00000010u,
0x00000002u, 0x0000000fu, 0x0004003bu, 0x00000010u, 0x00000011u, 0x00000002u, 0x00040015u, 0x00000012u,
0x00000020u, 0x00000001u, 0x0004002bu, 0x00000012u, 0x00000013u, 0x00000001u, 0x00040020u, 0x00000014u,
0x00000002u, 0x00000007u, 0x0004002bu, 0x00000006u, 0x00000018u, 0x40000000u, 0x0004002bu, 0x00000006u,
0x0000001au, 0x3f800000u, 0x00040015u, 0x0000001du, 0x00000020u, 0x00000000u, 0x0004002bu, 0x0000001du,
0x0000001eu, 0x00000001u, 0x00040020u, 0x0000001fu, 0x00000007u, 0x00000006u, 0x00040017u, 0x00000024u,
0x00000006u, 0x00000004u, 0x0004001cu, 0x00000025u, 0x00000006u, 0x0000001eu, 0x0006001eu, 0x00000026u,
0x00000024u, 0x00000006u, 0x00000025u, 0x00000025u, 0x00040020u, 0x00000027u, 0x00000003u, 0x00000026u,
0x0004003bu, 0x00000027u, 0x00000028u, 0x00000003u, 0x0004002bu, 0x00000012u, 0x00000029u, 0x00000000u,
0x0004002bu, 0x00000006u, 0x0000002bu, 0x00000000u, 0x00040020u, 0x0000002fu, 0x00000003u, 0x00000024u,
0x0004003bu, 0x0000002fu, 0x00000031u, 0x00000003u, 0x00040020u, 0x00000032u, 0x00000001u, 0x00000024u,
0x0004003bu, 0x00000032u, 0x00000033u, 0x00000001u, 0x00040020u, 0x00000035u, 0x00000003u, 0x00000007u,
0x0004003bu, 0x00000035u, 0x00000036u, 0x00000003u, 0x0004003bu, 0x0000000au, 0x00000037u, 0x00000001u,
0x00050036u, 0x00000002u, 0x00000004u, 0x00000000u, 0x00000003u, 0x000200f8u, 0x00000005u, 0x0004003bu,
0x00000008u, 0x00000009u, 0x00000007u, 0x0004003bu, 0x00000008u, 0x0000000du, 0x00000007u, 0x0004003du,
0x00000007u, 0x0000000cu, 0x0000000bu, 0x0003003eu, 0x00000009u, 0x0000000cu, 0x0004003du, 0x00000007u,
0x0000000eu, 0x00000009u, 0x00050041u, 0x00000014u, 0x00000015u, 0x00000011u, 0x00000013u, 0x0004003du,
0x00000007u, 0x00000016u, 0x00000015u, 0x00050088u, 0x00000007u, 0x00000017u, 0x0000000eu, 0x00000016u,
0x0005008eu, 0x00000007u, 0x00000019u, 0x00000017u, 0x00000018u, 0x00050050u, 0x00000007u, 0x0000001bu,
0x0000001au, 0x0000001au, 0x00050083u, 0x00000007u, 0x0000001cu, 0x00000019u, 0x0000001bu, 0x0003003eu,
0x0000000du, 0x0000001cu, 0x00050041u, 0x0000001fu, 0x00000020u, 0x0000000du, 0x0000001eu, 0x0004003du,
0x00000006u, 0x00000021u, 0x00000020u, 0x0004007fu, 0x00000006u, 0x00000022u, 0x00000021u, 0x00050041u,
0x0000001fu, 0x00000023u, 0x0000000du, 0x0000001eu, 0x0003003eu, 0x00000023u, 0x00000022u, 0x0004003du,
0x00000007u, 0x0000002au, 0x0000000du, 0x00050051u, 0x00000006u, 0x0000002cu, 0x0000002au, 0x00000000u,
0x00050051u, 0x00000006u, 0x0000002du, 0x0000002au, 0x00000001u, 0x00070050u, 0x00000024u, 0x0000002eu,
0x0000002cu, 0x0000002du, 0x0000002bu, 0x0000001au, 0x00050041u, 0x0000002fu, 0x00000030u, 0x00000028u,
0x00000029u, 0x0003003eu, 0x00000030u, 0x0000002eu, 0x0004003du, 0x00000024u, 0x00000034u, 0x00000033u,
0x0003003eu, 0x00000031u, 0x00000034u, 0x0004003du, 0x00000007u, 0x00000038u, 0x00000037u, 0x0003003eu,
0x00000036u, 0x00000038u, 0x000100fdu, 0x00010038u
0x69746973u, 0x00006e6fu, 0x00040005u, 0x0000000eu, 0x5863646eu, 0x00000000u, 0x00070005u, 0x00000013u,
0x66696e55u, 0x426d726fu, 0x65666675u, 0x6a624f72u, 0x00746365u, 0x00050006u, 0x00000013u, 0x00000000u,
0x656d6974u, 0x00000000u, 0x00050006u, 0x00000013u, 0x00000001u, 0x58736572u, 0x00000000u, 0x00050006u,
0x00000013u, 0x00000002u, 0x59736572u, 0x00000000u, 0x00060006u, 0x00000013u, 0x00000003u, 0x61746f72u,
0x6e6f6974u, 0x00000000u, 0x00060006u, 0x00000013u, 0x00000004u, 0x65766177u, 0x73616850u, 0x00000065u,
0x00060006u, 0x00000013u, 0x00000005u, 0x64646170u, 0x31676e69u, 0x00000000u, 0x00060006u, 0x00000013u,
0x00000006u, 0x64646170u, 0x32676e69u, 0x00000000u, 0x00030005u, 0x00000015u, 0x006f6275u, 0x00040005u,
0x00000020u, 0x5963646eu, 0x00000000u, 0x00060005u, 0x0000002cu, 0x505f6c67u, 0x65567265u, 0x78657472u,
0x00000000u, 0x00060006u, 0x0000002cu, 0x00000000u, 0x505f6c67u, 0x7469736fu, 0x006e6f69u, 0x00070006u,
0x0000002cu, 0x00000001u, 0x505f6c67u, 0x746e696fu, 0x657a6953u, 0x00000000u, 0x00070006u, 0x0000002cu,
0x00000002u, 0x435f6c67u, 0x4470696cu, 0x61747369u, 0x0065636eu, 0x00070006u, 0x0000002cu, 0x00000003u,
0x435f6c67u, 0x446c6c75u, 0x61747369u, 0x0065636eu, 0x00030005u, 0x0000002eu, 0x00000000u, 0x00050005u,
0x00000036u, 0x67617266u, 0x6f6c6f43u, 0x00000072u, 0x00040005u, 0x00000038u, 0x6f436e69u, 0x00726f6cu,
0x00060005u, 0x0000003bu, 0x67617266u, 0x43786554u, 0x64726f6fu, 0x00000000u, 0x00050005u, 0x0000003cu,
0x65546e69u, 0x6f6f4378u, 0x00006472u, 0x00040047u, 0x0000000bu, 0x0000001eu, 0x00000000u, 0x00050048u,
0x00000013u, 0x00000000u, 0x00000023u, 0x00000000u, 0x00050048u, 0x00000013u, 0x00000001u, 0x00000023u,
0x00000004u, 0x00050048u, 0x00000013u, 0x00000002u, 0x00000023u, 0x00000008u, 0x00050048u, 0x00000013u,
0x00000003u, 0x00000023u, 0x0000000cu, 0x00050048u, 0x00000013u, 0x00000004u, 0x00000023u, 0x00000010u,
0x00050048u, 0x00000013u, 0x00000005u, 0x00000023u, 0x00000014u, 0x00050048u, 0x00000013u, 0x00000006u,
0x00000023u, 0x00000018u, 0x00030047u, 0x00000013u, 0x00000002u, 0x00040047u, 0x00000015u, 0x00000022u,
0x00000000u, 0x00040047u, 0x00000015u, 0x00000021u, 0x00000000u, 0x00050048u, 0x0000002cu, 0x00000000u,
0x0000000bu, 0x00000000u, 0x00050048u, 0x0000002cu, 0x00000001u, 0x0000000bu, 0x00000001u, 0x00050048u,
0x0000002cu, 0x00000002u, 0x0000000bu, 0x00000003u, 0x00050048u, 0x0000002cu, 0x00000003u, 0x0000000bu,
0x00000004u, 0x00030047u, 0x0000002cu, 0x00000002u, 0x00040047u, 0x00000036u, 0x0000001eu, 0x00000000u,
0x00040047u, 0x00000038u, 0x0000001eu, 0x00000001u, 0x00040047u, 0x0000003bu, 0x0000001eu, 0x00000001u,
0x00040047u, 0x0000003cu, 0x0000001eu, 0x00000002u, 0x00020013u, 0x00000002u, 0x00030021u, 0x00000003u,
0x00000002u, 0x00030016u, 0x00000006u, 0x00000020u, 0x00040017u, 0x00000007u, 0x00000006u, 0x00000002u,
0x00040020u, 0x00000008u, 0x00000007u, 0x00000007u, 0x00040020u, 0x0000000au, 0x00000001u, 0x00000007u,
0x0004003bu, 0x0000000au, 0x0000000bu, 0x00000001u, 0x00040020u, 0x0000000du, 0x00000007u, 0x00000006u,
0x00040015u, 0x0000000fu, 0x00000020u, 0x00000000u, 0x0004002bu, 0x0000000fu, 0x00000010u, 0x00000000u,
0x0009001eu, 0x00000013u, 0x00000006u, 0x00000006u, 0x00000006u, 0x00000006u, 0x00000006u, 0x00000006u,
0x00000006u, 0x00040020u, 0x00000014u, 0x00000002u, 0x00000013u, 0x0004003bu, 0x00000014u, 0x00000015u,
0x00000002u, 0x00040015u, 0x00000016u, 0x00000020u, 0x00000001u, 0x0004002bu, 0x00000016u, 0x00000017u,
0x00000001u, 0x00040020u, 0x00000018u, 0x00000002u, 0x00000006u, 0x0004002bu, 0x00000006u, 0x0000001cu,
0x40000000u, 0x0004002bu, 0x00000006u, 0x0000001eu, 0x3f800000u, 0x0004002bu, 0x0000000fu, 0x00000021u,
0x00000001u, 0x0004002bu, 0x00000016u, 0x00000024u, 0x00000002u, 0x00040017u, 0x0000002au, 0x00000006u,
0x00000004u, 0x0004001cu, 0x0000002bu, 0x00000006u, 0x00000021u, 0x0006001eu, 0x0000002cu, 0x0000002au,
0x00000006u, 0x0000002bu, 0x0000002bu, 0x00040020u, 0x0000002du, 0x00000003u, 0x0000002cu, 0x0004003bu,
0x0000002du, 0x0000002eu, 0x00000003u, 0x0004002bu, 0x00000016u, 0x0000002fu, 0x00000000u, 0x0004002bu,
0x00000006u, 0x00000032u, 0x00000000u, 0x00040020u, 0x00000034u, 0x00000003u, 0x0000002au, 0x0004003bu,
0x00000034u, 0x00000036u, 0x00000003u, 0x00040020u, 0x00000037u, 0x00000001u, 0x0000002au, 0x0004003bu,
0x00000037u, 0x00000038u, 0x00000001u, 0x00040020u, 0x0000003au, 0x00000003u, 0x00000007u, 0x0004003bu,
0x0000003au, 0x0000003bu, 0x00000003u, 0x0004003bu, 0x0000000au, 0x0000003cu, 0x00000001u, 0x00050036u,
0x00000002u, 0x00000004u, 0x00000000u, 0x00000003u, 0x000200f8u, 0x00000005u, 0x0004003bu, 0x00000008u,
0x00000009u, 0x00000007u, 0x0004003bu, 0x0000000du, 0x0000000eu, 0x00000007u, 0x0004003bu, 0x0000000du,
0x00000020u, 0x00000007u, 0x0004003du, 0x00000007u, 0x0000000cu, 0x0000000bu, 0x0003003eu, 0x00000009u,
0x0000000cu, 0x00050041u, 0x0000000du, 0x00000011u, 0x00000009u, 0x00000010u, 0x0004003du, 0x00000006u,
0x00000012u, 0x00000011u, 0x00050041u, 0x00000018u, 0x00000019u, 0x00000015u, 0x00000017u, 0x0004003du,
0x00000006u, 0x0000001au, 0x00000019u, 0x00050088u, 0x00000006u, 0x0000001bu, 0x00000012u, 0x0000001au,
0x00050085u, 0x00000006u, 0x0000001du, 0x0000001bu, 0x0000001cu, 0x00050083u, 0x00000006u, 0x0000001fu,
0x0000001du, 0x0000001eu, 0x0003003eu, 0x0000000eu, 0x0000001fu, 0x00050041u, 0x0000000du, 0x00000022u,
0x00000009u, 0x00000021u, 0x0004003du, 0x00000006u, 0x00000023u, 0x00000022u, 0x00050041u, 0x00000018u,
0x00000025u, 0x00000015u, 0x00000024u, 0x0004003du, 0x00000006u, 0x00000026u, 0x00000025u, 0x00050088u,
0x00000006u, 0x00000027u, 0x00000023u, 0x00000026u, 0x00050085u, 0x00000006u, 0x00000028u, 0x00000027u,
0x0000001cu, 0x00050083u, 0x00000006u, 0x00000029u, 0x00000028u, 0x0000001eu, 0x0003003eu, 0x00000020u,
0x00000029u, 0x0004003du, 0x00000006u, 0x00000030u, 0x0000000eu, 0x0004003du, 0x00000006u, 0x00000031u,
0x00000020u, 0x00070050u, 0x0000002au, 0x00000033u, 0x00000030u, 0x00000031u, 0x00000032u, 0x0000001eu,
0x00050041u, 0x00000034u, 0x00000035u, 0x0000002eu, 0x0000002fu, 0x0003003eu, 0x00000035u, 0x00000033u,
0x0004003du, 0x0000002au, 0x00000039u, 0x00000038u, 0x0003003eu, 0x00000036u, 0x00000039u, 0x0004003du,
0x00000007u, 0x0000003du, 0x0000003cu, 0x0003003eu, 0x0000003bu, 0x0000003du, 0x000100fdu, 0x00010038u

View File

@ -126,7 +126,7 @@ bool VulkanRenderer::initialize(VkDevice device, VkPhysicalDevice physicalDevice
m_ubo.resolution[1] = static_cast<float>(m_height);
m_ubo.rotation = 0.0f;
m_ubo.wavePhase = 0.0f;
// Update all uniform buffers with initial values
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
if (m_uniformBuffersMapped[i] != nullptr) {
@ -139,12 +139,12 @@ bool VulkanRenderer::initialize(VkDevice device, VkPhysicalDevice physicalDevice
std::vector<uint16_t> bgIndices;
generateBackgroundQuad(bgVertices, bgIndices);
m_backgroundIndexCount = bgIndices.size();
if (!createVertexBuffer(bgVertices, m_backgroundVertexBuffer, m_backgroundVertexMemory)) {
logError("Failed to create background vertex buffer");
return false;
}
if (!createIndexBuffer(bgIndices, m_backgroundIndexBuffer, m_backgroundIndexMemory)) {
logError("Failed to create background index buffer");
return false;
@ -170,7 +170,7 @@ bool VulkanRenderer::initialize(VkDevice device, VkPhysicalDevice physicalDevice
imageInfo.sampler = m_fontSampler;
std::vector<VkWriteDescriptorSet> descriptorWrites(2);
// UBO descriptor
descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrites[0].dstSet = m_descriptorSets[i];
@ -243,7 +243,7 @@ void VulkanRenderer::cleanup()
// Clean up descriptors
if (m_descriptorPool) vkDestroyDescriptorPool(m_device, m_descriptorPool, nullptr);
if (m_descriptorSetLayout) vkDestroyDescriptorSetLayout(m_device, m_descriptorSetLayout, nullptr);
// Clean up transfer command pool
if (m_transferCommandPool) vkDestroyCommandPool(m_device, m_transferCommandPool, nullptr);
@ -270,23 +270,23 @@ void VulkanRenderer::cleanup()
bool VulkanRenderer::resize(uint32_t width, uint32_t height)
{
std::cout << "VulkanRenderer::resize called: " << width << "x" << height
std::cout << "VulkanRenderer::resize called: " << width << "x" << height
<< " (previous: " << m_width << "x" << m_height << ")" << std::endl;
m_width = width;
m_height = height;
// Update UBO resolution immediately
m_ubo.resolution[0] = static_cast<float>(m_width);
m_ubo.resolution[1] = static_cast<float>(m_height);
// Update all uniform buffers with new resolution
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
if (i < m_uniformBuffersMapped.size() && m_uniformBuffersMapped[i] != nullptr) {
memcpy(m_uniformBuffersMapped[i], &m_ubo, sizeof(m_ubo));
}
}
std::cout << " Updated UBO resolution to: (" << m_ubo.resolution[0] << ", " << m_ubo.resolution[1] << ")" << std::endl;
// Recreate framebuffers with new size
@ -298,7 +298,7 @@ bool VulkanRenderer::resize(uint32_t width, uint32_t height)
return createFramebuffers();
}
void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
uint32_t imageIndex,
VkImageView imageView,
int frameCount,
@ -310,7 +310,7 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
if (!m_initialized) {
return;
}
// Check for valid dimensions
if (m_width < 100 || m_height < 100) {
paintingEnabled = false;
@ -320,14 +320,14 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
if (paintingEnabled) {
std::vector<Vertex> circleVertices, waveVertices;
std::vector<uint16_t> circleIndices, waveIndices;
// Debug: Print dimensions used for geometry generation
static int geomDebugCounter = 0;
if (geomDebugCounter++ % 300 == 0) { // Every ~5 seconds at 60fps
std::cout << "VulkanRenderer geometry generation using: "
std::cout << "VulkanRenderer geometry generation using: "
<< m_width << "x" << m_height << std::endl;
}
generateRotatingCircles(circleVertices, circleIndices, rotationAngle);
generateWaveEffect(waveVertices, waveIndices, wavePhase);
@ -383,11 +383,11 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
updateUniformBuffer(i);
}
// Use consistent frame index for descriptor set binding
uint32_t frameIndex = static_cast<uint32_t>(frameCount) % MAX_FRAMES_IN_FLIGHT;
// Begin command buffer
VkCommandBufferBeginInfo beginInfo = {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@ -408,7 +408,7 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
vkDestroyFramebuffer(m_device, m_framebuffers[imageIndex], nullptr);
}
m_imageViews[imageIndex] = imageView;
VkFramebufferCreateInfo fbInfo = {};
fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
fbInfo.renderPass = m_renderPass;
@ -457,7 +457,7 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
renderPassInfo.pClearValues = &clearColor;
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
// Set dynamic viewport and scissor
@ -767,7 +767,7 @@ bool VulkanRenderer::createGeometryPipeline()
{
// Similar to background pipeline but with different blend mode for overlays
// For now, reuse the same structure
static const uint32_t geomVertCode[] = {
#include "shaders_spirv/geometry_vert.inc"
};
@ -928,7 +928,7 @@ bool VulkanRenderer::createGeometryPipeline()
bool VulkanRenderer::createLinePipeline()
{
// Create a pipeline for line rendering (waves)
static const uint32_t geomVertCode[] = {
#include "shaders_spirv/geometry_vert.inc"
};
@ -1222,14 +1222,14 @@ bool VulkanRenderer::createTextPipeline()
// Create descriptor set layout for text (with texture sampler)
VkDescriptorSetLayoutBinding bindings[2];
// UBO binding
bindings[0].binding = 0;
bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
bindings[0].descriptorCount = 1;
bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
bindings[0].pImmutableSamplers = nullptr;
// Texture sampler binding
bindings[1].binding = 1;
bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
@ -1296,14 +1296,14 @@ bool VulkanRenderer::createTextPipeline()
bool VulkanRenderer::createDescriptorSetLayout()
{
std::vector<VkDescriptorSetLayoutBinding> bindings(2);
// UBO binding
bindings[0].binding = 0;
bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
bindings[0].descriptorCount = 1;
bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
bindings[0].pImmutableSamplers = nullptr;
// Image sampler binding
bindings[1].binding = 1;
bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
@ -1325,11 +1325,11 @@ bool VulkanRenderer::createDescriptorSetLayout()
bool VulkanRenderer::createDescriptorPool()
{
std::vector<VkDescriptorPoolSize> poolSizes(2);
// UBO pool size
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
poolSizes[0].descriptorCount = MAX_FRAMES_IN_FLIGHT;
// Image sampler pool size
poolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
poolSizes[1].descriptorCount = MAX_FRAMES_IN_FLIGHT;
@ -1349,7 +1349,7 @@ bool VulkanRenderer::createDescriptorPool()
bool VulkanRenderer::createDescriptorSets()
{
std::vector<VkDescriptorSetLayout> layouts(MAX_FRAMES_IN_FLIGHT, m_descriptorSetLayout);
VkDescriptorSetAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = m_descriptorPool;
@ -1425,7 +1425,7 @@ bool VulkanRenderer::createUniformBuffers()
logError("Failed to map uniform buffer memory");
return false;
}
if (m_uniformBuffersMapped[i] == nullptr) {
logError("Uniform buffer mapped pointer is null");
return false;
@ -1444,7 +1444,7 @@ void VulkanRenderer::updateUniformBuffer(uint32_t currentImage)
logError("Uniform buffer mapped pointer is null");
}
} else {
std::cerr << "VulkanRenderer::updateUniformBuffer - currentImage " << currentImage
std::cerr << "VulkanRenderer::updateUniformBuffer - currentImage " << currentImage
<< " out of range (size: " << m_uniformBuffersMapped.size() << ")" << std::endl;
}
}
@ -1456,7 +1456,7 @@ bool VulkanRenderer::createVertexBuffer(const std::vector<Vertex>& vertices,
logError("Cannot create vertex buffer from empty vertices");
return false;
}
VkDeviceSize bufferSize = sizeof(Vertex) * vertices.size();
VkBuffer stagingBuffer;
@ -1476,7 +1476,7 @@ bool VulkanRenderer::createVertexBuffer(const std::vector<Vertex>& vertices,
vkFreeMemory(m_device, stagingBufferMemory, nullptr);
return false;
}
memcpy(data, vertices.data(), bufferSize);
vkUnmapMemory(m_device, stagingBufferMemory);
@ -1508,7 +1508,7 @@ bool VulkanRenderer::createIndexBuffer(const std::vector<uint16_t>& indices,
logError("Cannot create index buffer from empty indices");
return false;
}
VkDeviceSize bufferSize = sizeof(uint16_t) * indices.size();
VkBuffer stagingBuffer;
@ -1528,7 +1528,7 @@ bool VulkanRenderer::createIndexBuffer(const std::vector<uint16_t>& indices,
vkFreeMemory(m_device, stagingBufferMemory, nullptr);
return false;
}
memcpy(data, indices.data(), bufferSize);
vkUnmapMemory(m_device, stagingBufferMemory);
@ -1589,87 +1589,87 @@ bool VulkanRenderer::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, uint64_t
logError("Cannot copy buffer: source or destination is null");
return false;
}
if (m_graphicsQueue == VK_NULL_HANDLE) {
logError("Cannot copy buffer: graphics queue is null");
return false;
}
// Create a one-time command pool if not exists
if (m_transferCommandPool == VK_NULL_HANDLE) {
VkCommandPoolCreateInfo poolInfo = {};
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
poolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
poolInfo.queueFamilyIndex = m_queueFamilyIndex;
VkResult result = vkCreateCommandPool(m_device, &poolInfo, nullptr, &m_transferCommandPool);
if (result != VK_SUCCESS) {
logError("Failed to create transfer command pool");
return false;
}
}
// Allocate a one-time command buffer
VkCommandBufferAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandPool = m_transferCommandPool;
allocInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer;
VkResult result = vkAllocateCommandBuffers(m_device, &allocInfo, &commandBuffer);
if (result != VK_SUCCESS) {
logError("Failed to allocate command buffer for copy");
return false;
}
// Begin recording
VkCommandBufferBeginInfo beginInfo = {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
result = vkBeginCommandBuffer(commandBuffer, &beginInfo);
if (result != VK_SUCCESS) {
logError("Failed to begin command buffer for copy");
vkFreeCommandBuffers(m_device, m_transferCommandPool, 1, &commandBuffer);
return false;
}
// Copy command
VkBufferCopy copyRegion = {};
copyRegion.srcOffset = 0;
copyRegion.dstOffset = 0;
copyRegion.size = size;
vkCmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, 1, &copyRegion);
result = vkEndCommandBuffer(commandBuffer);
if (result != VK_SUCCESS) {
logError("Failed to end command buffer for copy");
vkFreeCommandBuffers(m_device, m_transferCommandPool, 1, &commandBuffer);
return false;
}
// Submit and wait
VkSubmitInfo submitInfo = {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffer;
result = vkQueueSubmit(m_graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
if (result != VK_SUCCESS) {
logError("Failed to submit copy command");
vkFreeCommandBuffers(m_device, m_transferCommandPool, 1, &commandBuffer);
return false;
}
result = vkQueueWaitIdle(m_graphicsQueue);
if (result != VK_SUCCESS) {
logError("Failed to wait for queue idle after copy");
}
// Free command buffer
vkFreeCommandBuffers(m_device, m_transferCommandPool, 1, &commandBuffer);
return true;
}
@ -1679,7 +1679,7 @@ uint32_t VulkanRenderer::findMemoryType(uint32_t typeFilter, uint32_t properties
vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &memProperties);
for (uint32_t i = 0; i < memProperties.memoryTypeCount; i++) {
if ((typeFilter & (1 << i)) &&
if ((typeFilter & (1 << i)) &&
(memProperties.memoryTypes[i].propertyFlags & properties) == properties) {
return i;
}
@ -2030,7 +2030,7 @@ void VulkanRenderer::generateRotatingCircles(std::vector<Vertex>& vertices,
{
vertices.clear();
indices.clear();
// Safety check for dimensions
if (m_width == 0 || m_height == 0) {
std::cout << "WARNING: generateRotatingCircles called with zero dimensions!" << std::endl;
@ -2044,7 +2044,7 @@ void VulkanRenderer::generateRotatingCircles(std::vector<Vertex>& vertices,
int numCircles = 8;
float orbitRadius = 80.0f; // Match CustomWidget
float circleRadius = 15.0f; // Match CustomWidget
for (int i = 0; i < numCircles; i++) {
@ -2062,7 +2062,7 @@ void VulkanRenderer::generateRotatingCircles(std::vector<Vertex>& vertices,
// Create circle as triangles
int segments = 16;
uint16_t centerIdx = vertices.size();
// Center vertex with more opaque alpha
vertices.push_back({{x, y}, {r, g, b, 0.9f}, {0.5f, 0.5f}});
@ -2087,7 +2087,7 @@ void VulkanRenderer::generateWaveEffect(std::vector<Vertex>& vertices,
{
vertices.clear();
indices.clear();
// Safety check for dimensions
if (m_width == 0 || m_height == 0) {
std::cout << "WARNING: generateWaveEffect called with zero dimensions!" << std::endl;
@ -2140,7 +2140,7 @@ void VulkanRenderer::generateTextQuads(const std::string& text, float x, float y
for (size_t i = 0; i < text.length(); i++) {
char c = text[i];
// Handle newline
if (c == '\n') {
currentX = x;
@ -2211,7 +2211,7 @@ void VulkanRenderer::drawBackground(VkCommandBuffer commandBuffer, int frameCoun
if (frameIndex >= m_descriptorSets.size()) {
return;
}
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
m_backgroundPipelineLayout, 0, 1, &m_descriptorSets[frameIndex], 0, nullptr);
@ -2251,11 +2251,11 @@ void VulkanRenderer::drawGeometry(VkCommandBuffer commandBuffer, int frameCount,
// Draw waves with line pipeline
if (m_linePipeline != VK_NULL_HANDLE && m_linePipelineLayout != VK_NULL_HANDLE &&
m_waveVertexBuffer != VK_NULL_HANDLE && m_waveIndexBuffer != VK_NULL_HANDLE && m_waveIndexCount > 0) {
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_linePipeline);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
m_linePipelineLayout, 0, 1, &m_descriptorSets[frameIndex], 0, nullptr);
VkBuffer waveBuffers[] = {m_waveVertexBuffer};
VkDeviceSize offsets[] = {0};
vkCmdBindVertexBuffers(commandBuffer, 0, 1, waveBuffers, offsets);
@ -2269,11 +2269,11 @@ void VulkanRenderer::drawText(VkCommandBuffer commandBuffer, int frameCount,
{
static int textDebugCounter = 0;
if (textDebugCounter++ % 300 == 0) { // Every ~5 seconds at 60fps
std::cout << "drawText called: charMap=" << m_charInfoMap.size()
std::cout << "drawText called: charMap=" << m_charInfoMap.size()
<< " pipeline=" << (m_textPipeline != VK_NULL_HANDLE ? "OK" : "NULL")
<< " fontTexView=" << (m_fontTextureView != VK_NULL_HANDLE ? "OK" : "NULL") << std::endl;
}
if (m_charInfoMap.empty() || m_textPipeline == VK_NULL_HANDLE) {
if (textDebugCounter % 300 == 1) {
std::cout << "Text rendering not available - skipping" << std::endl;
@ -2304,17 +2304,17 @@ void VulkanRenderer::drawText(VkCommandBuffer commandBuffer, int frameCount,
// Screen locked state
std::string title = "PAINTING DISABLED";
std::string subtitle = "(Screen Locked)";
generateTextQuads(title, m_width / 2.0f - 250.0f, m_height / 2.0f - 50.0f, 1.2f, white, vertices, indices);
generateTextQuads(subtitle, m_width / 2.0f - 180.0f, m_height / 2.0f + 30.0f, 0.9f, gray, vertices, indices);
generateTextQuads(title, m_width / 2.0f - 250.0f, m_height / 2.0f - 50.0f, 0.6f, white, vertices, indices);
generateTextQuads(subtitle, m_width / 2.0f - 180.0f, m_height / 2.0f + 30.0f, 0.5f, gray, vertices, indices);
// Stats
std::string stats = "Total Frames Painted: " + std::to_string(frameCount);
generateTextQuads(stats, 20.0f, m_height - 60.0f, 0.7f, gray, vertices, indices);
generateTextQuads(stats, 20.0f, m_height - 60.0f, 0.3f, gray, vertices, indices);
} else {
// Active rendering state
std::string title = "Screen Lock Detector - Painting Active";
generateTextQuads(title, m_width / 2.0f - 350.0f, 30.0f, 0.8f, white, vertices, indices);
generateTextQuads(title, m_width / 2.0f - 150.0f, 30.0f, 0.4f, white, vertices, indices);
// Stats info box
std::string frameStr = "Frame Count: " + std::to_string(frameCount);
@ -2322,16 +2322,16 @@ void VulkanRenderer::drawText(VkCommandBuffer commandBuffer, int frameCount,
std::string rotStr = "Rotation: " + std::to_string((int)m_ubo.rotation) + "°";
std::string timeStr = "Running Time: " + std::to_string((int)m_ubo.time) + "s";
generateTextQuads(frameStr, 20.0f, 90.0f, 0.6f, green, vertices, indices);
generateTextQuads(fpsStr, 20.0f, 130.0f, 0.6f, green, vertices, indices);
generateTextQuads(rotStr, 20.0f, 170.0f, 0.6f, green, vertices, indices);
generateTextQuads(timeStr, 20.0f, 210.0f, 0.6f, green, vertices, indices);
generateTextQuads(frameStr, 20.0f, 90.0f, 0.3f, green, vertices, indices);
generateTextQuads(fpsStr, 20.0f, 130.0f, 0.3f, green, vertices, indices);
generateTextQuads(rotStr, 20.0f, 170.0f, 0.3f, green, vertices, indices);
generateTextQuads(timeStr, 20.0f, 210.0f, 0.3f, green, vertices, indices);
// Lock info (if available)
if (!lockInfo.empty()) {
std::string lockTitle = "Last Lock Info:";
generateTextQuads(lockTitle, 20.0f, 270.0f, 0.65f, magenta, vertices, indices);
generateTextQuads(lockTitle, 20.0f, 270.0f, 0.3f, magenta, vertices, indices);
// Parse lock info (assuming format from lockInfo string)
size_t pos = 0;
int line = 0;
@ -2339,19 +2339,19 @@ void VulkanRenderer::drawText(VkCommandBuffer commandBuffer, int frameCount,
while ((pos = info.find('\n')) != std::string::npos) {
std::string token = info.substr(0, pos);
if (!token.empty()) {
generateTextQuads(token, 20.0f, 310.0f + line * 40.0f, 0.5f, magenta, vertices, indices);
generateTextQuads(token, 20.0f, 310.0f + line * 40.0f, 0.2f, magenta, vertices, indices);
line++;
}
info.erase(0, pos + 1);
}
if (!info.empty()) {
generateTextQuads(info, 20.0f, 310.0f + line * 40.0f, 0.5f, magenta, vertices, indices);
generateTextQuads(info, 20.0f, 310.0f + line * 40.0f, 0.2f, magenta, vertices, indices);
}
}
// Hint at bottom
std::string hint = "Lock your screen to see the painting stop automatically!";
generateTextQuads(hint, m_width / 2.0f - 420.0f, m_height - 50.0f, 0.65f, yellow, vertices, indices);
generateTextQuads(hint, m_width / 2.0f - 420.0f, m_height - 50.0f, 0.3f, yellow, vertices, indices);
}
// Create temporary buffers for text
@ -2361,14 +2361,14 @@ void VulkanRenderer::drawText(VkCommandBuffer commandBuffer, int frameCount,
}
return;
}
if (textDebugCounter % 300 == 1) {
std::cout << "Drawing text with " << vertices.size() << " vertices, "
std::cout << "Drawing text with " << vertices.size() << " vertices, "
<< indices.size() << " indices" << std::endl;
std::cout << "Window size: " << m_width << "x" << m_height << std::endl;
if (!vertices.empty()) {
std::cout << "First vertex pos: (" << vertices[0].pos[0] << ", " << vertices[0].pos[1] << ")" << std::endl;
std::cout << "First vertex color: (" << vertices[0].color[0] << ", " << vertices[0].color[1]
std::cout << "First vertex color: (" << vertices[0].color[0] << ", " << vertices[0].color[1]
<< ", " << vertices[0].color[2] << ", " << vertices[0].color[3] << ")" << std::endl;
}
}
@ -2378,7 +2378,7 @@ void VulkanRenderer::drawText(VkCommandBuffer commandBuffer, int frameCount,
static VkDeviceMemory textVertexMemory = VK_NULL_HANDLE;
static VkBuffer textIndexBuffer = VK_NULL_HANDLE;
static VkDeviceMemory textIndexMemory = VK_NULL_HANDLE;
// Cleanup old buffers if they exist
if (textVertexBuffer != VK_NULL_HANDLE) {
vkDestroyBuffer(m_device, textVertexBuffer, nullptr);
@ -2423,4 +2423,4 @@ void VulkanRenderer::logError(const char* message)
} else {
std::cerr << "VulkanRenderer Error: " << message << std::endl;
}
}
}