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 --- c2.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'c2.cpp') diff --git a/c2.cpp b/c2.cpp index af912e5..8ba1772 100644 --- a/c2.cpp +++ b/c2.cpp @@ -11,9 +11,9 @@ extern "C" { #define per_frame_memory_size (1024 * 1024) static float verts[] = { - 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, - -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, - 0.0f, -0.5f, 0.0f, 0.0f, 1.0f + 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.5f, 0.0f, + -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, + 0.0f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; struct C2 : public App { @@ -49,6 +49,15 @@ static Buffer_Id upload_verts(Device* dev) { return vbo; } +static Sampler_Id create_clamped_linear(Device* dev) { + Sampler_State s{}; + s.min = Filter_Mode::linear; + s.mag = Filter_Mode::linear; + s.address_u = Address_Mode::repeat; + s.address_v = Address_Mode::repeat; + return dev->create_sampler(s); +} + int main() { Arena video_arena; Arena asset_arena; @@ -57,6 +66,7 @@ int main() { Shader* shader; Texture* texture; Buffer_Id vbo; + Sampler_Id clamped_linear; C2* app = App::create("c2"); void* per_frame; app->running = 1; @@ -79,6 +89,7 @@ int main() { dev->heap, per_frame_memory_size ); + clamped_linear = create_clamped_linear(dev); assert(per_frame != 0); uint8_t r = 0; vbo = upload_verts(dev); @@ -97,6 +108,11 @@ int main() { pb.begin(); pb.shader(shader->id); pb.vertex_format(shader->vf); + pb.texture( + shader->descriptor_index("colour_texture"), + texture->id, + clamped_linear + ); Pipeline& pip = pb.build(); Vertex_Buffer_Binding binding[] = {{ @@ -118,6 +134,7 @@ int main() { app->end(); } assets.destroy(); + dev->destroy_sampler(clamped_linear); dev->destroy_buffer(vbo); dev->destroy(); app->destroy(); -- cgit v1.2.3-54-g00ecf