Rework engine
This commit is contained in:
		
							parent
							
								
									6151efb0b5
								
							
						
					
					
						commit
						b20395fc1c
					
				@ -226,6 +226,7 @@ if (NOT BB_IS_CI)
 | 
			
		||||
        "bootstrap/std/font_provider.c"
 | 
			
		||||
        "bootstrap/std/graphics.c"
 | 
			
		||||
        "bootstrap/std/render.c"
 | 
			
		||||
        "bootstrap/std/ui_core.c"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    target_include_directories(${COMPILER_NAME} PRIVATE dependencies/stb)
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@
 | 
			
		||||
STRUCT(Vec4)
 | 
			
		||||
{
 | 
			
		||||
    f32 v[4];
 | 
			
		||||
};
 | 
			
		||||
}__attribute__((aligned(16)));
 | 
			
		||||
 | 
			
		||||
STRUCT(Vertex)
 | 
			
		||||
{
 | 
			
		||||
@ -25,12 +25,23 @@ STRUCT(Vertex)
 | 
			
		||||
};
 | 
			
		||||
decl_vb(Vertex);
 | 
			
		||||
 | 
			
		||||
STRUCT(GPUDrawPushConstants)
 | 
			
		||||
fn TextureIndex white_texture_create(Arena* arena, Renderer* renderer)
 | 
			
		||||
{
 | 
			
		||||
    u64 vertex_buffer;
 | 
			
		||||
    f32 width;
 | 
			
		||||
    f32 height;
 | 
			
		||||
};
 | 
			
		||||
    u32 white_texture_width = 1024;
 | 
			
		||||
    u32 white_texture_height = white_texture_width;
 | 
			
		||||
    auto* white_texture_buffer = arena_allocate(arena, u32, white_texture_width * white_texture_height);
 | 
			
		||||
    memset(white_texture_buffer, 0xff, white_texture_width * white_texture_height * sizeof(u32));
 | 
			
		||||
 | 
			
		||||
    auto white_texture = renderer_texture_create(renderer, (TextureMemory) {
 | 
			
		||||
        .pointer = white_texture_buffer,
 | 
			
		||||
        .width = white_texture_width,
 | 
			
		||||
        .height = white_texture_height,
 | 
			
		||||
        .depth = 1,
 | 
			
		||||
        .format = TEXTURE_FORMAT_R8G8B8A8_SRGB,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return white_texture;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn void draw_string(Renderer* renderer, VirtualBuffer(Vertex)* vertices, VirtualBuffer(u32)* indices, u32 width, u32 height, Vec4 color, String string, TextureAtlas texture_atlas, u32 texture_index)
 | 
			
		||||
{
 | 
			
		||||
@ -49,8 +60,6 @@ fn void draw_string(Renderer* renderer, VirtualBuffer(Vertex)* vertices, Virtual
 | 
			
		||||
        auto uv_width = character->width;
 | 
			
		||||
        auto uv_height = character->height;
 | 
			
		||||
 | 
			
		||||
        print("UV x: {u32}. UV y: {u32}\n", uv_x, uv_y);
 | 
			
		||||
 | 
			
		||||
        *vb_add(vertices, 1) = (Vertex) {
 | 
			
		||||
            .x = pos_x,
 | 
			
		||||
            .y = pos_y,
 | 
			
		||||
@ -97,11 +106,27 @@ fn void draw_string(Renderer* renderer, VirtualBuffer(Vertex)* vertices, Virtual
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void run_app(Arena* arena)
 | 
			
		||||
STRUCT(BBWindow)
 | 
			
		||||
{
 | 
			
		||||
    OSWindow os;
 | 
			
		||||
    RenderWindow* render;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
STRUCT(BBGUIState)
 | 
			
		||||
{
 | 
			
		||||
    Arena* arena;
 | 
			
		||||
    BBWindow* first;
 | 
			
		||||
    BBWindow* last;
 | 
			
		||||
};
 | 
			
		||||
global_variable BBGUIState state;
 | 
			
		||||
 | 
			
		||||
void run_app()
 | 
			
		||||
{
 | 
			
		||||
    state.arena = arena_init(MB(512), MB(2), MB(2));
 | 
			
		||||
 | 
			
		||||
    u8 use_x11 = 1;
 | 
			
		||||
    graphics_init(use_x11);
 | 
			
		||||
    GraphicsWindow* window = graphics_window_create((GraphicsWindowCreate) {
 | 
			
		||||
    os_graphics_init(use_x11);
 | 
			
		||||
    OSWindow os_window = os_window_create((OSWindowCreate) {
 | 
			
		||||
        .name = strlit("Bloat Buster"),
 | 
			
		||||
        .size = {
 | 
			
		||||
            .width = 1024,
 | 
			
		||||
@ -109,67 +134,13 @@ void run_app(Arena* arena)
 | 
			
		||||
        },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (!window)
 | 
			
		||||
    if (!os_window)
 | 
			
		||||
    {
 | 
			
		||||
        failed_execution();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto initial_window_size = graphics_window_size_get(window);
 | 
			
		||||
 | 
			
		||||
    Renderer* renderer = renderer_initialize();
 | 
			
		||||
    RenderWindow* render_window = renderer_window_initialize(renderer, window);
 | 
			
		||||
 | 
			
		||||
    String shader_source_paths[] = {
 | 
			
		||||
        strlit("bootstrap/shaders/font.vert"),
 | 
			
		||||
        strlit("bootstrap/shaders/font.frag"),
 | 
			
		||||
    };
 | 
			
		||||
    PipelineLayoutCreate pipeline_layouts[] = {
 | 
			
		||||
        (PipelineLayoutCreate) {
 | 
			
		||||
            .push_constant_ranges = array_to_slice(((PushConstantRange[]){
 | 
			
		||||
                (PushConstantRange) {
 | 
			
		||||
                    .offset = 0,
 | 
			
		||||
                    .size = sizeof(GPUDrawPushConstants),
 | 
			
		||||
                    .stage = SHADER_STAGE_VERTEX,
 | 
			
		||||
                },
 | 
			
		||||
            })),
 | 
			
		||||
            .descriptor_set_layouts = array_to_slice(((DescriptorSetLayout[]){
 | 
			
		||||
                (DescriptorSetLayout) {
 | 
			
		||||
                    .bindings = array_to_slice(((DescriptorSetLayoutBinding[]) {
 | 
			
		||||
                        {
 | 
			
		||||
                            .binding = 0,
 | 
			
		||||
                            .type = DESCRIPTOR_TYPE_IMAGE_PLUS_SAMPLER,
 | 
			
		||||
                            .stage = SHADER_STAGE_FRAGMENT,
 | 
			
		||||
                            .count = 2,
 | 
			
		||||
                        },
 | 
			
		||||
                    })),
 | 
			
		||||
                },
 | 
			
		||||
            })),
 | 
			
		||||
        },
 | 
			
		||||
    };
 | 
			
		||||
    PipelineCreate pipeline_create[] = {
 | 
			
		||||
        (PipelineCreate) {
 | 
			
		||||
            .shader_source_indices = array_to_slice(((u16[]){0, 1})),
 | 
			
		||||
            .layout_index = 0,
 | 
			
		||||
        },
 | 
			
		||||
    };
 | 
			
		||||
    auto pipeline_index = renderer_graphics_pipelines_create(renderer, arena, (GraphicsPipelinesCreate){
 | 
			
		||||
        .layouts = array_to_slice(pipeline_layouts),
 | 
			
		||||
        .pipelines = array_to_slice(pipeline_create),
 | 
			
		||||
        .shader_sources = array_to_slice(shader_source_paths),
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    u32 white_texture_width = 1024;
 | 
			
		||||
    u32 white_texture_height = white_texture_width;
 | 
			
		||||
    auto* white_texture_buffer = arena_allocate(arena, u32, white_texture_width * white_texture_height / sizeof(u32));
 | 
			
		||||
    memset(white_texture_buffer, 0xff, white_texture_width * white_texture_height);
 | 
			
		||||
 | 
			
		||||
    auto white_texture = renderer_texture_create(renderer, (TextureMemory) {
 | 
			
		||||
        .pointer = white_texture_buffer,
 | 
			
		||||
        .width = white_texture_width,
 | 
			
		||||
        .height = white_texture_height,
 | 
			
		||||
        .depth = 1,
 | 
			
		||||
        .format = R8G8B8A8_SRGB,
 | 
			
		||||
    });
 | 
			
		||||
    Renderer* renderer = renderer_initialize(state.arena);
 | 
			
		||||
    RenderWindow* render_window = renderer_window_initialize(renderer, os_window);
 | 
			
		||||
 | 
			
		||||
    auto font_path = 
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
@ -179,122 +150,154 @@ strlit("/usr/share/fonts/TTF/FiraSans-Regular.ttf")
 | 
			
		||||
#else
 | 
			
		||||
#endif
 | 
			
		||||
;
 | 
			
		||||
    auto texture_atlas = font_create_texture_atlas(arena, (TextureAtlasCreate) {
 | 
			
		||||
 | 
			
		||||
    window_rect_texture_update_begin(render_window);
 | 
			
		||||
    {
 | 
			
		||||
        auto white_texture = white_texture_create(state.arena, renderer);
 | 
			
		||||
        auto monospace_font = font_texture_atlas_create(state.arena, renderer, (TextureAtlasCreate) {
 | 
			
		||||
                .font_path = font_path,
 | 
			
		||||
        .text_height = 72,
 | 
			
		||||
                .text_height = 180,
 | 
			
		||||
                });
 | 
			
		||||
    auto texture_atlas_image = renderer_texture_create(renderer, (TextureMemory) {
 | 
			
		||||
        .pointer = texture_atlas.pointer,
 | 
			
		||||
        .width = texture_atlas.width,
 | 
			
		||||
        .height = texture_atlas.height,
 | 
			
		||||
        .depth = 1,
 | 
			
		||||
        .format = R8G8B8A8_SRGB,
 | 
			
		||||
        auto proportional_font = font_texture_atlas_create(state.arena, renderer, (TextureAtlasCreate) {
 | 
			
		||||
                .font_path = font_path,
 | 
			
		||||
                .text_height = 180,
 | 
			
		||||
                });
 | 
			
		||||
    DescriptorSetUpdate descriptor_set_updates[] = {
 | 
			
		||||
        window_queue_rect_texture_update(render_window, RECT_TEXTURE_SLOT_WHITE, white_texture);
 | 
			
		||||
        renderer_queue_font_update(renderer, render_window, RENDER_FONT_TYPE_MONOSPACE, monospace_font);
 | 
			
		||||
        renderer_queue_font_update(renderer, render_window, RENDER_FONT_TYPE_PROPORTIONAL, proportional_font);
 | 
			
		||||
    }
 | 
			
		||||
    window_rect_texture_update_end(renderer, render_window);
 | 
			
		||||
 | 
			
		||||
    // Vec4 color = {1, 1, 1, 1};
 | 
			
		||||
    // static_assert(sizeof(color) == 4 * sizeof(float));
 | 
			
		||||
    //
 | 
			
		||||
    // u32 texture_index = 1;
 | 
			
		||||
    // // draw_string(renderer, &vertices, &indices, window_size.width, window_size.height, color, strlit("He"), texture_atlas, texture_index);
 | 
			
		||||
    //
 | 
			
		||||
    //
 | 
			
		||||
    // vb_copy_array(&vertices, box_vertices);
 | 
			
		||||
    // vb_copy_array(&indices, box_indices);
 | 
			
		||||
    //
 | 
			
		||||
    // auto vertex_buffer_size = sizeof(*vertices.pointer) * vertices.length;
 | 
			
		||||
    // auto index_buffer_size = sizeof(*indices.pointer) * indices.length;
 | 
			
		||||
    //
 | 
			
		||||
    // auto vertex_buffer = renderer_buffer_create(renderer, vertex_buffer_size, BUFFER_TYPE_VERTEX);
 | 
			
		||||
    // auto vertex_buffer_device_address = buffer_address(vertex_buffer);
 | 
			
		||||
    // auto index_buffer = renderer_buffer_create(renderer, index_buffer_size, BUFFER_TYPE_INDEX);
 | 
			
		||||
    // auto staging_buffer = renderer_buffer_create(renderer, vertex_buffer_size + index_buffer_size, BUFFER_TYPE_STAGING);
 | 
			
		||||
    //
 | 
			
		||||
    // renderer_copy_to_host(staging_buffer, (Slice(HostBufferCopy)) array_to_slice(((HostBufferCopy[]) {
 | 
			
		||||
    //     {
 | 
			
		||||
    //         .destination_offset = 0,
 | 
			
		||||
    //         .source = {
 | 
			
		||||
    //             .pointer = (u8*)vertices.pointer,
 | 
			
		||||
    //             .length = vertex_buffer_size,
 | 
			
		||||
    //         },
 | 
			
		||||
    //     },
 | 
			
		||||
    //     {
 | 
			
		||||
    //         .destination_offset = vertex_buffer_size,
 | 
			
		||||
    //         .source = {
 | 
			
		||||
    //             .pointer = (u8*)indices.pointer,
 | 
			
		||||
    //             .length = index_buffer_size,
 | 
			
		||||
    //         },
 | 
			
		||||
    //     },
 | 
			
		||||
    // })));
 | 
			
		||||
    //
 | 
			
		||||
    // renderer_copy_to_local(renderer, (Slice(LocalBufferCopy)) array_to_slice(((LocalBufferCopy[]) {
 | 
			
		||||
    //     {
 | 
			
		||||
    //         .destination = vertex_buffer,
 | 
			
		||||
    //         .source = staging_buffer,
 | 
			
		||||
    //         .regions = array_to_slice(((LocalBufferCopyRegion[]) {
 | 
			
		||||
    //             {
 | 
			
		||||
    //                 .source_offset = 0,
 | 
			
		||||
    //                 .destination_offset = 0,
 | 
			
		||||
    //                 .size = vertex_buffer_size,
 | 
			
		||||
    //             },
 | 
			
		||||
    //         })),
 | 
			
		||||
    //     },
 | 
			
		||||
    //     {
 | 
			
		||||
    //         .destination = index_buffer,
 | 
			
		||||
    //         .source = staging_buffer,
 | 
			
		||||
    //         .regions = array_to_slice(((LocalBufferCopyRegion[]) {
 | 
			
		||||
    //             {
 | 
			
		||||
    //                 .source_offset = vertex_buffer_size,
 | 
			
		||||
    //                 .destination_offset = 0,
 | 
			
		||||
    //                 .size = index_buffer_size,
 | 
			
		||||
    //             },
 | 
			
		||||
    //         })),
 | 
			
		||||
    //     },
 | 
			
		||||
    // })));
 | 
			
		||||
 | 
			
		||||
    while (!os_window_should_close(os_window))
 | 
			
		||||
    {
 | 
			
		||||
            .set = { .value = 0 },
 | 
			
		||||
            .type = DESCRIPTOR_TYPE_IMAGE_PLUS_SAMPLER,
 | 
			
		||||
            .binding = 0,
 | 
			
		||||
            .descriptor_count = 2,
 | 
			
		||||
            .textures = {
 | 
			
		||||
                [0] = white_texture,
 | 
			
		||||
                [1] = texture_atlas_image,
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
    };
 | 
			
		||||
        os_poll_events();
 | 
			
		||||
 | 
			
		||||
    renderer_update_pipeline_resources(renderer, pipeline_index, (Slice(DescriptorSetUpdate)) array_to_slice(descriptor_set_updates));
 | 
			
		||||
 | 
			
		||||
    VirtualBuffer(Vertex) vertices = {};
 | 
			
		||||
    VirtualBuffer(u32) indices = {};
 | 
			
		||||
 | 
			
		||||
    Vec4 color = {1, 1, 1, 1};
 | 
			
		||||
    static_assert(sizeof(color) == 4 * sizeof(float));
 | 
			
		||||
 | 
			
		||||
    u32 texture_index = 1;
 | 
			
		||||
    draw_string(renderer, &vertices, &indices, initial_window_size.width, initial_window_size.height, color, strlit("He"), texture_atlas, texture_index);
 | 
			
		||||
 | 
			
		||||
    auto vertex_buffer_size = sizeof(*vertices.pointer) * vertices.length;
 | 
			
		||||
    auto index_buffer_size = sizeof(*indices.pointer) * indices.length;
 | 
			
		||||
 | 
			
		||||
    auto vertex_buffer = renderer_buffer_create(renderer, vertex_buffer_size, BUFFER_TYPE_VERTEX);
 | 
			
		||||
    auto vertex_buffer_device_address = buffer_address(vertex_buffer);
 | 
			
		||||
    auto index_buffer = renderer_buffer_create(renderer, index_buffer_size, BUFFER_TYPE_INDEX);
 | 
			
		||||
    auto staging_buffer = renderer_buffer_create(renderer, vertex_buffer_size + index_buffer_size, BUFFER_TYPE_STAGING);
 | 
			
		||||
 | 
			
		||||
    renderer_copy_to_host(staging_buffer, (Slice(HostBufferCopy)) array_to_slice(((HostBufferCopy[]) {
 | 
			
		||||
        {
 | 
			
		||||
            .destination_offset = 0,
 | 
			
		||||
            .source = {
 | 
			
		||||
                .pointer = (u8*)vertices.pointer,
 | 
			
		||||
                .length = vertex_buffer_size,
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            .destination_offset = vertex_buffer_size,
 | 
			
		||||
            .source = {
 | 
			
		||||
                .pointer = (u8*)indices.pointer,
 | 
			
		||||
                .length = index_buffer_size,
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
    })));
 | 
			
		||||
 | 
			
		||||
    renderer_copy_to_local(renderer, (Slice(LocalBufferCopy)) array_to_slice(((LocalBufferCopy[]) {
 | 
			
		||||
        {
 | 
			
		||||
            .destination = vertex_buffer,
 | 
			
		||||
            .source = staging_buffer,
 | 
			
		||||
            .regions = array_to_slice(((LocalBufferCopyRegion[]) {
 | 
			
		||||
                {
 | 
			
		||||
                    .source_offset = 0,
 | 
			
		||||
                    .destination_offset = 0,
 | 
			
		||||
                    .size = vertex_buffer_size,
 | 
			
		||||
                },
 | 
			
		||||
            })),
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            .destination = index_buffer,
 | 
			
		||||
            .source = staging_buffer,
 | 
			
		||||
            .regions = array_to_slice(((LocalBufferCopyRegion[]) {
 | 
			
		||||
                {
 | 
			
		||||
                    .source_offset = vertex_buffer_size,
 | 
			
		||||
                    .destination_offset = 0,
 | 
			
		||||
                    .size = index_buffer_size,
 | 
			
		||||
                },
 | 
			
		||||
            })),
 | 
			
		||||
        },
 | 
			
		||||
    })));
 | 
			
		||||
 | 
			
		||||
    while (!graphics_window_should_close(window))
 | 
			
		||||
    {
 | 
			
		||||
        graphics_poll_events();
 | 
			
		||||
 | 
			
		||||
        auto mouse_position = graphics_window_cursor_position_get(window);
 | 
			
		||||
        auto mouse_position = os_window_cursor_position_get(os_window);
 | 
			
		||||
        // print("Mouse position: ({f64}, {f64})\n", mouse_position.x, mouse_position.y);
 | 
			
		||||
 | 
			
		||||
        auto frame_window_size = renderer_window_frame_begin(renderer, render_window);
 | 
			
		||||
        renderer_window_frame_begin(renderer, render_window);
 | 
			
		||||
        u32 box_x = 200;
 | 
			
		||||
        u32 box_y = 200;
 | 
			
		||||
        u32 box_width = 100;
 | 
			
		||||
        u32 box_height = 100;
 | 
			
		||||
 | 
			
		||||
        Vec4 box_color = { 1, 0, 0, 1 };
 | 
			
		||||
 | 
			
		||||
        window_command_begin(render_window);
 | 
			
		||||
 | 
			
		||||
        window_bind_pipeline(render_window, pipeline_index);
 | 
			
		||||
        window_bind_pipeline_descriptor_sets(render_window, pipeline_index);
 | 
			
		||||
        window_bind_index_buffer(render_window, index_buffer, 0, INDEX_TYPE_U32);
 | 
			
		||||
        GPUDrawPushConstants push_constants = {
 | 
			
		||||
            .vertex_buffer = vertex_buffer_device_address,
 | 
			
		||||
            .width = (f32)frame_window_size.width,
 | 
			
		||||
            .height = (f32)frame_window_size.height,
 | 
			
		||||
        };
 | 
			
		||||
        window_push_constants(render_window, pipeline_index, (SliceP(void)) array_to_slice(((void*[]) {&push_constants})));
 | 
			
		||||
 | 
			
		||||
        window_render_begin(render_window);
 | 
			
		||||
        Vertex box_vertices[] = {
 | 
			
		||||
            {
 | 
			
		||||
            window_draw_indexed(render_window, indices.length, 1, 0, 0, 0);
 | 
			
		||||
        }
 | 
			
		||||
        window_render_end(render_window);
 | 
			
		||||
                .x = box_x,
 | 
			
		||||
                .y = box_y,
 | 
			
		||||
                .color = box_color,
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                .x = box_x + box_width,
 | 
			
		||||
                .y = box_y,
 | 
			
		||||
                .color = box_color,
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                .x = box_x,
 | 
			
		||||
                .y = box_y + box_height,
 | 
			
		||||
                .color = box_color,
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                .x = box_x + box_width,
 | 
			
		||||
                .y = box_y + box_height,
 | 
			
		||||
                .color = box_color,
 | 
			
		||||
            },
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        window_command_end(render_window);
 | 
			
		||||
        u32 box_indices[] = {
 | 
			
		||||
            0, 1, 2,
 | 
			
		||||
            1, 3, 2,
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        window_pipeline_add_vertices(render_window, BB_PIPELINE_RECT, (String)array_to_bytes(box_vertices));
 | 
			
		||||
        window_pipeline_add_indices(render_window, BB_PIPELINE_RECT, (Slice(u32))array_to_slice(box_indices));
 | 
			
		||||
 | 
			
		||||
        renderer_window_frame_end(renderer, render_window);
 | 
			
		||||
        // window_size = os_window_size_get(os_window);
 | 
			
		||||
        //
 | 
			
		||||
        // window_command_begin(render_window);
 | 
			
		||||
        //
 | 
			
		||||
        // // window_bind_pipeline(render_window, pipeline_index);
 | 
			
		||||
        // // window_bind_pipeline_descriptor_sets(render_window, pipeline_index);
 | 
			
		||||
        // // window_bind_index_buffer(render_window, index_buffer, 0, INDEX_TYPE_U32);
 | 
			
		||||
        // // GPUDrawPushConstants push_constants = {
 | 
			
		||||
        // //     .vertex_buffer = vertex_buffer_device_address,
 | 
			
		||||
        // //     .width = (f32)window_size.width,
 | 
			
		||||
        // //     .height = (f32)window_size.height,
 | 
			
		||||
        // // };
 | 
			
		||||
        // // window_push_constants(render_window, pipeline_index, (SliceP(void)) array_to_slice(((void*[]) {&push_constants})));
 | 
			
		||||
        //
 | 
			
		||||
        // window_render_begin(render_window);
 | 
			
		||||
        // {
 | 
			
		||||
        //     // window_draw_indexed(render_window, indices.length, 1, 0, 0, 0);
 | 
			
		||||
        // }
 | 
			
		||||
        // window_render_end(render_window);
 | 
			
		||||
        //
 | 
			
		||||
        // window_command_end(render_window);
 | 
			
		||||
        //
 | 
			
		||||
        // renderer_window_frame_end(renderer, render_window);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: deinitialization
 | 
			
		||||
 | 
			
		||||
@ -24781,8 +24781,8 @@ void entry_point(int argc, char* argv[], char* envp[])
 | 
			
		||||
    unit_tests();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    Arena* global_arena = arena_init(MB(16), KB(64), KB(64));
 | 
			
		||||
#if BB_CI
 | 
			
		||||
    Arena* global_arena = arena_init(MB(512), KB(64), KB(64));
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
        arguments.length = cast_to(u64, s32, argc);
 | 
			
		||||
@ -24850,6 +24850,6 @@ void entry_point(int argc, char* argv[], char* envp[])
 | 
			
		||||
 | 
			
		||||
    thread_clear(thread);
 | 
			
		||||
#else
 | 
			
		||||
    run_app(global_arena);
 | 
			
		||||
    run_app();
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,6 @@
 | 
			
		||||
#include <std/base.h>
 | 
			
		||||
#include <std/os.h>
 | 
			
		||||
 | 
			
		||||
EXPORT void run_app(Arena* arena);
 | 
			
		||||
EXPORT void run_app();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -252,3 +252,8 @@ Hash64 hash_bytes(String bytes);
 | 
			
		||||
Hash32 hash64_to_hash32(Hash64 hash64);
 | 
			
		||||
 | 
			
		||||
u64 round_up_to_next_power_of_2(u64 n);
 | 
			
		||||
 | 
			
		||||
STRUCT(TextureIndex)
 | 
			
		||||
{
 | 
			
		||||
    u32 value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,5 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <std/base.h>
 | 
			
		||||
#include <std/os.h>
 | 
			
		||||
 | 
			
		||||
@ -23,6 +25,7 @@ STRUCT(TextureAtlas)
 | 
			
		||||
    s32 ascent;
 | 
			
		||||
    s32 descent;
 | 
			
		||||
    s32 line_gap;
 | 
			
		||||
    TextureIndex texture;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
STRUCT(TextureAtlasCreate)
 | 
			
		||||
@ -31,4 +34,6 @@ STRUCT(TextureAtlasCreate)
 | 
			
		||||
    u32 text_height;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
EXPORT TextureAtlas font_create_texture_atlas(Arena* arena, TextureAtlasCreate create);
 | 
			
		||||
#include <std/render.h>
 | 
			
		||||
 | 
			
		||||
EXPORT TextureAtlas font_texture_atlas_create(Arena* arena, Renderer* renderer, TextureAtlasCreate create);
 | 
			
		||||
 | 
			
		||||
@ -3,43 +3,48 @@
 | 
			
		||||
#include <std/base.h>
 | 
			
		||||
#include <std/os.h>
 | 
			
		||||
 | 
			
		||||
STRUCT(GraphicsWindowSize)
 | 
			
		||||
typedef void* OSWindow;
 | 
			
		||||
 | 
			
		||||
typedef void OSWindowResize(OSWindow window, void* context, u32 width, u32 height);
 | 
			
		||||
typedef void OSWindowRefresh(OSWindow window, void* context);
 | 
			
		||||
 | 
			
		||||
STRUCT(OSWindowSize)
 | 
			
		||||
{
 | 
			
		||||
    u32 width;
 | 
			
		||||
    u32 height;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
STRUCT(GraphicsWindowCreate)
 | 
			
		||||
STRUCT(OSWindowCreate)
 | 
			
		||||
{
 | 
			
		||||
    String name;
 | 
			
		||||
    GraphicsWindowSize size;
 | 
			
		||||
    OSWindowSize size;
 | 
			
		||||
    void* context;
 | 
			
		||||
    OSWindowResize* resize_callback;
 | 
			
		||||
    OSWindowRefresh* refresh_callback;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
STRUCT(GraphicsCursorPosition)
 | 
			
		||||
STRUCT(OSCursorPosition)
 | 
			
		||||
{
 | 
			
		||||
    f64 x;
 | 
			
		||||
    f64 y;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct GraphicsWindow GraphicsWindow;
 | 
			
		||||
 | 
			
		||||
EXPORT void graphics_init(u8 should_use_x11);
 | 
			
		||||
EXPORT GraphicsWindow* graphics_window_create(GraphicsWindowCreate create);
 | 
			
		||||
EXPORT u8 graphics_window_should_close(GraphicsWindow* window);
 | 
			
		||||
EXPORT void graphics_poll_events();
 | 
			
		||||
EXPORT GraphicsWindowSize graphics_window_size_get(GraphicsWindow* window);
 | 
			
		||||
EXPORT void graphics_window_consume_resize(GraphicsWindow* window);
 | 
			
		||||
EXPORT GraphicsCursorPosition graphics_window_cursor_position_get(GraphicsWindow* window);
 | 
			
		||||
EXPORT void os_graphics_init(u8 should_use_x11);
 | 
			
		||||
EXPORT OSWindow os_window_create(OSWindowCreate create);
 | 
			
		||||
EXPORT u8 os_window_should_close(OSWindow window);
 | 
			
		||||
EXPORT void os_poll_events();
 | 
			
		||||
EXPORT OSWindowSize os_window_size_get(OSWindow window);
 | 
			
		||||
EXPORT OSCursorPosition os_window_cursor_position_get(OSWindow window);
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
typedef unsigned long XID;
 | 
			
		||||
typedef struct _XDisplay Display;
 | 
			
		||||
typedef XID Window;
 | 
			
		||||
 | 
			
		||||
EXPORT Display* graphics_x11_display_get();
 | 
			
		||||
EXPORT Window graphics_x11_window_get(GraphicsWindow* window);
 | 
			
		||||
EXPORT Display* x11_display_get();
 | 
			
		||||
EXPORT Window x11_window_get(OSWindow window);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
EXPORT HANDLE graphics_win32_window_get(GraphicsWindow* window);
 | 
			
		||||
EXPORT HANDLE win32_window_get(GraphicsWindow* window);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -1,25 +1,46 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <std/base.h>
 | 
			
		||||
 | 
			
		||||
#include <std/graphics.h>
 | 
			
		||||
 | 
			
		||||
#define frame_overlap (2)
 | 
			
		||||
 | 
			
		||||
typedef struct Renderer Renderer;
 | 
			
		||||
 | 
			
		||||
#include <std/graphics.h>
 | 
			
		||||
#include <std/font_provider.h>
 | 
			
		||||
 | 
			
		||||
typedef struct RenderWindow RenderWindow;
 | 
			
		||||
typedef struct Pipeline Pipeline;
 | 
			
		||||
 | 
			
		||||
typedef enum BBPipeline
 | 
			
		||||
{
 | 
			
		||||
    BB_PIPELINE_RECT,
 | 
			
		||||
    BB_PIPELINE_COUNT,
 | 
			
		||||
} BBPipeline;
 | 
			
		||||
 | 
			
		||||
typedef enum RenderFontType
 | 
			
		||||
{
 | 
			
		||||
    RENDER_FONT_TYPE_MONOSPACE,
 | 
			
		||||
    RENDER_FONT_TYPE_PROPORTIONAL,
 | 
			
		||||
    RENDER_FONT_TYPE_COUNT,
 | 
			
		||||
} RenderFontType;
 | 
			
		||||
 | 
			
		||||
typedef enum RectTextureSlot
 | 
			
		||||
{
 | 
			
		||||
    RECT_TEXTURE_SLOT_WHITE,
 | 
			
		||||
    RECT_TEXTURE_SLOT_MONOSPACE_FONT,
 | 
			
		||||
    RECT_TEXTURE_SLOT_PROPORTIONAL_FONT,
 | 
			
		||||
    RECT_TEXTURE_SLOT_COUNT
 | 
			
		||||
} RectTextureSlot;
 | 
			
		||||
 | 
			
		||||
typedef enum IndexType : u8
 | 
			
		||||
{
 | 
			
		||||
    INDEX_TYPE_U16,
 | 
			
		||||
    INDEX_TYPE_U32,
 | 
			
		||||
} IndexType;
 | 
			
		||||
 | 
			
		||||
typedef enum TextureFormat : u8
 | 
			
		||||
{
 | 
			
		||||
    R8_UNORM,
 | 
			
		||||
    R8G8B8A8_SRGB,
 | 
			
		||||
    TEXTURE_FORMAT_R8_UNORM,
 | 
			
		||||
    TEXTURE_FORMAT_R8G8B8A8_SRGB,
 | 
			
		||||
} TextureFormat;
 | 
			
		||||
 | 
			
		||||
STRUCT(TextureMemory)
 | 
			
		||||
@ -67,16 +88,16 @@ STRUCT(DescriptorSetLayoutBinding)
 | 
			
		||||
};
 | 
			
		||||
declare_slice(DescriptorSetLayoutBinding);
 | 
			
		||||
 | 
			
		||||
STRUCT(DescriptorSetLayout)
 | 
			
		||||
STRUCT(DescriptorSetLayoutCreate)
 | 
			
		||||
{
 | 
			
		||||
    Slice(DescriptorSetLayoutBinding) bindings;
 | 
			
		||||
};
 | 
			
		||||
declare_slice(DescriptorSetLayout);
 | 
			
		||||
declare_slice(DescriptorSetLayoutCreate);
 | 
			
		||||
 | 
			
		||||
STRUCT(PipelineLayoutCreate)
 | 
			
		||||
{
 | 
			
		||||
    Slice(PushConstantRange) push_constant_ranges;
 | 
			
		||||
    Slice(DescriptorSetLayout) descriptor_set_layouts;
 | 
			
		||||
    Slice(DescriptorSetLayoutCreate) descriptor_set_layouts;
 | 
			
		||||
};
 | 
			
		||||
declare_slice(PipelineLayoutCreate);
 | 
			
		||||
 | 
			
		||||
@ -87,11 +108,6 @@ STRUCT(GraphicsPipelinesCreate)
 | 
			
		||||
    Slice(PipelineCreate) pipelines;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
STRUCT(TextureIndex)
 | 
			
		||||
{
 | 
			
		||||
    u32 value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
STRUCT(PipelineIndex)
 | 
			
		||||
{
 | 
			
		||||
    u32 value;
 | 
			
		||||
@ -107,21 +123,6 @@ STRUCT(DescriptorSetIndex)
 | 
			
		||||
    u32 value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define MAX_TEXTURE_UPDATE_COUNT (32)
 | 
			
		||||
#define MAX_DESCRIPTOR_SET_UPDATE_COUNT (16)
 | 
			
		||||
STRUCT(DescriptorSetUpdate)
 | 
			
		||||
{
 | 
			
		||||
    DescriptorSetIndex set;
 | 
			
		||||
    DescriptorType type;
 | 
			
		||||
    u32 binding;
 | 
			
		||||
    u32 descriptor_count;
 | 
			
		||||
    union
 | 
			
		||||
    {
 | 
			
		||||
        TextureIndex textures[MAX_TEXTURE_UPDATE_COUNT];
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
declare_slice(DescriptorSetUpdate);
 | 
			
		||||
 | 
			
		||||
typedef enum BufferType : u8
 | 
			
		||||
{
 | 
			
		||||
    BUFFER_TYPE_VERTEX,
 | 
			
		||||
@ -129,11 +130,6 @@ typedef enum BufferType : u8
 | 
			
		||||
    BUFFER_TYPE_STAGING,
 | 
			
		||||
} BufferType;
 | 
			
		||||
 | 
			
		||||
STRUCT(BufferIndex)
 | 
			
		||||
{
 | 
			
		||||
    u32 value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
STRUCT(HostBufferCopy)
 | 
			
		||||
{
 | 
			
		||||
    String source;
 | 
			
		||||
@ -149,35 +145,24 @@ STRUCT(LocalBufferCopyRegion)
 | 
			
		||||
};
 | 
			
		||||
declare_slice(LocalBufferCopyRegion);
 | 
			
		||||
 | 
			
		||||
STRUCT(LocalBufferCopy)
 | 
			
		||||
{
 | 
			
		||||
    BufferIndex destination;
 | 
			
		||||
    BufferIndex source;
 | 
			
		||||
    Slice(LocalBufferCopyRegion) regions;
 | 
			
		||||
};
 | 
			
		||||
declare_slice(LocalBufferCopy);
 | 
			
		||||
 | 
			
		||||
#define MAX_LOCAL_BUFFER_COPY_COUNT (16)
 | 
			
		||||
 | 
			
		||||
EXPORT Renderer* renderer_initialize();
 | 
			
		||||
EXPORT RenderWindow* renderer_window_initialize(Renderer* renderer, GraphicsWindow* window);
 | 
			
		||||
EXPORT Renderer* renderer_initialize(Arena* arena);
 | 
			
		||||
EXPORT RenderWindow* renderer_window_initialize(Renderer* renderer, OSWindow window);
 | 
			
		||||
EXPORT PipelineIndex renderer_graphics_pipelines_create(Renderer* renderer, Arena* arena, GraphicsPipelinesCreate create_data);
 | 
			
		||||
EXPORT PipelineLayoutIndex renderer_pipeline_get_layout(PipelineIndex pipeline);
 | 
			
		||||
EXPORT GraphicsWindowSize renderer_window_frame_begin(Renderer* renderer, RenderWindow* window);
 | 
			
		||||
EXPORT void renderer_window_frame_begin(Renderer* renderer, RenderWindow* window);
 | 
			
		||||
EXPORT void renderer_window_frame_end(Renderer* renderer, RenderWindow* window);
 | 
			
		||||
EXPORT TextureIndex renderer_texture_create(Renderer* renderer, TextureMemory texture_memory);
 | 
			
		||||
EXPORT BufferIndex renderer_buffer_create(Renderer* renderer, u64 size, BufferType type);
 | 
			
		||||
EXPORT void renderer_update_pipeline_resources(Renderer* renderer, PipelineIndex pipeline_index, Slice(DescriptorSetUpdate) descriptor_updates);
 | 
			
		||||
EXPORT void renderer_copy_to_host(BufferIndex buffer_index, Slice(HostBufferCopy) regions);
 | 
			
		||||
EXPORT void renderer_copy_to_local(Renderer* renderer, Slice(LocalBufferCopy) copies);
 | 
			
		||||
EXPORT void window_command_begin(RenderWindow* window);
 | 
			
		||||
EXPORT void window_command_end(RenderWindow* window);
 | 
			
		||||
EXPORT void window_render_begin(RenderWindow* window);
 | 
			
		||||
EXPORT void window_render_end(RenderWindow* window);
 | 
			
		||||
 | 
			
		||||
EXPORT void window_bind_pipeline(RenderWindow* window, PipelineIndex pipeline_index);
 | 
			
		||||
EXPORT void window_bind_pipeline_descriptor_sets(RenderWindow* window, PipelineIndex pipeline_index);
 | 
			
		||||
EXPORT void window_bind_index_buffer(RenderWindow* window, BufferIndex index_buffer, u64 offset, IndexType index_type);
 | 
			
		||||
EXPORT void window_push_constants(RenderWindow* window, PipelineIndex pipeline_index, SliceP(void) memories);
 | 
			
		||||
EXPORT u64 buffer_address(BufferIndex buffer_index);
 | 
			
		||||
EXPORT void window_draw_indexed(RenderWindow* window, u32 index_count, u32 instance_count, u32 first_index, s32 vertex_offset, u32 first_instance);
 | 
			
		||||
 | 
			
		||||
EXPORT void window_rect_texture_update_begin(RenderWindow* window);
 | 
			
		||||
EXPORT void renderer_queue_font_update(Renderer* renderer, RenderWindow* window, RenderFontType type, TextureAtlas atlas);
 | 
			
		||||
EXPORT void window_queue_rect_texture_update(RenderWindow* window, RectTextureSlot slot, TextureIndex texture_index);
 | 
			
		||||
EXPORT void window_rect_texture_update_end(Renderer* renderer, RenderWindow* window);
 | 
			
		||||
 | 
			
		||||
EXPORT void window_pipeline_add_vertices(RenderWindow* window, BBPipeline pipeline_index, String vertex_memory);
 | 
			
		||||
EXPORT void window_pipeline_add_indices(RenderWindow* window, BBPipeline pipeline_index, Slice(u32) indices);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								bootstrap/include/std/ui_core.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								bootstrap/include/std/ui_core.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
#include <std/base.h>
 | 
			
		||||
 | 
			
		||||
STRUCT(UI_State)
 | 
			
		||||
{
 | 
			
		||||
};
 | 
			
		||||
@ -15,8 +15,8 @@ layout(set = 0, binding = 0) uniform sampler2D textures[];
 | 
			
		||||
void main() 
 | 
			
		||||
{
 | 
			
		||||
    vec2 texture_size = textureSize(textures[texture_index], 0);
 | 
			
		||||
    //debugPrintfEXT("texture uv: (%f, %f)\n", in_screen_uv.x, in_screen_uv.y);
 | 
			
		||||
    vec2 uv = vec2(in_screen_uv.x / texture_size.x, in_screen_uv.y / texture_size.y);
 | 
			
		||||
    vec4 sampled = texture(textures[texture_index], uv);
 | 
			
		||||
    // debugPrintfEXT("In color: (%f, %f, %f, %f). Sampled: (%f, %f, %f, %f)\n", in_color.x, in_color.y, in_color.z, in_color.w, sampled.x, sampled.y, sampled.z, sampled.w);
 | 
			
		||||
    out_frag_color = in_color * sampled;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,7 @@
 | 
			
		||||
#include <stb_truetype.h>
 | 
			
		||||
#pragma clang diagnostic pop
 | 
			
		||||
 | 
			
		||||
TextureAtlas font_create_texture_atlas(Arena* arena, TextureAtlasCreate create)
 | 
			
		||||
TextureAtlas font_texture_atlas_create(Arena* arena, Renderer* renderer, TextureAtlasCreate create)
 | 
			
		||||
{
 | 
			
		||||
    auto font_file = file_read(arena, create.font_path);
 | 
			
		||||
    stbtt_fontinfo font_info;
 | 
			
		||||
@ -114,5 +114,13 @@ TextureAtlas font_create_texture_atlas(Arena* arena, TextureAtlasCreate create)
 | 
			
		||||
        stbtt_FreeBitmap(bitmap, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    result.texture = renderer_texture_create(renderer, (TextureMemory) {
 | 
			
		||||
        .pointer = result.pointer,
 | 
			
		||||
        .width = result.width,
 | 
			
		||||
        .height = result.height,
 | 
			
		||||
        .depth = 1,
 | 
			
		||||
        .format = TEXTURE_FORMAT_R8G8B8A8_SRGB,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,18 +6,7 @@
 | 
			
		||||
 | 
			
		||||
global_variable u8 use_x11 = 0;
 | 
			
		||||
 | 
			
		||||
STRUCT(GraphicsWindow)
 | 
			
		||||
{
 | 
			
		||||
    GLFWwindow* handle;
 | 
			
		||||
    u8 resized:1;
 | 
			
		||||
    u32 width;
 | 
			
		||||
    u32 height;
 | 
			
		||||
};
 | 
			
		||||
#define MAX_WINDOW_COUNT (32)
 | 
			
		||||
global_variable GraphicsWindow windows[MAX_WINDOW_COUNT];
 | 
			
		||||
global_variable u32 window_count = 0;
 | 
			
		||||
 | 
			
		||||
void graphics_init(u8 should_use_x11)
 | 
			
		||||
void os_graphics_init(u8 should_use_x11)
 | 
			
		||||
{
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
    use_x11 = should_use_x11;
 | 
			
		||||
@ -31,78 +20,80 @@ void graphics_init(u8 should_use_x11)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn void framebuffer_size_callback(GLFWwindow* w, int width, int height)
 | 
			
		||||
global_variable OSWindowResize* resize_callback;
 | 
			
		||||
global_variable OSWindowRefresh* refresh_callback;
 | 
			
		||||
 | 
			
		||||
fn void os_framebuffer_size_callback(GLFWwindow* w, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
    GraphicsWindow* window = glfwGetWindowUserPointer(w);
 | 
			
		||||
    assert(window->handle == w);
 | 
			
		||||
    window->width = width;
 | 
			
		||||
    window->height = height;
 | 
			
		||||
    window->resized = 1;
 | 
			
		||||
    void* context = glfwGetWindowUserPointer(w);
 | 
			
		||||
    if (resize_callback)
 | 
			
		||||
    {
 | 
			
		||||
        resize_callback(w, context, width, height);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef void (* GLFWframebuffersizefun)(GLFWwindow* window, int width, int height);
 | 
			
		||||
fn void os_window_refresh_callback(GLFWwindow* w)
 | 
			
		||||
{
 | 
			
		||||
    void* context = glfwGetWindowUserPointer(w);
 | 
			
		||||
    if (refresh_callback)
 | 
			
		||||
    {
 | 
			
		||||
        refresh_callback(w, context);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GraphicsWindow* graphics_window_create(GraphicsWindowCreate create)
 | 
			
		||||
OSWindow os_window_create(OSWindowCreate create)
 | 
			
		||||
{
 | 
			
		||||
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
 | 
			
		||||
    GraphicsWindow* window = &windows[window_count];
 | 
			
		||||
    *window = (GraphicsWindow) {
 | 
			
		||||
        .handle = glfwCreateWindow(create.size.width, create.size.height, string_to_c(create.name), 0, 0),
 | 
			
		||||
    };
 | 
			
		||||
    glfwSetWindowUserPointer(window->handle, window);
 | 
			
		||||
    glfwSetFramebufferSizeCallback(window->handle, &framebuffer_size_callback);
 | 
			
		||||
    window->width = create.size.width;
 | 
			
		||||
    window->height = create.size.height;
 | 
			
		||||
    GLFWwindow* window = glfwCreateWindow(create.size.width, create.size.height, string_to_c(create.name), 0, 0);
 | 
			
		||||
    glfwSetWindowUserPointer(window, create.context);
 | 
			
		||||
    glfwSetFramebufferSizeCallback(window, &os_framebuffer_size_callback);
 | 
			
		||||
    glfwSetWindowRefreshCallback(window, &os_window_refresh_callback);
 | 
			
		||||
    resize_callback = create.resize_callback;
 | 
			
		||||
    refresh_callback = create.refresh_callback;
 | 
			
		||||
 | 
			
		||||
    return window;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void graphics_window_consume_resize(GraphicsWindow* window)
 | 
			
		||||
u8 os_window_should_close(OSWindow window)
 | 
			
		||||
{
 | 
			
		||||
    assert(window->resized);
 | 
			
		||||
    window->resized = 0;
 | 
			
		||||
    return glfwWindowShouldClose(window);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
u8 graphics_window_should_close(GraphicsWindow* window)
 | 
			
		||||
{
 | 
			
		||||
    return glfwWindowShouldClose(window->handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void graphics_poll_events()
 | 
			
		||||
void os_poll_events()
 | 
			
		||||
{
 | 
			
		||||
    glfwPollEvents();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GraphicsWindowSize graphics_window_size_get(GraphicsWindow* window)
 | 
			
		||||
OSWindowSize os_window_size_get(OSWindow window)
 | 
			
		||||
{
 | 
			
		||||
    GraphicsWindowSize result;
 | 
			
		||||
    glfwGetWindowSize(window->handle, (int*)&result.width, (int*)&result.height);
 | 
			
		||||
    OSWindowSize result;
 | 
			
		||||
    glfwGetWindowSize(window, (int*)&result.width, (int*)&result.height);
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GraphicsCursorPosition graphics_window_cursor_position_get(GraphicsWindow* window)
 | 
			
		||||
OSCursorPosition os_window_cursor_position_get(OSWindow window)
 | 
			
		||||
{
 | 
			
		||||
    GraphicsCursorPosition result;
 | 
			
		||||
    glfwGetCursorPos(window->handle, &result.x, &result.y);
 | 
			
		||||
    OSCursorPosition result;
 | 
			
		||||
    glfwGetCursorPos(window, &result.x, &result.y);
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
HANDLE graphics_win32_window_get(GraphicsWindow* window)
 | 
			
		||||
HANDLE win32_window_get(OSWindow window)
 | 
			
		||||
{
 | 
			
		||||
    return glfwGetWin32Window(window->handle);
 | 
			
		||||
    return glfwGetWin32Window(window);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
Display* graphics_x11_display_get()
 | 
			
		||||
Display* x11_display_get()
 | 
			
		||||
{
 | 
			
		||||
    return glfwGetX11Display();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Window graphics_x11_window_get(GraphicsWindow* window)
 | 
			
		||||
Window x11_window_get(OSWindow window)
 | 
			
		||||
{
 | 
			
		||||
    return glfwGetX11Window(window->handle);
 | 
			
		||||
    return glfwGetX11Window(window);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ EXPORT TextureMemory texture_load_from_file(Arena* arena, String path)
 | 
			
		||||
        .pointer = buffer,
 | 
			
		||||
        .width = width,
 | 
			
		||||
        .height = height,
 | 
			
		||||
        .format = R8G8B8A8_SRGB,
 | 
			
		||||
        .format = TEXTURE_FORMAT_R8G8B8A8_SRGB,
 | 
			
		||||
        .depth = 1,
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -116,7 +116,11 @@ String compile_shader(Arena* arena, String path, ShaderStage shader_stage)
 | 
			
		||||
        strlit(".spv"),
 | 
			
		||||
    })));
 | 
			
		||||
    char* arguments[] = {
 | 
			
		||||
#if _WIN32
 | 
			
		||||
        "C:/VulkanSDK/1.3.296.0/Bin/glslangValidator.exe",
 | 
			
		||||
#else
 | 
			
		||||
        "/usr/bin/glslangValidator",
 | 
			
		||||
#endif
 | 
			
		||||
        "-V",
 | 
			
		||||
        string_to_c(path),
 | 
			
		||||
        "-o",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								bootstrap/std/ui_core.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								bootstrap/std/ui_core.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
#include <std/ui_core.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user