diff options
author | Leonard Kugis <leonardkugis@gmail.com> | 2018-02-01 01:27:30 +0100 |
---|---|---|
committer | Leonard Kugis <leonardkugis@gmail.com> | 2018-02-01 01:27:30 +0100 |
commit | 18e5b2554b4cd73207e936e76e32c9d376cd1ba8 (patch) | |
tree | 917dba471db5b3c40c78f247a601e8db2d73056b /src/render_opencl.c | |
parent | be4f2582062196dd6ecf393f55566367bc1dfa9f (diff) |
abstracted rendering, cpu currently crashing randomly while zooming
Diffstat (limited to 'src/render_opencl.c')
-rw-r--r-- | src/render_opencl.c | 110 |
1 files changed, 11 insertions, 99 deletions
diff --git a/src/render_opencl.c b/src/render_opencl.c index 7bc9620..aae7e41 100644 --- a/src/render_opencl.c +++ b/src/render_opencl.c @@ -7,26 +7,14 @@ #include "render_opencl.h" -void idle_opencl_dummy(void) -{ - glutPostRedisplay(); -} - void init_opencl(config_t *cfg) { - x_min_s_cl = -2.0; - x_max_s_cl = 1.0; - y_min_s_cl = -1.0; - y_max_s_cl = 1.0; - x_min_cl = x_min_s_cl; - x_max_cl = x_max_s_cl; - y_min_cl = y_min_s_cl; - y_max_cl = y_max_s_cl; config_opencl = cfg; output = (cl_uint *) malloc((config_opencl->width) * (config_opencl->height) * sizeof(cl_uchar4)); context = NULL; + width_cl = config_opencl->width; // Leave it in, cl needs different endianness cl_platform_id platform_id; @@ -140,7 +128,7 @@ void init_opencl(config_t *cfg) } } -void render_opencl(void) +void render_opencl(d64 x_min, d64 y_min, d64 x_max, d64 y_max) { cl_event events[MAX_DEVICES]; cl_int eventStatus = CL_QUEUED; @@ -149,15 +137,20 @@ void render_opencl(void) size_t kernelWorkGroupSize; cl_kernel kernel; + cl_double x_min_cl = (cl_double) x_min; + cl_double y_min_cl = (cl_double) y_min; + cl_double x_max_cl = (cl_double) x_max; + cl_double y_max_cl = (cl_double) y_max; + cl_double y_max_t; cl_float y_max_t_f; - cl_double x_delta = ((x_max_cl - x_min_cl) / (double) config_opencl->width); - cl_double y_delta = -((y_max_cl - y_min_cl) / (double) config_opencl->height); + cl_double x_delta = ((x_max_cl - x_min_cl) / (cl_double) config_opencl->width); + cl_double y_delta = -((y_max_cl - y_min_cl) / (cl_double) config_opencl->height); cl_float x_delta_f = (float) x_delta; cl_float y_delta_f = (float) y_delta; - cl_float x_min_f = (float) x_min_cl; + cl_float x_min_f = (float) x_min; globalThreads[0] = ((config_opencl->width) * (config_opencl->height)) / num_devices; @@ -176,7 +169,7 @@ void render_opencl(void) localThreads[0] = kernelWorkGroupSize; } - y_max_t = (((y_min_cl + y_max_cl) / 2.0) + (y_max_cl - y_min_cl) / 2.0 - ((double) i * (y_max_cl - y_min_cl)) / (double) num_devices); + y_max_t = (((y_min_cl + y_max_cl) / 2.0) + (y_max_cl - y_min_cl) / 2.0 - ((cl_double) i * (y_max_cl - y_min_cl)) / (cl_double) num_devices); ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &outputBuffer[i]); @@ -185,7 +178,6 @@ void render_opencl(void) //printf("x_delta: %f, y_delta: %f, x_delta_f: %f, y_delta_f: %f, x_min_f: %f, y_max_t: %f, y_max_t_f: %f\n", x_delta, y_delta, x_delta_f, y_delta_f, x_min_f, y_max_t, y_max_t_f); - printf("set args\n"); switch (config_opencl->config_opencl.fpu) { case OPENCL_FPU_32: // lel @@ -241,89 +233,9 @@ void render_opencl(void) ret = clWaitForEvents(1, &events[num_devices - i - 1]); ret = clReleaseEvent(events[num_devices - i - 1]); } - printf("ocl render2\n"); - - glBindTexture(GL_TEXTURE_2D, config_opencl->tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, config_opencl->width, - config_opencl->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, config_opencl->arr); - glBindTexture(GL_TEXTURE_2D, 0); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBindTexture(GL_TEXTURE_2D, config_opencl->tex); - glEnable(GL_TEXTURE_2D); - - glBegin(GL_QUADS); - glTexCoord2i(0, 0); glVertex2i(0, 0); - glTexCoord2i(0, 1); glVertex2i(0, config_opencl->height); - glTexCoord2i(1, 1); glVertex2i(config_opencl->width, config_opencl->height); - glTexCoord2i(1, 0); glVertex2i(config_opencl->width, 0); - glEnd(); - - glDisable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, 0); - glutSwapBuffers(); } void idle_opencl(void) { - int t = 0, delta = 0; - do - { - t = glutGet(GLUT_ELAPSED_TIME); - delta = t - t_old_opencl; - } while (delta < 16); // TODO: Hardcoded FPS - t_old_opencl = t; - - //glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, config_opencl->tex); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, config_opencl->width, - config_opencl->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, config_opencl->arr); - glBindTexture(GL_TEXTURE_2D, 0); - cl_ft += (config_opencl->speed * (delta / 1000.0)); - x_min_cl = x_min_s_cl + config_opencl->zoom_func(cl_ft, (cl_double) 2.0 + config_opencl->to_x); - y_min_cl = y_min_s_cl + config_opencl->zoom_func(cl_ft, (cl_double) 1.0 + config_opencl->to_y); - x_max_cl = x_max_s_cl - config_opencl->zoom_func(cl_ft, (cl_double) 1.0 - config_opencl->to_x); - y_max_cl = y_max_s_cl - config_opencl->zoom_func(cl_ft, (cl_double) 1.0 - config_opencl->to_y); - glutPostRedisplay(); -} - -void keyboard_opencl(unsigned char key, int mouseX, int mouseY) -{ - switch (key) - { - case 'i': - config_opencl->iterations++; - break; - case 'd': - config_opencl->iterations--; - break; - } -} -void mouse_opencl(int button, int state, int x, int y) -{ - if (state == GLUT_DOWN) - { - switch (button) - { - case GLUT_LEFT_BUTTON: - if (config_opencl->speed < 0) - config_opencl->speed = (-1) * config_opencl->speed; - break; - case GLUT_RIGHT_BUTTON: - if (config_opencl->speed > 0) - config_opencl->speed = (-1) * config_opencl->speed; - break; - } - config_opencl->to_x = x_min_cl + ((d64) x * (x_max_cl - x_min_cl)) / config_opencl->width; - config_opencl->to_y = y_min_cl + ((d64) y * (y_max_cl - y_min_cl)) / config_opencl->height; - t_old_opencl = glutGet(GLUT_ELAPSED_TIME); - glutIdleFunc(idle_opencl); - } - else if(state == GLUT_UP) - { - glutIdleFunc(idle_opencl_dummy); - } } |