summaryrefslogtreecommitdiff
path: root/src/render/shader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/shader.c')
-rw-r--r--src/render/shader.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/render/shader.c b/src/render/shader.c
new file mode 100644
index 0000000..c16e2db
--- /dev/null
+++ b/src/render/shader.c
@@ -0,0 +1,31 @@
+#include "render/shader.h"
+#include "render/renderer.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+VkResult shader_create_module(struct renderer *ren, const size_t len, uint8_t code[len], VkShaderModule *module) {
+ return vkCreateShaderModule(ren->gpu.device, &(VkShaderModuleCreateInfo) {
+ .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
+ .codeSize = len,
+ .pCode = (uint32_t *)code
+ }, NULL, module);
+}
+
+bool shader_load(const char *filename, struct shader *shader) {
+ assert(filename);
+ assert(shader);
+ FILE *fp = fopen(filename, "rb");
+ if (!fp)
+ return false;
+ fseek(fp, 0, SEEK_END);
+ shader->len = ftell(fp);
+ rewind(fp);
+
+ shader->code = calloc(shader->len, sizeof(*shader->code));
+ fread(shader->code, sizeof(*shader->code), shader->len, fp);
+
+ fclose(fp);
+ return true;
+}