From 078b97e48b5ad5fcf3f5a16bb081ea0efb1f931b Mon Sep 17 00:00:00 2001 From: quou Date: Mon, 23 Dec 2024 21:30:13 +1100 Subject: send textures to shaders --- video.hpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'video.hpp') diff --git a/video.hpp b/video.hpp index f05af57..dc0574e 100644 --- a/video.hpp +++ b/video.hpp @@ -39,10 +39,35 @@ struct Vertex_Format_Id : public Primitive_Id { struct Shader_Id : public Primitive_Id { using Primitive_Id::Primitive_Id; }; +struct Sampler_Id : public Primitive_Id { + using Primitive_Id::Primitive_Id; +}; + +struct Descriptor { + enum class Type { + texture + } type; + int slot; + Descriptor* next; +}; + +struct Texture_Descriptor : public Descriptor { + Sampler_Id sampler; + Texture_Id texture; +}; struct Pipeline { Vertex_Format_Id vertex_format; Shader_Id shader; + Descriptor* descriptors; + + int count_descriptors() const { + const Descriptor* d = descriptors; + int c = 0; + for (; d; d = d->next) + c++; + return c; + } }; struct Colour { @@ -92,6 +117,7 @@ struct Pipeline_Builder { void begin(); void shader(Shader_Id s); void vertex_format(Vertex_Format_Id vf); + void texture(int binding, Texture_Id t, Sampler_Id s); Pipeline& build(); void validate(); }; @@ -126,6 +152,30 @@ struct Buffer { Buffer_Id id; }; +enum class Filter_Mode { + point, + linear +}; + +enum class Address_Mode { + repeat, + mirror, + clamp, + border +}; + +struct Sampler_State { + Filter_Mode min; + Filter_Mode mag; + Filter_Mode mip; + Address_Mode address_u; + Address_Mode address_v; + Address_Mode address_w; + float border[4]; + float mip_bias; + bool aniso; +}; + struct Context; struct Shader; struct Device { @@ -156,6 +206,9 @@ struct Device { void destroy_buffer(Buffer_Id id); Shader& get_shader(Shader_Id id); + + Sampler_Id create_sampler(const Sampler_State& state); + void destroy_sampler(Sampler_Id id); }; struct Context { @@ -186,6 +239,8 @@ struct Shader : public Asset { int binding_index(const char* name); int attribute_index(const char* name); int target_index(const char* name); + int descriptor_index(const char* name); + int descriptor_stage(int slot); }; #endif -- cgit v1.2.3-54-g00ecf