aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cproject4
-rw-r--r--src/config.h46
-rw-r--r--src/creator.c50
-rw-r--r--src/creator.h2
-rw-r--r--src/mandelbrot-zoom.c23
-rw-r--r--src/mandelbrot-zoom.h3
-rw-r--r--src/render.c15
-rw-r--r--src/render.h20
-rw-r--r--src/render_cpu.c8
-rw-r--r--src/render_cpu.h22
-rw-r--r--src/render_opencl.c19
-rw-r--r--src/render_opencl.h23
12 files changed, 114 insertions, 121 deletions
diff --git a/.cproject b/.cproject
index 6b038e1..7957308 100644
--- a/.cproject
+++ b/.cproject
@@ -69,6 +69,8 @@
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="pthread"/>
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="amdocl"/>
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="amdocl12cl"/>
+ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="avcodec"/>
+ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="avutil"/>
</option>
<option id="gnu.c.link.option.paths.1322466417" name="Library search path (-L)" superClass="gnu.c.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${MSYS_HOME}\mingw32\lib&quot;"/>
@@ -199,6 +201,8 @@
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="OpenCL"/>
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="amdocl"/>
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="amdocl12cl"/>
+ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="avcodec"/>
+ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="avutil"/>
</option>
<option id="gnu.c.link.option.paths.1055912140" name="Library search path (-L)" superClass="gnu.c.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${MSYS_HOME}\mingw32\lib&quot;"/>
diff --git a/src/config.h b/src/config.h
new file mode 100644
index 0000000..004c1e5
--- /dev/null
+++ b/src/config.h
@@ -0,0 +1,46 @@
+/*
+ * config.h
+ *
+ * Created on: 31.01.2018
+ * Author: Superleo1810
+ */
+
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+typedef struct config_cpu {
+ u8 threads;
+} config_cpu_t;
+
+typedef struct config_opencl {
+ u8 fpu;
+ u8 fma;
+ u8 set_func; // id, not pointer!
+} config_opencl_t;
+
+typedef struct config {
+ config_cpu_t config_cpu;
+ config_opencl_t config_opencl;
+ u8 mode;
+ u8 zoomSpecific;
+ u8 video;
+ u8 filetype;
+ u16 width;
+ u16 height;
+ u8 videoFPS;
+ u32 bitrate;
+ u8 renderFPS;
+ d64 to_x;
+ d64 to_y;
+ d64 speed;
+ d64 (*zoom_func)(d64, d64);
+ u32 (*set_func)(d64, d64, u32);
+ GLuint tex;
+ u32 *arr;
+ u32 iterations;
+ u32 colorFrom;
+ u32 colorTo;
+ const char *path;
+} config_t;
+
+#endif /* CONFIG_H_ */
diff --git a/src/creator.c b/src/creator.c
index d8bd008..85fd0b0 100644
--- a/src/creator.c
+++ b/src/creator.c
@@ -24,7 +24,7 @@ static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
av_packet_unref(pkt);
}
}
-int generateVideo(filename, int width, int height, int fps, int bitRate)
+int generateVideo(char *filename, int width, int height, int fps, int bitRate)
{
avcodec_register_all();
@@ -77,36 +77,38 @@ int generateVideo(filename, int width, int height, int fps, int bitRate)
fprintf(stderr, "could not alloc the frame data\n");
exit(1);
}
+ return TRUE;
+}
void addFrame(int *frame)
{
- fflush(stdout);
- /* make sure the frame data is writable */
- ret = av_frame_make_writable(picture);
- if (ret < 0)
- exit(1);
+ fflush(stdout);
+ /* make sure the frame data is writable */
+ ret = av_frame_make_writable(picture);
+ if (ret < 0)
+ exit(1);
- picture->data[0] = frame;
+ picture->data[0] = frame;
- /* prepare a dummy image */
- /* Y */
- /*for(y=0;y<c->height;y++) {
- for(x=0;x<c->width;x++) {
- picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
- }
- } YCbCr colorCode
- /* Cb and Cr *
- for(y=0;y<c->height/2;y++) {
- for(x=0;x<c->width/2;x++) {
- picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
- picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
- }
- } */
+ /* prepare a dummy image */
+ /* Y */
+ /*for(y=0;y<c->height;y++) {
+ for(x=0;x<c->width;x++) {
+ picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
+ }
+ } YCbCr colorCode
+ /* Cb and Cr *
+ for(y=0;y<c->height/2;y++) {
+ for(x=0;x<c->width/2;x++) {
+ picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
+ picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
+ }
+ } */
- picture->pts = i;
- /* encode the image */
- encode(c, picture, pkt, f);
+ picture->pts = i;
+ /* encode the image */
+ encode(c, picture, pkt, f);
}
void endFile(void){
diff --git a/src/creator.h b/src/creator.h
index b89b16c..bcff35d 100644
--- a/src/creator.h
+++ b/src/creator.h
@@ -31,7 +31,7 @@ int i, ret, x, y;
static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile);
-int generateVideo(filename, int width, int height, int fps, int bitRate, Config *config, u32 (*sfunc) (long double, long double, u32));
+int generateVideo(char *filename, int width, int height, int fps, int bitRate);
void addFrame(int *frame);
diff --git a/src/mandelbrot-zoom.c b/src/mandelbrot-zoom.c
index f009e10..33b0353 100644
--- a/src/mandelbrot-zoom.c
+++ b/src/mandelbrot-zoom.c
@@ -103,8 +103,7 @@ void on_colorToBtn_clicked()
void on_startBtn_clicked()
{
- config.config_cpu.iterations = gtk_spin_button_get_value(ui_settings.iterationsSp);
- config.config_opencl.iterations = gtk_spin_button_get_value(ui_settings.iterationsSp);
+ config.iterations = gtk_spin_button_get_value(ui_settings.iterationsSp);
config.zoomSpecific = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui_settings.zoomSpecificCb));
@@ -119,15 +118,10 @@ void on_startBtn_clicked()
config.width = gtk_spin_button_get_value(ui_settings.widthSp);
- config.config_cpu.width = gtk_spin_button_get_value(ui_settings.widthSp);
- config.config_opencl.width = gtk_spin_button_get_value(ui_settings.widthSp);
config.height = gtk_spin_button_get_value(ui_settings.heightSp);
- config.config_cpu.height = gtk_spin_button_get_value(ui_settings.heightSp);
- config.config_opencl.height = gtk_spin_button_get_value(ui_settings.heightSp);
- config.config_cpu.renderFPS = gtk_spin_button_get_value(ui_settings.fpsRenderSp);
- config.config_opencl.renderFPS = gtk_spin_button_get_value(ui_settings.fpsRenderSp);
+ config.renderFPS = gtk_spin_button_get_value(ui_settings.fpsRenderSp);
config.videoFPS = gtk_spin_button_get_value(ui_settings.fpsVideoSp);
@@ -137,24 +131,21 @@ void on_startBtn_clicked()
sscanf(gtk_entry_get_text(ui_settings.zoomToXEntry), "%lf", &x);
sscanf(gtk_entry_get_text(ui_settings.zoomToYEntry), "%lf", &y);
sscanf(gtk_entry_get_text(ui_settings.speedEntry), "%lf", &speed);
- config.config_cpu.to_x = x;
- config.config_cpu.to_y = y;
- config.config_cpu.speed = speed;
- config.config_opencl.to_x = x;
- config.config_opencl.to_y = y;
- config.config_opencl.speed = speed;
+ config.to_x = x;
+ config.to_y = y;
+ config.speed = speed;
config.mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui_settings.modeGPURd));
//config.mode = MODE_CPU;
if (strcmp(gtk_combo_box_text_get_active_text(ui_settings.setCombo), "Mandelbrot") == 0)
{
- config.config_cpu.set_func = mandelbrot_r;
+ config.set_func = mandelbrot_r;
config.config_opencl.set_func = SFUNC_MANDELBROT;
}
else if (strcmp(gtk_combo_box_text_get_active_text(ui_settings.setCombo), "Julia") == 0)
{
- config.config_cpu.set_func = julia;
+ config.set_func = julia;
config.config_opencl.set_func = SFUNC_JULIA;
}
diff --git a/src/mandelbrot-zoom.h b/src/mandelbrot-zoom.h
index 5aa4dc4..1ff8f4f 100644
--- a/src/mandelbrot-zoom.h
+++ b/src/mandelbrot-zoom.h
@@ -13,6 +13,7 @@
#include "conversion.h"
#include "render.h"
#include "sets.h"
+#include "config.h"
typedef struct Ui_settings {
GtkWindow *settings;
@@ -46,7 +47,7 @@ typedef struct Ui_settings {
} Ui_settings;
Ui_settings ui_settings;
-Config config;
+config_t config;
u8 currentColor;
int main(int argc, char **argv);
diff --git a/src/render.c b/src/render.c
index 6c01029..e10e44b 100644
--- a/src/render.c
+++ b/src/render.c
@@ -9,12 +9,11 @@
//#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
-void init_render(Config *config)
+void init_render(config_t *config)
{
_config = config;
s_arr = (u32 *) malloc((_config->width) * (_config->height) * sizeof(u32));
- _config->config_cpu.arr = s_arr;
- _config->config_opencl.arr = s_arr;
+ _config->arr = s_arr;
//glutInit(0, NULL);
glutInitWindowPosition(0, 0);
glutInitWindowSize(_config->width, _config->height);
@@ -34,15 +33,13 @@ void init_render(Config *config)
glOrtho(0, _config->width, 0, _config->height, -1, 1);
glMatrixMode(GL_MODELVIEW);
- _config->config_cpu.tex = tex;
- _config->config_opencl.tex = tex;
- _config->config_cpu.zoom_func = zoom_func;
- _config->config_opencl.zoom_func = zoom_func;
+ _config->tex = tex;
+ _config->zoom_func = zoom_func;
switch(_config->mode)
{
case MODE_CPU:
- init_cpu(&_config->config_cpu);
+ init_cpu(_config);
glutDisplayFunc(render_cpu);
if (_config->zoomSpecific)
{
@@ -56,7 +53,7 @@ void init_render(Config *config)
}
break;
case MODE_OPENCL:
- init_opencl(&_config->config_opencl);
+ init_opencl(_config);
glutDisplayFunc(render_opencl);
if (_config->zoomSpecific)
{
diff --git a/src/render.h b/src/render.h
index 52be446..5972200 100644
--- a/src/render.h
+++ b/src/render.h
@@ -12,29 +12,15 @@
#include "render_opencl.h"
#include "render_cpu.h"
#include <math.h>
+#include "config.h"
-typedef struct config {
- CpuConfig config_cpu;
- OpenCLConfig config_opencl;
- u8 mode;
- u8 zoomSpecific;
- u8 video;
- u8 filetype;
- u16 width;
- u16 height;
- u8 videoFPS;
- u32 bitrate;
- const char *path;
- // TODO: key mapping als option in die struct
-} Config;
-
-Config *_config;
+config_t *_config;
u32 *s_arr;
GLuint tex;
d64 zoom_func(d64 ft, d64 s);
-void init_render(Config *config);
+void init_render(config_t *config);
void show_render();
#endif /* RENDER_H_ */
diff --git a/src/render_cpu.c b/src/render_cpu.c
index 64fc9ec..ef66e37 100644
--- a/src/render_cpu.c
+++ b/src/render_cpu.c
@@ -17,7 +17,7 @@ void idle_cpu_dummy(void)
glutPostRedisplay();
}
-void init_cpu(CpuConfig *config)
+void init_cpu(config_t *config)
{
config_cpu = config;
x_min_s = -2.0;
@@ -58,10 +58,10 @@ void render_cpu(void)
void calculate(d64 x_min, d64 y_min, d64 x_max, d64 y_max, u32 (*sfunc) (d64, d64, u32), u32 *arr)
{
pthread_t thread;
- ThreadArgs *args = (ThreadArgs *) malloc(config_cpu->threads * sizeof(ThreadArgs));
- for(u8 i = 0; i < config_cpu->threads; i++)
+ ThreadArgs *args = (ThreadArgs *) malloc(config_cpu->config_cpu.threads * sizeof(ThreadArgs));
+ for(u8 i = 0; i < config_cpu->config_cpu.threads; i++)
{
- args[i] = (ThreadArgs) { .tc = config_cpu->threads, .tid = i, .x_min = x_min, .y_min = y_min, .x_max = x_max, .y_max = y_max, .sfunc = sfunc, .arr = arr };
+ args[i] = (ThreadArgs) { .tc = config_cpu->config_cpu.threads, .tid = i, .x_min = x_min, .y_min = y_min, .x_max = x_max, .y_max = y_max, .sfunc = sfunc, .arr = arr };
pthread_create(&thread, NULL, calculate_t, (void *)&args[i]);
}
pthread_join(thread, NULL);
diff --git a/src/render_cpu.h b/src/render_cpu.h
index 7469ca2..0fc75eb 100644
--- a/src/render_cpu.h
+++ b/src/render_cpu.h
@@ -15,26 +15,10 @@
#include <pthread.h>
#include <time.h>
#include <math.h>
+#include "config.h"
#define COORDS(x, y, width) ((y)*(width)+(x))
-typedef struct config_cpu {
- u8 threads;
- GLuint tex;
- u32 *arr;
- d64 (*zoom_func)(d64, d64);
- u32 (*set_func)(d64, d64, u32);
- u32 iterations;
- u32 colorFrom;
- u32 colorTo;
- d64 to_x;
- d64 to_y;
- d64 speed;
- u16 width;
- u16 height;
- u8 renderFPS;
-} CpuConfig;
-
typedef struct t_args {
u8 tc;
u8 tid;
@@ -46,7 +30,7 @@ typedef struct t_args {
u32 *arr;
} ThreadArgs;
-CpuConfig *config_cpu;
+config_t *config_cpu;
u32 rendercnt;
float ft;
int t_old_cpu;
@@ -54,7 +38,7 @@ int t_old_cpu;
d64 x_min, x_max, y_min, y_max;
d64 x_min_s, x_max_s, y_min_s, y_max_s;
-void init_cpu(CpuConfig *config);
+void init_cpu(config_t *config);
void render_cpu(void);
void idle_cpu(void);
void idle_cpu_dummy(void);
diff --git a/src/render_opencl.c b/src/render_opencl.c
index 055a7f3..7bc9620 100644
--- a/src/render_opencl.c
+++ b/src/render_opencl.c
@@ -12,7 +12,7 @@ void idle_opencl_dummy(void)
glutPostRedisplay();
}
-void init_opencl(OpenCLConfig *config)
+void init_opencl(config_t *cfg)
{
x_min_s_cl = -2.0;
x_max_s_cl = 1.0;
@@ -23,7 +23,7 @@ void init_opencl(OpenCLConfig *config)
y_min_cl = y_min_s_cl;
y_max_cl = y_max_s_cl;
- config_opencl = config;
+ config_opencl = cfg;
output = (cl_uint *) malloc((config_opencl->width) * (config_opencl->height) * sizeof(cl_uchar4));
context = NULL;
@@ -47,10 +47,10 @@ void init_opencl(OpenCLConfig *config)
FILE *fp;
char *cl_src, *path, *flags = (char *)malloc(200 * sizeof(char));
flags[0] = '\0';
- switch(config_opencl->fpu)
+ switch(config_opencl->config_opencl.fpu)
{
case OPENCL_FPU_32:
- switch(config_opencl->set_func)
+ switch(config_opencl->config_opencl.set_func)
{
case SFUNC_JULIA:
path = "cl/julia32.cl";
@@ -62,7 +62,7 @@ void init_opencl(OpenCLConfig *config)
}
break;
case OPENCL_FPU_64:
- switch(config_opencl->set_func)
+ switch(config_opencl->config_opencl.set_func)
{
case SFUNC_JULIA:
path = "cl/julia64.cl";
@@ -123,7 +123,7 @@ void init_opencl(OpenCLConfig *config)
(sizeof(cl_uint) * (config_opencl->width)
* (config_opencl->height)) / num_devices, NULL, &ret);
}
- if (config_opencl->fma)
+ if (config_opencl->config_opencl.fma)
{
flags = strcat(flags, "-D MUL_ADD=fma ");
}
@@ -138,7 +138,6 @@ void init_opencl(OpenCLConfig *config)
{
kernel_vector[i] = clCreateKernel(program, "calculate", &ret);
}
-
}
void render_opencl(void)
@@ -186,7 +185,8 @@ 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);
- switch (config_opencl->fpu)
+ printf("set args\n");
+ switch (config_opencl->config_opencl.fpu)
{
case OPENCL_FPU_32: // lel
ret = clSetKernelArg(kernel, 1, sizeof(cl_float), (void *) &x_min_f);
@@ -220,7 +220,6 @@ void render_opencl(void)
ret = clWaitForEvents(1, &events[num_devices - i - 1]);
ret = clReleaseEvent(events[num_devices - i - 1]);
}
-
for (cl_uint i = 0; i < num_devices; i++)
{
ret = clEnqueueReadBuffer(commandQueue[i], outputBuffer[i],
@@ -232,7 +231,6 @@ void render_opencl(void)
/ num_devices) * i, 0,
NULL, &events[i]);
}
-
for (cl_uint i = 0; i < num_devices; i++)
{
ret = clFlush(commandQueue[i]);
@@ -243,6 +241,7 @@ 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,
diff --git a/src/render_opencl.h b/src/render_opencl.h
index bca77ad..51945d5 100644
--- a/src/render_opencl.h
+++ b/src/render_opencl.h
@@ -14,6 +14,7 @@
#include <CL/cl.h>
#include "sets.h"
#include <math.h>
+#include "config.h"
#define OPENCL_FPU_32 0
#define OPENCL_FPU_64 1
@@ -22,25 +23,7 @@
#define MAX_SOURCE_SIZE 0xFFFF // 64 KiB
#define MAX_DEVICES 4
-typedef struct config_opencl {
- u8 fpu;
- u8 fma;
- GLuint tex;
- d64 (*zoom_func)(d64, d64);
- u8 set_func; // id, not pointer!
- u32 *arr;
- u32 iterations;
- u32 colorFrom;
- u32 colorTo;
- d64 to_x;
- d64 to_y;
- d64 speed;
- u16 width;
- u16 height;
- u8 renderFPS;
-} OpenCLConfig;
-
-OpenCLConfig *config_opencl;
+config_t *config_opencl;
cl_double x_min_cl, x_max_cl, y_min_cl, y_max_cl;
cl_double x_min_s_cl, x_max_s_cl, y_min_s_cl, y_max_s_cl;
@@ -62,7 +45,7 @@ int t_old_opencl;
d64 zoom_func(d64 ft, d64 s);
-void init_opencl(OpenCLConfig *config);
+void init_opencl(config_t *cfg);
void render_opencl(void);
void idle_opencl(void);
void idle_opencl_dummy(void);