make surface example cooler
This commit is contained in:
parent
34101d2e8c
commit
7caa47b9fb
|
@ -1,4 +1,3 @@
|
||||||
.{memory} := @use("../../stn/src/lib.hb")
|
|
||||||
software := @use("software.hb")
|
software := @use("software.hb")
|
||||||
image := @use("image.hb")
|
image := @use("image.hb")
|
||||||
|
|
||||||
|
@ -7,34 +6,11 @@ mode := software
|
||||||
|
|
||||||
init := mode.init
|
init := mode.init
|
||||||
doublebuffer := mode.doublebuffer
|
doublebuffer := mode.doublebuffer
|
||||||
|
Surface := mode.Surface
|
||||||
Surface := struct {
|
new_surface := mode.new_surface
|
||||||
buf: ^Color,
|
surface_from_ptr := mode.surface_from_ptr
|
||||||
width: int,
|
clone_surface := mode.clone_surface
|
||||||
height: int,
|
free_surface := mode.free_surface
|
||||||
}
|
|
||||||
|
|
||||||
new_surface := fn(width: int, height: int): Surface {
|
|
||||||
return .(
|
|
||||||
@inline(memory.alloc, Color, width * height * @bitcast(@sizeof(Color))),
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
surface_from_ptr := fn(ptr: ^Color, width: int, height: int): Surface {
|
|
||||||
return .(
|
|
||||||
ptr,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
clone_surface := fn(surface: Surface): Surface {
|
|
||||||
new := new_surface(surface.width, surface.height)
|
|
||||||
@inline(memory.copy, Color, surface.buf, new.buf, @intcast(surface.width * surface.height))
|
|
||||||
return new
|
|
||||||
}
|
|
||||||
|
|
||||||
// Colours
|
// Colours
|
||||||
Color := packed struct {b: u8, g: u8, r: u8, a: u8}
|
Color := packed struct {b: u8, g: u8, r: u8, a: u8}
|
||||||
|
@ -68,10 +44,4 @@ put_vline := mode.put_vline
|
||||||
put_hline := mode.put_hline
|
put_hline := mode.put_hline
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
// width := mode.width
|
|
||||||
// height := mode.height
|
|
||||||
// dimensions := mode.dimensions
|
|
||||||
// set_height := mode.set_height
|
|
||||||
// set_width := mode.set_width
|
|
||||||
// set_dimensions := mode.set_dimensions
|
|
||||||
sync := mode.sync
|
sync := mode.sync
|
|
@ -1,14 +1,47 @@
|
||||||
.{math, memory, dt} := @use("../../stn/src/lib.hb");
|
.{math, memory, dt} := @use("../../stn/src/lib.hb");
|
||||||
.{Color, Surface, new_surface} := @use("lib.hb");
|
.{Color} := @use("lib.hb");
|
||||||
.{Vec2} := math
|
.{Vec2} := math
|
||||||
|
|
||||||
|
Surface := struct {
|
||||||
|
buf: ^Color,
|
||||||
|
width: int,
|
||||||
|
height: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
new_surface := fn(width: int, height: int): Surface {
|
||||||
|
return .(
|
||||||
|
@inline(memory.alloc, Color, width * height),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
surface_from_ptr := fn(ptr: ^Color, width: int, height: int): Surface {
|
||||||
|
return .(
|
||||||
|
ptr,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
clone_surface := fn(surface: ^Surface): Surface {
|
||||||
|
new := new_surface(surface.width, surface.height)
|
||||||
|
@inline(memory.copy, Color, surface.buf, new.buf, @intcast(surface.width * surface.height))
|
||||||
|
return new
|
||||||
|
}
|
||||||
|
|
||||||
|
free_surface := fn(surface: ^Surface): void {
|
||||||
|
// todo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
framebuffer := @as(^Color, idk)
|
framebuffer := @as(^Color, idk)
|
||||||
|
|
||||||
init := fn(double_buffer: bool): Surface {
|
init := fn(doublebuffer: bool): Surface {
|
||||||
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
|
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
|
||||||
width := dt.get(int, "framebuffer/fb0/width\0")
|
width := dt.get(int, "framebuffer/fb0/width\0")
|
||||||
height := dt.get(int, "framebuffer/fb0/height\0")
|
height := dt.get(int, "framebuffer/fb0/height\0")
|
||||||
if double_buffer {
|
if doublebuffer {
|
||||||
return new_surface(width, height)
|
return new_surface(width, height)
|
||||||
} else {
|
} else {
|
||||||
return .(framebuffer, width, height)
|
return .(framebuffer, width, height)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
PAGE_SIZE := 4096
|
PAGE_SIZE := 4096
|
||||||
MAX_ALLOC := 0xFF
|
MAX_ALLOC := 0xFF
|
||||||
|
|
||||||
alloc := fn($Expr: type, bytes: int): ^Expr {
|
alloc := fn($Expr: type, num: int): ^Expr {
|
||||||
pages := 1 + bytes / PAGE_SIZE
|
pages := 1 + @bitcast(@sizeof(Expr)) * num / PAGE_SIZE
|
||||||
if pages <= MAX_ALLOC {
|
if pages <= MAX_ALLOC {
|
||||||
return @bitcast(@inline(request_page, pages))
|
return @bitcast(@inline(request_page, pages))
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,11 @@ alloc := fn($Expr: type, bytes: int): ^Expr {
|
||||||
return @bitcast(ptr)
|
return @bitcast(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free := fn($Expr: type, ptr: ^Expr, num: int): void {
|
||||||
|
// todo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
request_page := fn(page_count: u8): ^u8 {
|
request_page := fn(page_count: u8): ^u8 {
|
||||||
msg := "\{00}\{01}xxxxxxxx\0"
|
msg := "\{00}\{01}xxxxxxxx\0"
|
||||||
msg_page_count := msg + 1;
|
msg_page_count := msg + 1;
|
||||||
|
|
|
@ -16,13 +16,14 @@ example := fn(): void {
|
||||||
pos_inner := Vec2(int).((image.width - side) / 2, (image.height - side) / 2)
|
pos_inner := Vec2(int).((image.width - side) / 2, (image.height - side) / 2)
|
||||||
color := random.range(render.Color, render.black, render.white)
|
color := random.range(render.Color, render.black, render.white)
|
||||||
loop {
|
loop {
|
||||||
render.clear(image, render.black)
|
|
||||||
render.clear(screen, render.black)
|
render.clear(screen, render.black)
|
||||||
|
// color += .(1, 1, 1, 1)
|
||||||
render.put_filled_rect(image, pos_inner, .(side, side), color)
|
render.put_filled_rect(image, pos_inner, .(side, side), color)
|
||||||
render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), render.white)
|
render.put_rect(image, pos_inner, .(side, side), render.black)
|
||||||
|
render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), color)
|
||||||
|
|
||||||
render.put_surface(screen, image, pos)
|
render.put_surface(screen, image, pos)
|
||||||
|
render.put_rect(image, pos_inner, .(side, side), color)
|
||||||
render.sync(screen)
|
render.sync(screen)
|
||||||
|
|
||||||
if pos_inner.x == 0 | pos_inner.x == image.width - side {
|
if pos_inner.x == 0 | pos_inner.x == image.width - side {
|
||||||
|
|
|
@ -31,17 +31,17 @@ resolution = "1024x768x24"
|
||||||
# [boot.limine.ableos.modules.diskio_driver]
|
# [boot.limine.ableos.modules.diskio_driver]
|
||||||
# path = "boot:///diskio_driver.hbf"
|
# path = "boot:///diskio_driver.hbf"
|
||||||
|
|
||||||
# [boot.limine.ableos.modules.render_example]
|
[boot.limine.ableos.modules.render_example]
|
||||||
# path = "boot:///render_example.hbf"
|
path = "boot:///render_example.hbf"
|
||||||
|
|
||||||
# [boot.limine.ableos.modules.serial_driver_test]
|
# [boot.limine.ableos.modules.serial_driver_test]
|
||||||
# path = "boot:///serial_driver_test.hbf"
|
# path = "boot:///serial_driver_test.hbf"
|
||||||
|
|
||||||
[boot.limine.ableos.modules.horizon]
|
# [boot.limine.ableos.modules.horizon]
|
||||||
path = "boot:///horizon.hbf"
|
# path = "boot:///horizon.hbf"
|
||||||
|
|
||||||
[boot.limine.ableos.modules.horizon_testing_program]
|
# [boot.limine.ableos.modules.horizon_testing_program]
|
||||||
path = "boot:///horizon_testing_program.hbf"
|
# path = "boot:///horizon_testing_program.hbf"
|
||||||
|
|
||||||
# [boot.limine.ableos.modules.dt_buffer_test]
|
# [boot.limine.ableos.modules.dt_buffer_test]
|
||||||
# path = "boot:///dt_buffer_test.hbf"
|
# path = "boot:///dt_buffer_test.hbf"
|
||||||
|
|
Loading…
Reference in a new issue