Blender V2.61 - r43446

kernel.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 /* CPU kernel entry points */
00020 
00021 #include "kernel.h"
00022 #include "kernel_compat_cpu.h"
00023 #include "kernel_math.h"
00024 #include "kernel_types.h"
00025 #include "kernel_globals.h"
00026 #include "kernel_film.h"
00027 #include "kernel_path.h"
00028 #include "kernel_displace.h"
00029 
00030 CCL_NAMESPACE_BEGIN
00031 
00032 /* Globals */
00033 
00034 KernelGlobals *kernel_globals_create()
00035 {
00036     KernelGlobals *kg = new KernelGlobals();
00037 #ifdef WITH_OSL
00038     kg->osl.use = false;
00039 #endif
00040     return kg;
00041 }
00042 
00043 void kernel_globals_free(KernelGlobals *kg)
00044 {
00045     delete kg;
00046 }
00047 
00048 /* OSL */
00049 
00050 #ifdef WITH_OSL
00051 
00052 void *kernel_osl_memory(KernelGlobals *kg)
00053 {
00054     return (void*)&kg->osl;
00055 }
00056 
00057 bool kernel_osl_use(KernelGlobals *kg)
00058 {
00059     return kg->osl.use;
00060 }
00061 
00062 #endif
00063 
00064 /* Memory Copy */
00065 
00066 void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size)
00067 {
00068     if(strcmp(name, "__data") == 0)
00069         memcpy(&kg->__data, host, size);
00070     else
00071         assert(0);
00072 }
00073 
00074 void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height)
00075 {
00076     if(0) {
00077     }
00078 
00079 #define KERNEL_TEX(type, ttype, tname) \
00080     else if(strcmp(name, #tname) == 0) { \
00081         kg->tname.data = (type*)mem; \
00082         kg->tname.width = width; \
00083     }
00084 #define KERNEL_IMAGE_TEX(type, ttype, tname)
00085 #include "kernel_textures.h"
00086 
00087     else if(strstr(name, "__tex_image")) {
00088         texture_image_uchar4 *tex = NULL;
00089         int id = atoi(name + strlen("__tex_image_"));
00090 
00091         switch(id) {
00092             case 0: tex = &kg->__tex_image_000; break;
00093             case 1: tex = &kg->__tex_image_001; break;
00094             case 2: tex = &kg->__tex_image_002; break;
00095             case 3: tex = &kg->__tex_image_003; break;
00096             case 4: tex = &kg->__tex_image_004; break;
00097             case 5: tex = &kg->__tex_image_005; break;
00098             case 6: tex = &kg->__tex_image_006; break;
00099             case 7: tex = &kg->__tex_image_007; break;
00100             case 8: tex = &kg->__tex_image_008; break;
00101             case 9: tex = &kg->__tex_image_009; break;
00102             case 10: tex = &kg->__tex_image_010; break;
00103             case 11: tex = &kg->__tex_image_011; break;
00104             case 12: tex = &kg->__tex_image_012; break;
00105             case 13: tex = &kg->__tex_image_013; break;
00106             case 14: tex = &kg->__tex_image_014; break;
00107             case 15: tex = &kg->__tex_image_015; break;
00108             case 16: tex = &kg->__tex_image_016; break;
00109             case 17: tex = &kg->__tex_image_017; break;
00110             case 18: tex = &kg->__tex_image_018; break;
00111             case 19: tex = &kg->__tex_image_019; break;
00112             case 20: tex = &kg->__tex_image_020; break;
00113             case 21: tex = &kg->__tex_image_021; break;
00114             case 22: tex = &kg->__tex_image_022; break;
00115             case 23: tex = &kg->__tex_image_023; break;
00116             case 24: tex = &kg->__tex_image_024; break;
00117             case 25: tex = &kg->__tex_image_025; break;
00118             case 26: tex = &kg->__tex_image_026; break;
00119             case 27: tex = &kg->__tex_image_027; break;
00120             case 28: tex = &kg->__tex_image_028; break;
00121             case 29: tex = &kg->__tex_image_029; break;
00122             case 30: tex = &kg->__tex_image_030; break;
00123             case 31: tex = &kg->__tex_image_031; break;
00124             case 32: tex = &kg->__tex_image_032; break;
00125             case 33: tex = &kg->__tex_image_033; break;
00126             case 34: tex = &kg->__tex_image_034; break;
00127             case 35: tex = &kg->__tex_image_035; break;
00128             case 36: tex = &kg->__tex_image_036; break;
00129             case 37: tex = &kg->__tex_image_037; break;
00130             case 38: tex = &kg->__tex_image_038; break;
00131             case 39: tex = &kg->__tex_image_039; break;
00132             case 40: tex = &kg->__tex_image_040; break;
00133             case 41: tex = &kg->__tex_image_041; break;
00134             case 42: tex = &kg->__tex_image_042; break;
00135             case 43: tex = &kg->__tex_image_043; break;
00136             case 44: tex = &kg->__tex_image_044; break;
00137             case 45: tex = &kg->__tex_image_045; break;
00138             case 46: tex = &kg->__tex_image_046; break;
00139             case 47: tex = &kg->__tex_image_047; break;
00140             case 48: tex = &kg->__tex_image_048; break;
00141             case 49: tex = &kg->__tex_image_049; break;
00142             case 50: tex = &kg->__tex_image_050; break;
00143             case 51: tex = &kg->__tex_image_051; break;
00144             case 52: tex = &kg->__tex_image_052; break;
00145             case 53: tex = &kg->__tex_image_053; break;
00146             case 54: tex = &kg->__tex_image_054; break;
00147             case 55: tex = &kg->__tex_image_055; break;
00148             case 56: tex = &kg->__tex_image_056; break;
00149             case 57: tex = &kg->__tex_image_057; break;
00150             case 58: tex = &kg->__tex_image_058; break;
00151             case 59: tex = &kg->__tex_image_059; break;
00152             case 60: tex = &kg->__tex_image_060; break;
00153             case 61: tex = &kg->__tex_image_061; break;
00154             case 62: tex = &kg->__tex_image_062; break;
00155             case 63: tex = &kg->__tex_image_063; break;
00156             case 64: tex = &kg->__tex_image_064; break;
00157             case 65: tex = &kg->__tex_image_065; break;
00158             case 66: tex = &kg->__tex_image_066; break;
00159             case 67: tex = &kg->__tex_image_067; break;
00160             case 68: tex = &kg->__tex_image_068; break;
00161             case 69: tex = &kg->__tex_image_069; break;
00162             case 70: tex = &kg->__tex_image_070; break;
00163             case 71: tex = &kg->__tex_image_071; break;
00164             case 72: tex = &kg->__tex_image_072; break;
00165             case 73: tex = &kg->__tex_image_073; break;
00166             case 74: tex = &kg->__tex_image_074; break;
00167             case 75: tex = &kg->__tex_image_075; break;
00168             case 76: tex = &kg->__tex_image_076; break;
00169             case 77: tex = &kg->__tex_image_077; break;
00170             case 78: tex = &kg->__tex_image_078; break;
00171             case 79: tex = &kg->__tex_image_079; break;
00172             case 80: tex = &kg->__tex_image_080; break;
00173             case 81: tex = &kg->__tex_image_081; break;
00174             case 82: tex = &kg->__tex_image_082; break;
00175             case 83: tex = &kg->__tex_image_083; break;
00176             case 84: tex = &kg->__tex_image_084; break;
00177             case 85: tex = &kg->__tex_image_085; break;
00178             case 86: tex = &kg->__tex_image_086; break;
00179             case 87: tex = &kg->__tex_image_087; break;
00180             case 88: tex = &kg->__tex_image_088; break;
00181             case 89: tex = &kg->__tex_image_089; break;
00182             case 90: tex = &kg->__tex_image_090; break;
00183             case 91: tex = &kg->__tex_image_091; break;
00184             case 92: tex = &kg->__tex_image_092; break;
00185             case 93: tex = &kg->__tex_image_093; break;
00186             case 94: tex = &kg->__tex_image_094; break;
00187             case 95: tex = &kg->__tex_image_095; break;
00188             case 96: tex = &kg->__tex_image_096; break;
00189             case 97: tex = &kg->__tex_image_097; break;
00190             case 98: tex = &kg->__tex_image_098; break;
00191             case 99: tex = &kg->__tex_image_099; break;
00192             default: break;
00193         }
00194 
00195         if(tex) {
00196             tex->data = (uchar4*)mem;
00197             tex->width = width;
00198             tex->height = height;
00199         }
00200     }
00201     else
00202         assert(0);
00203 }
00204 
00205 /* Path Tracing */
00206 
00207 void kernel_cpu_path_trace(KernelGlobals *kg, float4 *buffer, unsigned int *rng_state, int sample, int x, int y, int offset, int stride)
00208 {
00209     kernel_path_trace(kg, buffer, rng_state, sample, x, y, offset, stride);
00210 }
00211 
00212 /* Tonemapping */
00213 
00214 void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer, int sample, int resolution, int x, int y, int offset, int stride)
00215 {
00216     kernel_film_tonemap(kg, rgba, buffer, sample, resolution, x, y, offset, stride);
00217 }
00218 
00219 /* Shader Evaluation */
00220 
00221 void kernel_cpu_shader(KernelGlobals *kg, uint4 *input, float3 *output, int type, int i)
00222 {
00223     kernel_shader_evaluate(kg, input, output, (ShaderEvalType)type, i);
00224 }
00225 
00226 CCL_NAMESPACE_END
00227