1#if TATOOINE_GL_AVAILABLE
2#ifndef TATOOINE_GPU_UPLOAD_H
3#define TATOOINE_GPU_UPLOAD_H
12template <
typename GPUReal>
19template <
typename GPUReal>
26template <
typename GPUReal>
33template <
typename GPUReal>
40template <
floating_po
int GPUReal =
float,
typename Tensor>
45 std::vector<GPUReal> gpu_data;
46 for (
auto const& d : data) {
47 if constexpr (std::is_floating_point_v<Tensor>) {
48 gpu_data.push_back(d);
51 gpu_data.push_back(d(i));
55 if constexpr (rank<Tensor>() == 0) {
56 return texture<
sizeof...(res), GPUReal, R>(gpu_data, res...);
57 }
else if constexpr (rank<Tensor>() == 1) {
58 return texture<
sizeof...(res), GPUReal, RG>(gpu_data, res...);
59 }
else if constexpr (rank<Tensor>() == 2) {
60 return texture<
sizeof...(res), GPUReal, RGB>(gpu_data, res...);
61 }
else if constexpr (rank<Tensor>() == 3) {
62 return texture<
sizeof...(res), GPUReal, RGBA>(gpu_data, res...);
66template <
size_t Dimensions,
typename TexComps,
floating_point GPUReal = float,
67 typename Tensor,
size_t... Is>
69 std::index_sequence<Is...> )
requires
71 return upload_tex<TexComps, GPUReal>(data.data(), data.size(Is)...);
74template <
size_t Dimensions,
typename TexComps,
typename GPUReal = float,
78 static_assert(Dimensions >= 1 && Dimensions <= 3);
79 return upload_tex<Dimensions, TexComps, GPUReal>(
80 data, std::make_index_sequence<Dimensions>{});
83template <
typename GPUReal =
float,
typename Tensor>
87 if constexpr (rank<Tensor>() == 0) {
88 return upload_tex<1, R, GPUReal>(data);
89 }
else if constexpr (rank<Tensor>() == 1) {
90 return upload_tex<1, RG, GPUReal>(data);
91 }
else if constexpr (rank<Tensor>() == 2) {
92 return upload_tex<1, RGB, GPUReal>(data);
93 }
else if constexpr (rank<Tensor>() == 3) {
94 return upload_tex<1, RGBA, GPUReal>(data);
98template <
typename GPUReal =
float,
typename Tensor>
102 if constexpr (rank<Tensor>() == 0) {
103 return upload_tex<2, R, GPUReal>(data);
104 }
else if constexpr (rank<Tensor>() == 1) {
105 return upload_tex<2, RG, GPUReal>(data);
106 }
else if constexpr (rank<Tensor>() == 2) {
107 return upload_tex<2, RGB, GPUReal>(data);
108 }
else if constexpr (rank<Tensor>() == 3) {
109 return upload_tex<2, RGBA, GPUReal>(data);
113template <
typename GPUReal =
float,
typename Tensor>
117 if constexpr (rank<Tensor>() == 0) {
118 return upload_tex<3, R, GPUReal>(data);
119 }
else if constexpr (rank<Tensor>() == 1) {
120 return upload_tex<3, RG, GPUReal>(data);
121 }
else if constexpr (rank<Tensor>() == 2) {
122 return upload_tex<3, RGB, GPUReal>(data);
123 }
else if constexpr (rank<Tensor>() == 3) {
124 return upload_tex<3, RGBA, GPUReal>(data);
131 HasNonConstReference>
const&
132 grid_vertex_property) {
134 std::vector<GPUReal> gpu_data;
135 gpu_data.reserve(grid_vertex_property.grid().vertices().size());
136 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
137 gpu_data.push_back(
static_cast<GPUReal
>(grid_vertex_property(is...)));
140 auto tex = texture<1, GPUReal, R>(gpu_data,
141 grid_vertex_property.grid().template size<0>());
142 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
148 bool HasNonConstReference>
150 HasNonConstReference>
const&
151 grid_vertex_property) {
153 std::vector<GPUReal> gpu_data;
154 gpu_data.reserve(grid_vertex_property.grid().vertices().size());
155 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
156 gpu_data.push_back(
static_cast<GPUReal
>(grid_vertex_property(is...)));
159 auto tex = texture<2, GPUReal, R>(gpu_data,
160 grid_vertex_property.grid().template size<0>(),
161 grid_vertex_property.grid().template size<1>());
162 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
169auto upload(typed_grid_vertex_property_interface<
171 grid_vertex_property) {
173 std::vector<GPUReal> gpu_data;
174 gpu_data.reserve(grid_vertex_property.grid().vertices().size());
175 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
176 gpu_data.push_back(
static_cast<GPUReal
>(grid_vertex_property(is...)));
179 auto tex = texture<3, GPUReal, R>(gpu_data,
180 grid_vertex_property.grid().template size<0>(),
181 grid_vertex_property.grid().template size<1>(),
182 grid_vertex_property.grid().template size<2>());
183 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
190 HasNonConstReference>
const&
191 grid_vertex_property) {
193 std::vector<GPUReal> gpu_data;
194 gpu_data.reserve(grid_vertex_property.grid().vertices().size() * 2);
195 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
196 auto const& v = grid_vertex_property(is...);
197 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
198 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
201 auto tex = texture<1, GPUReal, RG>(
202 gpu_data, grid_vertex_property.grid().template size<0>());
203 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
209 bool HasNonConstReference>
212 HasNonConstReference>
const& data) {
214 std::vector<GPUReal> gpu_data;
216 data.grid().vertices().iterate_indices([&](
auto const... is) {
217 auto const& v = data(is...);
218 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
219 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
222 auto tex = texture<2, GPUReal, RG>(gpu_data, data.grid().template size<0>(),
223 data.grid().template size<1>());
224 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
231auto upload(typed_grid_vertex_property_interface<
233 HasNonConstReference>
const& grid_vertex_property) {
235 std::vector<GPUReal> gpu_data;
236 gpu_data.reserve(grid_vertex_property.grid().vertices().size() * 2);
237 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
238 auto const& v = grid_vertex_property(is...);
239 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
240 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
243 auto tex = texture<3, GPUReal, RG>(
244 gpu_data, grid_vertex_property.grid().template size<0>(),
245 grid_vertex_property.grid().template size<1>(),
246 grid_vertex_property.grid().template size<2>());
247 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
254 HasNonConstReference>
const&
255 grid_vertex_property) {
257 std::vector<GPUReal> gpu_data;
258 gpu_data.reserve(grid_vertex_property.grid().vertices().size() * 3);
259 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
260 auto const& v = grid_vertex_property(is...);
261 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
262 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
263 gpu_data.push_back(
static_cast<GPUReal
>(v(2)));
266 auto tex = texture<1, GPUReal, RGB>(
267 gpu_data, grid_vertex_property.grid().template size<0>());
268 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
274 bool HasNonConstReference>
275auto upload(typed_grid_vertex_property_interface<
277 grid_vertex_property) {
279 std::vector<GPUReal> gpu_data;
280 gpu_data.reserve(grid_vertex_property.grid().vertices().size() * 3);
281 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
282 auto const& v = grid_vertex_property(is...);
283 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
284 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
285 gpu_data.push_back(
static_cast<GPUReal
>(v(2)));
288 auto tex = texture<2, GPUReal, RGB>(
289 gpu_data, grid_vertex_property.grid().template size<0>(),
290 grid_vertex_property.grid().template size<1>());
291 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
298auto upload(typed_grid_vertex_property_interface<
300 HasNonConstReference>
const& grid_vertex_property) {
302 std::vector<GPUReal> gpu_data;
303 gpu_data.reserve(grid_vertex_property.grid().vertices().size() * 3);
304 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
305 auto const& v = grid_vertex_property(is...);
306 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
307 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
308 gpu_data.push_back(
static_cast<GPUReal
>(v(2)));
311 auto tex = texture<3, GPUReal, RGB>(
312 gpu_data, grid_vertex_property.grid().template size<0>(),
313 grid_vertex_property.grid().template size<1>(),
314 grid_vertex_property.grid().template size<2>());
315 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
322 HasNonConstReference>
const&
323 grid_vertex_property) {
325 std::vector<GPUReal> gpu_data;
326 gpu_data.reserve(grid_vertex_property.grid().vertices().size() * 4);
327 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
328 auto const& v = grid_vertex_property(is...);
329 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
330 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
331 gpu_data.push_back(
static_cast<GPUReal
>(v(2)));
332 gpu_data.push_back(
static_cast<GPUReal
>(v(3)));
335 auto tex = texture<1, GPUReal, RGBA>(
336 gpu_data, grid_vertex_property.grid().template size<0>());
337 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
343 bool HasNonConstReference>
344auto upload(typed_grid_vertex_property_interface<
346 grid_vertex_property) {
348 std::vector<GPUReal> gpu_data;
349 gpu_data.reserve(grid_vertex_property.grid().vertices().size() * 4);
350 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
351 auto const& v = grid_vertex_property(is...);
352 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
353 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
354 gpu_data.push_back(
static_cast<GPUReal
>(v(2)));
355 gpu_data.push_back(
static_cast<GPUReal
>(v(3)));
358 auto tex = texture<2, GPUReal, RGBA>(
359 gpu_data, grid_vertex_property.grid().template size<0>(),
360 grid_vertex_property.grid().template size<1>());
361 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
368auto upload(typed_grid_vertex_property_interface<
370 HasNonConstReference>
const& grid_vertex_property) {
372 std::vector<GPUReal> gpu_data;
373 grid_vertex_property.reserve(gpu_data.grid().vertices().size() * 4);
374 grid_vertex_property.grid().vertices().iterate_indices([&](
auto const... is) {
375 auto const& v = grid_vertex_property(is...);
376 gpu_data.push_back(
static_cast<GPUReal
>(v(0)));
377 gpu_data.push_back(
static_cast<GPUReal
>(v(1)));
378 gpu_data.push_back(
static_cast<GPUReal
>(v(2)));
379 gpu_data.push_back(
static_cast<GPUReal
>(v(3)));
382 auto tex = texture<3, GPUReal, RGBA>(
383 gpu_data, grid_vertex_property.grid().template size<0>(),
384 grid_vertex_property.grid().template size<1>(),
385 grid_vertex_property.grid().template size<2>());
386 tex.set_wrap_mode(gl::CLAMP_TO_EDGE);
Definition: dynamic_multidim_array.h:18
constexpr auto data(std::size_t const i) -> auto &
Definition: dynamic_multidim_array.h:311
auto width() const
Definition: texture.h:740
auto height() const
Definition: texture.h:742
auto download_data() const
Definition: texture.h:520
Definition: rectilinear_grid.h:38
Definition: concepts.h:94
Definition: concepts.h:30
Definition: concepts.h:21
Definition: tensor_concepts.h:23
Definition: line_renderer.h:7
auto upload_tex3d(const dynamic_multidim_array< Tensor > &data)
Definition: upload.h:114
auto upload_tex1d(dynamic_multidim_array< Tensor > const &data)
Definition: upload.h:84
auto upload_tex2d(const dynamic_multidim_array< Tensor > &data)
Definition: upload.h:99
auto download(gl::texture< 2, GPUReal, gl::R > const &tex)
Definition: upload.h:13
auto upload(const parameterized_line< Real, N, Interpolator > &l)
Definition: line_renderer.h:10
auto upload_tex(std::vector< Tensor > const &data, integral auto const ... res)
Definition: upload.h:41
tensor< real_number, Dimensions... > Tensor
Definition: tensor.h:184