Manually adding thirdparty libs

This commit is contained in:
2025-04-14 14:49:36 -04:00
parent 1bd2dc2333
commit 77f1466ae3
70 changed files with 60610 additions and 4 deletions

38
thirdparty/sokol/helpers/allocator.odin vendored Normal file
View File

@@ -0,0 +1,38 @@
package sokol_helpers
// Use native odin allocators in sokol allocator interface
import sapp "../app"
import sg "../gfx"
import "base:runtime"
import "core:c"
Allocator :: struct {
alloc_fn: proc "c" (size: c.size_t, user_data: rawptr) -> rawptr,
free_fn: proc "c" (ptr: rawptr, user_data: rawptr),
user_data: rawptr,
}
// context_ptr: a pointer to a context which persists during the lifetime of the program.
// Note: you can transmute() this into a logger for any specific sokol library.
allocator :: proc(context_ptr: ^runtime.Context) -> Allocator {
return {
alloc_fn = allocator_alloc_proc,
free_fn = allocator_free_proc,
user_data = cast(rawptr)context_ptr,
}
}
allocator_alloc_proc :: proc "c" (size: c.size_t, user_data: rawptr) -> rawptr {
context = (cast(^runtime.Context)user_data)^
bytes, err := runtime.mem_alloc(size = int(size))
if err != nil {
return nil
}
return raw_data(bytes)
}
allocator_free_proc :: proc "c" (ptr: rawptr, user_data: rawptr) {
context = (cast(^runtime.Context)user_data)^
runtime.mem_free(ptr)
}

37
thirdparty/sokol/helpers/glue.odin vendored Normal file
View File

@@ -0,0 +1,37 @@
package sokol_helpers
// Alternative native odin implementation of sokol_glue.h, in case you want to minimize C dependencies
// (since sokol_glue is only a few lines of code)
import sapp "../app"
import sg "../gfx"
glue_environment :: proc() -> (env: sg.Environment) {
env.defaults.color_format = cast(sg.Pixel_Format)sapp.color_format()
env.defaults.depth_format = cast(sg.Pixel_Format)sapp.depth_format()
env.defaults.sample_count = sapp.sample_count()
env.metal.device = sapp.metal_get_device()
env.d3d11.device = sapp.d3d11_get_device()
env.d3d11.device_context = sapp.d3d11_get_device_context()
env.wgpu.device = sapp.wgpu_get_device()
return env
}
glue_swapchain :: proc() -> (swapchain: sg.Swapchain) {
swapchain.width = sapp.width()
swapchain.height = sapp.height()
swapchain.sample_count = sapp.sample_count()
swapchain.color_format = cast(sg.Pixel_Format)sapp.color_format()
swapchain.depth_format = cast(sg.Pixel_Format)sapp.depth_format()
swapchain.metal.current_drawable = sapp.metal_get_current_drawable()
swapchain.metal.depth_stencil_texture = sapp.metal_get_depth_stencil_texture()
swapchain.metal.msaa_color_texture = sapp.metal_get_msaa_color_texture()
swapchain.d3d11.render_view = sapp.d3d11_get_render_view()
swapchain.d3d11.resolve_view = sapp.d3d11_get_resolve_view()
swapchain.d3d11.depth_stencil_view = sapp.d3d11_get_depth_stencil_view()
swapchain.wgpu.render_view = sapp.wgpu_get_render_view()
swapchain.wgpu.resolve_view = sapp.wgpu_get_resolve_view()
swapchain.wgpu.depth_stencil_view = sapp.wgpu_get_depth_stencil_view()
swapchain.gl.framebuffer = sapp.gl_get_framebuffer()
return swapchain
}

59
thirdparty/sokol/helpers/logger.odin vendored Normal file
View File

@@ -0,0 +1,59 @@
package sokol_helpers
// Pass sokol logs into native odin logging system
import sapp "../app"
import sg "../gfx"
import "base:runtime"
import "core:log"
Logger :: struct {
func: proc "c" (
tag: cstring,
log_level: u32,
log_item: u32,
message: cstring,
line_nr: u32,
filename: cstring,
user_data: rawptr,
),
user_data: rawptr,
}
// context_ptr: a pointer to a context which persists during the lifetime of the program.
// Note: you can transmute() this into a logger for any specific sokol library.
logger :: proc "contextless" (context_ptr: ^runtime.Context) -> Logger {
return {func = logger_proc, user_data = cast(rawptr)context_ptr}
}
logger_proc :: proc "c" (
tag: cstring,
log_level: u32,
log_item: u32,
message: cstring,
line_nr: u32,
filename: cstring,
user_data: rawptr,
) {
context = (cast(^runtime.Context)user_data)^
loc := runtime.Source_Code_Location {
file_path = string(filename),
line = i32(line_nr),
}
level: log.Level
switch log_level {
case 0:
log.panicf("Sokol Panic: (%i) %s: %s", log_item, tag, message, location = loc)
case 1:
level = .Error
case 2:
level = .Warning
case:
level = .Info
}
log.logf(level, "(%i) %s: %s", log_item, tag, message, location = loc)
}