vn/code/vn_platform.h

212 lines
4.2 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
2023-06-21 16:59:36 +00:00
#include "core/core.h"
#include "core/core_math.h"
#include "core/core_memory.h"
#include "core/core_string.h"
#include "core/core_thread_context.h"
2023-06-17 17:00:55 +00:00
2023-06-17 21:06:25 +00:00
// sixten: Services the platform provides to the application
2023-06-17 17:00:55 +00:00
enum
{
2024-01-20 11:18:57 +00:00
PlatformAccess_Read = 0x1,
PlatformAccess_Write = 0x2,
PlatformAccess_OpenAlways = 0x4,
2023-06-17 17:00:55 +00:00
};
typedef u32 platform_access_flags;
struct platform_file_handle
{
2023-12-23 07:27:22 +00:00
u64 Platform;
b32 IsValid;
2023-06-17 17:00:55 +00:00
};
struct platform_file_info
{
2023-12-23 07:27:22 +00:00
string Name;
b32 IsDirectory;
};
struct platform_file_iter
{
2023-12-23 07:27:22 +00:00
u64 U64[1024];
};
2023-06-17 17:00:55 +00:00
enum platform_cursor
{
2023-12-23 07:27:22 +00:00
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
2023-06-17 17:00:55 +00:00
};
2023-06-19 17:12:26 +00:00
enum platform_message_type
{
2023-12-23 07:27:22 +00:00
Platform_Message_Info,
Platform_Message_Warning,
Platform_Message_Error,
Platform_Message_Fatal,
2023-06-19 17:12:26 +00:00
};
2023-06-17 17:00:55 +00:00
enum platform_event_type
{
2023-12-23 07:27:22 +00:00
PlatformEvent_Press,
PlatformEvent_Release,
PlatformEvent_Text,
PlatformEvent_MouseScroll,
PlatformEvent_WindowClose,
2023-06-17 17:00:55 +00:00
};
enum platform_key
{
2023-12-23 07:27:22 +00:00
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_Return,
Key_PageUp, Key_PageDown,
Key_Home, Key_End,
2023-12-26 08:11:41 +00:00
Key_Plus, Key_Minus,
2023-12-26 09:52:45 +00:00
Key_Period, Key_Comma,
2023-12-23 07:27:22 +00:00
Key_Backspace, Key_Delete,
Key_Escape,
Key_MouseLeft, Key_MouseMiddle, Key_MouseRight,
2023-06-17 17:00:55 +00:00
};
typedef u32 platform_modifiers;
enum
{
2023-12-23 07:27:22 +00:00
PlatformModifier_Ctrl = (1 << 0),
PlatformModifier_Shift = (1 << 1),
PlatformModifier_Alt = (1 << 2),
PlatformModifier_DoesNotMatter = -1
2023-06-17 17:00:55 +00:00
};
struct platform_event
{
2023-12-23 07:27:22 +00:00
platform_event *Next;
platform_event *Prev;
platform_event_type Type;
platform_modifiers Modifiers;
platform_key Key;
u32 Codepoint;
2024-01-20 11:18:57 +00:00
v2_r32 P;
v2_r32 Scroll;
2023-06-17 17:00:55 +00:00
};
struct platform_event_list
{
2023-12-23 07:27:22 +00:00
platform_event *First;
platform_event *Last;
2023-06-17 17:00:55 +00:00
};
2023-07-19 15:09:41 +00:00
#include "generated/vn_platform.meta.h"
2023-06-17 17:00:55 +00:00
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"
2023-10-04 17:21:15 +00:00
#define RENDER_ALLOCATE_TEXTURE(name) render_handle name(v2_s32 Dim, render_texture_format Format, b32 GenerateMipmap, void *Data)
2023-06-17 17:00:55 +00:00
typedef RENDER_ALLOCATE_TEXTURE(render_allocate_texture);
2023-12-23 07:27:22 +00:00
#define RENDER_DEALLOCATE_TEXTURE(name) void name(render_handle Handle)
typedef RENDER_DEALLOCATE_TEXTURE(render_deallocate_texture);
2023-06-21 16:59:36 +00:00
#define RENDER_FILL_REGION(name) void name(render_handle Handle, v2_s32 DestP, v2_s32 DestDim, void *Data)
2023-06-17 17:00:55 +00:00
typedef RENDER_FILL_REGION(render_fill_region);
struct vn_render_commands
{
2023-12-23 07:27:22 +00:00
render_allocate_texture *AllocateTexture;
render_deallocate_texture *DeallocateTexture;
render_fill_region *FillRegion;
render_handle WhiteTexture;
u64 MaxPushBufferSize;
u8 *PushBufferBase;
u8 *PushBufferAt;
2023-08-22 03:19:51 +00:00
#if VN_USE_INSTANCING
2023-12-23 07:27:22 +00:00
s32 MaxInstancedQuadCount;
instanced_quad *InstancedQuadBase;
s32 InstancedQuadCount;
2023-08-22 03:19:51 +00:00
#else
2023-12-23 07:27:22 +00:00
s32 MaxQuadVertexCount;
quad_vertex *QuadVertexBase;
s32 QuadVertexCount;
s32 MaxQuadIndexCount;
s32 *QuadIndexBase;
s32 QuadIndexCount;
2023-08-22 03:19:51 +00:00
#endif
2023-12-23 07:27:22 +00:00
2024-01-20 11:18:57 +00:00
v2_r32 RenderDim;
2023-06-17 17:00:55 +00:00
};
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-12-23 07:27:22 +00:00
// sixten: Platform to application
platform_event_list *EventList;
2024-01-20 11:18:57 +00:00
v2_r32 MouseP;
v2_r32 dMouseP;
2023-12-23 07:27:22 +00:00
r32 dtForFrame;
// sixten: Application to platform
s32 RefreshRate;
b32 ExitRequested;
2023-06-17 17:00:55 +00:00
};
struct vn_memory
{
2023-12-23 07:27:22 +00:00
platform_api PlatformAPI;
struct vn_state *State;
2023-06-17 17:00:55 +00:00
};
#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);
2023-06-21 16:59:36 +00:00
#include "core/core_math.cpp"
#include "core/core_memory.cpp"
#include "core/core_string.cpp"
#include "core/core_thread_context.cpp"
2023-06-17 17:00:55 +00:00
#endif //VN_PLATFORM_H