summaryrefslogtreecommitdiff
path: root/src/render/shader.c
blob: c16e2db680f1e9562bce3d94933b9ab75244e5ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}