aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/render.c17
-rw-r--r--src/render.h4
-rw-r--r--src/render_cpu.c23
-rw-r--r--src/render_cpu.h2
4 files changed, 31 insertions, 15 deletions
diff --git a/src/render.c b/src/render.c
index 69b46e0..b9ad5e0 100644
--- a/src/render.c
+++ b/src/render.c
@@ -11,24 +11,28 @@
void init_render(Config *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;
//glutInit(0, NULL);
glutInitWindowPosition(0, 0);
glutInitWindowSize(_config->width, _config->height);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Renderer");
- if (_config->mode)
+ switch(_config->mode)
{
+ case MODE_CPU:
+ init_cpu(&_config->config_cpu);
glutDisplayFunc(render_cpu);
glutIdleFunc(idle_cpu);
- init_cpu(&_config->config_cpu);
- }
- else
- {
+ break;
+ case MODE_OPENCL:
+ init_opencl(&_config->config_opencl);
glutDisplayFunc(render_opencl);
glutIdleFunc(idle_opencl);
- init_opencl(&_config->config_opencl);
+ break;
}
glGenTextures(1, &tex);
@@ -43,6 +47,7 @@ void init_render(Config *config)
glOrtho(0, _config->width, 0, _config->height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
+
}
void show_render()
diff --git a/src/render.h b/src/render.h
index 2cb76c1..4ae2360 100644
--- a/src/render.h
+++ b/src/render.h
@@ -8,8 +8,6 @@
#ifndef RENDER_H_
#define RENDER_H_
-#define COORDS(x, y, width) ((y)*(width)+(x))
-
#include "defs.h"
#include "render_cpu.h"
#include "render_opencl.h"
@@ -29,7 +27,7 @@ typedef struct config {
} Config;
Config *_config;
-u32 s_arr;
+u32 *s_arr;
void init_render(Config *config);
void show_render();
diff --git a/src/render_cpu.c b/src/render_cpu.c
index 9370461..f3bf28e 100644
--- a/src/render_cpu.c
+++ b/src/render_cpu.c
@@ -5,12 +5,23 @@
* Author: Superleo1810
*/
-#include "render.h"
+#include "render_cpu.h"
#define HAVE_STRUCT_TIMESPEC
void init_cpu(CpuConfig *config)
{
config_cpu = config;
+ delta = glutGet(GLUT_ELAPSED_TIME);
+ 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;
+
+ calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr);
}
void render_cpu(void)
@@ -21,9 +32,9 @@ void render_cpu(void)
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(0, 0);
- glTexCoord2i(0, 1); glVertex2i(0, _config->height);
- glTexCoord2i(1, 1); glVertex2i(_config->width, _config->height);
- glTexCoord2i(1, 0); glVertex2i(_config->width, 0);
+ glTexCoord2i(0, 1); glVertex2i(0, config_cpu->height);
+ glTexCoord2i(1, 1); glVertex2i(config_cpu->width, config_cpu->height);
+ glTexCoord2i(1, 0); glVertex2i(config_cpu->width, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
@@ -50,7 +61,7 @@ void calculate_t(void *args)
u32 iterations;
for (u32 y = (config_cpu->height/_args->tc)*(_args->tid); y < config_cpu->height; y++)
{
- for (u32 x = 0; x < _config->width; x++)
+ for (u32 x = 0; x < config_cpu->width; x++)
{
x_math = _args->x_min + ((d64) x * (_args->x_max - _args->x_min)) / config_cpu->width;
y_math = _args->y_min + ((d64) (config_cpu->height - y) * (_args->y_max - _args->y_min)) / config_cpu->height;
@@ -72,7 +83,7 @@ void idle_cpu(void)
glBindTexture(GL_TEXTURE_2D, 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_cpu->width, config_cpu->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_arr);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, config_cpu->width, config_cpu->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, config_cpu->arr);
glBindTexture(GL_TEXTURE_2D, 0);
int t = glutGet(GLUT_ELAPSED_TIME);
dt = (t - delta) / 1000.0;
diff --git a/src/render_cpu.h b/src/render_cpu.h
index 6926687..b4141ae 100644
--- a/src/render_cpu.h
+++ b/src/render_cpu.h
@@ -14,6 +14,8 @@
#include <pthread.h>
#include <math.h>
+#define COORDS(x, y, width) ((y)*(width)+(x))
+
typedef struct config_cpu {
u8 threads;
u32 *arr;