summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rendering.cc75
-rw-r--r--src/rendering.h53
-rw-r--r--src/utils.h2
-rw-r--r--src/wlstate.cc6
4 files changed, 125 insertions, 11 deletions
diff --git a/src/rendering.cc b/src/rendering.cc
index b26106f..52d4eae 100644
--- a/src/rendering.cc
+++ b/src/rendering.cc
@@ -1,5 +1,76 @@
#include "rendering.h"
-bool atlas_init(atlas_t* atlas, u32 width, u32 height) {}
+#include <glad.h>
-void atlas_deinit(atlas_t* atlas) {}
+#include "utils.h"
+
+bool wayc_image_init(texture_t* texture, image_type_e type,
+ image_format_e format, u32 width, u32 height) {
+ bool success = false;
+ glGenTextures(1, texture);
+ wayc_defer_cond(glDeleteTextures(1, texture), success, true);
+
+ glBindTexture(type, *texture);
+ switch (type) {
+ case IMAGE_TYPE_2D:
+ glTexStorage2D(type, 1, format, width, height);
+ break;
+ default:
+ return success;
+ }
+
+ glBindTexture(type, 0);
+
+ success = true;
+ return success;
+}
+
+bool wayc_image_upload(texture_t texture, ivec2 offset, u32 width, u32 height,
+ image_type_e type, image_format_e format,
+ image_data_type_e data_type, const u8* data) {
+ glBindTexture(type, texture);
+ switch (type) {
+ case IMAGE_TYPE_2D:
+ glTexSubImage2D(type, 0, offset[0], offset[1], width, height, format,
+ data_type, data);
+ break;
+ default:
+ return false;
+ }
+
+ return true;
+}
+
+void wayc_image_use(texture_t texture, image_type_e type, u32 slot) {
+ glActiveTexture(GL_TEXTURE0 + slot);
+ glBindTexture(type, texture);
+}
+
+void wayc_image_deinit(texture_t* texture) { glDeleteTextures(1, texture); }
+
+bool wayc_sampler_init(sampler_t* sampler, sample_filter_e filter,
+ sample_wrap_e wrap) {
+ glGenSamplers(1, sampler);
+ if (*sampler == 0) return false;
+
+ glSamplerParameteri(*sampler, GL_TEXTURE_MIN_FILTER, filter);
+ glSamplerParameteri(*sampler, GL_TEXTURE_MAG_FILTER, filter);
+ glSamplerParameteri(*sampler, GL_TEXTURE_WRAP_S, wrap);
+ glSamplerParameteri(*sampler, GL_TEXTURE_WRAP_T, wrap);
+
+ return true;
+}
+
+void wayc_sampler_use(sampler_t sampler, u32 slot) {
+ glActiveTexture(GL_TEXTURE0 + slot);
+ glBindSampler(slot, sampler);
+}
+
+void wayc_sampler_deinit(sampler_t* sampler) { glDeleteSamplers(1, sampler); }
+
+bool wayc_atlas_init(atlas_t* atlas, image_format_e format, u32 width,
+ u32 height) {
+ return wayc_image_init(atlas, IMAGE_TYPE_2D, format, width, height);
+}
+
+void wayc_atlas_deinit(atlas_t* atlas) { wayc_image_deinit(atlas); }
diff --git a/src/rendering.h b/src/rendering.h
index b7d4a2a..7803040 100644
--- a/src/rendering.h
+++ b/src/rendering.h
@@ -3,14 +3,57 @@
#include <cglm/cglm.h>
#include "cglm/types.h"
+#include "glad.h"
#include "utils.h"
struct uv_s {
- vec2 uv0;
- vec2 uv1;
+ ivec2 uv0;
+ ivec2 uv1;
};
-typedef u32 atlas_t;
+enum image_type_e {
+ IMAGE_TYPE_2D = GL_TEXTURE_2D,
+};
+
+enum image_format_e {
+ IMAGE_FORMAT_RGBA = GL_RGBA,
+};
+
+enum image_data_type_e {
+ IMAGE_DATA_TYPE_UNSIGNED_BYTE = GL_UNSIGNED_BYTE,
+};
+
+typedef u32 texture_t;
+
+bool wayc_image_init(texture_t* texture, image_type_e type,
+ image_format_e format, u32 width, u32 height);
+
+bool wayc_image_upload(texture_t texture, ivec2 offset, u32 width, u32 height,
+ image_type_e type, image_format_e format,
+ image_data_type_e data_type, const u8* data);
+
+void wayc_image_use(texture_t texture, image_type_e type, u32 slot);
+void wayc_image_deinit(texture_t* texture);
+
+enum sample_filter_e {
+ SAMPLE_FILTER_NEAREST = GL_NEAREST,
+ SAMPLE_FILTER_LINEAR = GL_LINEAR,
+};
+
+enum sample_wrap_e {
+ SAMPLE_WRAP_CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
+ SAMPLE_WRAP_REPEAT = GL_REPEAT,
+};
+
+typedef u32 sampler_t;
+
+bool wayc_sampler_init(sampler_t* sampler, sample_filter_e filter,
+ sample_wrap_e wrap);
+void wayc_sampler_use(sampler_t sampler, u32 slot);
+void wayc_sampler_deinit(sampler_t* sampler);
+
+typedef texture_t atlas_t;
-bool atlas_init(atlas_t* atlas, u32 width, u32 height);
-void atlas_deinit(atlas_t* atlas);
+bool wayc_atlas_init(atlas_t* atlas, image_format_e format, u32 width,
+ u32 height);
+void wayc_atlas_deinit(atlas_t* atlas);
diff --git a/src/utils.h b/src/utils.h
index ce19428..f159c9b 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -62,7 +62,7 @@ static inline u32 wayc_min(u32 a, u32 b) { return a > b ? a : b; }
if (!(expr)) wayc_panic("Assertion failed: %s", #expr); \
} while (0)
-#define wayc_notnull(expr) wayc_assert(expr != NULL)
+#define wayc_notnull(expr) wayc_assert(expr != nullptr)
#define WAYC_CONCAT_IMPL(a, b) a##b
#define WAYC_CONCAT(a, b) WAYC_CONCAT_IMPL(a, b)
diff --git a/src/wlstate.cc b/src/wlstate.cc
index 940a011..0e65e38 100644
--- a/src/wlstate.cc
+++ b/src/wlstate.cc
@@ -64,8 +64,8 @@ enum wlstate_error_e wayc_wlstate_init(struct wlstate_s* state) {
wayc_notnull(state);
memset(state, 0, sizeof(*state));
- wl_display_t display = wl_display_connect(NULL);
- if (display == NULL) return WLSTATE_ERROR_CONNECTION;
+ wl_display_t display = wl_display_connect(nullptr);
+ if (display == nullptr) return WLSTATE_ERROR_CONNECTION;
i32 eventfd = wl_display_get_fd(display);
if (eventfd == -1) {
@@ -74,7 +74,7 @@ enum wlstate_error_e wayc_wlstate_init(struct wlstate_s* state) {
}
wl_registry_t registry = wl_display_get_registry(display);
- if (registry == NULL) {
+ if (registry == nullptr) {
wl_display_disconnect(display);
return WLSTATE_ERROR_REGISTRY;
}