vn/code/vn_platform.h

235 lines
5.6 KiB
C
Raw Normal View History

2023-06-17 17:00:55 +00:00
/* date = April 26th 2023 5:12 pm */
#ifndef VN_PLATFORM_H
#define VN_PLATFORM_H
#include "vn_core.h"
2023-06-17 21:06:25 +00:00
// sixten: Services the platform provides to the application
2023-06-17 17:00:55 +00:00
struct platform_memory_block
{
u8 *Base;
u64 Size;
u64 Used;
platform_memory_block *ArenaPrev;
};
#define PLATFORM_ALLOCATE_MEMORY(name) platform_memory_block *name(u64 Size)
typedef PLATFORM_ALLOCATE_MEMORY(platform_allocate_memory);
#define PLATFORM_DEALLOCATE_MEMORY(name) b32 name(platform_memory_block *Block)
typedef PLATFORM_DEALLOCATE_MEMORY(platform_deallocate_memory);
enum
{
PlatformAccess_Read = 0x1,
PlatformAccess_Write = 0x2,
};
typedef u32 platform_access_flags;
struct platform_file_handle
{
u64 Platform;
b32 IsValid;
};
#define PLATFORM_OPEN_FILE(name) platform_file_handle name(string Path, platform_access_flags FileAccess)
typedef PLATFORM_OPEN_FILE(platform_open_file);
#define PLATFORM_CLOSE_FILE(name) void name(platform_file_handle Handle)
typedef PLATFORM_CLOSE_FILE(platform_close_file);
#define PLATFORM_READ_FILE(name) void name(platform_file_handle Handle, void *Dest, u64 Offset, u64 Size)
typedef PLATFORM_READ_FILE(platform_read_file);
2023-06-19 17:12:26 +00:00
#define PLATFORM_WRITE_FILE(name) void name(platform_file_handle Handle, void *Source, u64 Offset, u64 Size)
typedef PLATFORM_WRITE_FILE(platform_write_file);
2023-06-17 17:00:55 +00:00
#define PLATFORM_GET_FILE_SIZE(name) u64 name(platform_file_handle Handle)
typedef PLATFORM_GET_FILE_SIZE(platform_get_file_size);
enum platform_cursor
{
PlatformCursor_Arrow,
PlatformCursor_Cross,
PlatformCursor_Hand,
PlatformCursor_Help,
PlatformCursor_IBeam,
PlatformCursor_SlashedCircle,
PlatformCursor_ArrowAll,
PlatformCursor_ArrowNESW,
PlatformCursor_ArrowVertical,
PlatformCursor_ArrowNWSE,
PlatformCursor_ArrowHorizontal,
PlatformCursor_Wait,
PlatformCursor_Count
};
#define PLATFORM_SET_CURSOR(name) void name(platform_cursor Cursor)
typedef PLATFORM_SET_CURSOR(platform_set_cursor);
#define PLATFORM_TOGGLE_FULLSCREEN(name) void name(void)
typedef PLATFORM_TOGGLE_FULLSCREEN(platform_toggle_fullscreen);
2023-06-19 17:12:26 +00:00
enum platform_message_type
{
Platform_Message_Info,
Platform_Message_Warning,
Platform_Message_Error,
Platform_Message_Fatal,
};
#define PLATFORM_SHOW_MESSAGE(name) void name(string Message, platform_message_type Type)
typedef PLATFORM_SHOW_MESSAGE(platform_show_message);
2023-06-17 17:00:55 +00:00
struct platform_api
{
platform_allocate_memory *AllocateMemory;
platform_deallocate_memory *DeallocateMemory;
platform_open_file *OpenFile;
platform_close_file *CloseFile;
platform_read_file *ReadFile;
2023-06-19 17:12:26 +00:00
platform_write_file *WriteFile;
2023-06-17 17:00:55 +00:00
platform_get_file_size *GetFileSize;
platform_set_cursor *SetCursor;
platform_toggle_fullscreen *ToggleFullscreen;
2023-06-19 17:12:26 +00:00
platform_show_message *ShowMessage;
2023-06-17 17:00:55 +00:00
};
enum platform_event_type
{
PlatformEvent_Press,
PlatformEvent_Release,
PlatformEvent_Text,
PlatformEvent_MouseScroll,
2023-06-19 17:12:26 +00:00
PlatformEvent_WindowClose,
2023-06-17 17:00:55 +00:00
};
enum platform_key
{
Key_Invalid,
Key_A, Key_B, Key_C, Key_D,
Key_E, Key_F, Key_G, Key_H,
Key_I, Key_J, Key_K, Key_L,
Key_M, Key_N, Key_O, Key_P,
Key_Q, Key_R, Key_S, Key_T,
Key_U, Key_V, Key_W, Key_X,
Key_Y, Key_Z,
Key_F1, Key_F2, Key_F3, Key_F4,
Key_F5, Key_F6, Key_F7, Key_F8,
Key_F9, Key_F10, Key_F11, Key_F12,
Key_Left, Key_Right, Key_Up, Key_Down,
Key_Space,
Key_PageUp, Key_PageDown,
Key_Home, Key_End,
Key_Backspace, Key_Delete,
Key_MouseLeft, Key_MouseMiddle, Key_MouseRight,
};
typedef u32 platform_modifiers;
enum
{
PlatformModifier_Ctrl = (1 << 0),
PlatformModifier_Shift = (1 << 1),
PlatformModifier_Alt = (1 << 2),
PlatformModifier_DoesNotMatter = -1
};
struct platform_event
{
platform_event *Next;
platform_event *Prev;
platform_event_type Type;
platform_modifiers Modifiers;
platform_key Key;
u32 Codepoint;
v2 P;
v2 Scroll;
};
struct platform_event_list
{
platform_event *First;
platform_event *Last;
};
static platform_api Platform;
2023-06-17 21:06:25 +00:00
// sixten: Services that the render backend provides to the application
2023-06-17 17:00:55 +00:00
#include "vn_render.h"
#define RENDER_ALLOCATE_TEXTURE(name) render_handle name(v2s Dim, render_texture_format Format, void *Data)
typedef RENDER_ALLOCATE_TEXTURE(render_allocate_texture);
#define RENDER_FILL_REGION(name) void name(render_handle Handle, v2s DestP, v2s DestDim, void *Data)
typedef RENDER_FILL_REGION(render_fill_region);
struct vn_render_commands
{
render_allocate_texture *AllocateTexture;
render_fill_region *FillRegion;
render_handle WhiteTexture;
u64 MaxPushBufferSize;
u8 *PushBufferBase;
u8 *PushBufferAt;
s32 MaxQuadVertexCount;
quad_vertex *QuadVertexBase;
s32 QuadVertexCount;
s32 MaxQuadIndexCount;
s32 *QuadIndexBase;
s32 QuadIndexCount;
v2 RenderDim;
};
#include "vn_memory.h"
#include "vn_string.h"
#include "vn_thread_context.h"
2023-06-17 21:06:25 +00:00
// sixten: Services the application provides to the platform
2023-06-17 17:00:55 +00:00
struct vn_input
{
2023-06-17 21:06:25 +00:00
// sixten: Platform to application
2023-06-17 17:00:55 +00:00
platform_event_list *EventList;
v2 MouseP;
v2 dMouseP;
r32 dtForFrame;
2023-06-17 21:06:25 +00:00
// sixten: Application to platform
2023-06-18 10:09:36 +00:00
s32 RefreshRate;
2023-06-19 17:12:26 +00:00
b32 ExitRequested;
2023-06-17 17:00:55 +00:00
};
struct vn_memory
{
platform_api PlatformAPI;
struct vn_state *State;
};
#define VN_UPDATE_AND_RENDER(name) void name(thread_context *ThreadContext, vn_memory *Memory, vn_input *Input, vn_render_commands *RenderCommands)
typedef VN_UPDATE_AND_RENDER(vn_update_and_render);
#endif //VN_PLATFORM_H