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
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#pragma once
#include <EGL/egl.h>
#include <wayland-egl.h>
#include "utils.h"
#include "window.h"
enum graphics_error_e : u8 {
GRAPHICS_ERROR_NONE = 0,
GRAPHICS_ERROR_ACQUIRE_DISPLAY,
GRAPHICS_ERROR_SELECT_CONFIG,
GRAPHICS_ERROR_USE_DESKTOP,
GRAPHICS_ERROR_CREATE_CONTEXT,
};
struct graphics_s {
EGLDisplay display;
EGLContext context;
EGLConfig config;
};
enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics,
struct wlstate_s* state);
void wayc_graphics_deinit(struct graphics_s* graphics);
enum renderer_error_e : u8 {
RENDERER_ERROR_NONE = 0,
RENDERER_ERROR_WINDOW_CREATION,
RENDERER_ERROR_SURFACE_CREATION,
};
struct renderer_s {
struct graphics_s* graphics;
wl_egl_window_t ewindow;
EGLSurface esurface;
i32 width, height;
};
enum renderer_error_e wayc_renderer_init(struct renderer_s* renderer,
struct window_s* window,
struct graphics_s* graphics, i32 width,
i32 height);
static inline void wayc_renderer_resize(struct renderer_s* renderer, i32 width,
i32 height) {
wayc_notnull(renderer);
renderer->width = width;
renderer->height = height;
wl_egl_window_resize(renderer->ewindow, width, height, 0, 0);
}
static inline void wayc_renderer_use(struct renderer_s* renderer) {
wayc_notnull(renderer);
struct graphics_s* graphics = renderer->graphics;
EGLDisplay display = graphics->display;
eglMakeCurrent(display, renderer->esurface, renderer->esurface,
graphics->context);
}
static inline void wayc_renderer_swap(struct renderer_s* renderer) {
wayc_notnull(renderer);
struct graphics_s* graphics = renderer->graphics;
EGLDisplay display = graphics->display;
eglSwapBuffers(display, renderer->esurface);
}
void wayc_renderer_deinit(struct renderer_s* renderer);
|