From b6cf1d104da53ec9c30dc45c35d9de48812f0afc Mon Sep 17 00:00:00 2001 From: Xander Swan Date: Wed, 3 Dec 2025 09:52:13 -0500 Subject: Initial commit --- src/draw/framebuffer.odin | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/draw/framebuffer.odin (limited to 'src/draw/framebuffer.odin') 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() +} -- cgit v1.3-2-g0d8e