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 #ifndef __SESSION_H__ 00020 #define __SESSION_H__ 00021 00022 #include "buffers.h" 00023 #include "device.h" 00024 #include "tile.h" 00025 00026 #include "util_progress.h" 00027 #include "util_thread.h" 00028 00029 CCL_NAMESPACE_BEGIN 00030 00031 class BufferParams; 00032 class Device; 00033 class DeviceScene; 00034 class DisplayBuffer; 00035 class Progress; 00036 class RenderBuffers; 00037 class Scene; 00038 00039 /* Session Parameters */ 00040 00041 class SessionParams { 00042 public: 00043 DeviceInfo device; 00044 bool background; 00045 string output_path; 00046 00047 bool progressive; 00048 bool experimental; 00049 int samples; 00050 int tile_size; 00051 int min_size; 00052 int threads; 00053 00054 double cancel_timeout; 00055 double reset_timeout; 00056 double text_timeout; 00057 00058 SessionParams() 00059 { 00060 background = false; 00061 output_path = ""; 00062 00063 progressive = false; 00064 experimental = false; 00065 samples = INT_MAX; 00066 tile_size = 64; 00067 min_size = 64; 00068 threads = 0; 00069 00070 cancel_timeout = 0.1; 00071 reset_timeout = 0.1; 00072 text_timeout = 1.0; 00073 } 00074 00075 bool modified(const SessionParams& params) 00076 { return !(device.type == params.device.type 00077 && device.id == params.device.id 00078 && background == params.background 00079 && output_path == params.output_path 00080 /* && samples == params.samples */ 00081 && progressive == params.progressive 00082 && experimental == params.experimental 00083 && tile_size == params.tile_size 00084 && min_size == params.min_size 00085 && threads == params.threads 00086 && cancel_timeout == params.cancel_timeout 00087 && reset_timeout == params.reset_timeout 00088 && text_timeout == params.text_timeout); } 00089 00090 }; 00091 00092 /* Session 00093 * 00094 * This is the class that contains the session thread, running the render 00095 * control loop and dispatching tasks. */ 00096 00097 class Session { 00098 public: 00099 Device *device; 00100 Scene *scene; 00101 RenderBuffers *buffers; 00102 DisplayBuffer *display; 00103 Progress progress; 00104 SessionParams params; 00105 int sample; 00106 00107 Session(const SessionParams& params); 00108 ~Session(); 00109 00110 void start(); 00111 bool draw(BufferParams& params); 00112 void wait(); 00113 00114 bool ready_to_reset(); 00115 void reset(BufferParams& params, int samples); 00116 void set_samples(int samples); 00117 void set_pause(bool pause); 00118 00119 protected: 00120 struct DelayedReset { 00121 thread_mutex mutex; 00122 bool do_reset; 00123 BufferParams params; 00124 int samples; 00125 } delayed_reset; 00126 00127 void run(); 00128 00129 void update_scene(); 00130 void update_status_time(bool show_pause = false, bool show_done = false); 00131 00132 void tonemap(); 00133 void path_trace(Tile& tile); 00134 void reset_(BufferParams& params, int samples); 00135 00136 void run_cpu(); 00137 bool draw_cpu(BufferParams& params); 00138 void reset_cpu(BufferParams& params, int samples); 00139 00140 void run_gpu(); 00141 bool draw_gpu(BufferParams& params); 00142 void reset_gpu(BufferParams& params, int samples); 00143 00144 TileManager tile_manager; 00145 bool device_use_gl; 00146 00147 thread *session_thread; 00148 00149 volatile bool display_outdated; 00150 00151 volatile bool gpu_draw_ready; 00152 volatile bool gpu_need_tonemap; 00153 thread_condition_variable gpu_need_tonemap_cond; 00154 00155 bool pause; 00156 thread_condition_variable pause_cond; 00157 thread_mutex pause_mutex; 00158 00159 double start_time; 00160 double reset_time; 00161 double preview_time; 00162 double paused_time; 00163 }; 00164 00165 CCL_NAMESPACE_END 00166 00167 #endif /* __SESSION_H__ */ 00168