From f6b60693e298ca9c155be75ed2e4c687f3fa0fa5 Mon Sep 17 00:00:00 2001 From: onelin Date: Thu, 10 Apr 2025 23:44:19 +0200 Subject: Copy GLFW + OpenGL initialization code --- src/rendering/include/engine/rendering/platform.h | 57 ++++++++++++++++++++++ .../include/engine/rendering/platform_glfw.h | 32 ++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 src/rendering/include/engine/rendering/platform.h create mode 100644 src/rendering/include/engine/rendering/platform_glfw.h (limited to 'src/rendering/include/engine') diff --git a/src/rendering/include/engine/rendering/platform.h b/src/rendering/include/engine/rendering/platform.h new file mode 100644 index 0000000..5d2408e --- /dev/null +++ b/src/rendering/include/engine/rendering/platform.h @@ -0,0 +1,57 @@ +#ifndef PLATFORM_H +#define PLATFORM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +// TODO: We only need the window once all the garbage in Instance is cleaned up. +#include +#include + +#define DAW_WINDOW_VSYNC (1 << 0) +#define DAW_WINDOW_FULLSCREEN (1 << 1) +#define DAW_WINDOW_RESIZEABLE (1 << 2) + +// Whether or not it is clever to force API consistency using a struct like this +// can be debated, at the time of writing it seemed like a smart idea. + +// Platform libraries must implement a struct Platform: +struct Platform { + /* Initialize a window for the given platform. The rendering backend should + * also be initialized here. + * Parameters: + * const char* title: window title. + * ivec2 windowsize: the size in pixels for the new window. + * const u32 flags: window flags, such as static size and fullscreen. + * The flags are platform agnostic and needs to be + * converted to the specific library + * Returns: + * A pointer to a struct Window, NULL on error. + */ + Window* (*window_init)(const Instance *restrict i, const char *restrict title, ivec2 windowsize, const u32 flags); + + /* Destroy, close, and free up resources related to the window and the + * platform library specific resources. + */ + void (*window_destroy)(Window *restrict w); + + /* Resize the given window. Resize callbacks are handled by the wrapper + * implementation. + */ + void (*window_resize)(Window *restrict window, int width, int height); + + /* Return true if the platform has ordered the window to exit. */ + bool (*window_should_close)(Window *restrict w); + + /* Poll events on the window from the operating system. */ + void (*window_poll)(void); +}; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/rendering/include/engine/rendering/platform_glfw.h b/src/rendering/include/engine/rendering/platform_glfw.h new file mode 100644 index 0000000..cbc3520 --- /dev/null +++ b/src/rendering/include/engine/rendering/platform_glfw.h @@ -0,0 +1,32 @@ +#ifndef PLATFORM_GLFW_H +#define PLATFORM_GLFW_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include +#include + +Window* window_init_glfw(const Instance *restrict i, const char *restrict windowtitle, ivec2 windowsize, const u32 flags); +void window_destroy_glfw(Window *restrict w); +void window_resize_glfw(Window *restrict window, int width, int height); +bool window_should_close_glfw(Window *restrict window); +void window_poll_glfw(void); + +const struct Platform Platform_GLFW = { + .window_init = window_init_glfw, + .window_destroy = window_destroy_glfw, + .window_resize = window_resize_glfw, + .window_should_close = window_should_close_glfw, + .window_poll = window_poll_glfw, +}; + +#ifdef __cplusplus +} +#endif +#endif + -- cgit v1.3