aboutsummaryrefslogtreecommitdiff
path: root/src/render_opencl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/render_opencl.c')
-rw-r--r--src/render_opencl.c85
1 files changed, 65 insertions, 20 deletions
diff --git a/src/render_opencl.c b/src/render_opencl.c
index 84fc314..127bae2 100644
--- a/src/render_opencl.c
+++ b/src/render_opencl.c
@@ -7,16 +7,21 @@
#include "render_opencl.h"
+void idle_opencl_dummy(void)
+{
+ glutPostRedisplay();
+}
+
void init_opencl(OpenCLConfig *config)
{
- x_min_s = -2.0;
- x_max_s = 1.0;
- y_min_s = -1.0;
- y_max_s = 1.0;
- x_min = x_min_s;
- x_max = x_max_s;
- y_min = y_min_s;
- y_max = y_max_s;
+ 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 = config;
output = (cl_uint *) malloc((config_opencl->width) * (config_opencl->height) * sizeof(cl_uchar4));
@@ -126,6 +131,7 @@ void init_opencl(OpenCLConfig *config)
{
flags = strcat(flags, "-D MUL_ADD=mad ");
}
+ printf("flags: %s\n", flags);
program = clCreateProgramWithSource(context, 1, (const char **)&cl_src, (const size_t *)&cl_src_sz, &ret);
ret = clBuildProgram(program, num_devices, devices, flags, NULL, NULL);
for (cl_uint i = 0; i < num_devices; i++)
@@ -147,12 +153,12 @@ void render_opencl(void)
cl_double y_max_t;
cl_float y_max_t_f;
- cl_double x_delta = ((x_max - x_min) / (double) config_opencl->width);
- cl_double y_delta = -((y_max - y_min) / (double) config_opencl->height);
+ 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_float x_delta_f = (float) x_delta;
cl_float y_delta_f = (float) y_delta;
- cl_float x_min_f = (float) x_min;
+ cl_float x_min_f = (float) x_min_cl;
globalThreads[0] = ((config_opencl->width) * (config_opencl->height))
/ num_devices;
@@ -171,7 +177,7 @@ void render_opencl(void)
localThreads[0] = kernelWorkGroupSize;
}
- y_max_t = (((y_min + y_max) / 2.0) + (y_max - y_min) / 2.0 - ((double) i * (y_max - y_min)) / (double) num_devices);
+ 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);
ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &outputBuffer[i]);
@@ -189,7 +195,7 @@ void render_opencl(void)
ret = clSetKernelArg(kernel, 4, sizeof(cl_float), (void *) &y_delta_f);
break;
case OPENCL_FPU_64:
- ret = clSetKernelArg(kernel, 1, sizeof(cl_double), (void *) &x_min);
+ ret = clSetKernelArg(kernel, 1, sizeof(cl_double), (void *) &x_min_cl);
ret = clSetKernelArg(kernel, 2, sizeof(cl_double), (void *) &y_max_t);
ret = clSetKernelArg(kernel, 3, sizeof(cl_double), (void *) &x_delta);
ret = clSetKernelArg(kernel, 4, sizeof(cl_double), (void *) &y_delta);
@@ -238,6 +244,11 @@ void render_opencl(void)
ret = clReleaseEvent(events[num_devices - i - 1]);
}
+ 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);
@@ -256,14 +267,13 @@ void render_opencl(void)
void idle_opencl(void)
{
- static int t_old;
int t = 0, delta = 0;
do
{
t = glutGet(GLUT_ELAPSED_TIME);
- delta = t - t_old;
+ delta = t - t_old_opencl;
} while (delta < 16); // TODO: Hardcoded FPS
- t_old = t;
+ t_old_opencl = t;
//glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, config_opencl->tex);
@@ -273,9 +283,44 @@ void idle_opencl(void)
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 = x_min_s + config_opencl->zoom_func(cl_ft, (d64) 2.0 + config_opencl->to_x);
- y_min = y_min_s + config_opencl->zoom_func(cl_ft, (d64) 1.0 + config_opencl->to_y);
- x_max = x_max_s - config_opencl->zoom_func(cl_ft, (d64) 1.0 - config_opencl->to_x);
- y_max = y_max_s - config_opencl->zoom_func(cl_ft, (d64) 1.0 - config_opencl->to_y);
+ 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:
+ 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) (config_opencl->height - y) * (y_max_cl - y_min_cl))
+ / config_opencl->height;
+ t_old_opencl = glutGet(GLUT_ELAPSED_TIME);
+ glutIdleFunc(idle_opencl);
+ break;
+ case GLUT_RIGHT_BUTTON:
+ glutIdleFunc(idle_opencl_dummy);
+ break;
+ }
+ }
+}