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 __BUFFERS_H__ 00020 #define __BUFFERS_H__ 00021 00022 #include "device_memory.h" 00023 00024 #include "util_string.h" 00025 #include "util_thread.h" 00026 #include "util_types.h" 00027 00028 CCL_NAMESPACE_BEGIN 00029 00030 class Device; 00031 struct float4; 00032 00033 /* Buffer Parameters 00034 Size of render buffer and how it fits in the full image (border render). */ 00035 00036 class BufferParams { 00037 public: 00038 /* width/height of the physical buffer */ 00039 int width; 00040 int height; 00041 00042 /* offset into and width/height of the full buffer */ 00043 int full_x; 00044 int full_y; 00045 int full_width; 00046 int full_height; 00047 00048 BufferParams() 00049 { 00050 width = 0; 00051 height = 0; 00052 00053 full_x = 0; 00054 full_y = 0; 00055 full_width = 0; 00056 full_height = 0; 00057 } 00058 00059 void get_offset_stride(int& offset, int& stride) 00060 { 00061 offset = -(full_x + full_y*width); 00062 stride = width; 00063 } 00064 00065 bool modified(const BufferParams& params) 00066 { 00067 return !(full_x == params.full_x 00068 && full_y == params.full_y 00069 && width == params.width 00070 && height == params.height 00071 && full_width == params.full_width 00072 && full_height == params.full_height); 00073 } 00074 }; 00075 00076 /* Render Buffers */ 00077 00078 class RenderBuffers { 00079 public: 00080 /* buffer parameters */ 00081 BufferParams params; 00082 /* float buffer */ 00083 device_vector<float4> buffer; 00084 /* random number generator state */ 00085 device_vector<uint> rng_state; 00086 /* mutex, must be locked manually by callers */ 00087 thread_mutex mutex; 00088 00089 RenderBuffers(Device *device); 00090 ~RenderBuffers(); 00091 00092 void reset(Device *device, BufferParams& params); 00093 float4 *copy_from_device(float exposure, int sample); 00094 00095 protected: 00096 void device_free(); 00097 00098 Device *device; 00099 }; 00100 00101 /* Display Buffer 00102 * 00103 * The buffer used for drawing during render, filled by tonemapping the render 00104 * buffers and converting to uchar4 storage. */ 00105 00106 class DisplayBuffer { 00107 public: 00108 /* buffer parameters */ 00109 BufferParams params; 00110 /* dimensions for how much of the buffer is actually ready for display. 00111 with progressive render we can be using only a subset of the buffer. 00112 if these are zero, it means nothing can be drawn yet */ 00113 int draw_width, draw_height; 00114 /* draw alpha channel? */ 00115 bool transparent; 00116 /* byte buffer for tonemapped result */ 00117 device_vector<uchar4> rgba; 00118 /* mutex, must be locked manually by callers */ 00119 thread_mutex mutex; 00120 00121 DisplayBuffer(Device *device); 00122 ~DisplayBuffer(); 00123 00124 void reset(Device *device, BufferParams& params); 00125 void write(Device *device, const string& filename); 00126 00127 void draw_set(int width, int height); 00128 void draw(Device *device); 00129 bool draw_ready(); 00130 00131 protected: 00132 void draw_transparency_grid(); 00133 void device_free(); 00134 00135 Device *device; 00136 }; 00137 00138 CCL_NAMESPACE_END 00139 00140 #endif /* __BUFFERS_H__ */ 00141