diff --git a/assets/NuberNext.otf b/assets/NuberNext.otf new file mode 100644 index 0000000..acc8fb6 Binary files /dev/null and b/assets/NuberNext.otf differ diff --git a/assets/NuberNextCondensed-DemiBold.otf b/assets/NuberNextCondensed-DemiBold.otf new file mode 100644 index 0000000..3ab6ad4 Binary files /dev/null and b/assets/NuberNextCondensed-DemiBold.otf differ diff --git a/assets/Roboto.ttf b/assets/Roboto.ttf new file mode 100644 index 0000000..d1586a8 Binary files /dev/null and b/assets/Roboto.ttf differ diff --git a/assets/gui.frag.spv b/assets/gui.frag.spv index 7bf5ca3..7e9ac86 100644 Binary files a/assets/gui.frag.spv and b/assets/gui.frag.spv differ diff --git a/assets/gui.vert.spv b/assets/gui.vert.spv index a8a2e35..8e72338 100644 Binary files a/assets/gui.vert.spv and b/assets/gui.vert.spv differ diff --git a/dub.json b/dub.json index 32ef420..ee30fc8 100644 --- a/dub.json +++ b/dub.json @@ -13,7 +13,7 @@ "sourcePaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"], "libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++", "xcb-xfixes", "freetype"], "libs-windows": [], - "versions": ["VK_DEBUG_PRINTF"], + "versions": [], "preGenerateCommands-linux": ["./build.sh"], "preGenerateCommands-windows": [], "dflags": ["-Xcc=-mno-sse", "-P-I/usr/include/freetype2", "-Jbuild", "-Jassets"], diff --git a/src/dlib b/src/dlib index f211a29..69f5cd1 160000 --- a/src/dlib +++ b/src/dlib @@ -1 +1 @@ -Subproject commit f211a29857111a6be26b9cb0e9799ffcb7631df6 +Subproject commit 69f5cd1a76ce0ee4f61201a5cae460664a5d8ca9 diff --git a/src/editor/editor.d b/src/editor/editor.d index 130a45f..7f53c7e 100644 --- a/src/editor/editor.d +++ b/src/editor/editor.d @@ -10,6 +10,7 @@ import buffer; import std.stdio; import std.exception; +//const u8[] FONT_BYTES = import("Roboto.ttf"); const u8[] FONT_BYTES = import("pc-9800.ttf"); const u8[] VERTEX_BYTES = import("gui.vert.spv"); const u8[] FRAGMENT_BYTES = import("gui.frag.spv"); @@ -65,6 +66,7 @@ struct Vertex f32 corner_radius; f32 edge_softness; f32 raised; + u32 texture; } void @@ -74,14 +76,19 @@ Cycle(Editor* ed) Reset(&ed.temp_arena); - f32 pos = 0.0; - f32 h = ed.atlas_buf.atlas.size; - DrawBuffer(ed, 0.0, 0.0, h, ed.active_buffer); //DrawRect(ed, 200.0, 200.0, 300.0, 300.0, 0.0, 0.0, 0.0, Vec4(0.2, 0.4, 0.8, 1.0)); //DrawRect(ed, 330.0, 330.0, 430.0, 430.0, 0.0, 0.0, 0.0, Vec4(0.2, 0.4, 0.8, 1.0)); - DrawRect(ed, 450.0, 450.0, 550.0, 550.0, 0.0, 5.0, 1.0, 20.0, [Vec4(0.2, 0.5, 0.9, 1.0), Vec4(Vec3(0.8), 1.0), Vec4(Vec3(0.8), 1.0), Vec4(Vec3(0.6), 1.0)]); - DrawRect(ed, 450.0, 450.0, 550.0, 550.0, 2.0, 5.0, 1.0, 20.0, [Vec4(Vec3(0.0), 1.0), Vec4(Vec3(0.0), 1.0), Vec4(Vec3(0.0), 1.0), Vec4(Vec3(0.0), 1.0)]); + Vec4 col = Vec4(0.2, 0.5, 0.9, 1.0); + Vec4 col2 = Vec4(0.2, 0.4, 0.7, 1.0); + Vec4 col3 = Vec4(0.2, 0.3, 0.65, 1.0); + Vec4 black = Vec4(0.0, 0.0, 0.0, 1.0); + DrawRect(ed, -1000.0, -1000.0, 3000.0, 3000.0, 0.0, 0.0, 0.0, 0.0, [black, black, black, black]); + //DrawRect(ed, 450.0, 450.0, 550.0, 550.0, 2.0, 5.0, 0.2, 20.0, [black, black, black, black]); + + f32 pos = 0.0; + f32 h = ed.atlas_buf.atlas.size; + DrawBuffer(ed, 0.0, 0.0, h, ed.active_buffer); BeginFrame(&ed.rd); @@ -148,7 +155,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name) Arena arena = CreateArena(MB(32)); FontFace font = OpenFont(cast(u8[])FONT_BYTES); - FontAtlasBuf atlas_buf = CreateAtlas(&arena, font, 14.0, 256); + FontAtlasBuf atlas_buf = CreateAtlas(&arena, font, 16.0, 256); Editor editor = { window: window, @@ -186,7 +193,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name) editor.desc_set = AllocDescSet(&editor.rd, editor.desc_set_layout); editor.pipeline_layout = CreatePipelineLayout(&editor.rd, editor.desc_set_layout, PushConst.sizeof); - Attribute[12] attributes = [ + Attribute[13] attributes = [ { binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 0}, { binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 1}, { binding: 0, location: 2, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof + Vec4.sizeof * 2}, @@ -199,6 +206,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name) { binding: 0, location: 9, format: FMT.R_F32, offset: Vertex.corner_radius.offsetof }, { binding: 0, location: 10, format: FMT.R_F32, offset: Vertex.edge_softness.offsetof }, { binding: 0, location: 11, format: FMT.R_F32, offset: Vertex.raised.offsetof }, + { binding: 0, location: 12, format: FMT.R_U32, offset: Vertex.texture.offsetof }, ]; GfxPipelineInfo ui_info = { @@ -227,7 +235,7 @@ CreateEditor(PlatformWindow* window, u8[] buffer_data, u8[] buffer_name) Write(&editor.rd, editor.desc_set, &editor.font_atlas, 0, DT.Image); - SetClearColors(&editor.rd, [0.149, 0.607, 0.768, 1.0], [0.0, 0.0, 0.0, 0.0]); + SetClearColors(&editor.rd, [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 0.0]); Reset(&editor.temp_arena); @@ -365,13 +373,15 @@ DrawGlyph(Editor* ed, Glyph* glyph, f32 scale, f32* x_pos, f32 y, Vec4 col = Vec v.cols[2] = col; v.cols[3] = col; + v.texture = 1; + AddUIIndices(ed); } *x_pos += glyph.advance * scale; } -void +pragma(inline) void DrawRect(Editor* ed, f32 p0_x, f32 p0_y, f32 p1_x, f32 p1_y, f32 border, f32 corner, f32 softness, f32 raised, Vec4[4] cols) { // Y reversed diff --git a/src/shaders/gui.frag.glsl b/src/shaders/gui.frag.glsl index d86d166..0154884 100644 --- a/src/shaders/gui.frag.glsl +++ b/src/shaders/gui.frag.glsl @@ -5,7 +5,9 @@ #include "gui.layout" -layout (location = 0) in struct FragDataIn { +layout (location = 0) flat in uint in_has_texture; + +layout (location = 1) in struct FragDataIn { vec4 color; vec2 uv; vec2 dst_pos; @@ -17,6 +19,7 @@ layout (location = 0) in struct FragDataIn { float border_thickness; } FD; + layout (location = 0) out vec4 FragColor; float RoundedRectSDF(vec2 pos, vec2 center, vec2 half_size, float radius) @@ -65,9 +68,18 @@ void main() border_factor = inside_f; } - vec4 tex_color = texture(sampler2D(SpriteAtlas, SamplerNearest), FD.uv); - debugPrintfEXT("tex_color %v4f", tex_color); - vec4 out_color = FD.color * tex_color * sdf_factor * border_factor; + vec4 inv_gamma = vec4(1.4); + vec4 gamma = vec4(1.0/1.4); + + vec4 tex_color = vec4(1.0); + if (in_has_texture != 0) + { + tex_color = texture(sampler2D(SpriteAtlas, SamplerNearest), FD.uv); + //tex_color = pow(tex_color, gamma); + } + + vec4 color = FD.color; + vec4 out_color = color * tex_color * sdf_factor * border_factor; FragColor = out_color; } diff --git a/src/shaders/gui.vert.glsl b/src/shaders/gui.vert.glsl index 5d76729..76c9692 100644 --- a/src/shaders/gui.vert.glsl +++ b/src/shaders/gui.vert.glsl @@ -16,8 +16,11 @@ layout (location = 8) in float border_thickness; layout (location = 9) in float corner_radius; layout (location = 10) in float edge_softness; layout (location = 11) in float raised; +layout (location = 12) in uint in_has_texture; -layout (location = 0) out struct FragDataOut { +layout (location = 0) flat out uint out_has_texture; + +layout (location = 1) out struct FragDataOut { vec4 color; vec2 uv; vec2 dst_pos; @@ -29,6 +32,7 @@ layout (location = 0) out struct FragDataOut { float border_thickness; } FragData; + vec2 Vertices[4] = vec2[4]( vec2(-1.0, -1.0), vec2(-1.0, +1.0), @@ -79,6 +83,7 @@ void main() FragData.softness = edge_softness; FragData.raised = raised; FragData.border_thickness = border_thickness; + out_has_texture = in_has_texture; vec4 v_pos = PC.projection * vec4(pos.x, pos.y, 0, 1); gl_Position = vec4(v_pos.x, v_pos.y, 0, 1);