main.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. // rasteriver.c
  2. #include <CL/cl.h>
  3. #include <SDL2/SDL.h>
  4. #include "../headers/rasteriver.h"
  5. #include "../headers/memory.h"
  6. #include "../headers/pitmap.h"
  7. #include <time.h>
  8. cl_int clerror;
  9. cl_event clevent;
  10. RI_context context;
  11. #define RI_realloc(__ptr, __size) written_RI_realloc(__ptr, __size, __func__, __LINE__, context)
  12. #define RI_malloc(__size) written_RI_malloc(__size, __func__, __LINE__, context)
  13. #define RI_calloc(__nmemb, __size) written_RI_calloc(__nmemb, __size, __func__, __LINE__, context)
  14. #define RI_free(__ptr) written_RI_free(__ptr, __func__, __LINE__, context)
  15. #define PI 3.14159265359
  16. #define PI2 1.57079632679
  17. void debug(char *string, int debug_flag, ...){
  18. if (!(context.debug_flags & debug_flag))
  19. return;
  20. va_list args;
  21. va_start(args, debug_flag);
  22. char message[500];
  23. strcpy(message, context.debug_prefix);
  24. strcat(message, string);
  25. vprintf(message, args);
  26. printf("\n");
  27. va_end(args);
  28. }
  29. RI_texture* RI_load_image(char* filename){
  30. PM_image* image = PM_load_image(filename);
  31. RI_texture* texture = RI_malloc(sizeof(RI_texture));
  32. int previous_length_of_textures_array = context.opencl.length_of_textures_array;
  33. texture->width = image->width;
  34. texture->height = image->height;
  35. texture->index = previous_length_of_textures_array;
  36. context.opencl.length_of_textures_array += image->width * image->height;
  37. context.opencl.textures = RI_realloc(context.opencl.textures, context.opencl.length_of_textures_array * sizeof(uint32_t));
  38. printf("%d\n", previous_length_of_textures_array);
  39. memcpy(context.opencl.textures + previous_length_of_textures_array, image->frame_buffer, sizeof(uint32_t) * image->width * image->height);
  40. if (context.opencl.textures_mem_buffer) clReleaseMemObject(context.opencl.textures_mem_buffer);
  41. context.opencl.textures_mem_buffer = clCreateBuffer(
  42. context.opencl.context,
  43. CL_MEM_READ_WRITE,
  44. sizeof(uint32_t) * context.opencl.length_of_textures_array,
  45. NULL, NULL
  46. );
  47. clEnqueueWriteBuffer(
  48. context.opencl.queue,
  49. context.opencl.textures_mem_buffer,
  50. CL_TRUE,
  51. 0,
  52. sizeof(uint32_t) * context.opencl.length_of_textures_array,
  53. context.opencl.textures,
  54. 0, NULL, NULL
  55. );
  56. clFinish(context.opencl.queue);
  57. clSetKernelArg(
  58. context.opencl.rasterization_kernel,
  59. 1,
  60. sizeof(cl_mem),
  61. &context.opencl.textures_mem_buffer
  62. );
  63. free(image->frame_buffer);
  64. free(image);
  65. return texture;
  66. }
  67. RI_material *RI_new_material(){
  68. RI_material *new_material = RI_malloc(sizeof(RI_material));
  69. new_material->albedo = 0xFFFF00FF;
  70. return new_material;
  71. }
  72. RI_actor *RI_new_actor(){
  73. RI_actor *new_actor = RI_malloc(sizeof(RI_actor));
  74. if (context.defaults.default_actor){
  75. *new_actor = *context.defaults.default_actor;
  76. } else {
  77. new_actor->position = (RI_vector_3){0, 0, 0};
  78. new_actor->scale = (RI_vector_3){1, 1, 1};
  79. new_actor->rotation = (RI_vector_4){1, 0, 0, 0};
  80. new_actor->active = 1;
  81. }
  82. return new_actor;
  83. }
  84. RI_scene *RI_new_scene(){
  85. RI_scene *new_scene = RI_malloc(sizeof(RI_scene));
  86. new_scene->camera.FOV = PI2;
  87. new_scene->camera.max_clip = 100000;
  88. new_scene->camera.min_clip = 0.01;
  89. new_scene->camera.position = (RI_vector_3){0, 0, 0};
  90. new_scene->camera.rotation = (RI_vector_4){1, 0, 0, 0};
  91. return new_scene;
  92. }
  93. RI_mesh *RI_load_mesh(char *filename){
  94. clock_t start_time, end_time;
  95. start_time = clock();
  96. RI_mesh *new_mesh = RI_malloc(sizeof(RI_mesh));
  97. int previous_face_count = context.opencl.face_count;
  98. int previous_vertecies_count = context.opencl.vertex_count;
  99. int previous_normals_count = context.opencl.normal_count;
  100. int previous_uvs_count = context.opencl.uv_count;
  101. FILE *file = fopen(filename, "r");
  102. if (!file){
  103. debug("[Mesh Loader] Error! File \"%s\" not found", RI_DEBUG_MESH_LOADER_ERROR, filename);
  104. return NULL;
  105. }
  106. char line[512];
  107. int face_count = 0;
  108. int object_face_count = 0;
  109. int object_vertecies_count = 0;
  110. int object_normals_count = 0;
  111. int object_uvs_count = 0;
  112. while (fgets(line, sizeof(line), file)) {
  113. if (line[0] == 'f' && line[1] == ' ') { // face
  114. ++face_count;
  115. ++context.opencl.face_count;
  116. ++object_face_count;
  117. }
  118. else if (line[0] == 'v'){
  119. if (line[1] == ' ') { // vertex
  120. ++context.opencl.vertex_count;
  121. ++object_vertecies_count;
  122. }
  123. else if (line[1] == 'n') { // normal
  124. ++context.opencl.normal_count;
  125. ++object_normals_count;
  126. }
  127. else if (line[1] == 't') { // UV
  128. ++context.opencl.uv_count;
  129. ++object_uvs_count;
  130. }
  131. }
  132. }
  133. rewind(file);
  134. debug(
  135. "%d faces %d vertecies %d normals %d uvs",
  136. RI_DEBUG_MESH_LOADER_FACE_VERT_NORM_UV_COUNT,
  137. object_face_count,
  138. object_vertecies_count,
  139. object_normals_count,
  140. object_uvs_count
  141. );
  142. context.opencl.faces = RI_realloc(context.opencl.faces, sizeof(RI_face) * context.opencl.face_count);
  143. context.opencl.temp_faces = RI_malloc(sizeof(RI_face) * object_face_count);
  144. context.opencl.temp_vertecies = RI_malloc(sizeof(RI_vector_3) * object_vertecies_count);
  145. if (object_normals_count > 0) context.opencl.temp_normals = RI_malloc(
  146. sizeof(RI_vector_3) * object_normals_count
  147. );
  148. if (object_uvs_count > 0) context.opencl.temp_uvs = RI_malloc(sizeof(RI_vector_2) * object_uvs_count);
  149. int current_face_index = 0;
  150. int current_vertex_index = 0;
  151. int current_normal_index = 0;
  152. int current_uv_index = 0;
  153. int has_normals, has_uvs;
  154. has_normals = has_uvs = 0;
  155. while (fgets(line, sizeof(line), file)) {
  156. if (line[0] == 'f' && line[1] == ' ') {
  157. int vertex_0_index,
  158. vertex_1_index,
  159. vertex_2_index,
  160. normal_0_index,
  161. normal_1_index,
  162. normal_2_index,
  163. uv_0_index,
  164. uv_1_index,
  165. uv_2_index
  166. ;
  167. int matches = sscanf(line, "f %d/%d/%d %d/%d/%d %d/%d/%d/",
  168. &vertex_0_index, &uv_0_index, &normal_0_index,
  169. &vertex_1_index, &uv_1_index, &normal_1_index,
  170. &vertex_2_index, &uv_2_index, &normal_2_index);
  171. if (matches != 9){
  172. vertex_0_index = -1;
  173. vertex_1_index = -1;
  174. vertex_2_index = -1;
  175. normal_0_index = -1;
  176. normal_1_index = -1;
  177. normal_2_index = -1;
  178. uv_0_index = -1;
  179. uv_1_index = -1;
  180. uv_2_index = -1;
  181. if (strchr(line, '/')){
  182. sscanf(line, "f %d//%d %d//%d %d//%d",
  183. &vertex_0_index, &normal_0_index,
  184. &vertex_1_index, &normal_1_index,
  185. &vertex_2_index, &normal_2_index);
  186. has_normals = 1;
  187. }
  188. else {
  189. sscanf(line, "f %d %d %d",
  190. &vertex_0_index,
  191. &vertex_1_index,
  192. &vertex_2_index);
  193. }
  194. }
  195. else {
  196. has_normals = has_uvs = 1;
  197. }
  198. context.opencl.temp_faces[current_face_index].position_0_index = vertex_0_index - 1;
  199. context.opencl.temp_faces[current_face_index].position_1_index = vertex_1_index - 1;
  200. context.opencl.temp_faces[current_face_index].position_2_index = vertex_2_index - 1;
  201. context.opencl.temp_faces[current_face_index].normal_0_index = normal_0_index - 1;
  202. context.opencl.temp_faces[current_face_index].normal_1_index = normal_1_index - 1;
  203. context.opencl.temp_faces[current_face_index].normal_2_index = normal_2_index - 1;
  204. context.opencl.temp_faces[current_face_index].uv_0_index = uv_0_index - 1;
  205. context.opencl.temp_faces[current_face_index].uv_1_index = uv_1_index - 1;
  206. context.opencl.temp_faces[current_face_index].uv_2_index = uv_2_index - 1;
  207. context.opencl.faces[current_face_index].should_render = 1;
  208. ++current_face_index;
  209. }
  210. else if (line[0] == 'v' && line[1] == ' ') {
  211. double x, y, z;
  212. sscanf(line, "v %lf %lf %lf", &x, &y, &z);
  213. context.opencl.temp_vertecies[current_vertex_index].x = x;
  214. context.opencl.temp_vertecies[current_vertex_index].y = y;
  215. context.opencl.temp_vertecies[current_vertex_index].z = z;
  216. ++current_vertex_index;
  217. }
  218. else if (line[0] == 'v' && line[1] == 'n') {
  219. double x, y, z;
  220. sscanf(line, "vn %lf %lf %lf", &x, &y, &z);
  221. context.opencl.temp_normals[current_normal_index].x = x;
  222. context.opencl.temp_normals[current_normal_index].y = y;
  223. context.opencl.temp_normals[current_normal_index].z = z;
  224. ++current_normal_index;
  225. }
  226. else if (line[0] == 'v' && line[1] == 't') {
  227. double x, y, z;
  228. sscanf(line, "vt %lf %lf %lf", &x, &y, &z);
  229. context.opencl.temp_uvs[current_uv_index].x = x;
  230. context.opencl.temp_uvs[current_uv_index].y = y;
  231. // UVS are almost always 2D so we don't need Z (the type itself is a vector 2f, not 3f)
  232. ++current_uv_index;
  233. }
  234. }
  235. for (int i = 0; i < object_face_count; ++i){
  236. context.opencl.faces[i + previous_face_count].position_0 = context.opencl.temp_vertecies[context.opencl.temp_faces[i].position_0_index];
  237. context.opencl.faces[i + previous_face_count].position_1 = context.opencl.temp_vertecies[context.opencl.temp_faces[i].position_1_index];
  238. context.opencl.faces[i + previous_face_count].position_2 = context.opencl.temp_vertecies[context.opencl.temp_faces[i].position_2_index];
  239. context.opencl.faces[i + previous_face_count].normal_0 = context.opencl.temp_normals[context.opencl.temp_faces[i].normal_0_index];
  240. context.opencl.faces[i + previous_face_count].normal_1 = context.opencl.temp_normals[context.opencl.temp_faces[i].normal_1_index];
  241. context.opencl.faces[i + previous_face_count].normal_2 = context.opencl.temp_normals[context.opencl.temp_faces[i].normal_2_index];
  242. context.opencl.faces[i + previous_face_count].uv_0 = context.opencl.temp_uvs[context.opencl.temp_faces[i].uv_0_index];
  243. context.opencl.faces[i + previous_face_count].uv_1 = context.opencl.temp_uvs[context.opencl.temp_faces[i].uv_1_index];
  244. context.opencl.faces[i + previous_face_count].uv_2 = context.opencl.temp_uvs[context.opencl.temp_faces[i].uv_2_index];
  245. }
  246. free(context.opencl.temp_faces);
  247. free(context.opencl.temp_vertecies);
  248. if (object_normals_count > 0) free(context.opencl.temp_normals);
  249. if (object_uvs_count > 0) free(context.opencl.temp_uvs);
  250. char* loading_mesh_notice_string;
  251. if (has_normals && !has_uvs) loading_mesh_notice_string = "normals";
  252. else if (!has_normals && has_uvs) loading_mesh_notice_string = "UVs";
  253. else if (!has_normals && !has_uvs) loading_mesh_notice_string = "normals and UVs";
  254. if (!has_normals || !has_uvs) debug(
  255. "[Mesh Loader] Notice! Mesh \"%s\" is missing %s",
  256. RI_DEBUG_MESH_LOADER_ERROR,
  257. filename,
  258. loading_mesh_notice_string
  259. );
  260. new_mesh->has_normals = has_normals;
  261. new_mesh->has_uvs = has_uvs;
  262. new_mesh->face_count = object_face_count;
  263. new_mesh->face_index = previous_face_count;
  264. debug(
  265. "[Mesh Loader] Loaded mesh \"%s\"! %d faces, %d verticies, %d normals, %d uvs",
  266. RI_DEBUG_MESH_LOADER_LOADED_MESH,
  267. filename,
  268. current_face_index,
  269. current_vertex_index,
  270. current_normal_index,
  271. current_uv_index
  272. );
  273. clFinish(context.opencl.queue);
  274. if (previous_face_count != context.opencl.face_count) {
  275. if (context.opencl.faces_mem_buffer) clReleaseMemObject(context.opencl.faces_mem_buffer);
  276. context.opencl.faces_mem_buffer = clCreateBuffer(
  277. context.opencl.context,
  278. CL_MEM_READ_WRITE,
  279. sizeof(RI_face) * context.opencl.face_count,
  280. NULL, NULL
  281. );
  282. clEnqueueWriteBuffer(
  283. context.opencl.queue,
  284. context.opencl.faces_mem_buffer,
  285. CL_TRUE,
  286. 0,
  287. sizeof(RI_face) * context.opencl.face_count,
  288. context.opencl.faces,
  289. 0, NULL, NULL
  290. );
  291. clFinish(context.opencl.queue);
  292. clSetKernelArg(
  293. context.opencl.transformation_kernel,
  294. 0,
  295. sizeof(cl_mem),
  296. &context.opencl.faces_mem_buffer
  297. );
  298. if (context.opencl.face_count * 2 > context.opencl.length_of_renderable_faces_array){
  299. debug(
  300. "old renderable faces count (%d) less than current (%d). Reallocating...",
  301. RI_DEBUG_MESH_LOADER_REALLOCATION,
  302. context.opencl.length_of_renderable_faces_array,
  303. context.opencl.face_count * 2
  304. );
  305. context.opencl.length_of_renderable_faces_array = context.opencl.face_count * 2;
  306. debug(
  307. "reallocating %f mb (%d renderable faces)",
  308. RI_DEBUG_MESH_LOADER_REALLOCATION,
  309. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array / 1048576.0,
  310. context.opencl.length_of_renderable_faces_array
  311. );
  312. context.opencl.faces_to_render = RI_malloc(
  313. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array
  314. );
  315. clerror = clReleaseMemObject(context.opencl.renderable_faces_mem_buffer);
  316. if (clerror != CL_SUCCESS){
  317. debug("couldn't free renderable faces memory buffer (error %d)",
  318. RI_DEBUG_MESH_LOADER_ERROR,
  319. clerror);
  320. exit(1);
  321. }
  322. context.opencl.renderable_faces_mem_buffer = clCreateBuffer(
  323. context.opencl.context,
  324. CL_MEM_READ_WRITE,
  325. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array,
  326. NULL, &clerror
  327. );
  328. if (clerror != CL_SUCCESS){
  329. debug("couldn't reallocate renderable faces memory buffer (error %d)",
  330. RI_DEBUG_MESH_LOADER_ERROR,
  331. clerror);
  332. exit(1);
  333. }
  334. }
  335. }
  336. fclose(file);
  337. end_time = clock();
  338. debug("loading mesh took %lf seconds",
  339. RI_DEBUG_MESH_LOADER_TIME,
  340. (double)(end_time - start_time) / CLOCKS_PER_SEC);
  341. return new_mesh;
  342. }
  343. void RI_render(RI_scene *scene){
  344. clock_t start_time, end_time;
  345. start_time = clock();
  346. debug("---FRAME START-------------------------------------------\n",
  347. RI_DEBUG_FRAME_START_END_MARKERS
  348. );
  349. // transformer
  350. double horizontal_fov_factor = (double)context.window.width / tanf(0.5 * scene->camera.FOV);
  351. double vertical_fov_factor = (double)context.window.height / tanf(0.5 * scene->camera.FOV);
  352. if (context.window.aspect_mode == RI_ASPECT_MODE_LETTERBOX) horizontal_fov_factor /= horizontal_fov_factor / vertical_fov_factor;
  353. // kernel args
  354. // 18, double horizontal_fov_factor
  355. clSetKernelArg(context.opencl.transformation_kernel, 18, sizeof(double), &horizontal_fov_factor);
  356. // 19, double vertical_fov_factor
  357. clSetKernelArg(context.opencl.transformation_kernel, 19, sizeof(double), &vertical_fov_factor);
  358. // 20, double min_clip
  359. clSetKernelArg(context.opencl.transformation_kernel, 20, sizeof(float), &scene->camera.min_clip);
  360. // 21, double max_clip
  361. clSetKernelArg(context.opencl.transformation_kernel, 21, sizeof(float), &scene->camera.max_clip);
  362. // 22, double camera_x
  363. clSetKernelArg(context.opencl.transformation_kernel, 22, sizeof(double), &scene->camera.position.x);
  364. // 23, double camera_y
  365. clSetKernelArg(context.opencl.transformation_kernel, 23, sizeof(double), &scene->camera.position.y);
  366. // 24, double camera_z
  367. clSetKernelArg(context.opencl.transformation_kernel, 24, sizeof(double), &scene->camera.position.z);
  368. // 25, double camera_r_w
  369. clSetKernelArg(context.opencl.transformation_kernel, 25, sizeof(double), &scene->camera.rotation.w);
  370. // 26, double camera_r_x
  371. clSetKernelArg(context.opencl.transformation_kernel, 26, sizeof(double), &scene->camera.rotation.x);
  372. // 27, double camera_r_y
  373. clSetKernelArg(context.opencl.transformation_kernel, 27, sizeof(double), &scene->camera.rotation.y);
  374. // 28, double camera_r_z
  375. clSetKernelArg(context.opencl.transformation_kernel, 28, sizeof(double), &scene->camera.rotation.z);
  376. int local_group_size_x = 16;
  377. int local_group_size_y = 16;
  378. // count faces
  379. scene->face_count = 0;
  380. for (int actor_index = 0; actor_index < scene->length_of_actors_array; ++actor_index){
  381. scene->face_count += scene->actors[actor_index]->mesh->face_count;
  382. }
  383. // allocate faces_to_render if face count increases
  384. if (scene->face_count * 2 > context.opencl.length_of_renderable_faces_array){
  385. context.opencl.faces_to_render = RI_realloc(
  386. context.opencl.faces_to_render,
  387. sizeof(RI_renderable_face) * scene->face_count * 2
  388. ); // x2 because faces can be split
  389. context.opencl.length_of_renderable_faces_array = scene->face_count * 2;
  390. debug(
  391. "old renderable faces count (%d) less than current (%d). Reallocating %f mb",
  392. RI_DEBUG_RENDER_REALLOCATION,
  393. context.opencl.length_of_renderable_faces_array, scene->face_count * 2,
  394. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array / 1048576.0
  395. );
  396. context.opencl.faces_to_render = RI_malloc(
  397. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array
  398. );
  399. clerror = clReleaseMemObject(context.opencl.renderable_faces_mem_buffer);
  400. if (clerror != CL_SUCCESS){
  401. debug("couldn't free renderable faces memory buffer (error %d)",
  402. RI_DEBUG_RENDER_ERROR,
  403. clerror);
  404. exit(1);
  405. }
  406. context.opencl.renderable_faces_mem_buffer = clCreateBuffer(
  407. context.opencl.context,
  408. CL_MEM_READ_WRITE,
  409. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array,
  410. NULL, &clerror
  411. );
  412. if (clerror != CL_SUCCESS){
  413. debug("couldn't reallocate renderable faces memory buffer (error %d)",
  414. RI_DEBUG_RENDER_ERROR,
  415. clerror);
  416. exit(1);
  417. }
  418. }
  419. // set faces_to_render to zero
  420. memset(context.opencl.faces_to_render, 0, sizeof(RI_renderable_face) * scene->face_count * 2);
  421. clSetKernelArg(
  422. context.opencl.transformation_kernel,
  423. 1,
  424. sizeof(cl_mem),
  425. &context.opencl.renderable_faces_mem_buffer
  426. );
  427. context.current_renderable_face_index = 0;
  428. context.current_split_renderable_face_index = 0;
  429. debug("transforming polygons...", RI_DEBUG_TRANSFORMER_MESSAGE);
  430. int renderable_face_index = 0;
  431. cl_ulong start, end;
  432. // transform polygons
  433. for (int actor_index = 0; actor_index < scene->length_of_actors_array; ++actor_index){
  434. RI_actor *actor = scene->actors[actor_index];
  435. debug("actor index: %d face count: %d",
  436. RI_DEBUG_TRANSFORMER_CURRENT_ACTOR,
  437. actor_index,
  438. actor->mesh->face_count
  439. );
  440. if (scene->actors[actor_index]->mesh->face_count <= 0) continue;
  441. int face_sqrt = ceil(sqrt(scene->actors[actor_index]->mesh->face_count));
  442. int local_t_size = (int)fmin(face_sqrt, local_group_size_x);
  443. const size_t t_global_work_size[2] = {
  444. local_t_size * ceil(face_sqrt / (float)local_t_size),
  445. local_t_size * ceil(face_sqrt / (float)local_t_size)
  446. };
  447. const size_t t_local_work_size[2] = {
  448. (int)fmin(face_sqrt, local_group_size_x),
  449. (int)fmin(face_sqrt, local_group_size_y)
  450. };
  451. debug("transformer global work size: {%d, %d}",
  452. RI_DEBUG_TRANSFORMER_GLOBAL_SIZE,
  453. t_global_work_size[0],
  454. t_global_work_size[1]
  455. );
  456. debug("transformer local work size: {%d, %d}",
  457. RI_DEBUG_TRANSFORMER_LOCAL_SIZE,
  458. t_local_work_size[0],
  459. t_local_work_size[1]
  460. );
  461. debug(
  462. "(%d extra work items; %d items (%dx%d) - %d faces)",
  463. RI_DEBUG_TRANSFORMER_EXTRA_WORK_ITEMS,
  464. t_global_work_size[0] * t_global_work_size[1] - scene->actors[actor_index]->mesh->face_count,
  465. t_global_work_size[0] * t_global_work_size[1],
  466. t_global_work_size[0],
  467. t_global_work_size[1],
  468. scene->actors[actor_index]->mesh->face_count
  469. );
  470. // 2, double actor_x
  471. clSetKernelArg(context.opencl.transformation_kernel, 2, sizeof(double), &actor->position.x);
  472. // 3, double actor_y
  473. clSetKernelArg(context.opencl.transformation_kernel, 3, sizeof(double), &actor->position.y);
  474. // 4, double actor_z
  475. clSetKernelArg(context.opencl.transformation_kernel, 4, sizeof(double), &actor->position.z);
  476. // 5, double actor_r_w
  477. clSetKernelArg(context.opencl.transformation_kernel, 5, sizeof(double), &actor->rotation.w);
  478. // 6, double actor_r_x
  479. clSetKernelArg(context.opencl.transformation_kernel, 6, sizeof(double), &actor->rotation.x);
  480. // 7, double actor_r_y
  481. clSetKernelArg(context.opencl.transformation_kernel, 7, sizeof(double), &actor->rotation.y);
  482. // 8, double actor_r_z
  483. clSetKernelArg(context.opencl.transformation_kernel, 8, sizeof(double), &actor->rotation.z);
  484. // 9, double actor_s_x
  485. clSetKernelArg(context.opencl.transformation_kernel, 9, sizeof(double), &actor->scale.x);
  486. // 10, double actor_s_y
  487. clSetKernelArg(context.opencl.transformation_kernel, 10, sizeof(double), &actor->scale.y);
  488. // 11, double actor_s_z
  489. clSetKernelArg(context.opencl.transformation_kernel, 11, sizeof(double), &actor->scale.z);
  490. // 12, int has_normals
  491. clSetKernelArg(context.opencl.transformation_kernel, 12, sizeof(int), &actor->mesh->has_normals);
  492. // 13, int has_uvs
  493. clSetKernelArg(context.opencl.transformation_kernel, 13, sizeof(int), &actor->mesh->has_uvs);
  494. // 14, int face_array_offset_index
  495. clSetKernelArg(context.opencl.transformation_kernel, 14, sizeof(int), &actor->mesh->face_index);
  496. // 15, int face_count
  497. clSetKernelArg(context.opencl.transformation_kernel, 15, sizeof(int), &actor->mesh->face_count);
  498. // 29, int renderable_face_offset
  499. clSetKernelArg(context.opencl.transformation_kernel, 29, sizeof(int), &renderable_face_index);
  500. // 30, int face_sqrt
  501. clSetKernelArg(context.opencl.transformation_kernel, 30, sizeof(int), &face_sqrt);
  502. debug("texture width: %d texture height: %d texture index %d", RI_DEBUG_TRANSFORMER_TEXTURE, actor->texture->width, actor->texture->height, actor->texture->index);
  503. // 31: uint16_t texture_width
  504. clSetKernelArg(context.opencl.transformation_kernel, 31, sizeof(uint16_t), &actor->texture->width);
  505. // 32: uint16_t texture_height
  506. clSetKernelArg(context.opencl.transformation_kernel, 32, sizeof(uint16_t), &actor->texture->height);
  507. // 33: uint32_t texture_index
  508. clSetKernelArg(context.opencl.transformation_kernel, 33, sizeof(uint32_t), &actor->texture->index);
  509. debug("running actor #%d's transformation kernel...",
  510. RI_DEBUG_TRANSFORMER_MESSAGE,
  511. actor_index
  512. );
  513. clerror = clEnqueueNDRangeKernel(
  514. context.opencl.queue,
  515. context.opencl.transformation_kernel,
  516. 2,
  517. NULL,
  518. t_global_work_size,
  519. t_local_work_size,
  520. 0, NULL, &clevent
  521. );
  522. if (clerror != CL_SUCCESS)
  523. debug("error enqueing kernel (%d)",
  524. RI_DEBUG_TRANSFORMER_ERROR,
  525. clerror
  526. );
  527. clFinish(context.opencl.queue);
  528. clGetEventProfilingInfo(clevent, CL_PROFILING_COMMAND_START, sizeof(start), &start, NULL);
  529. clGetEventProfilingInfo(clevent, CL_PROFILING_COMMAND_END, sizeof(end), &end, NULL);
  530. double ns = (double)(end - start);
  531. debug("actor #%d's transformation kernel took %f seconds\n",
  532. RI_DEBUG_TRANSFORMER_TIME,
  533. actor_index,
  534. ns / 1e9
  535. );
  536. renderable_face_index += actor->mesh->face_count * 2;
  537. }
  538. // rasterize
  539. // set width, height and kernel width, height
  540. int x = context.window.width;
  541. int y = context.window.height;
  542. int x_div_32 = ceil(context.window.width / (float)local_group_size_x);
  543. int y_div_32 = ceil(context.window.height / (float)local_group_size_y);
  544. if (context.window.width % local_group_size_x != 0)
  545. x = local_group_size_x * x_div_32;
  546. if (context.window.height % local_group_size_y != 0)
  547. y = local_group_size_y * y_div_32;
  548. const size_t r_global_work_size[2] = {x, y};
  549. const size_t r_local_work_size[2] = {local_group_size_x, local_group_size_y};
  550. debug("rasterizer global work size: {%d, %d}",
  551. RI_DEBUG_RASTERIZER_GLOBAL_SIZE,
  552. x,
  553. y
  554. );
  555. debug("rasterizer local work size: {%d, %d}",
  556. RI_DEBUG_RASTERIZER_GLOBAL_SIZE,
  557. local_group_size_x,
  558. local_group_size_y
  559. );
  560. // kernel args
  561. clSetKernelArg(
  562. context.opencl.rasterization_kernel,
  563. 0,
  564. sizeof(cl_mem),
  565. &context.opencl.renderable_faces_mem_buffer
  566. );
  567. clSetKernelArg(context.opencl.rasterization_kernel, 7, sizeof(int), &scene->face_count);
  568. clSetKernelArg(
  569. context.opencl.rasterization_kernel,
  570. 8,
  571. sizeof(int),
  572. &context.current_split_renderable_face_index
  573. );
  574. debug("rasterizing...", RI_DEBUG_RASTERIZER_MESSAGE);
  575. // run raster kernel
  576. clEnqueueNDRangeKernel(
  577. context.opencl.queue,
  578. context.opencl.rasterization_kernel,
  579. 2,
  580. NULL,
  581. r_global_work_size,
  582. r_local_work_size,
  583. 0, NULL, &clevent
  584. );
  585. clFinish(context.opencl.queue);
  586. clGetEventProfilingInfo(clevent, CL_PROFILING_COMMAND_START, sizeof(start), &start, NULL);
  587. clGetEventProfilingInfo(clevent, CL_PROFILING_COMMAND_END, sizeof(end), &end, NULL);
  588. debug("rasterization kernel took %f seconds\n",
  589. RI_DEBUG_RASTERIZER_TIME,
  590. (double)(end - start) / 1e9
  591. );
  592. // put GPU frame buffer into CPU
  593. clEnqueueReadBuffer(
  594. context.opencl.queue,
  595. context.opencl.frame_buffer_mem_buffer,
  596. CL_TRUE,
  597. 0,
  598. context.window.width * context.window.height * sizeof(uint32_t),
  599. context.sdl.frame_buffer,
  600. 0, NULL, &clevent
  601. );
  602. clFinish(context.opencl.queue);
  603. clGetEventProfilingInfo(clevent, CL_PROFILING_COMMAND_START, sizeof(start), &start, NULL);
  604. clGetEventProfilingInfo(clevent, CL_PROFILING_COMMAND_END, sizeof(end), &end, NULL);
  605. debug("reading GPU frame buffer took %f seconds",
  606. RI_DEBUG_RENDER_FRAME_BUFFER_READ_TIME,
  607. (double)(end - start) / 1e9
  608. );
  609. context.opencl.number_of_faces_just_rendered += scene->face_count;
  610. end_time = clock();
  611. debug("rendering took %lf seconds",
  612. RI_DEBUG_RENDER_TIME,
  613. (double)(end_time - start_time) / CLOCKS_PER_SEC
  614. );
  615. }
  616. void RI_tick(){
  617. clock_t start_time, end_time;
  618. start_time = clock();
  619. SDL_Event event;
  620. while (SDL_PollEvent(&event)){
  621. switch (event.type){
  622. case SDL_QUIT: {
  623. context.is_running = ri_false;
  624. break;
  625. }
  626. default: {
  627. break;
  628. }
  629. }
  630. }
  631. SDL_LockTexture(
  632. context.sdl.frame_buffer_texture,
  633. NULL,
  634. (void*)&context.sdl.frame_buffer,
  635. &context.sdl.pitch
  636. );
  637. SDL_UnlockTexture(context.sdl.frame_buffer_texture);
  638. SDL_RenderCopy(context.sdl.renderer, context.sdl.frame_buffer_texture, NULL, NULL);
  639. SDL_RenderPresent(context.sdl.renderer);
  640. ++context.current_frame;
  641. end_time = clock();
  642. debug("Done! ticking took %lf seconds",
  643. RI_DEBUG_TICK_TIME,
  644. (double)(end_time - start_time) / CLOCKS_PER_SEC
  645. );
  646. debug("---FRAME END---(frame #%d, %d polygons)----------------\n",
  647. RI_DEBUG_FRAME_START_END_MARKERS,
  648. context.current_frame,
  649. context.opencl.number_of_faces_just_rendered
  650. );
  651. context.opencl.number_of_faces_just_rendered = 0;
  652. return;
  653. }
  654. RI_context *RI_get_context(){
  655. context.sdl = (RI_SDL){NULL, NULL, NULL, NULL, -1};
  656. context.opencl = (RI_CL){NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 1, 0, 0};
  657. context.window = (RI_window){800, 800, 400, 400, "RasterIver Window", RI_ASPECT_MODE_LETTERBOX};
  658. context.debug_flags = RI_DEBUG_ERRORS;
  659. context.current_frame = 0;
  660. context.is_running = ri_true;
  661. context.debug_prefix = "[RasterIver] ";
  662. return &context;
  663. }
  664. // Convert a CL file to a string
  665. char *load_kernel_source(const char *filename) {
  666. FILE *f = fopen(filename, "rb");
  667. if (f == NULL){
  668. debug("couldn't open kernel file \"%s\"",
  669. RI_DEBUG_KERNEL_LOADER_ERROR,
  670. filename
  671. );
  672. }
  673. fseek(f, 0, SEEK_END);
  674. size_t size = ftell(f);
  675. rewind(f);
  676. char *source = malloc(size + 1);
  677. fread(source, 1, size, f);
  678. source[size] = '\0';
  679. fclose(f);
  680. return source;
  681. }
  682. int RI_init(){
  683. context.window.half_width = context.window.width / 2;
  684. context.window.half_height = context.window.height / 2;
  685. // init SDL
  686. context.sdl.window = SDL_CreateWindow(
  687. context.window.title,
  688. SDL_WINDOWPOS_CENTERED,
  689. SDL_WINDOWPOS_CENTERED,
  690. context.window.width,
  691. context.window.height, 0
  692. );
  693. context.sdl.renderer = SDL_CreateRenderer(context.sdl.window, -1, SDL_RENDERER_ACCELERATED);
  694. context.sdl.frame_buffer_texture = SDL_CreateTexture(
  695. context.sdl.renderer,
  696. SDL_PIXELFORMAT_BGRA8888,
  697. SDL_TEXTUREACCESS_STREAMING,
  698. context.window.width,
  699. context.window.height
  700. );
  701. context.sdl.frame_buffer = malloc(
  702. sizeof(uint32_t) * context.window.width * context.window.height
  703. );
  704. if (!context.debug_flags)
  705. context.debug_flags = RI_DEBUG_ERRORS;
  706. context.defaults.default_actor = RI_new_actor();
  707. // init OpenCL
  708. context.opencl.faces_to_render = RI_malloc(
  709. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array
  710. );
  711. context.opencl.faces = RI_malloc(sizeof(RI_face) * context.opencl.face_count);
  712. cl_uint num_platforms = 0;
  713. clerror = clGetPlatformIDs(0, NULL, &num_platforms);
  714. cl_platform_id *platforms = malloc(sizeof(cl_platform_id) * num_platforms);
  715. clerror = clGetPlatformIDs(num_platforms, platforms, NULL);
  716. cl_device_id *devices;
  717. cl_platform_id chosen_platform = NULL;
  718. char pname[256];
  719. for (cl_uint i = 0; i < num_platforms; i++) {
  720. clerror = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(pname), pname, NULL);
  721. debug("get platform info result: %d", RI_DEBUG_INIT_PLATFORMS, clerror);
  722. cl_uint num_devices = 0;
  723. clerror = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
  724. debug("num devices result: %d", RI_DEBUG_INIT_PLATFORMS, clerror);
  725. devices = malloc(sizeof(cl_device_id) * num_devices);
  726. clerror = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
  727. if (i == 0){
  728. context.opencl.device = devices[0];
  729. }
  730. debug("get device ids result: %d", RI_DEBUG_INIT_PLATFORMS, clerror);
  731. debug("-platform #%d: NAME: %s | DEVICE COUNT: %d", RI_DEBUG_INIT_PLATFORMS, i, pname, num_devices);
  732. for (cl_uint j = 0; j < num_devices; ++j){
  733. debug("-\\ device #%d: ID: %u", RI_DEBUG_INIT_PLATFORMS, j, devices[j]);
  734. }
  735. free(devices);
  736. }
  737. context.opencl.platform = platforms[0];
  738. debug("chosen device id: %u", RI_DEBUG_INIT_PLATFORMS, context.opencl.device);
  739. context.opencl.context = clCreateContext(NULL, 1, &context.opencl.device, NULL, NULL, NULL);
  740. context.opencl.queue = clCreateCommandQueueWithProperties(
  741. context.opencl.context,
  742. context.opencl.device,
  743. (const cl_queue_properties[]){CL_QUEUE_PROPERTIES, CL_QUEUE_PROFILING_ENABLE, 0},
  744. &clerror
  745. );
  746. if (!context.opencl.context){
  747. debug("failed to create OpenCL context", RI_DEBUG_OPENCL_ERROR);
  748. exit(1);
  749. }
  750. // build programs
  751. char *program_source = load_kernel_source("src/kernels/kernels.cl");
  752. cl_program rasterization_program = clCreateProgramWithSource(
  753. context.opencl.context,
  754. 1,
  755. (const char**)&program_source,
  756. NULL, NULL
  757. );
  758. free(program_source);
  759. cl_int result = clBuildProgram(rasterization_program, 1, &context.opencl.device, "", NULL, NULL);
  760. if (result != CL_SUCCESS){
  761. char log[10001];
  762. clGetProgramBuildInfo(
  763. rasterization_program,
  764. context.opencl.device,
  765. CL_PROGRAM_BUILD_LOG,
  766. 10000, log, NULL);
  767. debug("rasterization program build failed (%d). Log: \n %s", RI_DEBUG_OPENCL_ERROR, result, log);
  768. return 1;
  769. }
  770. // kernels
  771. context.opencl.rasterization_kernel = clCreateKernel(rasterization_program, "rasterizer", &clerror);
  772. if (clerror != CL_SUCCESS){
  773. debug("couldn't create rasterizer kernel", RI_DEBUG_OPENCL_ERROR);
  774. return 1;
  775. }
  776. context.opencl.transformation_kernel = clCreateKernel(rasterization_program, "transformer", &clerror);
  777. if (clerror != CL_SUCCESS){
  778. debug("couldn't create transformer kernel", RI_DEBUG_OPENCL_ERROR);
  779. return 1;
  780. }
  781. // rasterizer
  782. context.opencl.renderable_faces_mem_buffer = clCreateBuffer(
  783. context.opencl.context,
  784. CL_MEM_READ_WRITE,
  785. sizeof(RI_renderable_face) * context.opencl.length_of_renderable_faces_array,
  786. NULL, &clerror);
  787. if (clerror != CL_SUCCESS){
  788. debug("couldn't create renderable faces memory buffer", RI_DEBUG_OPENCL_ERROR);
  789. return 1;
  790. }
  791. context.opencl.frame_buffer_mem_buffer = clCreateBuffer(
  792. context.opencl.context,
  793. CL_MEM_READ_WRITE,
  794. sizeof(uint32_t) * context.window.width * context.window.height,
  795. NULL, &clerror);
  796. if (clerror != CL_SUCCESS || !context.opencl.frame_buffer_mem_buffer){
  797. debug("couldn't create frame buffer memory buffer", RI_DEBUG_OPENCL_ERROR);
  798. return 1;
  799. }
  800. context.opencl.textures_mem_buffer = clCreateBuffer(
  801. context.opencl.context,
  802. CL_MEM_READ_WRITE,
  803. 1,
  804. NULL, &clerror);
  805. if (clerror != CL_SUCCESS || !context.opencl.textures_mem_buffer){
  806. debug("couldn't create textures memory buffer", RI_DEBUG_OPENCL_ERROR);
  807. return 1;
  808. }
  809. // rasterizer(__global RI_renderable_face *renderable_faces, __global uint *frame_buffer,
  810. // int width, int height, int half_width, int half_height, int number_of_renderable_faces,
  811. // int number_of_split_renderable_faces)
  812. clSetKernelArg(context.opencl.rasterization_kernel, 0, sizeof(cl_mem), &context.opencl.renderable_faces_mem_buffer);
  813. clSetKernelArg(context.opencl.rasterization_kernel, 1, sizeof(cl_mem), &context.opencl.textures_mem_buffer);
  814. clSetKernelArg(context.opencl.rasterization_kernel, 2, sizeof(cl_mem), &context.opencl.frame_buffer_mem_buffer);
  815. clSetKernelArg(context.opencl.rasterization_kernel, 3, sizeof(int), &context.window.width);
  816. clSetKernelArg(context.opencl.rasterization_kernel, 4, sizeof(int), &context.window.height);
  817. clSetKernelArg(context.opencl.rasterization_kernel, 5, sizeof(int), &context.window.half_width);
  818. clSetKernelArg(context.opencl.rasterization_kernel, 6, sizeof(int), &context.window.half_height);
  819. clSetKernelArg(context.opencl.rasterization_kernel, 7, sizeof(int), &context.current_renderable_face_index);
  820. clSetKernelArg(context.opencl.rasterization_kernel, 8, sizeof(int), &context.current_split_renderable_face_index);
  821. // transformer
  822. // transformer
  823. // __global RI_face *faces, __global RI_vector_3 *vertecies,
  824. // __global RI_vector_3 *normals, __global RI_vector_2 *uvs,
  825. // __global RI_renderable_face *renderable_faces,
  826. // double actor_x, double actor_y, double actor_z,
  827. // double actor_r_w, double actor_r_x, double actor_r_y, double actor_r_z,
  828. // double actor_s_x, double actor_s_y, double actor_s_z,
  829. // int has_normals, int has_uvs, int face_array_offset_index, int face_count,
  830. // int width, int height, double horizontal_fov_factor, double vertical_fov_factor,
  831. // double min_clip, double max_clip,
  832. // double camera_x, double camera_y, double camera_z,
  833. // double camera_r_w, double camera_r_x, double camera_r_y, double camera_r_z
  834. // // 0: __global RI_face *faces
  835. // clSetKernelArg(context.opencl.transformation_kernel, 0, sizeof(cl_mem), &context.opencl.faces_mem_buffer);
  836. // // 1: __global RI_renderable_face *renderable_faces
  837. // clSetKernelArg(context.opencl.transformation_kernel, 1, sizeof(cl_mem), &context.opencl.renderable_faces_mem_buffer);
  838. // // 2: double actor_x
  839. // clSetKernelArg(context.opencl.transformation_kernel, 2, sizeof(double), &actor_x);
  840. // // 3: double actor_y
  841. // clSetKernelArg(context.opencl.transformation_kernel, 3, sizeof(double), &actor_y);
  842. // // 4: double actor_z
  843. // clSetKernelArg(context.opencl.transformation_kernel, 4, sizeof(double), &actor_z);
  844. // // 5: double actor_r_w
  845. // clSetKernelArg(context.opencl.transformation_kernel, 5, sizeof(double), &actor_r_w);
  846. // // 6: double actor_r_x
  847. // clSetKernelArg(context.opencl.transformation_kernel, 6, sizeof(double), &actor_r_x);
  848. // // 7: double actor_r_y
  849. // clSetKernelArg(context.opencl.transformation_kernel, 7, sizeof(double), &actor_r_y);
  850. // // 8: double actor_r_z
  851. // clSetKernelArg(context.opencl.transformation_kernel, 8, sizeof(double), &actor_r_z);
  852. // // 9: double actor_s_x
  853. // clSetKernelArg(context.opencl.transformation_kernel, 9, sizeof(double), &actor_s_x);
  854. // // 10: double actor_s_y
  855. // clSetKernelArg(context.opencl.transformation_kernel, 10, sizeof(double), &actor_s_y);
  856. // // 11: double actor_s_z
  857. // clSetKernelArg(context.opencl.transformation_kernel, 11, sizeof(double), &actor_s_z);
  858. // // 12: int has_normals
  859. // clSetKernelArg(context.opencl.transformation_kernel, 12, sizeof(int), &has_normals);
  860. // // 13: int has_uvs
  861. // clSetKernelArg(context.opencl.transformation_kernel, 13, sizeof(int), &has_uvs);
  862. // // 14: int face_array_offset_index
  863. // clSetKernelArg(context.opencl.transformation_kernel, 14, sizeof(int), &face_array_offset_index);
  864. // // 15: int face_count
  865. // clSetKernelArg(context.opencl.transformation_kernel, 15, sizeof(int), &face_count);
  866. // // 16: int width
  867. clSetKernelArg(context.opencl.transformation_kernel, 16, sizeof(int), &context.window.width);
  868. // // 17: int height
  869. clSetKernelArg(context.opencl.transformation_kernel, 17, sizeof(int), &context.window.height);
  870. // // 18: double horizontal_fov_factor
  871. // clSetKernelArg(context.opencl.transformation_kernel, 18, sizeof(double), &horizontal_fov_factor);
  872. // // 19: double vertical_fov_factor
  873. // clSetKernelArg(context.opencl.transformation_kernel, 19, sizeof(double), &vertical_fov_factor);
  874. // // 20: float min_clip
  875. // clSetKernelArg(context.opencl.transformation_kernel, 20, sizeof(float), &min_clip_f);
  876. // // 21: float max_clip
  877. // clSetKernelArg(context.opencl.transformation_kernel, 21, sizeof(float), &max_clip_f);
  878. // // 22: double camera_x
  879. // clSetKernelArg(context.opencl.transformation_kernel, 22, sizeof(double), &camera_x);
  880. // // 23: double camera_y
  881. // clSetKernelArg(context.opencl.transformation_kernel, 23, sizeof(double), &camera_y);
  882. // // 24: double camera_z
  883. // clSetKernelArg(context.opencl.transformation_kernel, 24, sizeof(double), &camera_z);
  884. // // 25: double camera_r_w
  885. // clSetKernelArg(context.opencl.transformation_kernel, 25, sizeof(double), &camera_r_w);
  886. // // 26: double camera_r_x
  887. // clSetKernelArg(context.opencl.transformation_kernel, 26, sizeof(double), &camera_r_x);
  888. // // 27: double camera_r_y
  889. // clSetKernelArg(context.opencl.transformation_kernel, 27, sizeof(double), &camera_r_y);
  890. // // 28: double camera_r_z
  891. // clSetKernelArg(context.opencl.transformation_kernel, 28, sizeof(double), &camera_r_z);
  892. // // 29: int renderable_face_offset
  893. // clSetKernelArg(context.opencl.transformation_kernel, 29, sizeof(int), &renderable_face_offset);
  894. // // 30: int face_sqrt
  895. // clSetKernelArg(context.opencl.transformation_kernel, 30, sizeof(int), &face_sqrt);
  896. // // 31: uint16_t texture_width
  897. // clSetKernelArg(context.opencl.transformation_kernel, 31, sizeof(uint16_t), &texture_width);
  898. // // 32: uint16_t texture_height
  899. // clSetKernelArg(context.opencl.transformation_kernel, 32, sizeof(uint16_t), &texture_height);
  900. // // 33: uint32_t texture_index
  901. // clSetKernelArg(context.opencl.transformation_kernel, 33, sizeof(uint32_t), &texture_index);
  902. context.defaults.default_actor->mesh = RI_load_mesh("objects/error_object.obj");
  903. return 0;
  904. }