33 #include "texture_reference.h" 34 #include "texture_view.h" 36 #include <cugar/basic/types.h> 37 #include <cugar/linalg/vector.h> 52 template <BufferType TYPE>
57 template <BufferType UTYPE>
60 template <BufferType UTYPE>
69 const float4* ptr()
const {
return c.ptr(); }
70 float4* ptr() {
return c.ptr(); }
72 void resize(
const uint32 _res_x,
const uint32 _res_y)
77 c.alloc(res_x * res_y);
80 size_t size()
const {
return res_x * res_y; }
82 uint2 res()
const {
return make_uint2(res_x, res_y); }
109 template <BufferType TYPE>
113 typedef std::shared_ptr<TextureStorage<TYPE> > TexturePtr;
124 template <BufferType UTYPE>
127 this->operator=(other);
130 template <BufferType UTYPE>
135 n_levels = other.n_levels;
137 levels.alloc( n_levels );
138 for (uint32 l = 0; l < n_levels; ++l)
140 levels[l] = TexturePtr(
new TextureType);
141 *levels[l] = *other.levels[l];
144 level_views.alloc(n_levels);
145 for (uint32 l = 0; l < n_levels; ++l)
146 level_views.set(l, levels[l]->view());
151 void set(TexturePtr texture)
153 res_x = texture->res().x;
154 res_y = texture->res().y;
159 uint32 l_res_x = res_x;
160 uint32 l_res_y = res_y;
161 while (l_res_x >= 1 && l_res_y >= 1)
168 levels.alloc(n_levels);
177 level_views.alloc(n_levels);
178 for (uint32 l = 0; l < n_levels; ++l)
179 level_views.set(l, levels[l]->view());
182 void resize(
const uint32_t _res_x,
const uint32_t _res_y)
190 uint32 l_res_x = res_x;
191 uint32 l_res_y = res_y;
192 while (l_res_x >= 1 && l_res_y >= 1)
199 levels.alloc(n_levels);
204 uint32 l_res_x = res_x;
205 uint32 l_res_y = res_y;
206 while (l_res_x >= 1 && l_res_y >= 1)
208 levels[n_levels] = TexturePtr(
new TextureType);
209 levels[n_levels]->resize(l_res_x, l_res_y);
217 level_views.resize(n_levels);
218 for (uint32 l = 0; l < n_levels; ++l)
219 level_views.set(l, levels[l]->view());
226 uint32 l_res_x = res_x/2;
227 uint32 l_res_y = res_y/2;
228 while (l_res_x >= 1 && l_res_y >= 1)
230 levels[level] = TexturePtr(
new TextureType);
231 levels[level]->resize(l_res_x, l_res_y);
233 downsample(levels[level - 1], levels[level]);
241 static void downsample(TexturePtr src, TexturePtr dst)
246 for (uint32 y = 0; y < dst_view.res_y; ++y)
248 for (uint32 x = 0; x < dst_view.res_x; ++x)
251 for (uint32 j = 0; j < 2; ++j)
252 for (uint32 i = 0; i < 2; ++i)
255 dst_view(x, y) = t / 4.0f;
260 uint32 level_count()
const 262 return uint32(n_levels);
268 r.n_levels = n_levels;
271 r.levels = level_views.ptr();
Definition: texture_view.h:57
Definition: texture.h:110
Definition: texture_view.h:73