aboutsummaryrefslogtreecommitdiff
path: root/src/draw/draw.odin
diff options
context:
space:
mode:
authorXander Swan <email>2025-12-03 09:52:13 -0500
committerXander Swan <email>2025-12-03 09:52:13 -0500
commit53cba1d004451f0782312cb203afb7da47a29c5f (patch)
treeb772324597c52674a626c7137359d34f528b1bd2 /src/draw/draw.odin
parentbb52b5f9c9def80b1e8704acabde6f8c6a34e1a2 (diff)
update renderer structure a lil
Diffstat (limited to 'src/draw/draw.odin')
-rw-r--r--src/draw/draw.odin37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/draw/draw.odin b/src/draw/draw.odin
index 1bc24d1..d67e16c 100644
--- a/src/draw/draw.odin
+++ b/src/draw/draw.odin
@@ -10,23 +10,23 @@ import sglue "shared:sokol/glue"
Vec2 :: [2]f32
Vec3 :: [3]f32
-Mat4 :: matrix[4, 4]f32
Rect :: struct {
start: Vec2,
size: Vec2,
}
+Mat4 :: matrix[4, 4]f32
+
Color :: [4]f32
SCREEN_WIDTH :: 256
SCREEN_HEIGHT :: 256
Renderer :: struct {
- screen: struct {
- framebuffer: Framebuffer,
- },
- display: struct {
+ screen: Framebuffer,
+
+ window_pass: struct {
pass_action: sg.Pass_Action,
pipe: sg.Pipeline,
},
@@ -52,7 +52,7 @@ Batch :: struct {
}
init :: proc(r: ^Renderer) {
- r.display.pipe = sg.make_pipeline({
+ r.window_pass.pipe = sg.make_pipeline({
shader = sg.make_shader(default_shader_desc(sg.query_backend())),
layout = {
attrs = {
@@ -63,14 +63,14 @@ init :: proc(r: ^Renderer) {
},
})
- r.display.pass_action = {
+ r.window_pass.pass_action = {
colors = {
0 = {load_action = .CLEAR, clear_value = {0, 0, 0, 1}},
},
}
init_framebuffer(
- &r.screen.framebuffer,
+ &r.screen,
SCREEN_WIDTH, SCREEN_HEIGHT,
Color{0.2, 0.2, 0.2, 1.0},
)
@@ -84,17 +84,16 @@ init :: proc(r: ^Renderer) {
deinit :: proc(r: ^Renderer) {
delete_batch(&r.current_batch)
- sg.destroy_pipeline(r.screen.framebuffer.pipe)
- sg.destroy_pipeline(r.display.pipe)
+ sg.destroy_pipeline(r.window_pass.pipe)
sg.destroy_view(r.view)
sg.destroy_sampler(r.sampler)
- destroy_framebuffer(&r.screen.framebuffer)
+ destroy_framebuffer(&r.screen)
}
new_frame :: proc(r: ^Renderer) {
- framebuffer_draw_start(r.screen.framebuffer)
+ framebuffer_draw_start(r.screen)
r.projection = linalg.matrix_ortho3d(
0, f32(SCREEN_WIDTH),
f32(SCREEN_HEIGHT), 0,
@@ -106,7 +105,7 @@ end_frame :: proc(r: ^Renderer) {
flush_current_batch(r)
clear(&r.current_batch.vertices)
- framebuffer_draw_end(r.screen.framebuffer)
+ framebuffer_draw_end(r.screen)
r.projection = linalg.matrix_ortho3d(
0, f32(sapp.width()),
@@ -114,8 +113,8 @@ end_frame :: proc(r: ^Renderer) {
0.0, 1.0,
)
- sg.begin_pass({action=r.display.pass_action, swapchain=sglue.swapchain()})
- sg.apply_pipeline(r.display.pipe)
+ sg.begin_pass({action=r.window_pass.pass_action, swapchain=sglue.swapchain()})
+ sg.apply_pipeline(r.window_pass.pipe)
scale := math.min(
f32(sapp.height()) / f32(SCREEN_HEIGHT) ,
@@ -128,7 +127,7 @@ end_frame :: proc(r: ^Renderer) {
draw_texture(
r,
- r.screen.framebuffer.img,
+ r.screen.img,
screen_start,
scale = Vec2{scale, scale},
)
@@ -227,8 +226,8 @@ draw_texture_quad :: proc(
assert(quad.size.x > 0 && quad.size.y > 0)
batch := request_batch(r, img)
-
- top_left := pos - (offset * scale)
+
+ top_left := pos + offset * scale
bot_rght := top_left + quad.size * scale
size := Vec2{
@@ -266,3 +265,5 @@ draw_texture_full :: proc(
}
draw_texture_quad(r, img, Rect{Vec2{0, 0}, size}, pos, offset, scale)
}
+
+