diff options
| author | Xander Swan <email> | 2025-12-03 09:52:13 -0500 |
|---|---|---|
| committer | Xander Swan <email> | 2025-12-03 09:52:13 -0500 |
| commit | b6cf1d104da53ec9c30dc45c35d9de48812f0afc (patch) | |
| tree | 49421206d8d866e82a8a743cba5ced494cbfc785 /src/draw/framebuffer.odin | |
Initial commit
Diffstat (limited to 'src/draw/framebuffer.odin')
| -rw-r--r-- | src/draw/framebuffer.odin | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/draw/framebuffer.odin b/src/draw/framebuffer.odin new file mode 100644 index 0000000..cd7848b --- /dev/null +++ b/src/draw/framebuffer.odin @@ -0,0 +1,94 @@ +package draw + +import sg "shared:sokol/gfx" + +Framebuffer :: struct { + img: sg.Image, + view: sg.View, + pipe: sg.Pipeline, + pass: sg.Pass, +} + +init_framebuffer :: proc( + fb: ^Framebuffer, + width: i32, + height: i32, + clear_color := Color{0, 0, 0, 0}, +) { + fb.pipe = sg.make_pipeline({ + shader = sg.make_shader(default_shader_desc(sg.query_backend())), + layout = { + attrs = { + ATTR_default_vposition = {format = .FLOAT2}, + ATTR_default_vuv = {format = .FLOAT2}, + ATTR_default_vcolor = {format = .FLOAT4}, + }, + }, + depth = { + pixel_format = .NONE, + }, + sample_count = 1, + colors = { + 0 = { + pixel_format = .RGBA8, + blend = { + enabled = true, + src_factor_rgb = .SRC_ALPHA, + dst_factor_rgb = .ONE_MINUS_SRC_ALPHA, + src_factor_alpha = .ONE, + dst_factor_alpha = .ZERO, + }, + }, + }, + }) + + fb.img = sg.make_image({ + usage = { + color_attachment = true, + }, + + width = width, + height = height, + + pixel_format = .RGBA8, + sample_count = 1, + }) + + fb.view = sg.make_view({ + texture = { + image = fb.img, + }, + }) + + fb.pass = { + attachments = { + colors = { + 0 = sg.make_view({ + color_attachment = { + image = fb.img, + }, + }), + }, + }, + action = { + colors = { + 0 = {load_action = .CLEAR, clear_value = transmute(sg.Color)clear_color}, + }, + }, + } +} + +destroy_framebuffer :: proc(fb: ^Framebuffer) { + sg.destroy_pipeline(fb.pipe) + sg.destroy_view(fb.view) + sg.destroy_image(fb.img) +} + +framebuffer_draw_start :: proc(fb: Framebuffer) { + sg.begin_pass(fb.pass) + sg.apply_pipeline(fb.pipe) +} + +framebuffer_draw_end :: proc(fb: Framebuffer) { + sg.end_pass() +} |
