karl2d.doc.odin 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. // This file is purely documentational. It is generated from the contents of 'karl2d.odin'.
  2. #+build ignore
  3. package karl2d
  4. //-----------------------------------------------//
  5. // SETUP, WINDOW MANAGEMENT AND FRAME MANAGEMENT //
  6. //-----------------------------------------------//
  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_internal_state`.
  10. init :: proc(window_width: int, window_height: int, window_title: string,
  11. window_creation_flags := Window_Flags {},
  12. allocator := context.allocator, loc := #caller_location) -> ^State
  13. // Returns true the user has pressed the close button on the window, or used a key stroke such as
  14. // ALT+F4 on Windows. The application can decide if it wants to shut down or if it wants to show
  15. // some kind of confirmation dialogue.
  16. //
  17. // Commonly used for creating the "main loop" of a game: `for !k2.shutdown_wanted {}`
  18. shutdown_wanted :: proc() -> bool
  19. // Closes the window and cleans up Karl2D's internal state.
  20. shutdown :: proc()
  21. // Clear the "screen" with the supplied color. By default this will clear your window. But if you
  22. // have set a Render Texture using the `set_render_texture` procedure, then that Render Texture will
  23. // be cleared instead.
  24. clear :: proc(color: Color)
  25. // Call at the start of each frame. This procedure does two main things:
  26. // - Fetches how long the previous frame took and how long since the program started. These values
  27. // can be fetched using `get_frame_time()` and `get_time()`
  28. // - Clears Karl2D's internal "frame_allocator" -- that's the allocator the library uses for
  29. // dynamic memory that has a lifetime of a single frame.
  30. new_frame :: proc()
  31. // "Flips the backbuffer": Call at end of frame to make everything you've drawn appear on the screen.
  32. //
  33. // When you draw using for example `draw_texture`, then that stuff is drawn to an invisible texture
  34. // called a "backbuffer". This makes sure that we don't see half-drawn frames. So when you are happy
  35. // with a frame and want to show it to the player, call this procedure.
  36. //
  37. // WebGL note: WebGL does the backbuffer flipping automatically. But you should still call this to
  38. // make sure that all rendering has been sent off to the GPU (it calls `draw_current_batch()`).
  39. present :: proc()
  40. // Call at start or end of frame to process all events that have arrived to the window. This
  41. // includes keyboard, mouse, gamepad and window events.
  42. //
  43. // WARNING: Not calling this will make your program impossible to interact with.
  44. process_events :: proc()
  45. // Returns how many seconds the previous frame took. Often a tiny number such as 0.016 s.
  46. //
  47. // You must call `new_frame()` at the start of your frame in order for the frame_time to be updated.
  48. get_frame_time :: proc() -> f32
  49. // Returns how many seconds has elapsed since the game started.
  50. //
  51. // You must call `new_frame()` at the start of your frame for this value to get updated.
  52. get_time :: proc() -> f64
  53. // Gets the width of the drawing area within the window. The returned number is not scaled by any
  54. // monitor DPI scaling. You do that manually using the number returned by `get_window_scale()`.
  55. get_screen_width :: proc() -> int
  56. // Gets the height of the drawing area within the window. The returned number is not scaled by any
  57. // monitor DPI scaling. You do that manually using the number returned by `get_window_scale()`.
  58. get_screen_height :: proc() -> int
  59. // Moves the window.
  60. //
  61. // WebGL note: This moves the canvas within the window, which may not be what you want.
  62. set_window_position :: proc(x: int, y: int)
  63. // Resize the window to a new size. If the window has the flag Resizable set, then the backbuffer
  64. // will also be resized.
  65. set_window_size :: proc(width: int, height: int)
  66. // Fetch the scale of the window. This usually comes from some DPI scaling setting in the OS.
  67. // 1 means 100% scale, 1.5 means 150% etc.
  68. get_window_scale :: proc() -> f32
  69. // These are the same kind of flags that you can send to `init`.
  70. set_window_flags :: proc(flags: Window_Flags)
  71. // Flushes the current batch. This sends off everything to the GPU that has been queued in the
  72. // current batch. Normally, you do not need to do this manually. It is done automatically when these
  73. // procedures run:
  74. //
  75. // - present
  76. // - set_camera
  77. // - set_shader
  78. // - set_shader_constant
  79. // - set_scissor_rect
  80. // - set_blend_mode
  81. // - set_render_texture
  82. // - clear
  83. // - draw_texture_* IF previous draw did not use the same texture (1)
  84. // - draw_rect_*, draw_circle_*, draw_line IF previous draw did not use the shapes drawing texture (2)
  85. //
  86. // (1) When drawing textures, the current texture is fed into the active shader. Everything within
  87. // the same batch must use the same texture. So drawing with a new texture forces the current to
  88. // be drawn. You can combine several textures into an atlas to get bigger batches.
  89. //
  90. // (2) In order to use the same shader for shapes drawing and textured drawing, the shapes drawing
  91. // uses a blank, white texture. For the same reasons as (1), drawing something else than shapes
  92. // before drawing a shape will break up the batches. In a future update I'll add so that you can
  93. // set your own shapes drawing texture, making it possible to combine it with a bigger atlas.
  94. //
  95. // The batch has maximum size of VERTEX_BUFFER_MAX bytes. The shader dictates how big a vertex is
  96. // so the maximum number of vertices that can be drawn in each batch is
  97. // VERTEX_BUFFER_MAX / shader.vertex_size
  98. draw_current_batch :: proc()
  99. //-------//
  100. // INPUT //
  101. //-------//
  102. // Returns true if a keyboard key went down between the current and the previous frame. Set when
  103. // 'process_events' runs.
  104. key_went_down :: proc(key: Keyboard_Key) -> bool
  105. // Returns true if a keyboard key went up (was released) between the current and the previous frame.
  106. // Set when 'process_events' runs.
  107. key_went_up :: proc(key: Keyboard_Key) -> bool
  108. // Returns true if a keyboard is currently being held down. Set when 'process_events' runs.
  109. key_is_held :: proc(key: Keyboard_Key) -> bool
  110. // Returns true if a mouse button went down between the current and the previous frame. Specify
  111. // which mouse button using the `button` parameter.
  112. //
  113. // Set when 'process_events' runs.
  114. mouse_button_went_down :: proc(button: Mouse_Button) -> bool
  115. // Returns true if a mouse button went up (was released) between the current and the previous frame.
  116. // Specify which mouse button using the `button` parameter.
  117. //
  118. // Set when 'process_events' runs.
  119. mouse_button_went_up :: proc(button: Mouse_Button) -> bool
  120. // Returns true if a mouse button is currently being held down. Specify which mouse button using the
  121. // `button` parameter. Set when 'process_events' runs.
  122. mouse_button_is_held :: proc(button: Mouse_Button) -> bool
  123. // Returns how many clicks the mouse wheel has scrolled between the previous and current frame.
  124. get_mouse_wheel_delta :: proc() -> f32
  125. // Returns the mouse position, measured from the top-left corner of the window.
  126. get_mouse_position :: proc() -> Vec2
  127. // Returns how many pixels the mouse moved between the previous and the current frame.
  128. get_mouse_delta :: proc() -> Vec2
  129. // Returns true if a gamepad with the supplied index is connected. The parameter should be a value
  130. // between 0 and MAX_GAMEPADS.
  131. is_gamepad_active :: proc(gamepad: Gamepad_Index) -> bool
  132. // Returns true if a gamepad button went down between the previous and the current frame.
  133. gamepad_button_went_down :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
  134. // Returns true if a gamepad button went up (was released) between the previous and the current
  135. // frame.
  136. gamepad_button_went_up :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
  137. // Returns true if a gamepad button is currently held down.
  138. //
  139. // The "trigger buttons" on some gamepads also have an analogue "axis value" associated with them.
  140. // Fetch that value using `get_gamepad_axis()`.
  141. gamepad_button_is_held :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
  142. // Returns the value of analogue gamepad axes such as the thumbsticks and trigger buttons. The value
  143. // is in the range -1 to 1 for sticks and 0 to 1 for trigger buttons.
  144. get_gamepad_axis :: proc(gamepad: Gamepad_Index, axis: Gamepad_Axis) -> f32
  145. // Set the left and right vibration motor speed. The range of left and right is 0 to 1. Note that on
  146. // most gamepads, the left motor is "low frequency" and the right motor is "high frequency". They do
  147. // not vibrate with the same speed.
  148. set_gamepad_vibration :: proc(gamepad: Gamepad_Index, left: f32, right: f32)
  149. //---------//
  150. // DRAWING //
  151. //---------//
  152. // Draw a colored rectangle. The rectangles have their (x, y) position in the top-left corner of the
  153. // rectangle.
  154. draw_rect :: proc(r: Rect, c: Color)
  155. // Creates a rectangle from a position and a size and draws it.
  156. draw_rect_vec :: proc(pos: Vec2, size: Vec2, c: Color)
  157. // Draw a rectangle with a custom origin and rotation.
  158. //
  159. // The origin says which point the rotation rotates around. If the origin is `(0, 0)`, then the
  160. // rectangle rotates around the top-left corner of the rectangle. If it is `(rect.w/2, rect.h/2)`
  161. // then the rectangle rotates around its center.
  162. draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color)
  163. // Draw the outline of a rectangle with a specific thickness. The outline is drawn using four
  164. // rectangles.
  165. draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color)
  166. // Draw a circle with a certain center and radius. Note the `segments` parameter: This circle is not
  167. // perfect! It is drawn using a number of "cake segments".
  168. draw_circle :: proc(center: Vec2, radius: f32, color: Color, segments := 16)
  169. // Like `draw_circle` but only draws the outer edge of the circle.
  170. draw_circle_outline :: proc(center: Vec2, radius: f32, thickness: f32, color: Color, segments := 16)
  171. // Draws a line from `start` to `end` of a certain thickness.
  172. draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color)
  173. // Draw a texture at a specific position. The texture will be drawn with its top-left corner at
  174. // position `pos`.
  175. //
  176. // Load textures using `load_texture_from_file` or `load_texture_from_bytes`.
  177. draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE)
  178. // Draw a section of a texture at a specific position. `rect` is a rectangle measured in pixels. It
  179. // tells the procedure which part of the texture to display. The texture will be drawn with its
  180. // top-left corner at position `pos`.
  181. draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE)
  182. // Draw a texture by taking a section of the texture specified by `src` and draw it into the area of
  183. // the screen specified by `dst`. You can also rotate the texture around an origin point of your
  184. // choice.
  185. //
  186. // Tip: Use `k2.get_texture_rect(tex)` for `src` if you want to draw the whole texture.
  187. draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE)
  188. // Tells you how much space some text of a certain size will use on the screen. The font used is the
  189. // default font. The return value contains the width and height of the text.
  190. measure_text :: proc(text: string, font_size: f32) -> Vec2
  191. // Tells you how much space some text of a certain size will use on the screen, using a custom font.
  192. // The return value contains the width and height of the text.
  193. measure_text_ex :: proc(font_handle: Font_Handle, text: string, font_size: f32) -> Vec2
  194. // Draw text at a position with a size. This uses the default font. `pos` will be equal to the
  195. // top-left position of the text.
  196. draw_text :: proc(text: string, pos: Vec2, font_size: f32, color := BLACK)
  197. // Draw text at a position with a size, using a custom font. `pos` will be equal to the top-left
  198. // position of the text.
  199. draw_text_ex :: proc(font_handle: Font_Handle, text: string, pos: Vec2, font_size: f32, color := BLACK)
  200. //--------------------//
  201. // TEXTURE MANAGEMENT //
  202. //--------------------//
  203. // Create an empty texture.
  204. create_texture :: proc(width: int, height: int, format: Pixel_Format) -> Texture
  205. // Load a texture from disk and upload it to the GPU so you can draw it to the screen.
  206. // Supports PNG, BMP, TGA and baseline PNG. Note that progressive PNG files are not supported!
  207. //
  208. // The `options` parameter can be used to specify things things such as premultiplication of alpha.
  209. load_texture_from_file :: proc(filename: string, options: Load_Texture_Options = {}) -> Texture
  210. // Load a texture from a byte slice and upload it to the GPU so you can draw it to the screen.
  211. // Supports PNG, BMP, TGA and baseline PNG. Note that progressive PNG files are not supported!
  212. //
  213. // The `options` parameter can be used to specify things things such as premultiplication of alpha.
  214. load_texture_from_bytes :: proc(bytes: []u8, options: Load_Texture_Options = {}) -> Texture
  215. // Load raw texture data. You need to specify the data, size and format of the texture yourself.
  216. // This assumes that there is no header in the data. If your data has a header (you read the data
  217. // from a file on disk), then please use `load_texture_from_bytes` instead.
  218. load_texture_from_bytes_raw :: proc(bytes: []u8, width: int, height: int, format: Pixel_Format) -> Texture
  219. // Get a rectangle that spans the whole texture. Coordinates will be (x, y) = (0, 0) and size
  220. // (w, h) = (texture_width, texture_height)
  221. get_texture_rect :: proc(t: Texture) -> Rect
  222. // Update a texture with new pixels. `bytes` is the new pixel data. `rect` is the rectangle in
  223. // `tex` where the new pixels should end up.
  224. update_texture :: proc(tex: Texture, bytes: []u8, rect: Rect) -> bool
  225. // Destroy a texture, freeing up any memory it has used on the GPU.
  226. destroy_texture :: proc(tex: Texture)
  227. // Controls how a texture should be filtered. You can choose "point" or "linear" filtering. Which
  228. // means "pixly" or "smooth". This filter will be used for up and down-scaling as well as for
  229. // mipmap sampling. Use `set_texture_filter_ex` if you need to control these settings separately.
  230. set_texture_filter :: proc(t: Texture, filter: Texture_Filter)
  231. // Controls how a texture should be filtered. `scale_down_filter` and `scale_up_filter` controls how
  232. // the texture is filtered when we render the texture at a smaller or larger size.
  233. // `mip_filter` controls how the texture is filtered when it is sampled using _mipmapping_.
  234. //
  235. // TODO: Add mipmapping generation controls for texture and refer to it from here.
  236. set_texture_filter_ex :: proc(
  237. t: Texture,
  238. scale_down_filter: Texture_Filter,
  239. scale_up_filter: Texture_Filter,
  240. mip_filter: Texture_Filter,
  241. )
  242. //-----------------//
  243. // RENDER TEXTURES //
  244. //-----------------//
  245. // Create a texture that you can render into. Meaning that you can draw into it instead of drawing
  246. // onto the screen. Use `set_render_texture` to enable this Render Texture for drawing.
  247. create_render_texture :: proc(width: int, height: int) -> Render_Texture
  248. // Destroy a Render_Texture previously created using `create_render_texture`.
  249. destroy_render_texture :: proc(render_texture: Render_Texture)
  250. // Make all rendering go into a texture instead of onto the screen. Create the render texture using
  251. // `create_render_texture`. Pass `nil` to resume drawing onto the screen.
  252. set_render_texture :: proc(render_texture: Maybe(Render_Texture))
  253. //-------//
  254. // FONTS //
  255. //-------//
  256. load_font_from_file :: proc(filename: string) -> Font_Handle
  257. load_font_from_bytes :: proc(data: []u8) -> Font_Handle
  258. destroy_font :: proc(font: Font_Handle)
  259. get_default_font :: proc() -> Font_Handle
  260. //---------//
  261. // SHADERS //
  262. //---------//
  263. load_shader_from_file :: proc(
  264. vertex_filename: string,
  265. fragment_filename: string,
  266. layout_formats: []Pixel_Format = {}
  267. ) -> Shader
  268. load_shader_from_bytes :: proc(
  269. vertex_shader_bytes: []byte,
  270. fragment_shader_bytes: []byte,
  271. layout_formats: []Pixel_Format = {},
  272. ) -> Shader
  273. destroy_shader :: proc(shader: Shader)
  274. get_default_shader :: proc() -> Shader
  275. set_shader :: proc(shader: Maybe(Shader))
  276. set_shader_constant :: proc(shd: Shader, loc: Shader_Constant_Location, val: any)
  277. override_shader_input :: proc(shader: Shader, input: int, val: any)
  278. pixel_format_size :: proc(f: Pixel_Format) -> int
  279. //-------------------------------//
  280. // CAMERA AND COORDINATE SYSTEMS //
  281. //-------------------------------//
  282. set_camera :: proc(camera: Maybe(Camera))
  283. screen_to_world :: proc(pos: Vec2, camera: Camera) -> Vec2
  284. world_to_screen :: proc(pos: Vec2, camera: Camera) -> Vec2
  285. get_camera_view_matrix :: proc(c: Camera) -> Mat4
  286. get_camera_world_matrix :: proc(c: Camera) -> Mat4
  287. //------//
  288. // MISC //
  289. //------//
  290. // Choose how the alpha channel is used when mixing half-transparent color with what is already
  291. // drawn. The default is the .Alpha mode, but you also have the option of using .Premultiply_Alpha.
  292. set_blend_mode :: proc(mode: Blend_Mode)
  293. set_scissor_rect :: proc(scissor_rect: Maybe(Rect))
  294. // Restore the internal state using the pointer returned by `init`. Useful after reloading the
  295. // library (for example, when doing code hot reload).
  296. set_internal_state :: proc(state: ^State)
  297. //---------------------//
  298. // TYPES AND CONSTANTS //
  299. //---------------------//
  300. Vec2 :: [2]f32
  301. Vec3 :: [3]f32
  302. Vec4 :: [4]f32
  303. Mat4 :: matrix[4,4]f32
  304. // A rectangle that sits at position (x, y) and has size (w, h).
  305. Rect :: struct {
  306. x, y: f32,
  307. w, h: f32,
  308. }
  309. // An RGBA (Red, Green, Blue, Alpha) color. Each channel can have a value between 0 and 255.
  310. Color :: [4]u8
  311. WHITE :: Color { 255, 255, 255, 255 }
  312. BLACK :: Color { 0, 0, 0, 255 }
  313. GRAY :: Color { 127, 127, 127, 255 }
  314. RED :: Color { 198, 40, 90, 255 }
  315. GREEN :: Color { 30, 240, 30, 255 }
  316. YELLOW :: Color {240, 190, 0, 255 }
  317. BLANK :: Color { 0, 0, 0, 0 }
  318. BLUE :: Color { 30, 116, 240, 255 }
  319. // These are from Raylib. They are here so you can easily port a Raylib program to Karl2D.
  320. RL_LIGHTGRAY :: Color { 200, 200, 200, 255 }
  321. RL_GRAY :: Color { 130, 130, 130, 255 }
  322. RL_DARKGRAY :: Color { 80, 80, 80, 255 }
  323. RL_YELLOW :: Color { 253, 249, 0, 255 }
  324. RL_GOLD :: Color { 255, 203, 0, 255 }
  325. RL_ORANGE :: Color { 255, 161, 0, 255 }
  326. RL_PINK :: Color { 255, 109, 194, 255 }
  327. RL_RED :: Color { 230, 41, 55, 255 }
  328. RL_MAROON :: Color { 190, 33, 55, 255 }
  329. RL_GREEN :: Color { 0, 228, 48, 255 }
  330. RL_LIME :: Color { 0, 158, 47, 255 }
  331. RL_DARKGREEN :: Color { 0, 117, 44, 255 }
  332. RL_SKYBLUE :: Color { 102, 191, 255, 255 }
  333. RL_BLUE :: Color { 0, 121, 241, 255 }
  334. RL_DARKBLUE :: Color { 0, 82, 172, 255 }
  335. RL_PURPLE :: Color { 200, 122, 255, 255 }
  336. RL_VIOLET :: Color { 135, 60, 190, 255 }
  337. RL_DARKPURPLE :: Color { 112, 31, 126, 255 }
  338. RL_BEIGE :: Color { 211, 176, 131, 255 }
  339. RL_BROWN :: Color { 127, 106, 79, 255 }
  340. RL_DARKBROWN :: Color { 76, 63, 47, 255 }
  341. RL_WHITE :: WHITE
  342. RL_BLACK :: BLACK
  343. RL_BLANK :: BLANK
  344. RL_MAGENTA :: Color { 255, 0, 255, 255 }
  345. RL_RAYWHITE :: Color { 245, 245, 245, 255 }
  346. Texture :: struct {
  347. handle: Texture_Handle,
  348. width: int,
  349. height: int,
  350. }
  351. Load_Texture_Option :: enum {
  352. Premultiply_Alpha,
  353. }
  354. Load_Texture_Options :: bit_set[Load_Texture_Option]
  355. Blend_Mode :: enum {
  356. Alpha,
  357. Premultiplied_Alpha, // Requires the alpha-channel to be multiplied into texture RGB channels.
  358. }
  359. Render_Texture :: struct {
  360. texture: Texture,
  361. render_target: Render_Target_Handle,
  362. }
  363. Texture_Filter :: enum {
  364. Point, // Similar to "nearest neighbor". Pixly texture scaling.
  365. Linear, // Smoothed texture scaling.
  366. }
  367. Camera :: struct {
  368. target: Vec2,
  369. offset: Vec2,
  370. rotation: f32,
  371. zoom: f32,
  372. }
  373. Window_Flag :: enum {
  374. Resizable,
  375. }
  376. Window_Flags :: bit_set[Window_Flag]
  377. Shader_Handle :: distinct Handle
  378. SHADER_NONE :: Shader_Handle {}
  379. Shader_Constant_Location :: struct {
  380. offset: int,
  381. size: int,
  382. }
  383. Shader :: struct {
  384. handle: Shader_Handle,
  385. // We store the CPU-side value of all constants in a single buffer to have less allocations.
  386. // The 'constants' array says where in this buffer each constant is, and 'constant_lookup'
  387. // maps a name to a constant location.
  388. constants_data: []u8,
  389. constants: []Shader_Constant_Location,
  390. constant_lookup: map[string]Shader_Constant_Location,
  391. // Maps built in constant types such as "model view projection matrix" to a location.
  392. constant_builtin_locations: [Shader_Builtin_Constant]Maybe(Shader_Constant_Location),
  393. texture_bindpoints: []Texture_Handle,
  394. texture_lookup: map[string]int,
  395. default_texture_index: Maybe(int),
  396. inputs: []Shader_Input,
  397. input_overrides: []Shader_Input_Value_Override,
  398. default_input_offsets: [Shader_Default_Inputs]int,
  399. vertex_size: int,
  400. }
  401. SHADER_INPUT_VALUE_MAX_SIZE :: 256
  402. Shader_Input_Value_Override :: struct {
  403. val: [SHADER_INPUT_VALUE_MAX_SIZE]u8,
  404. used: int,
  405. }
  406. Shader_Input_Type :: enum {
  407. F32,
  408. Vec2,
  409. Vec3,
  410. Vec4,
  411. }
  412. Shader_Builtin_Constant :: enum {
  413. MVP,
  414. }
  415. Shader_Default_Inputs :: enum {
  416. Unknown,
  417. Position,
  418. UV,
  419. Color,
  420. }
  421. Shader_Input :: struct {
  422. name: string,
  423. register: int,
  424. type: Shader_Input_Type,
  425. format: Pixel_Format,
  426. }
  427. Pixel_Format :: enum {
  428. Unknown,
  429. RGBA_32_Float,
  430. RGB_32_Float,
  431. RG_32_Float,
  432. R_32_Float,
  433. RGBA_8_Norm,
  434. RG_8_Norm,
  435. R_8_Norm,
  436. R_8_UInt,
  437. }
  438. Font :: struct {
  439. atlas: Texture,
  440. // internal
  441. fontstash_handle: int,
  442. }
  443. Handle :: hm.Handle
  444. Texture_Handle :: distinct Handle
  445. Render_Target_Handle :: distinct Handle
  446. Font_Handle :: distinct int
  447. FONT_NONE :: Font_Handle {}
  448. TEXTURE_NONE :: Texture_Handle {}
  449. RENDER_TARGET_NONE :: Render_Target_Handle {}
  450. // This keeps track of the internal state of the library. Usually, you do not need to poke at it.
  451. // It is created and kept as a global variable when 'init' is called. However, 'init' also returns
  452. // the pointer to it, so you can later use 'set_internal_state' to restore it (after for example hot
  453. // reload).
  454. State :: struct {
  455. allocator: runtime.Allocator,
  456. frame_arena: runtime.Arena,
  457. frame_allocator: runtime.Allocator,
  458. win: Window_Interface,
  459. window_state: rawptr,
  460. rb: Render_Backend_Interface,
  461. rb_state: rawptr,
  462. fs: fs.FontContext,
  463. shutdown_wanted: bool,
  464. mouse_position: Vec2,
  465. mouse_delta: Vec2,
  466. mouse_wheel_delta: f32,
  467. key_went_down: #sparse [Keyboard_Key]bool,
  468. key_went_up: #sparse [Keyboard_Key]bool,
  469. key_is_held: #sparse [Keyboard_Key]bool,
  470. mouse_button_went_down: #sparse [Mouse_Button]bool,
  471. mouse_button_went_up: #sparse [Mouse_Button]bool,
  472. mouse_button_is_held: #sparse [Mouse_Button]bool,
  473. gamepad_button_went_down: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
  474. gamepad_button_went_up: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
  475. gamepad_button_is_held: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
  476. window: Window_Handle,
  477. default_font: Font_Handle,
  478. fonts: [dynamic]Font,
  479. shape_drawing_texture: Texture_Handle,
  480. batch_font: Font_Handle,
  481. batch_camera: Maybe(Camera),
  482. batch_shader: Shader,
  483. batch_scissor: Maybe(Rect),
  484. batch_texture: Texture_Handle,
  485. batch_render_target: Render_Target_Handle,
  486. batch_blend_mode: Blend_Mode,
  487. view_matrix: Mat4,
  488. proj_matrix: Mat4,
  489. depth: f32,
  490. depth_start: f32,
  491. depth_increment: f32,
  492. vertex_buffer_cpu: []u8,
  493. vertex_buffer_cpu_used: int,
  494. default_shader: Shader,
  495. // Time when the first call to `new_frame` happened
  496. start_time: time.Time,
  497. prev_frame_time: time.Time,
  498. // "dt"
  499. frame_time: f32,
  500. time: f64,
  501. }
  502. // Support for up to 255 mouse buttons. Cast an int to type `Mouse_Button` to use things outside the
  503. // options presented here.
  504. Mouse_Button :: enum {
  505. Left,
  506. Right,
  507. Middle,
  508. Max = 255,
  509. }
  510. // Based on Raylib / GLFW
  511. Keyboard_Key :: enum {
  512. None = 0,
  513. // Numeric keys (top row)
  514. N0 = 48,
  515. N1 = 49,
  516. N2 = 50,
  517. N3 = 51,
  518. N4 = 52,
  519. N5 = 53,
  520. N6 = 54,
  521. N7 = 55,
  522. N8 = 56,
  523. N9 = 57,
  524. // Letter keys
  525. A = 65,
  526. B = 66,
  527. C = 67,
  528. D = 68,
  529. E = 69,
  530. F = 70,
  531. G = 71,
  532. H = 72,
  533. I = 73,
  534. J = 74,
  535. K = 75,
  536. L = 76,
  537. M = 77,
  538. N = 78,
  539. O = 79,
  540. P = 80,
  541. Q = 81,
  542. R = 82,
  543. S = 83,
  544. T = 84,
  545. U = 85,
  546. V = 86,
  547. W = 87,
  548. X = 88,
  549. Y = 89,
  550. Z = 90,
  551. // Special characters
  552. Apostrophe = 39,
  553. Comma = 44,
  554. Minus = 45,
  555. Period = 46,
  556. Slash = 47,
  557. Semicolon = 59,
  558. Equal = 61,
  559. Left_Bracket = 91,
  560. Backslash = 92,
  561. Right_Bracket = 93,
  562. Backtick = 96,
  563. // Function keys, modifiers, caret control etc
  564. Space = 32,
  565. Escape = 256,
  566. Enter = 257,
  567. Tab = 258,
  568. Backspace = 259,
  569. Insert = 260,
  570. Delete = 261,
  571. Right = 262,
  572. Left = 263,
  573. Down = 264,
  574. Up = 265,
  575. Page_Up = 266,
  576. Page_Down = 267,
  577. Home = 268,
  578. End = 269,
  579. Caps_Lock = 280,
  580. Scroll_Lock = 281,
  581. Num_Lock = 282,
  582. Print_Screen = 283,
  583. Pause = 284,
  584. F1 = 290,
  585. F2 = 291,
  586. F3 = 292,
  587. F4 = 293,
  588. F5 = 294,
  589. F6 = 295,
  590. F7 = 296,
  591. F8 = 297,
  592. F9 = 298,
  593. F10 = 299,
  594. F11 = 300,
  595. F12 = 301,
  596. Left_Shift = 340,
  597. Left_Control = 341,
  598. Left_Alt = 342,
  599. Left_Super = 343,
  600. Right_Shift = 344,
  601. Right_Control = 345,
  602. Right_Alt = 346,
  603. Right_Super = 347,
  604. Menu = 348,
  605. // Numpad keys
  606. NP_0 = 320,
  607. NP_1 = 321,
  608. NP_2 = 322,
  609. NP_3 = 323,
  610. NP_4 = 324,
  611. NP_5 = 325,
  612. NP_6 = 326,
  613. NP_7 = 327,
  614. NP_8 = 328,
  615. NP_9 = 329,
  616. NP_Decimal = 330,
  617. NP_Divide = 331,
  618. NP_Multiply = 332,
  619. NP_Subtract = 333,
  620. NP_Add = 334,
  621. NP_Enter = 335,
  622. NP_Equal = 336,
  623. }
  624. MAX_GAMEPADS :: 4
  625. // A value between 0 and MAX_GAMEPADS - 1
  626. Gamepad_Index :: int
  627. Gamepad_Axis :: enum {
  628. Left_Stick_X,
  629. Left_Stick_Y,
  630. Right_Stick_X,
  631. Right_Stick_Y,
  632. Left_Trigger,
  633. Right_Trigger,
  634. }
  635. Gamepad_Button :: enum {
  636. // DPAD buttons
  637. Left_Face_Up,
  638. Left_Face_Down,
  639. Left_Face_Left,
  640. Left_Face_Right,
  641. Right_Face_Up, // XBOX: Y, PS: Triangle
  642. Right_Face_Down, // XBOX: A, PS: X
  643. Right_Face_Left, // XBOX: X, PS: Square
  644. Right_Face_Right, // XBOX: B, PS: Circle
  645. Left_Shoulder,
  646. Left_Trigger,
  647. Right_Shoulder,
  648. Right_Trigger,
  649. Left_Stick_Press, // Clicking the left analogue stick
  650. Right_Stick_Press, // Clicking the right analogue stick
  651. Middle_Face_Left, // Select / back / options button
  652. Middle_Face_Middle, // PS button (not available on XBox)
  653. Middle_Face_Right, // Start
  654. }