1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
* render.c
*
* Created on: 15.01.2018
* Author: Superleo1810
*/
#include "render_cpu.h"
#define HAVE_STRUCT_TIMESPEC
void init_cpu(config_t *config)
{
config_cpu = config;
}
void render_cpu(d64 x_min, d64 y_min, d64 x_max, d64 y_max)
{
calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr);
printf("end render cpu\n");
}
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->config_cpu.threads * sizeof(ThreadArgs));
for(u8 i = 0; i < config_cpu->config_cpu.threads; i++)
{
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);
free(args);
}
void calculate_t(void *args)
{
ThreadArgs *_args = (ThreadArgs *)args;
d64 x_math, y_math;
u32 iterations;
for (u32 y = (config_cpu->height/_args->tc)*(_args->tid); y < config_cpu->height; y++)
{
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;
iterations = _args->sfunc(x_math, y_math, config_cpu->iterations);
// color[2].s0 = ((1.0f + native_cos(c)) * 0.5f) * 255;
// color[2].s1 = ((1.0f + native_cos(2.0f * c + 2.0f * 3.1416f / 3.0f)) * 0.5f) * 255;
// color[2].s2 = ((1.0f + native_cos(c - 2.0f * 3.1416f / 3.0f)) * 0.5f) * 255;
_args->arr[COORDS(x, y, config_cpu->width)] = (((1<<24)-1)*iterations)/config_cpu->iterations;
}
}
}
void idle_cpu(void)
{
}
|