From 35a70d71f62e41d78d68247075ce174f2b6d997a Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Wed, 7 Feb 2024 22:49:00 +0100 Subject: inital commit -- THE CUBES SPIN Signed-off-by: Anna (navi) Figueiredo Gomes --- src/render/shader.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/render/shader.c (limited to 'src/render/shader.c') 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 +#include +#include + +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; +} -- cgit v1.2.3