diff options
| -rw-r--r-- | src/graphics.cc | 16 | ||||
| -rw-r--r-- | src/graphics.h | 4 | ||||
| -rw-r--r-- | src/utils.h | 2 | ||||
| -rw-r--r-- | src/wayclock.cc | 4 |
4 files changed, 23 insertions, 3 deletions
diff --git a/src/graphics.cc b/src/graphics.cc index 40e67ab..cd606b2 100644 --- a/src/graphics.cc +++ b/src/graphics.cc @@ -6,6 +6,7 @@ #include <cstring> +#include "cglm/vec4.h" #include "utils.h" #include "wlstate.h" @@ -98,7 +99,7 @@ void wayc_graphics_deinit(struct graphics_s* graphics) { enum renderer_error_e wayc_renderer_init(struct renderer_s* renderer, struct window_s* window, struct graphics_s* graphics, i32 width, - i32 height) { + i32 height, vec4 ccolor) { wayc_notnull(renderer); wayc_notnull(window); wayc_notnull(graphics); @@ -125,6 +126,7 @@ enum renderer_error_e wayc_renderer_init(struct renderer_s* renderer, renderer->esurface = esurface; renderer->width = width; renderer->height = height; + glm_vec4_copy(ccolor, renderer->ccolor); wayc_renderer_use(renderer); if (gladLoadGLLoader((GLADloadproc)eglGetProcAddress) == 0) { @@ -145,9 +147,21 @@ void wayc_renderer_begin(struct renderer_s* renderer) { swap.gl = gl_swap; swap.width = renderer->width; swap.height = renderer->height; + swap.sample_count = 1; + + sg_color_attachment_action color_action = {}; + color_action.load_action = SG_LOADACTION_CLEAR; + color_action.clear_value = { + WAYC_X(renderer->ccolor), WAYC_Y(renderer->ccolor), + WAYC_Z(renderer->ccolor), WAYC_A(renderer->ccolor)}; + color_action.store_action = SG_STOREACTION_STORE; + + sg_pass_action action = {}; + action.colors[0] = color_action; sg_pass pass = {}; pass.swapchain = swap; + pass.action = action; sg_begin_pass(&pass); } diff --git a/src/graphics.h b/src/graphics.h index 315a879..f8398a2 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -4,6 +4,7 @@ #include <sokol_gfx.h> #include <wayland-egl.h> +#include "cglm/types.h" #include "glad.h" #include "utils.h" #include "window.h" @@ -39,12 +40,13 @@ struct renderer_s { EGLSurface esurface; i32 width, height; + vec4 ccolor; }; enum renderer_error_e wayc_renderer_init(struct renderer_s* renderer, struct window_s* window, struct graphics_s* graphics, i32 width, - i32 height); + i32 height, vec4 ccolor); static inline void wayc_renderer_resize(struct renderer_s* renderer, i32 width, i32 height) { wayc_notnull(renderer); diff --git a/src/utils.h b/src/utils.h index 41eab56..8e739a1 100644 --- a/src/utils.h +++ b/src/utils.h @@ -76,6 +76,8 @@ static inline u32 wayc_min(u32 a, u32 b) { return a > b ? a : b; } #define WAYC_X(v) ((v)[0]) #define WAYC_Y(v) ((v)[1]) +#define WAYC_Z(v) ((v)[2]) +#define WAYC_A(v) ((v)[3]) #define WAYC_TRIANGLE_NVERTS 3 #define WAYC_TRIANGLE_NINDICES 3 diff --git a/src/wayclock.cc b/src/wayclock.cc index c2ef95c..9b71cc4 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -15,6 +15,7 @@ #define WAYC_ATLAS_WIDTH 512 #define WAYC_ATLAS_HEIGHT 512 #define WAYC_FONT_SIZE 48 +#define WAYC_CLEAR_COLOR vec4{0.1f, 0.2f, 0.2f, 1.0f} struct app_s { struct renderer_s* renderer; @@ -101,7 +102,8 @@ int main() { struct renderer_s renderer; if (wayc_renderer_init(&renderer, &window, &graphics, WAYC_APP_WIDTH, - WAYC_APP_HEIGHT) != RENDERER_ERROR_NONE) + WAYC_APP_HEIGHT, + WAYC_CLEAR_COLOR) != RENDERER_ERROR_NONE) wayc_panic("Failed to initialize renderer"); wayc_defer(wayc_renderer_deinit(&renderer)); |
