summaryrefslogtreecommitdiff
path: root/src/renderer/render.c
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-05-18 23:53:11 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-05-18 23:53:11 +1000
commitd79a8aa200bd64b14b85d2ec0c207601ba5c7922 (patch)
tree742c45019abe645355ec27a74924e1bec7963c7a /src/renderer/render.c
parentc69fab91c3cd8976ad660939765ca9a5e32a239a (diff)
working on image creation
Diffstat (limited to 'src/renderer/render.c')
-rw-r--r--src/renderer/render.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/renderer/render.c b/src/renderer/render.c
index b06620b..fc45093 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -1,11 +1,15 @@
-#include "render.h"
#include <glfw3.h>
+#include "maths_types.h"
+#define STB_IMAGE_IMPLEMENTATION
+#include <stb_image.h>
+
#include "camera.h"
#include "file.h"
#include "log.h"
#include "mem.h"
#include "ral.h"
#include "ral_types.h"
+#include "render.h"
/** @brief Creates the pipelines built into Celeritas such as rendering static opaque geometry,
debug visualisations, immediate mode UI, etc */
@@ -194,3 +198,41 @@ mesh mesh_create(geometry_data* geometry, bool free_on_upload) {
return m;
}
+
+// --- Textures
+
+texture_data texture_data_load(const char* path, bool invert_y) {
+ TRACE("Load texture %s", path);
+
+ // load the file data
+ int width, height, num_channels;
+ stbi_set_flip_vertically_on_load(invert_y);
+
+#pragma GCC diagnostic ignored "-Wpointer-sign"
+ char* data = stbi_load(path, &width, &height, &num_channels, 0); // STBI_rgb_alpha);
+ if (data) {
+ DEBUG("loaded texture: %s", path);
+ } else {
+ WARN("failed to load texture");
+ }
+
+ unsigned int channel_type;
+ if (num_channels == 4) {
+ channel_type = GL_RGBA;
+ } else {
+ channel_type = GL_RGB;
+ }
+ texture_desc desc = { .extents = { width, height },
+ .format = CEL_TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM,
+ .tex_type = CEL_TEXTURE_TYPE_2D };
+
+ return (texture_data){ .description = desc, .image_data = data };
+}
+
+texture_handle texture_data_upload(texture_data data, bool free_on_upload) {
+ texture_handle handle = gpu_texture_create(data.description, data.image_data);
+ if (free_on_upload) {
+ stbi_image_free(data.image_data);
+ }
+ return handle;
+}