karl2d.doc.odin 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // This file is purely documentational and never built.
  2. #+ignore
  3. package karl2d
  4. Handle :: hm.Handle
  5. Texture_Handle :: distinct Handle
  6. TEXTURE_NONE :: Texture_Handle {}
  7. // Opens a window and initializes some internal state. The internal state will use `allocator` for
  8. // all dynamically allocated memory. The return value can be ignored unless you need to later call
  9. // `set_state`.
  10. init :: proc(window_width: int, window_height: int, window_title: string,
  11. allocator := context.allocator, loc := #caller_location) -> ^State
  12. VERTEX_BUFFER_MAX :: 1000000
  13. make_default_projection :: proc(w, h: int) -> matrix[4,4]f32
  14. DEFAULT_SHADER_SOURCE :: #load("shader.hlsl")
  15. // Closes the window and cleans up the internal state.
  16. shutdown :: proc()
  17. // Clear the backbuffer with supplied color.
  18. clear :: proc(color: Color)
  19. // Present the backbuffer. Call at end of frame to make everything you've drawn appear on the screen.
  20. present :: proc()
  21. // Call at start or end of frame to process all events that have arrived to the window.
  22. //
  23. // WARNING: Not calling this will make your program impossible to interact with.
  24. process_events :: proc()
  25. /* Flushes the current batch. This sends off everything to the GPU that has been queued in the
  26. current batch. Normally, you do not need to do this manually. It is done automatically when these
  27. procedures run:
  28. present
  29. set_camera
  30. set_shader
  31. TODO: complete this list and motivate why it needs to happen on those procs (or do that in the
  32. docs for those procs).
  33. */
  34. draw_current_batch :: proc()
  35. // Can be used to restore the internal state using the pointer returned by `init`. Useful after
  36. // reloading the library (for example, when doing code hot reload).
  37. set_internal_state :: proc(state: ^State)
  38. get_screen_width :: proc() -> int
  39. get_screen_height :: proc() -> int
  40. key_went_down :: proc(key: Keyboard_Key) -> bool
  41. key_went_up :: proc(key: Keyboard_Key) -> bool
  42. key_is_held :: proc(key: Keyboard_Key) -> bool
  43. shutdown_wanted :: proc() -> bool
  44. set_window_position :: proc(x: int, y: int)
  45. set_window_size :: proc(width: int, height: int)
  46. set_camera :: proc(camera: Maybe(Camera))
  47. load_texture_from_file :: proc(filename: string) -> Texture
  48. destroy_texture :: proc(tex: Texture)
  49. draw_rect :: proc(r: Rect, c: Color)
  50. draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color)
  51. draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color)
  52. draw_circle :: proc(center: Vec2, radius: f32, color: Color, segments := 16)
  53. draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color)
  54. draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE)
  55. draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE)
  56. draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE)
  57. load_shader :: proc(shader_source: string, layout_formats: []Shader_Input_Format = {}) -> Shader
  58. get_shader_input_default_type :: proc(name: string, type: Shader_Input_Type) -> Shader_Default_Inputs
  59. get_shader_input_format :: proc(name: string, type: Shader_Input_Type) -> Shader_Input_Format
  60. destroy_shader :: proc(shader: Shader)
  61. set_shader :: proc(shader: Maybe(Shader))
  62. maybe_handle_equal :: proc(m1: Maybe($T), m2: Maybe(T)) -> bool
  63. set_shader_constant :: proc(shd: Shader, loc: Shader_Constant_Location, val: $T)
  64. set_shader_constant_mat4 :: proc(shader: Shader, loc: Shader_Constant_Location, val: matrix[4,4]f32)
  65. set_shader_constant_f32 :: proc(shader: Shader, loc: Shader_Constant_Location, val: f32)
  66. set_shader_constant_vec2 :: proc(shader: Shader, loc: Shader_Constant_Location, val: Vec2)
  67. get_default_shader :: proc() -> Shader
  68. set_scissor_rect :: proc(scissor_rect: Maybe(Rect))
  69. screen_to_world :: proc(pos: Vec2, camera: Camera) -> Vec2
  70. draw_text :: proc(text: string, pos: Vec2, font_size: f32, color: Color)
  71. mouse_button_went_down :: proc(button: Mouse_Button) -> bool
  72. mouse_button_went_up :: proc(button: Mouse_Button) -> bool
  73. mouse_button_is_held :: proc(button: Mouse_Button) -> bool
  74. get_mouse_wheel_delta :: proc() -> f32
  75. get_mouse_position :: proc() -> Vec2
  76. _batch_vertex :: proc(v: Vec2, uv: Vec2, color: Color)
  77. shader_input_format_size :: proc(f: Shader_Input_Format) -> int
  78. State :: struct {
  79. allocator: runtime.Allocator,
  80. custom_context: runtime.Context,
  81. win: Window_Interface,
  82. window_state: rawptr,
  83. rb: Rendering_Backend_Interface,
  84. rb_state: rawptr,
  85. shutdown_wanted: bool,
  86. mouse_position: Vec2,
  87. mouse_delta: Vec2,
  88. mouse_wheel_delta: f32,
  89. keys_went_down: #sparse [Keyboard_Key]bool,
  90. keys_went_up: #sparse [Keyboard_Key]bool,
  91. keys_is_held: #sparse [Keyboard_Key]bool,
  92. window: Window_Handle,
  93. width: int,
  94. height: int,
  95. shape_drawing_texture: Texture_Handle,
  96. batch_camera: Maybe(Camera),
  97. batch_shader: Maybe(Shader),
  98. batch_texture: Texture_Handle,
  99. view_matrix: Mat4,
  100. proj_matrix: Mat4,
  101. vertex_buffer_cpu: []u8,
  102. vertex_buffer_cpu_used: int,
  103. default_shader: Shader,
  104. }