types.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #ifndef STRUCTS_H
  2. #define STRUCTS_H
  3. #include <SDL2/SDL.h>
  4. #include <CL/cl.h>
  5. #include "math.h"
  6. enum {
  7. RI_ASPECT_MODE_STRETCH = 1 << 0,
  8. RI_ASPECT_MODE_LETTERBOX = 1 << 1,
  9. };
  10. enum {
  11. RI_DEBUG_NONE = 0,
  12. // frame-level
  13. RI_DEBUG_FRAME_START_END_MARKERS = 1 << 0,
  14. RI_DEBUG_TICK_TIME = 1 << 1,
  15. RI_DEBUG_KERNEL_LOADER_ERROR = 1 << 2,
  16. // transformer
  17. RI_DEBUG_TRANSFORMER_CURRENT_ACTOR = 1 << 3,
  18. RI_DEBUG_TRANSFORMER_GLOBAL_SIZE = 1 << 5,
  19. RI_DEBUG_TRANSFORMER_LOCAL_SIZE = 1 << 6,
  20. RI_DEBUG_TRANSFORMER_EXTRA_WORK_ITEMS= 1 << 7,
  21. RI_DEBUG_TRANSFORMER_TIME = 1 << 8,
  22. RI_DEBUG_TRANSFORMER_MESSAGE = 1 << 9,
  23. RI_DEBUG_TRANSFORMER_ERROR = 1 << 11,
  24. RI_DEBUG_TRANSFORMER_TEXTURE = 1 << 29,
  25. RI_DEBUG_TRANSFORMER_ALL = (
  26. RI_DEBUG_TRANSFORMER_CURRENT_ACTOR |
  27. RI_DEBUG_TRANSFORMER_GLOBAL_SIZE |
  28. RI_DEBUG_TRANSFORMER_LOCAL_SIZE |
  29. RI_DEBUG_TRANSFORMER_EXTRA_WORK_ITEMS |
  30. RI_DEBUG_TRANSFORMER_TIME |
  31. RI_DEBUG_TRANSFORMER_MESSAGE |
  32. RI_DEBUG_TRANSFORMER_ERROR |
  33. RI_DEBUG_TRANSFORMER_TEXTURE ),
  34. // rasterizer
  35. RI_DEBUG_RASTERIZER_TIME = 1 << 12,
  36. RI_DEBUG_RASTERIZER_GLOBAL_SIZE = 1 << 13,
  37. RI_DEBUG_RASTERIZER_LOCAL_SIZE = 1 << 14,
  38. RI_DEBUG_RASTERIZER_MESSAGE = 1 << 15,
  39. RI_DEBUG_RASTERIZER_ = 1 << 16,
  40. RI_DEBUG_RASTERIZER_ALL = (
  41. RI_DEBUG_RASTERIZER_TIME |
  42. RI_DEBUG_RASTERIZER_GLOBAL_SIZE |
  43. RI_DEBUG_RASTERIZER_LOCAL_SIZE |
  44. RI_DEBUG_RASTERIZER_MESSAGE |
  45. RI_DEBUG_RASTERIZER_ ),
  46. // mesh loader
  47. RI_DEBUG_MESH_LOADER_ERROR = 1 << 17,
  48. RI_DEBUG_MESH_LOADER_LOADED_MESH = 1 << 18,
  49. RI_DEBUG_MESH_LOADER_REALLOCATION = 1 << 19,
  50. RI_DEBUG_MESH_LOADER_TIME = 1 << 20,
  51. RI_DEBUG_MESH_LOADER_FACE_VERT_NORM_UV_COUNT = 1 << 28,
  52. RI_DEBUG_MESH_LOADER_ALL = (
  53. RI_DEBUG_MESH_LOADER_ERROR |
  54. RI_DEBUG_MESH_LOADER_LOADED_MESH |
  55. RI_DEBUG_MESH_LOADER_REALLOCATION |
  56. RI_DEBUG_MESH_LOADER_TIME |
  57. RI_DEBUG_MESH_LOADER_FACE_VERT_NORM_UV_COUNT ),
  58. // render function
  59. RI_DEBUG_RENDER_REALLOCATION = 1 << 21,
  60. RI_DEBUG_RENDER_ERROR = 1 << 22,
  61. RI_DEBUG_RENDER_FRAME_BUFFER_READ_TIME = 1 << 23,
  62. RI_DEBUG_RENDER_TIME = 1 << 24,
  63. RI_DEBUG_RENDER_ALL = (
  64. RI_DEBUG_RENDER_REALLOCATION |
  65. RI_DEBUG_RENDER_ERROR |
  66. RI_DEBUG_RENDER_FRAME_BUFFER_READ_TIME |
  67. RI_DEBUG_RENDER_TIME ),
  68. // OpenCL
  69. RI_DEBUG_OPENCL_ERROR = 1 << 25,
  70. // init
  71. RI_DEBUG_INIT_PLATFORMS = 1 << 26,
  72. RI_DEBUG_INIT_ERROR = (1 << 27) | RI_DEBUG_OPENCL_ERROR,
  73. // multi-flags
  74. RI_DEBUG_ETC = (
  75. RI_DEBUG_FRAME_START_END_MARKERS |
  76. RI_DEBUG_TICK_TIME |
  77. RI_DEBUG_KERNEL_LOADER_ERROR ),
  78. RI_DEBUG_ERRORS = (
  79. RI_DEBUG_TRANSFORMER_ERROR |
  80. RI_DEBUG_MESH_LOADER_ERROR |
  81. RI_DEBUG_RENDER_ERROR |
  82. RI_DEBUG_INIT_ERROR ),
  83. RI_DEBUG_ALL = (
  84. RI_DEBUG_ETC |
  85. RI_DEBUG_TRANSFORMER_ALL |
  86. RI_DEBUG_MESH_LOADER_ALL |
  87. RI_DEBUG_RASTERIZER_ALL |
  88. RI_DEBUG_RENDER_ALL )
  89. };
  90. typedef enum {
  91. ri_true = 1,
  92. ri_false = 0,
  93. } ri_bool;
  94. typedef struct {
  95. uint16_t width;
  96. uint16_t height;
  97. uint32_t index;
  98. } RI_texture;
  99. typedef struct {
  100. RI_vector_3 position_0;
  101. RI_vector_3 position_1;
  102. RI_vector_3 position_2;
  103. RI_vector_3 normal_0;
  104. RI_vector_3 normal_1;
  105. RI_vector_3 normal_2;
  106. RI_vector_2 uv_0;
  107. RI_vector_2 uv_1;
  108. RI_vector_2 uv_2;
  109. unsigned char should_render;
  110. } RI_face;
  111. typedef struct {
  112. int position_0_index;
  113. int position_1_index;
  114. int position_2_index;
  115. int normal_0_index;
  116. int normal_1_index;
  117. int normal_2_index;
  118. int uv_0_index;
  119. int uv_1_index;
  120. int uv_2_index;
  121. } RI_temp_face;
  122. typedef struct {
  123. int face_count;
  124. int face_index;
  125. int has_normals;
  126. int has_uvs;
  127. } RI_mesh;
  128. typedef struct {
  129. double r, g, b;
  130. } RI_color;
  131. typedef struct {
  132. uint32_t albedo;
  133. } RI_material;
  134. typedef struct {
  135. RI_vector_3 position;
  136. RI_vector_4 rotation;
  137. RI_vector_3 scale;
  138. RI_mesh *mesh;
  139. RI_texture* texture;
  140. int active;
  141. int material_index;
  142. } RI_actor;
  143. typedef struct {
  144. RI_vector_3 position_0, position_1, position_2;
  145. RI_vector_3 normal_0, normal_1, normal_2;
  146. RI_vector_2 uv_0, uv_1, uv_2;
  147. int16_t min_screen_x, max_screen_x, min_screen_y, max_screen_y;
  148. unsigned char should_render;
  149. uint16_t texture_width, height;
  150. uint32_t texture_index;
  151. } RI_renderable_face;
  152. typedef struct {
  153. RI_vector_3 position;
  154. RI_vector_4 rotation;
  155. float FOV, min_clip, max_clip;
  156. } RI_camera;
  157. typedef struct {
  158. RI_actor **actors;
  159. RI_camera camera;
  160. int length_of_actors_array, face_count;
  161. } RI_scene;
  162. typedef struct {
  163. size_t size;
  164. void *pointer;
  165. int reallocated_free;
  166. int reallocated_alloc;
  167. int freed;
  168. int allocated;
  169. int line;
  170. } RI_memory_allocation;
  171. typedef struct {
  172. int width, height, half_width, half_height;
  173. char* title;
  174. unsigned char aspect_mode;
  175. } RI_window;
  176. typedef struct {
  177. SDL_Window *window;
  178. SDL_Renderer *renderer;
  179. SDL_Texture *frame_buffer_texture;
  180. uint32_t *frame_buffer;
  181. int pitch;
  182. } RI_SDL;
  183. typedef struct {
  184. cl_platform_id platform;
  185. cl_device_id device;
  186. cl_context context;
  187. cl_command_queue queue;
  188. cl_kernel rasterization_kernel;
  189. cl_kernel transformation_kernel;
  190. cl_mem textures_mem_buffer;
  191. cl_mem renderable_faces_mem_buffer;
  192. cl_mem faces_mem_buffer;
  193. cl_mem frame_buffer_mem_buffer;
  194. cl_mem vertecies_mem_buffer;
  195. cl_mem normals_mem_buffer;
  196. cl_mem uvs_mem_buffer;
  197. RI_renderable_face *faces_to_render;
  198. RI_face *faces;
  199. RI_temp_face *temp_faces;
  200. RI_vector_3 *temp_vertecies;
  201. RI_vector_3 *temp_normals;
  202. RI_vector_2 *temp_uvs;
  203. uint32_t* textures;
  204. int face_count;
  205. int vertex_count;
  206. int normal_count;
  207. int uv_count;
  208. int length_of_renderable_faces_array;
  209. int number_of_faces_just_rendered;
  210. int length_of_textures_array;
  211. } RI_CL;
  212. typedef struct {
  213. int debug_memory;
  214. RI_memory_allocation *allocation_table;
  215. int current_allocation_index;
  216. int allocation_search_limit;
  217. int allocation_table_length;
  218. } RI_memory;
  219. typedef struct {
  220. RI_actor *default_actor;
  221. } RI_defaults;
  222. typedef struct {
  223. RI_window window;
  224. RI_SDL sdl;
  225. RI_CL opencl;
  226. RI_memory memory;
  227. RI_defaults defaults;
  228. int is_running;
  229. char* debug_prefix;
  230. int current_renderable_face_index;
  231. int current_split_renderable_face_index;
  232. int current_frame;
  233. int debug_flags;
  234. } RI_context;
  235. #endif