diff options
author | quou <quou@disroot.org> | 2024-12-21 21:25:22 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-12-21 21:25:22 +1100 |
commit | 5bc8f90c38981045515bab04d26687f929f62ec1 (patch) | |
tree | d1d603ded306ae218e75f7eff4b69807f2a14e26 /video.hpp | |
parent | 3283c6c8c32f980bd01591e441acd9c712c650ef (diff) |
render a triangle
Diffstat (limited to 'video.hpp')
-rw-r--r-- | video.hpp | 83 |
1 files changed, 77 insertions, 6 deletions
@@ -1,17 +1,42 @@ #ifndef video_hpp #define video_hpp +#include <stddef.h> #include <stdint.h> struct App; struct Arena; struct Heap; -typedef uint32_t Texture_Id; -typedef uint32_t Buffer_Id; +template <typename T> +struct Primitive_Id { + T index; + Primitive_Id(): index(0) {} + Primitive_Id(T i): index(i) {} + bool operator==(Primitive_Id<T> other) const { + return index == other.index; + } + operator bool() const { + return index != 0; + } +}; -struct Pipeline { +struct Texture_Id : public Primitive_Id<uint32_t> { + using Primitive_Id<uint32_t>::Primitive_Id; +}; +struct Buffer_Id : public Primitive_Id<uint32_t> { + using Primitive_Id<uint32_t>::Primitive_Id; +}; +struct Vertex_Format_Id : public Primitive_Id<uint32_t> { + using Primitive_Id<uint32_t>::Primitive_Id; +}; +struct Shader_Id : public Primitive_Id<uint32_t> { + using Primitive_Id<uint32_t>::Primitive_Id; +}; +struct Pipeline { + Vertex_Format_Id vertex_format; + Shader_Id shader; }; struct Colour { @@ -26,19 +51,30 @@ struct Render_Pass { int size = sizeof *this, i; uint8_t* bba = (uint8_t*)this; uint8_t* bbb = (uint8_t*)&other; - for (i = 0; i < size; i++) + for (i = 0; i < size; i++, bba++, bbb++) if (*bba != *bbb) return false; return true; } }; -struct Draw { +struct Vertex_Buffer_Binding { + Buffer_Id id; + size_t offset; + int target; +}; +struct Draw { + Vertex_Buffer_Binding* verts; + int vertex_count; + int instance_count; + int first_vertex; + int first_instance; }; struct Pipeline_Builder { Arena* arena; Render_Pass* pass; + Pipeline* pip; Pipeline_Builder(Arena* arena); @@ -46,6 +82,12 @@ struct Pipeline_Builder { void rp_target(Texture_Id id, Colour clear_colour); Render_Pass& build_rp(); void validate_rp(); + + void begin(); + void shader(Shader_Id s); + void vertex_format(Vertex_Format_Id vf); + Pipeline& build(); + void validate(); }; struct Texture { @@ -53,6 +95,21 @@ struct Texture { bool alias; }; +namespace Buffer_Flags { + enum { + index_buffer = 1 << 0, + vertex_buffer = 1 << 1, + uniform_buffer = 1 << 2, + storage_buffer = 1 << 3, + cpu_read = 1 << 4, + cpu_readwrite = 1 << 5, + copy_src = 1 << 6, + copy_dst = 1 << 7 + }; +}; + +struct Buffer {}; + struct Context; struct Shader; struct Device { @@ -76,7 +133,15 @@ struct Device { Texture& get_texture(Texture_Id id); void destroy_texture(Texture_Id id); - Shader* load_shader(const char* fname); + Buffer_Id create_buffer(size_t size, int flags); + void* map_buffer(Buffer_Id id, size_t offset, size_t size); + void unmap_buffer(Buffer_Id id); + Buffer& get_buffer(Buffer_Id id); + void destroy_buffer(Buffer_Id id); + + Shader_Id load_shader(const char* fname); + Shader& get_shader(Shader_Id id); + void destroy_shader(Shader_Id id); }; struct Context { @@ -98,7 +163,13 @@ struct Context { }; struct Shader { + Vertex_Format_Id vf; void destroy(Device* dev); + + /* -1 on failure */ + int binding_index(const char* name); + int attribute_index(const char* name); + int target_index(const char* name); }; #endif |