r3d_instance.odin 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* r3d_instance.odin -- R3D Instance Module.
  2. *
  3. * Copyright (c) 2025-2026 Le Juez Victor
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * For conditions of distribution and use, see accompanying LICENSE file.
  7. */
  8. package r3d
  9. import rl "vendor:raylib"
  10. when ODIN_OS == .Windows {
  11. foreign import lib {
  12. "windows/libr3d.a",
  13. "system:raylib",
  14. "system:assimp",
  15. }
  16. } else when ODIN_OS == .Linux {
  17. foreign import lib {
  18. "linux/libr3d.a",
  19. "system:raylib",
  20. "system:assimp",
  21. }
  22. } else when ODIN_OS == .Darwin {
  23. foreign import lib {
  24. "darwin/libr3d.a",
  25. "system:raylib",
  26. "system:assimp",
  27. }
  28. }
  29. R3D_INSTANCE_CUSTOM :: (1<<4) /*< rl.Vector4 */
  30. /**
  31. * @brief GPU buffers storing instance attribute streams.
  32. *
  33. * buffers: One VBO per attribute (indexed by flag order).
  34. * capcity: Maximum number of instances.
  35. * flags: Enabled attribute mask.
  36. */
  37. InstanceBuffer :: struct {
  38. buffers: [5]u32,
  39. capacity: i32,
  40. flags: i32,
  41. }
  42. @(default_calling_convention="c", link_prefix="R3D_")
  43. foreign lib {
  44. /**
  45. * @brief Create instance buffers on the GPU.
  46. * @param capacity Max instances.
  47. * @param flags Attribute mask to allocate.
  48. * @return Initialized instance buffer.
  49. */
  50. LoadInstanceBuffer :: proc(capacity: i32, flags: InstanceFlags) -> InstanceBuffer ---
  51. /**
  52. * @brief Destroy all GPU buffers owned by this instance buffer.
  53. */
  54. UnloadInstanceBuffer :: proc(buffer: InstanceBuffer) ---
  55. /**
  56. * @brief Upload a contiguous range of instance data.
  57. * @param flag Attribute being updated (single bit).
  58. * @param offset First instance index.
  59. * @param count Number of instances.
  60. * @param data Source pointer.
  61. */
  62. UploadInstances :: proc(buffer: InstanceBuffer, flag: InstanceFlags, offset: i32, count: i32, data: rawptr) ---
  63. /**
  64. * @brief Map an attribute buffer for CPU write access.
  65. * @param flag Attribute to map (single bit).
  66. * @return Writable pointer, or NULL on error.
  67. */
  68. MapInstances :: proc(buffer: InstanceBuffer, flag: InstanceFlags) -> rawptr ---
  69. /**
  70. * @brief Unmap one or more previously mapped attribute buffers.
  71. * @param flags Bitmask of attributes to unmap.
  72. */
  73. UnmapInstances :: proc(buffer: InstanceBuffer, flags: InstanceFlags) ---
  74. }
  75. /**
  76. * @brief Bitmask defining which instance attributes are present.
  77. */
  78. InstanceFlag :: enum u32 {
  79. POSITION = 0,
  80. ROTATION = 1,
  81. SCALE = 2,
  82. COLOR = 3,
  83. CUSTOM = 4,
  84. }
  85. InstanceFlags :: bit_set[InstanceFlag; u32]