r3d_screen_shader.odin 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* r3d_screen_shader.odin -- R3D Screen Shader 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. ScreenShader :: struct {}
  30. @(default_calling_convention="c", link_prefix="R3D_")
  31. foreign lib {
  32. /**
  33. * @brief Loads a screen shader from a file.
  34. *
  35. * The shader must define a single entry point:
  36. * `void fragment()`. Any other entry point, such as `vertex()`,
  37. * or any varyings will be ignored.
  38. *
  39. * @param filePath Path to the shader source file.
  40. * @return Pointer to the loaded screen shader, or NULL on failure.
  41. */
  42. LoadScreenShader :: proc(filePath: cstring) -> ^ScreenShader ---
  43. /**
  44. * @brief Loads a screen shader from a source code string in memory.
  45. *
  46. * The shader must define a single entry point:
  47. * `void fragment()`. Any other entry point, such as `vertex()`,
  48. * or any varyings will be ignored.
  49. *
  50. * @param code Null-terminated shader source code.
  51. * @return Pointer to the loaded screen shader, or NULL on failure.
  52. */
  53. LoadScreenShaderFromMemory :: proc(code: cstring) -> ^ScreenShader ---
  54. /**
  55. * @brief Unloads and destroys a screen shader.
  56. *
  57. * @param shader Screen shader to unload.
  58. */
  59. UnloadScreenShader :: proc(shader: ^ScreenShader) ---
  60. /**
  61. * @brief Sets a uniform value for the current frame.
  62. *
  63. * Once a uniform is set, it remains valid for the all frames.
  64. * If an uniform is set multiple times during the same frame,
  65. * the last value defined before R3D_End() is used.
  66. *
  67. * Supported types:
  68. * bool, int, float,
  69. * ivec2, ivec3, ivec4,
  70. * vec2, vec3, vec4,
  71. * mat2, mat3, mat4
  72. *
  73. * @warning Boolean values are read as 4 bytes.
  74. *
  75. * @param shader Target screen shader.
  76. * May be NULL. In that case, the call is ignored
  77. * and a warning is logged.
  78. * @param name Name of the uniform. Must not be NULL.
  79. * @param value Pointer to the uniform value. Must not be NULL.
  80. */
  81. SetScreenShaderUniform :: proc(shader: ^ScreenShader, name: cstring, value: rawptr) ---
  82. /**
  83. * @brief Sets a texture sampler for the current frame.
  84. *
  85. * Once a sampler is set, it remains valid for all frames.
  86. * If a sampler is set multiple times during the same frame,
  87. * the last value defined before R3D_End() is used.
  88. *
  89. * Supported samplers:
  90. * sampler1D, sampler2D, sampler3D, samplerCube
  91. *
  92. * @param shader Target screen shader.
  93. * May be NULL. In that case, the call is ignored
  94. * and a warning is logged.
  95. * @param name Name of the sampler uniform. Must not be NULL.
  96. * @param texture rl.Texture to bind to the sampler.
  97. */
  98. SetScreenShaderSampler :: proc(shader: ^ScreenShader, name: cstring, texture: rl.Texture) ---
  99. /**
  100. * @brief Sets the list of screen shaders to execute at the end of the frame.
  101. *
  102. * The maximum number of shaders is defined by `R3D_MAX_SCREEN_SHADERS`.
  103. * If the provided count exceeds this limit, a warning is emitted and only
  104. * the first `R3D_MAX_SCREEN_SHADERS` shaders are used.
  105. *
  106. * Shader pointers are copied internally, so the original array can be modified or freed after the call.
  107. * NULL entries are allowed safely within the list.
  108. *
  109. * Calling this function resets all internal screen shaders before copying the new list.
  110. * To disable all screen shaders, call this function with `shaders = NULL` and/or `count = 0`.
  111. *
  112. * @param shaders Array of pointers to R3D_ScreenShader objects.
  113. * @param count Number of shaders in the array.
  114. */
  115. SetScreenShaderChain :: proc(shaders: ^^ScreenShader, count: i32) ---
  116. }