Blender V2.61 - r43446
|
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 #include <stdlib.h> 00020 00021 #include "background.h" 00022 #include "camera.h" 00023 #include "device.h" 00024 #include "film.h" 00025 #include "filter.h" 00026 #include "integrator.h" 00027 #include "light.h" 00028 #include "shader.h" 00029 #include "mesh.h" 00030 #include "object.h" 00031 #include "scene.h" 00032 #include "svm.h" 00033 #include "osl.h" 00034 00035 #include "util_foreach.h" 00036 #include "util_progress.h" 00037 00038 CCL_NAMESPACE_BEGIN 00039 00040 Scene::Scene(const SceneParams& params_) 00041 : params(params_) 00042 { 00043 device = NULL; 00044 memset(&dscene.data, 0, sizeof(dscene.data)); 00045 00046 camera = new Camera(); 00047 filter = new Filter(); 00048 film = new Film(); 00049 background = new Background(); 00050 light_manager = new LightManager(); 00051 mesh_manager = new MeshManager(); 00052 object_manager = new ObjectManager(); 00053 integrator = new Integrator(); 00054 image_manager = new ImageManager(); 00055 shader_manager = ShaderManager::create(this); 00056 } 00057 00058 Scene::~Scene() 00059 { 00060 if(device) camera->device_free(device, &dscene); 00061 delete camera; 00062 00063 if(device) filter->device_free(device, &dscene); 00064 delete filter; 00065 00066 if(device) film->device_free(device, &dscene); 00067 delete film; 00068 00069 if(device) background->device_free(device, &dscene); 00070 delete background; 00071 00072 if(device) mesh_manager->device_free(device, &dscene); 00073 delete mesh_manager; 00074 00075 if(device) object_manager->device_free(device, &dscene); 00076 delete object_manager; 00077 00078 if(device) integrator->device_free(device, &dscene); 00079 delete integrator; 00080 00081 if(device) shader_manager->device_free(device, &dscene); 00082 delete shader_manager; 00083 00084 if(device) light_manager->device_free(device, &dscene); 00085 delete light_manager; 00086 00087 foreach(Shader *s, shaders) 00088 delete s; 00089 foreach(Mesh *m, meshes) 00090 delete m; 00091 foreach(Object *o, objects) 00092 delete o; 00093 foreach(Light *l, lights) 00094 delete l; 00095 00096 if(device) image_manager->device_free(device, &dscene); 00097 delete image_manager; 00098 } 00099 00100 void Scene::device_update(Device *device_, Progress& progress) 00101 { 00102 if(!device) 00103 device = device_; 00104 00105 /* The order of updates is important, because there's dependencies between 00106 * the different managers, using data computed by previous managers. 00107 * 00108 * - Background generates shader graph compiled by shader manager. 00109 * - Image manager uploads images used by shaders. 00110 * - Camera may be used for adapative subdivison. 00111 * - Displacement shader must have all shader data available. 00112 * - Light manager needs final mesh data to compute emission CDF. 00113 */ 00114 00115 progress.set_status("Updating Background"); 00116 background->device_update(device, &dscene, this); 00117 00118 if(progress.get_cancel()) return; 00119 00120 progress.set_status("Updating Shaders"); 00121 shader_manager->device_update(device, &dscene, this, progress); 00122 00123 if(progress.get_cancel()) return; 00124 00125 progress.set_status("Updating Images"); 00126 image_manager->device_update(device, &dscene, progress); 00127 00128 if(progress.get_cancel()) return; 00129 00130 progress.set_status("Updating Camera"); 00131 camera->device_update(device, &dscene); 00132 00133 if(progress.get_cancel()) return; 00134 00135 progress.set_status("Updating Objects"); 00136 object_manager->device_update(device, &dscene, this, progress); 00137 00138 if(progress.get_cancel()) return; 00139 00140 progress.set_status("Updating Meshes"); 00141 mesh_manager->device_update(device, &dscene, this, progress); 00142 00143 if(progress.get_cancel()) return; 00144 00145 progress.set_status("Updating Lights"); 00146 light_manager->device_update(device, &dscene, this, progress); 00147 00148 if(progress.get_cancel()) return; 00149 00150 progress.set_status("Updating Filter"); 00151 filter->device_update(device, &dscene); 00152 00153 if(progress.get_cancel()) return; 00154 00155 progress.set_status("Updating Integrator"); 00156 integrator->device_update(device, &dscene); 00157 00158 if(progress.get_cancel()) return; 00159 00160 progress.set_status("Updating Film"); 00161 film->device_update(device, &dscene); 00162 00163 if(progress.get_cancel()) return; 00164 00165 progress.set_status("Updating Device", "Writing constant memory"); 00166 device->const_copy_to("__data", &dscene.data, sizeof(dscene.data)); 00167 } 00168 00169 bool Scene::need_update() 00170 { 00171 return (need_reset() || film->need_update); 00172 } 00173 00174 bool Scene::need_reset() 00175 { 00176 return (background->need_update 00177 || image_manager->need_update 00178 || camera->need_update 00179 || object_manager->need_update 00180 || mesh_manager->need_update 00181 || light_manager->need_update 00182 || filter->need_update 00183 || integrator->need_update 00184 || shader_manager->need_update); 00185 } 00186 00187 CCL_NAMESPACE_END 00188