diff options
author | quou <quou@disroot.org> | 2024-12-23 21:30:13 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-12-23 21:30:13 +1100 |
commit | 078b97e48b5ad5fcf3f5a16bb081ea0efb1f931b (patch) | |
tree | d04bfb2d25952b214a4df303823ff7c5d2743681 /c2.cpp | |
parent | b293168cc158d65f1a5146f155921ff82119d1bc (diff) |
send textures to shaders
Diffstat (limited to 'c2.cpp')
-rw-r--r-- | c2.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -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>("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(); |