summaryrefslogtreecommitdiff
path: root/src/rendering/include/engine/rendering/platform.h
blob: ea51c474c0779e80dee252deef694587e0aa68d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef PLATFORM_H
#define PLATFORM_H

#ifdef __cplusplus
extern "C" {
#endif

#include <cglm/ivec2.h>

#include <engine/core/types.h>
// TODO: We only need the window once all the garbage in Instance is cleaned up.
#include <engine/core/platform.h>
#include <engine/rendering/window.h>

#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 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