visualizer work

This commit is contained in:
PS 2022-04-13 16:23:53 +02:00
parent f6ab76ee2a
commit 73afc87a48
5 changed files with 79 additions and 25 deletions

View File

@ -207,6 +207,47 @@ ed_init(App_State* state)
ed_sculpture_visualizer_init(state); ed_sculpture_visualizer_init(state);
} }
internal u8*
ed_leds_to_texture(App_State* state, Allocator_Scratch* scratch, u32 pixels_dim)
{
u32 at = 0;
u32* pixels = allocator_alloc_array(scratch->a, u32, pixels_dim * pixels_dim);
for (u32 a = 0; a < state->assemblies.len; a++)
{
Assembly_Pixel_Buffer leds = state->assemblies.pixel_buffers[a];
for (u32 p = 0; p < leds.len; p++)
{
Assembly_Pixel led = leds.pixels[p];
u32 index = at++;
pixels[index] = (
led.r << 0 |
led.g << 8 |
led.b << 16 |
0xFF << 24
);
}
}
#if 0
for (u32 y = 0; y < pixels_dim; y++)
{
for (u32 x = 0; x < pixels_dim; x++)
{
r32 rp = (r32)y / (r32)pixels_dim;
r32 bp = (r32)x / (r32)pixels_dim;
u8 rb = (u8)(255 * rp);
u8 bb = (u8)(255 * bp);
u32 c = (
0xFF0000FF |
(rb << 8) |
(bb << 16)
);
pixels[(y * pixels_dim) + x] = c;
}
}
#endif
return (u8*)pixels;
}
internal void internal void
ed_sculpture_updated(App_State* state, r32 scale, r32 led_size) ed_sculpture_updated(App_State* state, r32 scale, r32 led_size)
{ {
@ -299,24 +340,8 @@ ed_sculpture_updated(App_State* state, r32 scale, r32 led_size)
// TODO(PS): destroy the old texture // TODO(PS): destroy the old texture
} }
u32* pixels = allocator_alloc_array(scratch.a, u32, pixels_count); u8* pixels = ed_leds_to_texture(state, &scratch, pixels_dim);
for (u32 y = 0; y < pixels_dim; y++) ed->sculpture_tex = platform_texture_create(pixels, pixels_dim, pixels_dim, pixels_dim);
{
for (u32 x = 0; x < pixels_dim; x++)
{
r32 rp = (r32)y / (r32)pixels_dim;
r32 bp = (r32)x / (r32)pixels_dim;
u8 rb = (u8)(255 * rp);
u8 bb = (u8)(255 * bp);
u32 c = (
0xFF0000FF |
(rb << 8) |
(bb << 16)
);
pixels[(y * pixels_dim) + x] = c;
}
}
ed->sculpture_tex = platform_texture_create((u8*)pixels, pixels_dim, pixels_dim, pixels_dim);
} }
internal void internal void
@ -328,7 +353,15 @@ ed_frame_prepare(App_State* state)
internal void internal void
ed_frame(App_State* state) ed_frame(App_State* state)
{ {
UI* ui = &state->editor->ui; Editor* ed = state->editor;
UI* ui = &ed->ui;
{
scratch_get(scratch);
u32 w = ed->sculpture_tex.w;
u8* pixels = ed_leds_to_texture(state, &scratch, w);
platform_texture_update(ed->sculpture_tex, pixels, w, w, w);
}
edr_render_begin(state); edr_render_begin(state);
ui_draw(&state->editor->ui); ui_draw(&state->editor->ui);

View File

@ -83,7 +83,7 @@ ed_sculpture_visualizer(App_State* state)
); );
// TODO(PS): TEMPORARY CAMERA CODE // TODO(PS): TEMPORARY CAMERA CODE
cam_theta += 0.05f; //cam_theta += 0.05f;
v3 camera_pos = v3{sinf(cam_theta) * 50, 0, cosf(cam_theta) * 50}; v3 camera_pos = v3{sinf(cam_theta) * 50, 0, cosf(cam_theta) * 50};
r32 aspect = view_dim.x / view_dim.y; r32 aspect = view_dim.x / view_dim.y;
m44 proj = HMM_Perspective(45.0, aspect, 0.01f, 500); m44 proj = HMM_Perspective(45.0, aspect, 0.01f, 500);

View File

@ -5,6 +5,7 @@ en_init(App_State* state, App_Init_Desc desc)
state->assemblies = assembly_array_create(permanent, desc.assembly_cap); state->assemblies = assembly_array_create(permanent, desc.assembly_cap);
Output* o = &state->output; Output* o = &state->output;
register_output_method(o, OutputData_Invalid, 0, 0);
register_output_method(o, OutputData_NetworkSACN, output_network_sacn_build, output_network_sacn_init()); register_output_method(o, OutputData_NetworkSACN, output_network_sacn_build, output_network_sacn_init());
register_output_method(o, OutputData_ComUART, output_network_sacn_build, output_com_uart_init()); register_output_method(o, OutputData_ComUART, output_network_sacn_build, output_com_uart_init());
} }
@ -15,19 +16,40 @@ en_frame_prepare(App_State* state)
} }
global r32 tt = 0;
internal void internal void
en_frame(App_State* state) en_frame(App_State* state)
{ {
#if 0 scratch_get(scratch);
Assembly_Array assemblies = state->assemblies;
///////////////////////////////////////
// Temp Pattern Simulation
tt += 1.0f / 60.0f;
r32 hrange = 1;
r32 range = hrange * 2;
for (u32 i = 0; i < assemblies.len; i++)
{
Assembly_Pixel_Buffer pixels = assemblies.pixel_buffers[i];
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = pixels.positions[j];
pixels.pixels[j].r = (u8)(((sinf((5 * tt) + (p.x * 10)) + 1) * 0.5f) * 255);
pixels.pixels[j].b = (u8)(((sinf((5 * tt) + (p.z * 10)) + 1) * 0.5f) * 255);
}
}
/////////////////////////////////////// ///////////////////////////////////////
// Output Data // Output Data
Output_Data_Queue output_queue = {}; Output_Data_Queue output_queue = {};
output_queue.a = scratch; output_queue.a = scratch.a;
// build output data buffers // build output data buffers
Output_Methods methods; Output_Methods methods = state->output.methods;
Assembly_Array assemblies = state->assemblies;
for (u32 i = 0; i < assemblies.len; i++) for (u32 i = 0; i < assemblies.len; i++)
{ {
Assembly_Strip_Array strips = assemblies.strip_arrays[i]; Assembly_Strip_Array strips = assemblies.strip_arrays[i];
@ -65,7 +87,6 @@ en_frame(App_State* state)
invalid_code_path; invalid_code_path;
} }
} }
#endif
} }
internal void internal void