building graphics layer i.e. opening a window.
This commit is contained in:
parent
b0bca46b46
commit
79b6e83147
@ -1 +1,7 @@
|
|||||||
internal void main_thread_entry_point(void) { ThreadNameF("[main thread]"); }
|
internal void main_thread_entry_point(void) {
|
||||||
|
ThreadNameF("[main thread]");
|
||||||
|
|
||||||
|
#if defined(OS_GFX_H)
|
||||||
|
os_gfx_init();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
20
src/goff/goff.c
Normal file
20
src/goff/goff.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
internal void update_and_render(OS_Handle repaint_window_handle) {
|
||||||
|
Temp scratch = scratch_begin(0, 0);
|
||||||
|
|
||||||
|
// pick target hz
|
||||||
|
f32 target_hz = os_get_gfx_info()->default_referesh_rate;
|
||||||
|
|
||||||
|
// Target HZ -> delta time
|
||||||
|
f32 dt = 1.f / target_hz;
|
||||||
|
|
||||||
|
// Get events from OS
|
||||||
|
OS_EventList events = {0};
|
||||||
|
if (os_handle_match(repaint_window_handle, os_handle_zero())) {
|
||||||
|
events = os_get_events(scratch.arena, df_gfx_state->num_frames_requested == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// begin frames
|
||||||
|
{
|
||||||
|
df_core_begin(scratch.arena,
|
||||||
|
}
|
||||||
|
}
|
6
src/goff/goff.h
Normal file
6
src/goff/goff.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef GOFF_H
|
||||||
|
#define GOFF_H
|
||||||
|
|
||||||
|
internal void update_and_render(OS_HANDLE repaint_window);
|
||||||
|
|
||||||
|
#endif // GOFF_H
|
@ -10,4 +10,28 @@
|
|||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
u64 main(int argc, char **argv) { return 0; }
|
// Entry Point
|
||||||
|
|
||||||
|
internal void entry_point() {
|
||||||
|
Temp scratch = scratch_begin(0, 0);
|
||||||
|
|
||||||
|
// Setup layers
|
||||||
|
// {
|
||||||
|
// df_core_init();
|
||||||
|
// df_gfx_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main application loop
|
||||||
|
{
|
||||||
|
for (;;) {
|
||||||
|
|
||||||
|
// Update and render frame here
|
||||||
|
OS_Handle repaint_window = {0};
|
||||||
|
update_and_render(repaint_window);
|
||||||
|
|
||||||
|
// Quit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scratch_end(scratch);
|
||||||
|
}
|
||||||
|
@ -11,6 +11,12 @@ struct OS_SystemInfo {
|
|||||||
String8 machine_name;
|
String8 machine_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle types
|
||||||
|
typedef struct OS_Handle OS_Handle;
|
||||||
|
struct OS_Handle {
|
||||||
|
u64 l_u64[1];
|
||||||
|
}
|
||||||
|
|
||||||
// Process Information
|
// Process Information
|
||||||
typedef struct OS_ProcessInfo OS_ProcessInfo;
|
typedef struct OS_ProcessInfo OS_ProcessInfo;
|
||||||
struct OS_ProcessInfo {
|
struct OS_ProcessInfo {
|
||||||
|
33
src/os/gfx/os_gfx.h
Normal file
33
src/os/gfx/os_gfx.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndefine OS_GFX_H
|
||||||
|
#define OS_GFX_H
|
||||||
|
|
||||||
|
typedef void OS_WindowRepaintFunctionType(OS_Handle window, void *user_data);
|
||||||
|
|
||||||
|
ty
|
||||||
|
|
||||||
|
typedef struct OS_Event OS_Event;
|
||||||
|
struct OS_Event {
|
||||||
|
OS_Event *next;
|
||||||
|
OS_Event *previous;
|
||||||
|
u64 timestamp_us;
|
||||||
|
OS_Handle window;
|
||||||
|
OS_EventKind kind;
|
||||||
|
OS_EventFlag flags;
|
||||||
|
OS_Key key;
|
||||||
|
b32 is_repeat;
|
||||||
|
b32 right_sided;
|
||||||
|
u32 character;
|
||||||
|
u32 repeat_count;
|
||||||
|
Vec2F32 position;
|
||||||
|
Vec2F32 delta;
|
||||||
|
String8List strings;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct OS_EventList OS_EventList;
|
||||||
|
struct OS_EventList {
|
||||||
|
u64 count;
|
||||||
|
OS_Event *first;
|
||||||
|
OS_Event *last;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OS_GFX_H
|
4
src/os/gfx/win32/os_gfx_win32.c
Normal file
4
src/os/gfx/win32/os_gfx_win32.c
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
internal void os_gfx_init(void) {
|
||||||
|
Arena *arena = arena_alloc();
|
||||||
|
os_w32_gfx_state =
|
||||||
|
}
|
51
src/os/gfx/win32/os_gfx_win32.h
Normal file
51
src/os/gfx/win32/os_gfx_win32.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef OS_GFX_WIN32_H
|
||||||
|
#define OS_GFX_WIN32_H
|
||||||
|
|
||||||
|
// Windows
|
||||||
|
typedef struct OS_W32_Window OS_W32_Window;
|
||||||
|
struct OS_W32_Window {
|
||||||
|
OS_W32_Window *next;
|
||||||
|
OS_W32_Window *prev;
|
||||||
|
HWND *hwnd;
|
||||||
|
WINDOWPLACEMENT last_window_placement;
|
||||||
|
OS_WindowRepaintFunctionType *repaint;
|
||||||
|
void *repaint_user_data;
|
||||||
|
f32 dpi;
|
||||||
|
b32 first_paint_done;
|
||||||
|
b32 maximized;
|
||||||
|
Arena *pain_arena;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Global State
|
||||||
|
typedef struct OS_W32_GfxState OS_W32_GfxState;
|
||||||
|
struct OS_W32_GfxState {
|
||||||
|
Arena *arena;
|
||||||
|
u32 gfx_thread_id;
|
||||||
|
HINSTANCE hInstance;
|
||||||
|
HCURSOR hCursor;
|
||||||
|
OS_GfxInfo gfx_info;
|
||||||
|
OS_W32_Window *first_window;
|
||||||
|
OS_W32_Window *last_window;
|
||||||
|
OS_W32_Window *free_window;
|
||||||
|
OS_KEY key_from_vkey_table[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Globals
|
||||||
|
global OS_W32_GfxState *os_w32_gfx_state = 0;
|
||||||
|
global OS_EventList os_w32_event_list = {0};
|
||||||
|
global Arena *os_w32_event_arena = 0;
|
||||||
|
b32 os_w32_resizing = 0;
|
||||||
|
|
||||||
|
// Windows
|
||||||
|
internal OS_Handle os_w32_handle_from_window(OS_W32_Window *window);
|
||||||
|
internal OS_W32_Window *os_w32_window_from_handle(OS_Handle window);
|
||||||
|
internal OS_W32_Window *os_w32_window_from_hwnd(HWND hwnd);
|
||||||
|
internal HWND os_w32_hwnd_from_window(OS_W32_Window *window);
|
||||||
|
internal OS_W32_Window *os_w32_window_alloc(void);
|
||||||
|
internal void os_w32_window_release(OS_W32_Window *window);
|
||||||
|
internal OS_Event *os_w32_push_event(OS_EventKind kind, OS_W32_Window *window);
|
||||||
|
internal OS_Key os_w32_os_key_from_vkey(WPARAM vkey);
|
||||||
|
internal WPARAM os_w32_vkey_from_os_key(OS_Key key);
|
||||||
|
internal LRESULT os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
|
#endif // OS_GFX_WIN32_H
|
Loading…
Reference in New Issue
Block a user