add BLI_strcpy_rlen, replace strcat, which was used in misleading way.
[blender.git] / intern / cycles / kernel / kernel.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 /* CPU kernel entry points */
20
21 #include "kernel.h"
22 #include "kernel_compat_cpu.h"
23 #include "kernel_math.h"
24 #include "kernel_types.h"
25 #include "kernel_globals.h"
26 #include "kernel_film.h"
27 #include "kernel_path.h"
28 #include "kernel_displace.h"
29
30 CCL_NAMESPACE_BEGIN
31
32 /* Memory Copy */
33
34 void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size)
35 {
36         if(strcmp(name, "__data") == 0)
37                 memcpy(&kg->__data, host, size);
38         else
39                 assert(0);
40 }
41
42 void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height)
43 {
44         if(0) {
45         }
46
47 #define KERNEL_TEX(type, ttype, tname) \
48         else if(strcmp(name, #tname) == 0) { \
49                 kg->tname.data = (type*)mem; \
50                 kg->tname.width = width; \
51         }
52 #define KERNEL_IMAGE_TEX(type, ttype, tname)
53 #include "kernel_textures.h"
54
55         else if(strstr(name, "__tex_image_float")) {
56                 texture_image_float4 *tex = NULL;
57                 int id = atoi(name + strlen("__tex_image_float_"));
58                 int array_index = id;
59
60                 if (array_index >= 0 && array_index < MAX_FLOAT_IMAGES) {
61                         tex = &kg->texture_float_images[array_index];
62                 }
63
64                 if(tex) {
65                         tex->data = (float4*)mem;
66                         tex->width = width;
67                         tex->height = height;
68                 }
69         }
70         else if(strstr(name, "__tex_image")) {
71                 texture_image_uchar4 *tex = NULL;
72                 int id = atoi(name + strlen("__tex_image_"));
73                 int array_index = id - MAX_FLOAT_IMAGES;
74
75                 if (array_index >= 0 && array_index < MAX_BYTE_IMAGES) {
76                         tex = &kg->texture_byte_images[array_index];
77                 }
78
79                 if(tex) {
80                         tex->data = (uchar4*)mem;
81                         tex->width = width;
82                         tex->height = height;
83                 }
84         }
85         else
86                 assert(0);
87 }
88
89 /* Path Tracing */
90
91 void kernel_cpu_path_trace(KernelGlobals *kg, float *buffer, unsigned int *rng_state, int sample, int x, int y, int offset, int stride)
92 {
93         kernel_path_trace(kg, buffer, rng_state, sample, x, y, offset, stride);
94 }
95
96 /* Tonemapping */
97
98 void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float *buffer, int sample, int x, int y, int offset, int stride)
99 {
100         kernel_film_tonemap(kg, rgba, buffer, sample, x, y, offset, stride);
101 }
102
103 /* Shader Evaluation */
104
105 void kernel_cpu_shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int i)
106 {
107         kernel_shader_evaluate(kg, input, output, (ShaderEvalType)type, i);
108 }
109
110 CCL_NAMESPACE_END
111