summaryrefslogtreecommitdiff
path: root/include/vlkn.h
blob: a03ca9f67a78267aca286ab44146a5f945608419 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef _VLKN_H_
#define _VLKN_H_

#include <vulkan/vulkan.h>
#include <stdbool.h>

struct vlkn_window;
struct vlkn_renderer;
struct vlkn_pipeline;

struct vlkn_buffer {
	VkBuffer buffer;
	VkDeviceSize size;
	VkDeviceMemory memory;
};

struct vec3 {
	float x, y, z;
};

struct vec4 {
	float x, y, z, w;
};

struct vlkn_vertex {
	struct vec3 position;
	struct vec3 normal;
	struct vec4 color;
};

struct vlkn_mesh {
	struct vlkn_buffer vertex;
	struct vlkn_buffer index;
	size_t index_count;
	struct vec3 position;
};

struct vlkn_window *vlkn_window_init(const char *title);
void vlkn_window_destroy(struct vlkn_window *win);

struct vlkn_renderer *vlkn_renderer_init(struct vlkn_window *win);
void vlkn_renderer_destroy(struct vlkn_renderer *renderer);
void vlkn_render(struct vlkn_renderer *renderer);
void vlkn_draw(struct vlkn_renderer *renderer, struct vlkn_pipeline *pipeline,
		size_t mesh_len, struct vlkn_mesh meshes[mesh_len]);
void vlkn_present(struct vlkn_renderer *renderer);

struct vlkn_shader {
	VkShaderStageFlagBits stages;
	VkShaderModule module;
};

// TODO: error enum
bool vlkn_shader_load(struct vlkn_renderer *renderer,
		const char *path, VkShaderStageFlagBits stage, struct vlkn_shader *shader);
void vlkn_shader_unload(struct vlkn_renderer *renderer, struct vlkn_shader *shader);

struct vlkn_pipeline_opts {
	size_t shader_len;
	struct vlkn_shader *shaders;
	size_t attrs_len;
	VkVertexInputAttributeDescription *attrs;
	VkVertexInputBindingDescription attrs_desc;
	size_t descriptors_len;
	VkDescriptorSetLayoutBinding *descriptors;
	size_t push_contant_len;
	VkPushConstantRange *push_constants;
};

struct vlkn_pipeline *vlkn_pipeline_init(struct vlkn_renderer *renderer, struct vlkn_pipeline_opts *opts);

struct vlkn_mesh vlkn_mesh_upload(struct vlkn_renderer *renderer, size_t vertex_count, struct vlkn_vertex vertices[vertex_count],
		size_t index_count, uint32_t indices[index_count], struct vec3 position);

#endif