render_backend_interface.odin 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package karl2d
  2. import "base:runtime"
  3. Shader_Constant_Desc :: struct {
  4. name: string,
  5. size: int,
  6. }
  7. Shader_Texture_Bindpoint_Desc :: struct {
  8. name: string,
  9. }
  10. Shader_Desc :: struct {
  11. constants: []Shader_Constant_Desc,
  12. texture_bindpoints: []Shader_Texture_Bindpoint_Desc,
  13. inputs: []Shader_Input,
  14. }
  15. Render_Backend_Interface :: struct #all_or_none {
  16. state_size: proc() -> int,
  17. init: proc(state: rawptr, window_handle: Window_Handle, swapchain_width, swapchain_height: int, allocator := context.allocator),
  18. shutdown: proc(),
  19. clear: proc(render_target: Render_Target_Handle, color: Color),
  20. present: proc(),
  21. draw: proc(
  22. shader: Shader,
  23. render_target: Render_Target_Handle,
  24. bound_textures: []Texture_Handle,
  25. scissor: Maybe(Rect),
  26. blend: Blend_Mode,
  27. vertex_buffer: []u8,
  28. ),
  29. set_internal_state: proc(state: rawptr),
  30. create_texture: proc(width: int, height: int, format: Pixel_Format) -> Texture_Handle,
  31. load_texture: proc(data: []u8, width: int, height: int, format: Pixel_Format) -> Texture_Handle,
  32. update_texture: proc(handle: Texture_Handle, data: []u8, rect: Rect) -> bool,
  33. destroy_texture: proc(handle: Texture_Handle),
  34. texture_needs_vertical_flip: proc(handle: Texture_Handle) -> bool,
  35. create_render_texture: proc(width: int, height: int) -> (Texture_Handle, Render_Target_Handle),
  36. destroy_render_target: proc(render_texture: Render_Target_Handle),
  37. set_texture_filter: proc(
  38. handle: Texture_Handle,
  39. scale_down_filter: Texture_Filter,
  40. scale_up_filter: Texture_Filter,
  41. mip_filter: Texture_Filter,
  42. ),
  43. load_shader: proc(
  44. vertex_shader_data: []byte,
  45. pixel_shader_data: []byte,
  46. desc_allocator: runtime.Allocator,
  47. layout_formats: []Pixel_Format = {},
  48. ) -> (
  49. handle: Shader_Handle,
  50. desc: Shader_Desc,
  51. ),
  52. destroy_shader: proc(shader: Shader_Handle),
  53. resize_swapchain: proc(width, height: int),
  54. get_swapchain_width: proc() -> int,
  55. get_swapchain_height: proc() -> int,
  56. flip_z: proc() -> bool,
  57. default_shader_vertex_source: proc() -> []byte,
  58. default_shader_fragment_source: proc() -> []byte,
  59. }