RI_types.h 7.3 KB

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