working on text renderer now

This commit is contained in:
peterino2 2025-09-01 09:05:05 -07:00
parent c47b598a48
commit 3c1ae7d1b6
22 changed files with 1581 additions and 88 deletions

View File

@ -319,6 +319,7 @@ pub const Parser = struct {
pub fn setupConfigs(configFilePath: []const u8) !void { pub fn setupConfigs(configFilePath: []const u8) !void {
_ = try core.createObject(ConfigRegistry, .{}); _ = try core.createObject(ConfigRegistry, .{});
core.engine_log("loading configs {s}", .{configFilePath});
try getConfigRegistry().loadConfigFile(configFilePath); try getConfigRegistry().loadConfigFile(configFilePath);
} }

View File

@ -400,7 +400,7 @@ pub const Renderer = struct {
} }
} }
fn addAttribute(list: *std.ArrayList(gpu.GPUVertexAttribute), offset: *u32, size: u32, format: gpu.GPUVertexElementFormat) !void { pub fn addAttribute(list: *std.ArrayList(gpu.GPUVertexAttribute), offset: *u32, size: u32, format: gpu.GPUVertexElementFormat) !void {
try list.append(.{ .location = @intCast(list.items.len), .offset = offset.*, .format = format, .buffer_slot = 0 }); try list.append(.{ .location = @intCast(list.items.len), .offset = offset.*, .format = format, .buffer_slot = 0 });
offset.* = offset.* + size; offset.* = offset.* + size;
} }

View File

@ -5,8 +5,10 @@
Texture2D<float4> Texture0 : register(t0, space2); Texture2D<float4> Texture0 : register(t0, space2);
SamplerState Sampler0 : register(s0, space2); SamplerState Sampler0 : register(s0, space2);
StructuredBuffer<FontInfo> fontBuffer: register(t1, space2);
float4 main( float4 main(
float4 Color : TEXCOORD0, uint Color : TEXCOORD0,
float2 UV : TEXCOORD1, float2 UV : TEXCOORD1,
float2 pixelPosition: TEXCOORD2, float2 pixelPosition: TEXCOORD2,
uint Instance: TEXCOORD3 uint Instance: TEXCOORD3
@ -26,11 +28,16 @@ float4 main(
discard; discard;
} }
float4 textColor = float4(
getRedFromUint(Color),
getGreenFromUint(Color),
getBlueFromUint(Color),
getAlphaFromUint(Color));
if(isSdf == 1) if(isSdf == 1)
{ {
float dist = tex.r; float dist = tex.r;
float width = fwidth(dist); float width = fwidth(dist);
float4 textColor = clamp(Color, 0.0, 1.0);
float outerEdge = 1.0f - (120.0f / 255.0f); float outerEdge = 1.0f - (120.0f / 255.0f);
float alpha = contour(dist, outerEdge, width); float alpha = contour(dist, outerEdge, width);
@ -49,16 +56,17 @@ float4 main(
// so 1 + 0.5*4 = 3 is the divisor // so 1 + 0.5*4 = 3 is the divisor
alpha = (alpha + 0.5 * asum) / 3.0; alpha = (alpha + 0.5 * asum) / 3.0;
textColor = float4(Color.xyz, alpha);//textColor.* alpha); textColor = float4(textColor.xyz, alpha);//textColor.* alpha);
textColor.xyz = pow(textColor.xyz, 2.2); // gamma correction textColor.xyz = pow(textColor.xyz, 2.2); // gamma correction
// Premultiplied alpha output. // Premultiplied alpha output.
o = textColor; o = textColor;
} }
else { else
{
float alpha = 1.0; float alpha = 1.0;
float gray = dot(Color.xyz, float3(0.2126, 0.7152, 0.0722)); float gray = dot(textColor.xyz, float3(0.2126, 0.7152, 0.0722));
o = float4(Color.xyz , pow(tex.x / gray, 1/(2.2)) );//textColor.* alpha); o = float4(textColor.xyz , pow(tex.x / gray, 1/(2.2)) );//textColor.* alpha);
//outFragColor = vec4(1.0, 0.0, 0.0, 1.0); //outFragColor = vec4(1.0, 0.0, 0.0, 1.0);
} }

View File

@ -6,7 +6,7 @@
} }
], ],
"types" : { "types" : {
"_9" : { "_13" : {
"name" : "FontInfo", "name" : "FontInfo",
"members" : [ "members" : [
{ {
@ -36,12 +36,12 @@
} }
] ]
}, },
"_8" : { "_12" : {
"name" : "type.StructuredBuffer.FontInfo", "name" : "type.StructuredBuffer.FontInfo",
"members" : [ "members" : [
{ {
"name" : "_m0", "name" : "_m0",
"type" : "_9", "type" : "_13",
"array" : [ "array" : [
0 0
], ],
@ -56,7 +56,7 @@
}, },
"inputs" : [ "inputs" : [
{ {
"type" : "vec4", "type" : "uint",
"name" : "in.var.TEXCOORD0", "name" : "in.var.TEXCOORD0",
"location" : 0 "location" : 0
}, },
@ -101,12 +101,12 @@
], ],
"ssbos" : [ "ssbos" : [
{ {
"type" : "_8", "type" : "_12",
"name" : "fontBuffer", "name" : "fontBuffer",
"readonly" : true, "readonly" : true,
"block_size" : 0, "block_size" : 0,
"set" : 0, "set" : 2,
"binding" : 0 "binding" : 1
} }
] ]
} }

View File

@ -1,9 +1,16 @@
#include "text_shared.hlsli" #include "text_shared.hlsli"
StructuredBuffer<FontInfo> fontBuffer: register(t0, space0);
cbuffer Uniforms : register(b0, space1)
{
float2 Extents;
};
struct VSOut struct VSOut
{ {
float4 Color : TEXCOORD0; uint Color : TEXCOORD0;
float2 UV : TEXCOORD1; float2 UV : TEXCOORD1;
float2 pixelPosition: TEXCOORD2; float2 pixelPosition: TEXCOORD2;
uint Instance: TEXCOORD3; uint Instance: TEXCOORD3;
@ -13,13 +20,9 @@ struct VSOut
struct Input struct Input
{ {
float3 Position : TEXCOORD0; float2 Position : TEXCOORD0;
float3 Normal : TEXCOORD1; float2 UV : TEXCOORD1;
float4 Color : TEXCOORD2; uint Color: TEXCOORD2;
float2 UV : TEXCOORD3;
uint Bones : TEXCOORD4;
uint weights : TEXCOORD5;
uint Instance : SV_InstanceID; uint Instance : SV_InstanceID;
}; };
@ -28,11 +31,10 @@ VSOut main(Input v)
FontInfo s = fontBuffer[v.Instance]; FontInfo s = fontBuffer[v.Instance];
VSOut o; VSOut o;
float2 t = v.Position.xy + s.position; float2 t = v.Position + s.position;
o.pixelPosition = t; o.pixelPosition = t;
//gl_Position = vec4(( (v.Position.xy + pos) / PushConstants.extent) * 2 + vec2(-1.0f, -1.0f), v.Position.z, 1.0); o.Position = float4((t / Extents) * 2 + float2(-1.0f, -1.0f), 0.0, 1.0);
o.Position = float4((t / Extents) * 2 + float2(-1.0f, -1.0f), v.Position.z, 1.0);
o.UV = v.UV; o.UV = v.UV;
o.Color = v.Color; o.Color = v.Color;

View File

@ -66,24 +66,24 @@
}, },
"inputs" : [ "inputs" : [
{ {
"type" : "vec3", "type" : "vec2",
"name" : "in.var.TEXCOORD0", "name" : "in.var.TEXCOORD0",
"location" : 0 "location" : 0
}, },
{ {
"type" : "vec4", "type" : "vec2",
"name" : "in.var.TEXCOORD2", "name" : "in.var.TEXCOORD1",
"location" : 2 "location" : 1
}, },
{ {
"type" : "vec2", "type" : "uint",
"name" : "in.var.TEXCOORD3", "name" : "in.var.TEXCOORD2",
"location" : 3 "location" : 2
} }
], ],
"outputs" : [ "outputs" : [
{ {
"type" : "vec4", "type" : "uint",
"name" : "out.var.TEXCOORD0", "name" : "out.var.TEXCOORD0",
"location" : 0 "location" : 0
}, },

View File

@ -6,9 +6,23 @@ struct FontInfo {
float2 pad2; // 8 bytes float2 pad2; // 8 bytes
}; };
StructuredBuffer<FontInfo> fontBuffer: register(t0, space0); float getRedFromUint(uint color)
cbuffer Uniforms : register(b0, space1)
{ {
float2 Extents; return float(color & 0xFF) / 255.0;
}; }
float getGreenFromUint(uint color)
{
return float((color >> 8) & 0xFF) / 255.0;
}
float getBlueFromUint(uint color)
{
return float((color >> 16) & 0xFF) / 255.0;
}
float getAlphaFromUint(uint color)
{
return float((color >> 24) & 0xFF) / 255.0;
}

View File

@ -18,7 +18,7 @@ drawList: papyrus.DrawList,
first: bool = true, first: bool = true,
rectPipeline: *gpu.GPUGraphicsPipeline = undefined, rectPipeline: *gpu.GPUGraphicsPipeline = undefined,
// textPipeline: *gpu.GPUGraphicsPipeline = undefined, textPipeline: *gpu.GPUGraphicsPipeline = undefined,
tempDrawCommand: std.ArrayListUnmanaged(DrawCommand) = .{}, tempDrawCommand: std.ArrayListUnmanaged(DrawCommand) = .{},
@ -123,8 +123,15 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
pub fn setup(self: *@This()) !void { pub fn setup(self: *@This()) !void {
core.graphics_log("imgui startup", .{}); core.graphics_log("imgui startup", .{});
try rend.registerRendererObject(@This(), self); try rend.registerRendererObject(@This(), self);
const ctx = rend.context();
try self.createRectPipeline(); try self.createRectPipeline();
try self.createTextPipeline();
self.screenBuffers = ScreenBuffers.init(ctx.device);
} }
pub fn destroy(self: *@This()) void { pub fn destroy(self: *@This()) void {
@ -136,7 +143,32 @@ pub fn destroy(self: *@This()) void {
self.allocator.destroy(self); self.allocator.destroy(self);
} }
pub fn createTextPipeline() !void {} pub fn createTextPipeline(self: *@This()) !void {
const ctx = rend.context();
const vertex = try ctx.loadShader("text.vert", text_vert.LoadArgs);
const fragment = try ctx.loadShader("text.frag", text_frag.LoadArgs);
core.graphics_log("text shaders created", .{});
var pci = std.mem.zeroes(gpu.GPUGraphicsPipelineCreateInfo);
pci.vertex_shader = vertex;
pci.fragment_shader = fragment;
var attributes = try textRenderer.addVertexAttributes(&pci);
defer attributes.deinit();
pci.target_info.num_color_targets = 1;
pci.target_info.color_target_descriptions = &[_]gpu.GPUColorTargetDescription{
.{
.format = ctx.swapchainTargetFormat,
.blend_state = std.mem.zeroes(gpu.GPUColorTargetBlendState),
},
};
pci.rasterizer_state.fill_mode = .fillmodeFill;
self.textPipeline = ctx.device.createGPUGraphicsPipeline(&pci);
}
pub fn createRectPipeline(self: *@This()) !void { pub fn createRectPipeline(self: *@This()) !void {
const ctx = rend.context(); const ctx = rend.context();
@ -171,8 +203,6 @@ pub fn createRectPipeline(self: *@This()) !void {
pci.rasterizer_state.fill_mode = .fillmodeFill; pci.rasterizer_state.fill_mode = .fillmodeFill;
self.rectPipeline = ctx.device.createGPUGraphicsPipeline(&pci); self.rectPipeline = ctx.device.createGPUGraphicsPipeline(&pci);
self.screenBuffers = ScreenBuffers.init(ctx.device);
} }
pub fn postRender(p: *anyopaque, cmd: *gpu.GPUCommandBuffer) void { pub fn postRender(p: *anyopaque, cmd: *gpu.GPUCommandBuffer) void {
@ -307,5 +337,9 @@ pub fn drawToTarget(self: *@This(), cmd: *gpu.GPUCommandBuffer, ctx: *papyrus.Co
self.tempDrawCommand.clearRetainingCapacity(); self.tempDrawCommand.clearRetainingCapacity();
} }
pub const textRenderer = @import("textRenderer.zig");
pub const rect_frag = @import("rect.frag"); pub const rect_frag = @import("rect.frag");
pub const rect_vert = @import("rect.vert"); pub const rect_vert = @import("rect.vert");
pub const text_frag = @import("text.frag");
pub const text_vert = @import("text.vert");

View File

@ -0,0 +1,47 @@
// reusing the exact same setup that i used to have in neonwood.
//
const vec2 = text_frag.vec2;
const u8vec4 = text_frag.u8vec4;
const TextMeshVertex = extern struct {
position: vec2,
uv: vec2,
Color: u8vec4,
};
pub fn addVertexAttributes(pci: *gpu.GPUGraphicsPipelineCreateInfo) !std.ArrayList(gpu.GPUVertexAttribute) {
const ctx = rend.context();
var list = std.ArrayList(gpu.GPUVertexAttribute).init(ctx.allocator);
var offset: u32 = 0;
{
const Renderer = rend.renderer.Renderer;
try Renderer.addAttribute(&list, &offset, @sizeOf(f32) * 2, .vertexelementformatFloat2);
try Renderer.addAttribute(&list, &offset, @sizeOf(f32) * 2, .vertexelementformatFloat2);
try Renderer.addAttribute(&list, &offset, @sizeOf(u32), .vertexelementformatUint);
}
pci.vertex_input_state = .{
.num_vertex_buffers = 1,
.vertex_buffer_descriptions = &[_]gpu.GPUVertexBufferDescription{
.{ .slot = 0, .pitch = @sizeOf(TextMeshVertex), .input_rate = .vertexinputrateVertex, .instance_step_rate = 0 },
},
.num_vertex_attributes = @intCast(list.items.len),
.vertex_attributes = @ptrCast(list.items.ptr),
};
return list;
}
const TextBuffer = struct {
pub fn create() @This() {}
};
pub const text_frag = @import("text.frag");
pub const text_vert = @import("text.vert");
pub const rend = @import("rend");
pub const std = @import("std");
const sdl = @import("sdl3");
const gpu = sdl.gpu;

View File

@ -141,11 +141,6 @@ pub const TBMap = struct {
physics.context().system.update(0.001, .{}) catch {}; physics.context().system.update(0.001, .{}) catch {};
// for (self.shapes.items) |*shapeName| {
// //_ = shapeName;
// physics.removeShape(shapeName);
// }
self.shapes.deinit(self.allocator); self.shapes.deinit(self.allocator);
self.root.destroy(); self.root.destroy();

View File

View File

@ -46,5 +46,16 @@ pub fn build(b: *std.Build) void {
newProjectMaker.setModuleEnabled("sys", true); newProjectMaker.setModuleEnabled("sys", true);
_ = newProjectMaker.compileInstall(); _ = newProjectMaker.compileInstall();
const toolbox = blbuild.program(.{
.name = "toolbox",
.desc = "graphical toolbox for random stuff",
.root_source_file = b.path("tools/toolbox.zig"),
});
toolbox.setModuleEnabled("imgui", true);
toolbox.setModuleEnabled("audio", false);
toolbox.setModuleEnabled("sys", true);
_ = toolbox.compileInstall();
blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast); blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast);
} }

View File

@ -18,6 +18,8 @@ struct type_StructuredBuffer_FontInfo
FontInfo _m0[1]; FontInfo _m0[1];
}; };
constant float _60 = {};
struct main0_out struct main0_out
{ {
float4 out_var_SV_Target0 [[color(0)]]; float4 out_var_SV_Target0 [[color(0)]];
@ -25,76 +27,79 @@ struct main0_out
struct main0_in struct main0_in
{ {
float4 in_var_TEXCOORD0 [[user(locn0)]]; uint in_var_TEXCOORD0 [[user(locn0)]];
float2 in_var_TEXCOORD1 [[user(locn1)]]; float2 in_var_TEXCOORD1 [[user(locn1)]];
float2 in_var_TEXCOORD2 [[user(locn2)]]; float2 in_var_TEXCOORD2 [[user(locn2)]];
uint in_var_TEXCOORD3 [[user(locn3)]]; uint in_var_TEXCOORD3 [[user(locn3)]];
}; };
fragment main0_out main0(main0_in in [[stage_in]], const device type_StructuredBuffer_FontInfo& fontBuffer [[buffer(4294967295)]], texture2d<float> Texture0 [[texture(0)]], sampler Sampler0 [[sampler(0)]]) fragment main0_out main0(main0_in in [[stage_in]], const device type_StructuredBuffer_FontInfo& fontBuffer [[buffer(0)]], texture2d<float> Texture0 [[texture(0)]], sampler Sampler0 [[sampler(0)]])
{ {
main0_out out = {}; main0_out out = {};
float4 _64 = Texture0.sample(Sampler0, in.in_var_TEXCOORD1); float4 _68 = Texture0.sample(Sampler0, in.in_var_TEXCOORD1);
bool _99; bool _103;
do do
{ {
bool _81; bool _85;
if (in.in_var_TEXCOORD2.x >= fontBuffer._m0[in.in_var_TEXCOORD3].position.x) if (in.in_var_TEXCOORD2.x >= fontBuffer._m0[in.in_var_TEXCOORD3].position.x)
{ {
_81 = in.in_var_TEXCOORD2.x <= (fontBuffer._m0[in.in_var_TEXCOORD3].position.x + fontBuffer._m0[in.in_var_TEXCOORD3].size); _85 = in.in_var_TEXCOORD2.x <= (fontBuffer._m0[in.in_var_TEXCOORD3].position.x + fontBuffer._m0[in.in_var_TEXCOORD3].size);
} }
else else
{ {
_81 = false; _85 = false;
} }
bool _88; bool _92;
if (_81) if (_85)
{ {
_88 = in.in_var_TEXCOORD2.y >= fontBuffer._m0[in.in_var_TEXCOORD3].position.y; _92 = in.in_var_TEXCOORD2.y >= fontBuffer._m0[in.in_var_TEXCOORD3].position.y;
} }
else else
{ {
_88 = false; _92 = false;
} }
bool _96; bool _100;
if (_88) if (_92)
{ {
_96 = in.in_var_TEXCOORD2.y <= (fontBuffer._m0[in.in_var_TEXCOORD3].position.y + fontBuffer._m0[in.in_var_TEXCOORD3].size); _100 = in.in_var_TEXCOORD2.y <= (fontBuffer._m0[in.in_var_TEXCOORD3].position.y + fontBuffer._m0[in.in_var_TEXCOORD3].size);
} }
else else
{ {
_96 = false; _100 = false;
} }
if (_96) if (_100)
{ {
_99 = true; _103 = true;
break; break;
} }
_99 = false; _103 = false;
break; break;
} while(false); } while(false);
if (!_99) if (!_103)
{ {
discard_fragment(); discard_fragment();
} }
float4 _170; float _109 = float(in.in_var_TEXCOORD0 & 255u) * 0.0039215688593685626983642578125;
float _113 = float((in.in_var_TEXCOORD0 >> 8u) & 255u) * 0.0039215688593685626983642578125;
float _117 = float((in.in_var_TEXCOORD0 >> 16u) & 255u) * 0.0039215688593685626983642578125;
float4 _180;
if (fontBuffer._m0[in.in_var_TEXCOORD3].isSdf == 1u) if (fontBuffer._m0[in.in_var_TEXCOORD3].isSdf == 1u)
{ {
float _107 = _64.x; float _123 = _68.x;
float _108 = fwidth(_107); float _124 = fwidth(_123);
float _109 = 0.529411792755126953125 - _108; float _125 = 0.529411792755126953125 - _124;
float _110 = 0.529411792755126953125 + _108; float _126 = 0.529411792755126953125 + _124;
float2 _116 = (dfdx(in.in_var_TEXCOORD1) + dfdy(in.in_var_TEXCOORD1)) * 0.3540000021457672119140625; float2 _132 = (dfdx(in.in_var_TEXCOORD1) + dfdy(in.in_var_TEXCOORD1)) * 0.3540000021457672119140625;
float4 _123 = float4(in.in_var_TEXCOORD1 - _116, in.in_var_TEXCOORD1 + _116); float4 _139 = float4(in.in_var_TEXCOORD1 - _132, in.in_var_TEXCOORD1 + _132);
float4 _157 = float4(in.in_var_TEXCOORD0.xyz, (fast::clamp(smoothstep(_109, _110, _107), 0.0, 1.0) + (0.5 * (((fast::clamp(smoothstep(_109, _110, Texture0.sample(Sampler0, _123.xy).x), 0.0, 1.0) + fast::clamp(smoothstep(_109, _110, Texture0.sample(Sampler0, _123.zw).x), 0.0, 1.0)) + fast::clamp(smoothstep(_109, _110, Texture0.sample(Sampler0, _123.xw).x), 0.0, 1.0)) + fast::clamp(smoothstep(_109, _110, Texture0.sample(Sampler0, _123.zy).x), 0.0, 1.0)))) * 0.3333333432674407958984375); float4 _170 = float4(_109, _113, _117, (fast::clamp(smoothstep(_125, _126, _123), 0.0, 1.0) + (0.5 * (((fast::clamp(smoothstep(_125, _126, Texture0.sample(Sampler0, _139.xy).x), 0.0, 1.0) + fast::clamp(smoothstep(_125, _126, Texture0.sample(Sampler0, _139.zw).x), 0.0, 1.0)) + fast::clamp(smoothstep(_125, _126, Texture0.sample(Sampler0, _139.xw).x), 0.0, 1.0)) + fast::clamp(smoothstep(_125, _126, Texture0.sample(Sampler0, _139.zy).x), 0.0, 1.0)))) * 0.3333333432674407958984375);
float3 _159 = powr(_157.xyz, float3(2.2000000476837158203125)); float3 _172 = powr(_170.xyz, float3(2.2000000476837158203125));
_170 = float4(_159.x, _159.y, _159.z, _157.w); _180 = float4(_172.x, _172.y, _172.z, _170.w);
} }
else else
{ {
_170 = float4(in.in_var_TEXCOORD0.xyz, powr(_64.x / dot(in.in_var_TEXCOORD0.xyz, float3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875)), 0.4545454680919647216796875)); _180 = float4(_109, _113, _117, powr(_68.x / dot(float4(_109, _113, _117, _60).xyz, float3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875)), 0.4545454680919647216796875));
} }
out.out_var_SV_Target0 = _170; out.out_var_SV_Target0 = _180;
return out; return out;
} }

View File

@ -25,7 +25,7 @@ struct type_Uniforms
struct main0_out struct main0_out
{ {
float4 out_var_TEXCOORD0 [[user(locn0)]]; uint out_var_TEXCOORD0 [[user(locn0)]];
float2 out_var_TEXCOORD1 [[user(locn1)]]; float2 out_var_TEXCOORD1 [[user(locn1)]];
float2 out_var_TEXCOORD2 [[user(locn2)]]; float2 out_var_TEXCOORD2 [[user(locn2)]];
uint out_var_TEXCOORD3 [[user(locn3)]]; uint out_var_TEXCOORD3 [[user(locn3)]];
@ -34,20 +34,20 @@ struct main0_out
struct main0_in struct main0_in
{ {
float3 in_var_TEXCOORD0 [[attribute(0)]]; float2 in_var_TEXCOORD0 [[attribute(0)]];
float4 in_var_TEXCOORD2 [[attribute(2)]]; float2 in_var_TEXCOORD1 [[attribute(1)]];
float2 in_var_TEXCOORD3 [[attribute(3)]]; uint in_var_TEXCOORD2 [[attribute(2)]];
}; };
vertex main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_FontInfo& fontBuffer [[buffer(1)]], uint gl_InstanceIndex [[instance_id]]) vertex main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_FontInfo& fontBuffer [[buffer(1)]], uint gl_InstanceIndex [[instance_id]])
{ {
main0_out out = {}; main0_out out = {};
float2 _51 = in.in_var_TEXCOORD0.xy + fontBuffer._m0[gl_InstanceIndex].position; float2 _46 = in.in_var_TEXCOORD0 + fontBuffer._m0[gl_InstanceIndex].position;
out.out_var_TEXCOORD0 = in.in_var_TEXCOORD2; out.out_var_TEXCOORD0 = in.in_var_TEXCOORD2;
out.out_var_TEXCOORD1 = in.in_var_TEXCOORD3; out.out_var_TEXCOORD1 = in.in_var_TEXCOORD1;
out.out_var_TEXCOORD2 = _51; out.out_var_TEXCOORD2 = _46;
out.out_var_TEXCOORD3 = gl_InstanceIndex; out.out_var_TEXCOORD3 = gl_InstanceIndex;
out.gl_Position = float4(((_51 / Uniforms.Extents) * 2.0) + float2(-1.0), in.in_var_TEXCOORD0.z, 1.0); out.gl_Position = float4(((_46 / Uniforms.Extents) * 2.0) + float2(-1.0), 0.0, 1.0);
return out; return out;
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
[platform.window]
name="Toolbox"
width=640
height=800

View File

@ -28,8 +28,6 @@ pub fn start_module(args: core.ModuleLoaderArgs) !void {
return; return;
} }
core.logDisplay("externGame", "extern game reloaded ", .{});
core.logDisplay("externGame", "hello mother fucker", .{});
core.logDisplay("externGame", "accessing old object at {x} same object? {d}", .{ @intFromPtr(core.EngineObject(ExternGameObject).get()), @sizeOf(ExternGameObject) }); core.logDisplay("externGame", "accessing old object at {x} same object? {d}", .{ @intFromPtr(core.EngineObject(ExternGameObject).get()), @sizeOf(ExternGameObject) });
// getting rid of dumb comment // getting rid of dumb comment

174
projects/tools/toolbox.zig Normal file
View File

@ -0,0 +1,174 @@
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "main");
const GameContext = @This();
allocator: std.mem.Allocator,
commandQueue: core.RingQueue(Task),
activeCommand: ?*sys.SubprocessTask = null,
showInstructions: bool = false,
dockingInitialized: bool = false,
const Task = union(enum(u8)) {
subprocess: *sys.SubprocessTask,
func: *const fn (*GameContext) void,
};
pub fn init(allocator: std.mem.Allocator) !*@This() {
const self = try allocator.create(@This());
self.* = .{
.allocator = allocator,
.commandQueue = try core.RingQueue(Task).init(self.allocator, 4096),
};
return self;
}
pub fn prepare(self: *@This()) !void {
_ = self;
core.engine_log("program ready", .{});
if (core.getEngineObject(imgui.utils.TopBar)) |topbar| {
topbar.menuOpen = true;
}
}
pub fn tick(self: *@This(), dt: f64) void {
_ = dt;
self.tickTasks() catch {};
if (self.activeCommand != null or self.commandQueue.count() > 0) {
ig.setNextWindowPos(.{ .x = 20, .y = 20 }, .{}, .{});
if (ig.begin("tasks", null, .{
.always_auto_resize = true,
.no_title_bar = true,
.no_move = true,
.no_resize = true,
.no_collapse = true,
})) {}
ig.end();
}
// Initialize docking layout on first run
if (!self.dockingInitialized) {
// Get the main viewport dockspace ID (created by dockSpaceOverViewport)
const main_dockspace_id = ig.getID_Str("##DockSpaceViewport_11111111");
// Dock our toolbox window to the center of the main dockspace
ig.dockBuilderDockWindow("Toolbox Window", main_dockspace_id);
ig.dockBuilderFinish(main_dockspace_id);
self.dockingInitialized = true;
}
// Create a docked window
if (ig.begin("Toolbox Window", null, .{})) {
ig.textf("This is a docked toolbox window", .{});
if (ig.button("Recompile Shaders", .{})) {
start_RecompileShaders() catch {};
}
ig.separator();
ig.textf("Additional toolbox content can go here", .{});
if (self.activeCommand != null or self.commandQueue.count() > 0) {
ig.textf("outstanding tasks: {d}", .{self.commandQueue.count() + 1});
if (self.activeCommand) |cmd| {
ig.textf("current command: ", .{});
for (cmd.args) |arg| {
ig.textf("{s}", .{arg});
ig.sameLine(0, 4);
}
}
}
}
ig.end();
}
fn start_RecompileShaders() !void {}
fn tickTasks(self: *@This()) !void {
if (self.activeCommand == null) {
if (self.commandQueue.popFromLocked()) |task| {
switch (task) {
.subprocess => |t| {
self.activeCommand = t;
// core.engine_log("starting task {any}", .{t.args});
try t.run();
},
.func => |f| {
f(self);
},
}
}
}
if (self.activeCommand) |active| {
if (active.checkComplete()) {
active.destroy();
core.engine_logs("task complete");
self.activeCommand = null;
}
}
}
fn loadFileAllocFromCwd(allocator: std.mem.Allocator, dir: std.fs.Dir, path: []const u8) ![]u8 {
var file = try dir.openFile(path, .{});
defer file.close();
const filesize = (try file.stat()).size + 1; // add null byte
const buffer: []u8 = try allocator.alloc(u8, filesize);
errdefer allocator.free(buffer);
try file.reader().readNoEof(buffer[0 .. buffer.len - 1]);
buffer[buffer.len - 1] = 0;
return buffer;
}
fn displayInstructions(self: *@This()) void {
self.showInstructions = true;
}
pub fn deinit(self: *@This()) void {
self.allocator.destroy(self);
}
fn copyRecursiveDir(
allocator: std.mem.Allocator,
src_dir: *std.fs.Dir,
dest_dir: *std.fs.Dir,
) !void {
var walker = try src_dir.walk(allocator);
defer walker.deinit();
while (try walker.next()) |entry| {
switch (entry.kind) {
.file => {
try entry.dir.copyFile(entry.basename, dest_dir.*, entry.path, .{});
},
.directory => {
try dest_dir.makeDir(entry.path);
},
else => {},
}
}
}
pub fn main() anyerror!void {
var spec = try api.getSpec("New Project Dialogue");
try spec.put("useGPA", .{ .boolean = false });
try spec.put("configName", .{ .string = "toolbox" });
_ = api.startEngine(&NeonObjectTable, &spec);
}
const builtin = @import("builtin");
const std = @import("std");
const api = @import("backlog");
const imgui = api.imgui;
const ig = api.imgui.api;
const core = api.core;
const sys = api.sys;