-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmaterial_image_helpers.hpp
1949 lines (1755 loc) · 146 KB
/
material_image_helpers.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include "image_data.hpp"
#include "material_gpu_data_ext.hpp"
#include "model.hpp"
#include "serializer.hpp"
#include "context_vulkan.hpp"
namespace avk
{
static std::tuple<avk::image, avk::command::action_type_command> create_1px_texture_cached(std::array<uint8_t, 4> aColor, avk::layout::image_layout aImageLayout, vk::Format aFormat = vk::Format::eR8G8B8A8Unorm, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_texture, std::optional<std::reference_wrapper<avk::serializer>> aSerializer = {})
{
auto stagingBuffer = context().create_buffer(
AVK_STAGING_BUFFER_MEMORY_USAGE,
vk::BufferUsageFlagBits::eTransferSrc,
avk::generic_buffer_meta::create_from_size(sizeof(aColor))
);
if (!aSerializer) {
auto nop = stagingBuffer->fill(aColor.data(), 0);
assert(!nop.mBeginFun);
assert(!nop.mEndFun);
}
else if (aSerializer && aSerializer->get().mode() == avk::serializer::mode::serialize) {
auto nop = stagingBuffer->fill(aColor.data(), 0);
assert(!nop.mBeginFun);
assert(!nop.mEndFun);
aSerializer->get().archive_memory(aColor.data(), sizeof(aColor));
}
else if (aSerializer && aSerializer->get().mode() == avk::serializer::mode::deserialize) {
aSerializer->get().archive_buffer(*stagingBuffer);
}
auto img = context().create_image(1u, 1u, aFormat, 1, aMemoryUsage, aImageUsage);
using namespace avk;
auto actionTypeCommand = avk::command::action_type_command{
{},
{ // Resource-specific sync-hints (will be accumulated later into mSyncHint):
// No need for a sync hint for the staging buffer; it is in host-visible memory. Nothing must be waited on before we can start to fill it.
std::make_tuple(img->handle(), avk::sync::sync_hint{ // But create a sync hint for the image:
avk::stage::none + avk::access::none, // No need for any dependencies to previous commands. The host-visible data is made available on the queue submit.
avk::stage::transfer + avk::access::transfer_write // Dependency chain with the last image_memory_barrier
})
},
{}, // No mBeginFun, only nested commands:
{
avk::sync::image_memory_barrier(*img, // No need to wait on the staging buffer since it is in host-visible memory
avk::stage::none >> avk::stage::copy,
avk::access::none >> avk::access::transfer_read | avk::access::transfer_write // Just wait on the image layout transition
).with_layout_transition(avk::layout::undefined >> avk::layout::transfer_dst),
copy_buffer_to_image(stagingBuffer, img.get(), avk::layout::transfer_dst),
avk::sync::image_memory_barrier(*img,
avk::stage::copy >> avk::stage::transfer,
avk::access::transfer_write >> avk::access::none
).with_layout_transition(avk::layout::transfer_dst >> aImageLayout)
}
};
actionTypeCommand.infer_sync_hint_from_resource_sync_hints();
return std::make_tuple(std::move(img), std::move(actionTypeCommand));
}
static std::tuple<avk::image, avk::command::action_type_command> create_1px_texture(std::array<uint8_t, 4> aColor, avk::layout::image_layout aImageLayout, vk::Format aFormat = vk::Format::eR8G8B8A8Unorm, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_texture)
{
return create_1px_texture_cached(aColor, aImageLayout, aFormat, aMemoryUsage, aImageUsage);
}
static std::tuple<avk::image, avk::command::action_type_command> create_1px_texture_cached(avk::serializer& aSerializer, std::array<uint8_t, 4> aColor, avk::layout::image_layout aImageLayout, vk::Format aFormat = vk::Format::eR8G8B8A8Unorm, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_texture)
{
return create_1px_texture_cached(aColor, aImageLayout, aFormat, aMemoryUsage, aImageUsage, aSerializer);
}
/** Create image_data from texture file
* @param aPath file name of a texture file to load the image data from
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @return an object referencing the possibly converted and transformed image data
*/
static image_data get_image_data(const std::string& aPath, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true,
int aPreferredNumberOfTextureComponents = 4)
{
image_data result(aPath, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents);
return result;
}
/** Create cube map image_data from individual texture files for each face
* @param aPaths a vector of file names of texture files to load the image data from. The vector must contain six file names, each specifying one side of a cube map texture, in the order +X, -X, +Y, -Y, +Z, -Z. The image data from all files must have the same dimensions and texture formats, after possible HDR and sRGB conversions.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @return an object referencing the possibly converted and transformed image data
*/
static image_data get_image_data(const std::vector<std::string>& aPaths, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true,
int aPreferredNumberOfTextureComponents = 4)
{
image_data result(aPaths, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents);
return result;
}
/** Create cube map from image_data, with optional caching
* Loads image data from an image_data object or the serializer cache.
* @param aImageData a valid instance of image_data containing cube map image data.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
* @param aSerializer a serializer to use for caching data loaded from disk.
*/
extern std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_image_data_cached(image_data& aImageData, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture, std::optional<std::reference_wrapper<avk::serializer>> aSerializer = {});
/** Create cube map from image_data, with caching
* Loads image data from an image_data object or the serializer cache.
* @param aSerializer a serializer to use for caching data loaded from disk.
* @param aImageData a valid instance of image_data containing cube map image data.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_image_data_cached(avk::serializer& aSerializer, image_data& aImageData, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture)
{
return create_cubemap_from_image_data_cached(aImageData, aImageLayout, aMemoryUsage, aImageUsage, aSerializer);
}
/** Create cube map from image_data
* Loads image data from an image_data object.
* @param aImageData a valid instance of image_data containing cube map image data.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_image_data(image_data& aImageData, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture)
{
return create_cubemap_from_image_data_cached(aImageData, aImageLayout, aMemoryUsage, aImageUsage);
}
/** Create cube map from a single file, with optional caching
* Loads image data from a file or the serializer cache.
* @param aPath file name of a texture file to load the image data from.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
* @param aSerializer a serializer to use for caching data loaded from disk.
*/
extern std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_file_cached(const std::string& aPath, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true,
int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture, std::optional<std::reference_wrapper<avk::serializer>> aSerializer = {});
/** Create cube map from a single file, with caching
* Loads image data from a file or the serializer cache.
* @param aSerializer a serializer to use for caching data loaded from disk.
* @param aPath file name of a texture file to load the image data from.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_file_cached(avk::serializer& aSerializer, const std::string& aPath, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true,
int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture)
{
return create_cubemap_from_file_cached(aPath, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents, aImageLayout, aMemoryUsage, aImageUsage, aSerializer);
}
/** Create cube map from a single file
* Loads image data from a file.
* @param aPath file name of a texture file to load the image data from.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_file(const std::string& aPath, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true,
int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture)
{
return create_cubemap_from_file_cached(aPath, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents, aImageLayout, aMemoryUsage, aImageUsage);
}
/** Create cube map from six individual files, with optional caching
* Loads image data from files or the serializer cache.
* @param aPaths a vector of file names of texture files to load the image data from. The vector must contain six file names, each specifying one side of a cube map texture, in the order +X, -X, +Y, -Y, +Z, -Z. The image data from all
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
* @param aSerializer a serializer to use for caching data loaded from disk.
*/
extern std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_file_cached(const std::vector<std::string>& aPaths, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true,
int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture, std::optional<std::reference_wrapper<avk::serializer>> aSerializer = {});
/** Create cube map from six individual files, with caching
* Loads image data from files or the serializer cache.
* @param aSerializer a serializer to use for caching data loaded from disk.
* @param aPaths a vector of file names of texture files to load the image data from. The vector must contain six file names, each specifying one side of a cube map texture, in the order +X, -X, +Y, -Y, +Z, -Z. The image data from all files must have the same dimensions and texture formats, after possible HDR and sRGB conversions.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_file_cached(avk::serializer& aSerializer, const std::vector<std::string>& aPaths, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true, int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture)
{
return create_cubemap_from_file_cached(aPaths, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents, aImageLayout, aMemoryUsage, aImageUsage, aSerializer);
}
/** Create cube map from six individual files
* Loads image data from files or the serializer cache.
* @param aPaths a vector of file names of texture files to load the image data from. The vector must contain six file names, each specifying one side of a cube map texture, in the order +X, -X, +Y, -Y, +Z, -Z. The image data from all files must have the same dimensions and texture formats, after possible HDR and sRGB conversions.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_cubemap_from_file(const std::vector<std::string>& aPaths, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true, int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_cube_map_texture)
{
return create_cubemap_from_file_cached(aPaths, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents, aImageLayout, aMemoryUsage, aImageUsage);
}
/** Create image from image_data, with optional caching
* Loads image data from an image_data object or the serializer cache.
* @param aImageData the image data to create the image from.
* @param aImageLayout the image layout which the resulting image shall be tranformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
* @param aSerializer a serializer to use for caching data loaded from disk.
*/
extern std::tuple<avk::image, avk::command::action_type_command> create_image_from_image_data_cached(image_data& aImageData, avk::layout::image_layout aImageLayout, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_texture, std::optional<std::reference_wrapper<avk::serializer>> aSerializer = {});
/** Create image from image_data, with caching
* Loads image data from an image_data object or the serializer cache.
* @param aSerializer a serializer to use for caching data loaded from disk.
* @param aImageData the image data to create the image from.
* @param aImageLayout the image layout which the resulting image shall be tranformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_image_from_image_data_cached(avk::serializer& aSerializer, image_data& aImageData, avk::layout::image_layout aImageLayout, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_texture)
{
return create_image_from_image_data_cached(aImageData, aImageLayout, aMemoryUsage, aImageUsage, aSerializer);
}
/** Create image from image_data
* Loads image data from an image_data object.
* @param aImageData the image data to create the image from.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_image_from_image_data(image_data& aImageData, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device,
avk::image_usage aImageUsage = avk::image_usage::general_texture)
{
return create_image_from_image_data_cached(aImageData, aImageLayout, aMemoryUsage, aImageUsage);
}
/** Create image from a single file, with optional caching
* Loads image data from a file or the serializer cache.
* @param aPath file name of a texture file to load the image data from.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
* @param aSerializer a serializer to use for caching data loaded from disk.
*/
extern std::tuple<avk::image, avk::command::action_type_command> create_image_from_file_cached(const std::string& aPath, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true, int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_texture, std::optional<std::reference_wrapper<avk::serializer>> aSerializer = {});
/** Create image from a single file, with caching
* Loads image data from a file or the serializer cache.
* @param aSerializer a serializer to use for caching data loaded from disk.
* @param aPath file name of a texture file to load the image data from.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_image_from_file_cached(avk::serializer& aSerializer, const std::string& aPath, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true, int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_texture)
{
return create_image_from_file_cached(aPath, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents, aImageLayout, aMemoryUsage, aImageUsage, aSerializer);
}
/** Create image from a single file
* Loads image data from a file.
* @param aPath file name of a texture file to load the image data from.
* @param aLoadHdrIfPossible load the texture as HDR (high dynamic range) data, if supported by the image loading library. If set to true, the image data may be returned in a HDR format even if the texture file does not contain HDR data. If set to false, the image data may be returned in an LDR format even if the texture contains HDR data. It is therefore advised to set this parameter according to the data format of the texture file.
* @param aLoadSrgbIfApplicable load the texture as sRGB color-corrected data, if supported by the image loading library. If set to true, the image data may be returned in an sRGB format even if the texture file does not contain sRGB data. If set to false, the image data may be returned in a plain RGB format even if the texture contains sRGB data. It is therefore advised to set this parameter according to the color space of the texture file.
* @param aFlip flip the image vertically (upside-down) if set to true. This may be needed if the layout of the image data in the texture file does not match the texture coordinates with which it is used. This parameter may not be supported for all image loaders and texture formats, in particular for some compressed textures.
* @param aPreferredNumberOfTextureComponents defines the number of color channels in the returned image_data. The default of 4 corresponds to RGBA texture components. A value of 1 and 2 denote grey value and grey value with alpha, respectively. If the texture file does not contain an alpha channel, the result will be fully opaque. Note that many Vulkan implementations only support textures with RGBA components. This parameter may be ignored by the image loader.
* @param aImageLayout the image layout that the image shall be transformed into
* @param aMemoryUsage the intended memory usage of the returned image resource.
* @param aImageUsage the intended image usage of the returned image resource.
*/
static std::tuple<avk::image, avk::command::action_type_command> create_image_from_file(const std::string& aPath, bool aLoadHdrIfPossible = true, bool aLoadSrgbIfApplicable = true, bool aFlip = true, int aPreferredNumberOfTextureComponents = 4, avk::layout::image_layout aImageLayout = avk::layout::general, avk::memory_usage aMemoryUsage = avk::memory_usage::device, avk::image_usage aImageUsage = avk::image_usage::general_texture)
{
return create_image_from_file_cached(aPath, aLoadHdrIfPossible, aLoadSrgbIfApplicable, aFlip, aPreferredNumberOfTextureComponents, aImageLayout, aMemoryUsage, aImageUsage);
}
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult)
{ }
// Forward-declare some overloads:
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult, const model& aModel, const Rest&... rest);
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult, const avk::mesh_index_t& aMeshIndex, const Rest&... rest);
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult, const std::vector<avk::mesh_index_t>& aMeshIndices, const Rest&... rest);
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult, const model_t& aModel, const Rest&... rest)
{
aResult.push_back(std::forward_as_tuple(aModel, std::vector<avk::mesh_index_t>{}));
add_tuple_or_indices(aResult, rest...);
}
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult, const model& aModel, const Rest&... rest)
{
// Convenience overload to also support owning_resource references:
add_tuple_or_indices(aResult, aModel.get(), rest...);
}
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult, const avk::mesh_index_t& aMeshIndex, const Rest&... rest)
{
std::get<std::vector<avk::mesh_index_t>>(aResult.back()).emplace_back(aMeshIndex);
add_tuple_or_indices(aResult, rest...);
}
template <typename... Rest>
void add_tuple_or_indices(std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aResult, const std::vector<avk::mesh_index_t>& aMeshIndices, const Rest&... rest)
{
auto& idxes = std::get<std::vector<avk::mesh_index_t>>(aResult.back());
idxes.insert(std::end(idxes), std::begin(aMeshIndices), std::end(aMeshIndices));
add_tuple_or_indices(aResult, rest...);
}
/** This is a convenience method that allows to compile a selection of models and mesh indices.
* Valid usage means passing a model as parameter, and following it up with one or multiple mesh index parameters.
*
* Model parameters must be bindable by const model&.
* Mesh index parameters are supported in the forms:
* - avk::mesh_index_t
* - std::vector<avk::mesh_index_t>
*
* Examples of valid parameters:
* - make_models_and_meshes_selection(myModel, 1, 2, 3); // => a model and 3x avk::mesh_index_t
* - make_models_and_meshes_selection(myModel, 1, std::vector<avk::mesh_index_t>{ 2, 3 }); // => a model and then 1x avk::mesh_index_t, and 1x vector of avk::mesh_index_t (containing two indices)
* - make_models_and_meshes_selection(myModel, 1, myOtherModel, std::vector<avk::mesh_index_t>{ 0, 1 }); // => a model and then 1x avk::mesh_index_t; another model and 1x vector of avk::mesh_index_t (containing two indices)
*/
template <typename... Args>
std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>> make_model_references_and_mesh_indices_selection(const Args&... args)
{
std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>> result;
add_tuple_or_indices(result, args...);
return result;
}
template <typename... Rest>
void add_tuple_or_indices_shared(std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>>& aResult)
{ }
// Forward-declare some of the overloads:
template <typename... Rest>
void add_tuple_or_indices_shared(std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>>& aResult, avk::mesh_index_t& aMeshIndex, Rest&... rest);
template <typename... Rest>
void add_tuple_or_indices_shared(std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>>& aResult, std::vector<avk::mesh_index_t>& aMeshIndices, Rest&... rest);
template <typename... Rest>
void add_tuple_or_indices_shared(std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>>& aResult, model& aModel, Rest&... rest)
{
aResult.push_back(std::forward_as_tuple(aModel, std::vector<avk::mesh_index_t>{}));
add_tuple_or_indices_shared(aResult, rest...);
}
template <typename... Rest>
void add_tuple_or_indices_shared(std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>>& aResult, avk::mesh_index_t& aMeshIndex, Rest&... rest)
{
std::get<std::vector<avk::mesh_index_t>>(aResult.back()).emplace_back(aMeshIndex);
add_tuple_or_indices_shared(aResult, rest...);
}
template <typename... Rest>
void add_tuple_or_indices_shared(std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>>& aResult, std::vector<avk::mesh_index_t>& aMeshIndices, Rest&... rest)
{
auto& idxes = std::get<std::vector<avk::mesh_index_t>>(aResult.back());
idxes.insert(std::end(idxes), std::begin(aMeshIndices), std::end(aMeshIndices));
add_tuple_or_indices_shared(aResult, rest...);
}
/** This is a convenience function that allows to compile a selection of models and associated mesh indices.
* Valid usage means passing a model as parameter, and following it up with one or multiple mesh index parameters.
*
* Shared ownership will be enabled on the models.
* Mesh index parameters are supported in the forms:
* - avk::mesh_index_t
* - std::vector<avk::mesh_index_t>
*
* Examples of valid parameters:
* - make_selection_of_shared_models_and_mesh_indices(myModel, 1, 2, 3); // => a model and 3x avk::mesh_index_t
* - make_selection_of_shared_models_and_mesh_indices(myModel, 1, std::vector<avk::mesh_index_t>{ 2, 3 }); // => a model and then 1x avk::mesh_index_t, and 1x vector of avk::mesh_index_t (containing two indices)
* - make_selection_of_shared_models_and_mesh_indices(myModel, 1, myOtherModel, std::vector<avk::mesh_index_t>{ 0, 1 }); // => a model and then 1x avk::mesh_index_t; another model and 1x vector of avk::mesh_index_t (containing two indices)
*/
template <typename... Args>
std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>> make_models_and_mesh_indices_selection(Args&... args)
{
std::vector<std::tuple<avk::model, std::vector<mesh_index_t>>> result;
add_tuple_or_indices_shared(result, args...);
return result;
}
/** Helper function to fill a given device buffer with a staging buffer whose contents are loaded from a cache file.
* @param aSerializer The serializer in avk::serializer::mode::deserialize
* @param aQueue The queue to submit the commands to
* @param aDeviceBuffer The target buffer
* @param aTotalSize Size of the staging buffer
*/
static inline avk::command::action_type_command fill_device_buffer_from_cache(avk::serializer& aSerializer, avk::resource_argument<avk::buffer_t> aDeviceBuffer, size_t aTotalSize)
{
assert(aSerializer.mode() == avk::serializer::mode::deserialize);
// Create host visible staging buffer for filling on host side from file
auto sb = context().create_buffer(
AVK_STAGING_BUFFER_MEMORY_USAGE,
vk::BufferUsageFlagBits::eTransferSrc,
avk::generic_buffer_meta::create_from_size(aTotalSize)
);
// Let the serializer map and fill the buffer
aSerializer.archive_buffer(*sb);
auto actionTypeCommand = avk::copy_buffer_to_another(std::move(sb), std::move(aDeviceBuffer), 0, 0, aTotalSize);
return actionTypeCommand;
}
/** Get a tuple of <0>:vertices and <1>:indices from the given selection of models and associated mesh indices.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @return Combined position and index data of all specified model + mesh-indices tuples, where the returned tuple's elements refer to:
* <0>: vertex positions
* <1>: indices
*/
extern std::tuple<std::vector<glm::vec3>, std::vector<uint32_t>> get_vertices_and_indices(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
/** Get a tuple of <0>:vertices and <1>:indices from the given selection of models and associated mesh indices.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. The order is maintained.
* @return Combined position and index data of all specified model + mesh-indices tuples, where the returned tuple's elements refer to:
* <0>: vertex positions
* <1>: indices
*/
extern std::tuple<std::vector<glm::vec3>, std::vector<uint32_t>> get_vertices_and_indices_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
// A concept which requires a type to have a .describe_member(size_t aOffset, content_description aContent)
template <typename T>
concept has_describe_member = requires (T x)
{
x.describe_member(size_t{ 0 }, vk::Format::eUndefined, avk::content_description::position);
};
// A concept which requires a type to have a .set_format<glm::uvec3>(avk::content_description)
template <typename T>
concept has_set_format_for_index_buffer = requires (T x)
{
x.template set_format<glm::uvec3>(avk::content_description::index);
};
// Helper which creates meta data for uniform/storage_texel_buffer_view metas:
template <typename Meta>
auto set_up_meta_from_data_for_index_buffer(const std::vector<uint32_t>& aIndicesData) requires has_set_format_for_index_buffer<Meta>
{
return Meta::create_from_data(aIndicesData).template set_format<glm::uvec3>(avk::content_description::index); // Combine 3 consecutive elements to one unit
}
// ...and another helper which creates metas for other Meta types:
template <typename Meta>
auto set_up_meta_from_data_for_index_buffer(const std::vector<uint32_t>& aIndicesData) requires (!has_set_format_for_index_buffer<Meta>)
{
return Meta::create_from_data(aIndicesData);
}
// Helper which creates meta data for uniform/storage_texel_buffer_view metas:
template <typename Meta>
auto set_up_meta_from_data_for_vertex_buffer(const std::vector<glm::vec3>& aVerticesData) requires has_describe_member<Meta>
{
return Meta::create_from_data(aVerticesData).describe_member(0, avk::format_for<std::remove_reference_t<decltype(aVerticesData)>::value_type>(), avk::content_description::position);
}
// ...and another helper which creates metas for other Meta types:
template <typename Meta>
auto set_up_meta_from_data_for_vertex_buffer(const std::vector<glm::vec3>& aVerticesData) requires (!has_describe_member<Meta>)
{
return Meta::create_from_data(aVerticesData);
}
// Helper which creates meta data for uniform/storage_texel_buffer_view from size specification
template <typename Meta>
auto set_up_meta_from_total_size_for_index_buffer(size_t aTotalSize, size_t aNumElements) requires has_set_format_for_index_buffer<Meta>
{
return Meta::create_from_total_size(aTotalSize, aNumElements).template set_format<glm::uvec3>(avk::content_description::index); // Combine 3 consecutive elements to one unit
}
// ...and another helper which creates metas for other Meta types:
template <typename Meta>
auto set_up_meta_from_total_size_for_index_buffer(size_t aTotalSize, size_t aNumElements) requires (!has_set_format_for_index_buffer<Meta>)
{
return Meta::create_from_total_size(aTotalSize, aNumElements);
}
// Helper which creates meta data for uniform/storage_texel_buffer_view from size specification
template <typename Meta, typename FMT>
auto set_up_meta_from_total_size_for_vertex_buffer(size_t aTotalSize, size_t aNumElements) requires has_describe_member<Meta>
{
return Meta::create_from_total_size(aTotalSize, aNumElements).describe_member(0, avk::format_for<FMT>(), avk::content_description::position);
}
// ...and another helper which creates metas for other Meta types:
template <typename Meta, typename FMT>
auto set_up_meta_from_total_size_for_vertex_buffer(size_t aTotalSize, size_t aNumElements) requires (!has_describe_member<Meta>)
{
return Meta::create_from_total_size(aTotalSize, aNumElements);
}
// Helper which creates meta data for a given data + content description, but only if the Meta type in question has a describe_member member:
template <typename T, typename Meta>
auto set_up_meta_for_data_with_or_without_describe_member(const T& aData, avk::content_description aContentDescription) requires has_describe_member<Meta>
{
return Meta::create_from_data(aData).describe_member(0, avk::format_for<typename std::remove_reference_t<decltype(aData)>::value_type>(), aContentDescription);
}
// Helper which creates meta data for a given data + content description, but only if the Meta type in question has a describe_member member:
template <typename T, typename Meta>
auto set_up_meta_for_data_with_or_without_describe_member(const T& aData, avk::content_description aContentDescription) requires (!has_describe_member<Meta>)
{
return Meta::create_from_data(aData);
}
// Helper which creates meta data for a given data + size specifications, but only if the Meta type in question has a describe_member member:
template <typename T, typename Meta>
auto set_up_meta_from_total_size_with_or_without_describe_member(const T& aData, size_t bufferTotalSize, size_t numBufferEntries, avk::content_description aContentDescription) requires has_describe_member<Meta>
{
return Meta::create_from_total_size(bufferTotalSize, numBufferEntries).describe_member(0, avk::format_for<typename std::remove_reference_t<decltype(aData)>::value_type>(), aContentDescription);
}
// Helper which creates meta data for a given data + size specifications, but only if the Meta type in question has a describe_member member:
template <typename T, typename Meta>
auto set_up_meta_from_total_size_with_or_without_describe_member(const T& aData, size_t bufferTotalSize, size_t numBufferEntries, avk::content_description aContentDescription) requires (!has_describe_member<Meta>)
{
return Meta::create_from_total_size(bufferTotalSize, numBufferEntries);
}
/** Get a tuple of two buffers, containing vertex positions and index positions, respectively, from the given input data.
* @param aVerticesAndIndices A tuple containing vertex positions data in the first element, and index data in the second element.
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of each buffer besides their obligatory
* avk::vertex_buffer_meta, and avk::index_buffer_meta, as appropriate for the two buffers.
* The additional meta data declarations will always refer to the whole data in the buffers; specifying subranges is not supported.
* @return A tuple of two buffers in device memory which contain the given input data, where the returned tuple's elements refer to:
* <0>: Buffer containing vertex positions. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <2>) have completed execution.
* <1>: Buffer containing indices. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <2>) have completed execution.
* <2>: Commands that need to be executed on a queue to complete the operation.
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::buffer, avk::command::action_type_command> create_vertex_and_index_buffers(const std::tuple<std::vector<glm::vec3>, std::vector<uint32_t>>& aVerticesAndIndices, vk::BufferUsageFlags aUsageFlags = {})
{
const auto& [positionsData, indicesData] = aVerticesAndIndices;
avk::command::action_type_command actionTypeCommand{};
auto positionsBuffer = context().create_buffer(
avk::memory_usage::device, aUsageFlags,
avk::vertex_buffer_meta::create_from_data(positionsData).describe_member(0, avk::format_for<typename std::remove_reference_t<decltype(positionsData)>::value_type>(), avk::content_description::position),
set_up_meta_from_data_for_vertex_buffer<Metas>(positionsData)...
);
actionTypeCommand.mNestedCommandsAndSyncInstructions.push_back(positionsBuffer->fill(positionsData.data(), 0));
// It is fine to let positionsData go out of scope, since its data has been copied to a
// staging buffer within fill, which is lifetime-handled by the command buffer.
auto indexBuffer = context().create_buffer(
avk::memory_usage::device, aUsageFlags,
avk::index_buffer_meta::create_from_data(indicesData),
set_up_meta_from_data_for_index_buffer<Metas>(indicesData)...
);
actionTypeCommand.mNestedCommandsAndSyncInstructions.push_back(indexBuffer->fill(indicesData.data(), 0));
actionTypeCommand.infer_sync_hint_from_nested_commands();
return std::make_tuple(std::move(positionsBuffer), std::move(indexBuffer), std::move(actionTypeCommand));
}
/** Get a tuple of two buffers, containing vertex positions and index positions, respectively, from the given input data.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of each buffer besides their obligatory
* avk::vertex_buffer_meta, and avk::index_buffer_meta, as appropriate for the two buffers.
* The additional meta data declarations will always refer to the whole data in the buffers; specifying subranges is not supported.
* @return A tuple of two buffers in device memory which contain the given input data, where the returned tuple's elements refer to:
* <0>: buffer containing vertex positions
* <1>: buffer containing indices
* <2>: commands that need to be executed on a queue to complete the operation
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::buffer, avk::command::action_type_command> create_vertex_and_index_buffers(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
return create_vertex_and_index_buffers<Metas...>(get_vertices_and_indices(aModelsAndSelectedMeshes), aUsageFlags);
}
/** Get a tuple of two buffers, containing vertex positions and index positions, respectively, from the given input data.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aVerticesAndIndices A tuple containing vertex positions data in the first element, and index data in the second element.
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of each buffer besides their obligatory
* avk::vertex_buffer_meta, and avk::index_buffer_meta, as appropriate for the two buffers.
* The additional meta data declarations will always refer to the whole data in the buffers; specifying subranges is not supported.
* @return A tuple of two buffers in device memory which contain the given input data, where the tuple elements refer to:
* <0>: Buffer containing vertex positions. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <2>) have completed execution.
* <1>: Buffer containing indices. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <2>) have completed execution.
* <2>: Commands that need to be executed on a queue to complete the operation.
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::buffer, avk::command::action_type_command> create_vertex_and_index_buffers_cached(avk::serializer& aSerializer, std::tuple<std::vector<glm::vec3>, std::vector<uint32_t>>& aVerticesAndIndices, vk::BufferUsageFlags aUsageFlags = {})
{
size_t numPositions = 0;
size_t totalPositionsSize = 0;
size_t numIndices = 0;
size_t totalIndicesSize = 0;
auto& [positionsData, indicesData] = aVerticesAndIndices;
if (aSerializer.mode() == avk::serializer::mode::serialize) {
numPositions = positionsData.size();
totalPositionsSize = sizeof(std::remove_reference_t<decltype(positionsData)>::value_type) * numPositions;
numIndices = indicesData.size();
totalIndicesSize = sizeof(std::remove_reference_t<decltype(indicesData)>::value_type) * numIndices;
aSerializer.archive(numPositions);
aSerializer.archive(totalPositionsSize);
aSerializer.archive(numIndices);
aSerializer.archive(totalIndicesSize);
aSerializer.archive_memory(positionsData.data(), totalPositionsSize);
aSerializer.archive_memory(indicesData.data(), totalIndicesSize);
return create_vertex_and_index_buffers<Metas...>(std::make_tuple(std::move(positionsData), std::move(indicesData)), aUsageFlags);
}
else {
aSerializer.archive(numPositions);
aSerializer.archive(totalPositionsSize);
aSerializer.archive(numIndices);
aSerializer.archive(totalIndicesSize);
auto positionsBuffer = context().create_buffer(
avk::memory_usage::device, aUsageFlags,
avk::vertex_buffer_meta::create_from_total_size(totalPositionsSize, numPositions).describe_member(0, avk::format_for<typename std::remove_reference_t<decltype(positionsData)>::value_type>(), avk::content_description::position),
set_up_meta_from_total_size_for_vertex_buffer<Metas, std::remove_reference_t<decltype(positionsData)>::value_type>(totalPositionsSize, numPositions)...
);
avk::command::action_type_command actionTypeCommand{};
actionTypeCommand.mNestedCommandsAndSyncInstructions.push_back(fill_device_buffer_from_cache(aSerializer, positionsBuffer, totalPositionsSize));
auto indexBuffer = context().create_buffer(
avk::memory_usage::device, aUsageFlags,
avk::index_buffer_meta::create_from_total_size(totalIndicesSize, numIndices),
set_up_meta_from_total_size_for_index_buffer<Metas>(totalIndicesSize, numIndices)...
);
actionTypeCommand.mNestedCommandsAndSyncInstructions.push_back(fill_device_buffer_from_cache(aSerializer, indexBuffer, totalIndicesSize));
actionTypeCommand.infer_sync_hint_from_nested_commands();
return std::make_tuple(std::move(positionsBuffer), std::move(indexBuffer), std::move(actionTypeCommand));
}
}
/** Get a tuple of two buffers, containing vertex positions and index positions, respectively, from the given input data.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of each buffer besides their obligatory
* avk::vertex_buffer_meta, and avk::index_buffer_meta, as appropriate for the two buffers.
* The additional meta data declarations will always refer to the whole data in the buffers; specifying subranges is not supported.
* @return A tuple of two buffers in device memory which contain the given input data, where the tuple elements refer to:
* <0>: Buffer containing vertex positions. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <2>) have completed execution.
* <1>: Buffer containing indices. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <2>) have completed execution.
* <2>: Commands that need to be executed on a queue to complete the operation.
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::buffer, avk::command::action_type_command> create_vertex_and_index_buffers_cached(avk::serializer& aSerializer, std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
std::tuple<std::vector<glm::vec3>, std::vector<uint32_t>> verticesAndIndicesData;
if (aSerializer.mode() == avk::serializer::mode::serialize) {
verticesAndIndicesData = get_vertices_and_indices(aModelsAndSelectedMeshes);
}
return create_vertex_and_index_buffers_cached<Metas...>(aSerializer, verticesAndIndicesData, aUsageFlags);
}
/** Create a device buffer that contains the given input data
* @param aBufferData Data to be stored in the buffer
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the given input data. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename T, typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_buffer(const T& aBufferData, vk::BufferUsageFlags aUsageFlags = {})
{
auto buffer = context().create_buffer(
avk::memory_usage::device, aUsageFlags,
avk::generic_buffer_meta::create_from_data(aBufferData),
Metas::create_from_data(aBufferData)...
);
auto actionTypeCommand = buffer->fill(aBufferData.data(), 0);
return std::make_tuple(std::move(buffer), std::move(actionTypeCommand));
}
/** Create a device buffer that contains the given input data
* @param aBufferData Data to be stored in the buffer
* @param aContentDescription Description of the buffer's content
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the given input data. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename T, typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_buffer(const T& aBufferData, avk::content_description aContentDescription, vk::BufferUsageFlags aUsageFlags = {})
{
auto buffer = context().create_buffer(
avk::memory_usage::device, aUsageFlags,
avk::generic_buffer_meta::create_from_data(aBufferData),
set_up_meta_for_data_with_or_without_describe_member<T, Metas>(aBufferData, aContentDescription)...
);
auto actionTypeCommand = buffer->fill(aBufferData.data(), 0);
return std::make_tuple(std::move(buffer), std::move(actionTypeCommand));
}
/** Create a device buffer that contains the given input data
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aBufferData Data to be stored in the buffer
* @param aContentDescription Description of the buffer's content
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the given input data. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename T, typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_buffer_cached(avk::serializer& aSerializer, T& aBufferData, avk::content_description aContentDescription, vk::BufferUsageFlags aUsageFlags = {})
{
size_t numBufferEntries = 0;
size_t bufferTotalSize = 0;
if (aSerializer.mode() == avk::serializer::mode::serialize) {
numBufferEntries = aBufferData.size();
bufferTotalSize = sizeof(typename std::remove_reference_t<decltype(aBufferData)>::value_type) * numBufferEntries;
aSerializer.archive(numBufferEntries);
aSerializer.archive(bufferTotalSize);
aSerializer.archive_memory(aBufferData.data(), bufferTotalSize);
return create_buffer<T, Metas...>(aBufferData, aContentDescription, aUsageFlags);
}
else {
aSerializer.archive(numBufferEntries);
aSerializer.archive(bufferTotalSize);
auto buffer = context().create_buffer(
avk::memory_usage::device, aUsageFlags,
avk::generic_buffer_meta::create_from_size(bufferTotalSize),
set_up_meta_from_total_size_with_or_without_describe_member<T, Metas>(aBufferData, bufferTotalSize, numBufferEntries, aContentDescription)...
);
auto actionTypeCommand = fill_device_buffer_from_cache(aSerializer, buffer, bufferTotalSize);
return std::make_tuple(std::move(buffer), std::move(actionTypeCommand));
}
}
/** Get normals from the given selection of models and associated mesh indices.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @return Combined normals data of all specified model + mesh-indices.
*/
extern std::vector<glm::vec3> get_normals(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
/** Get normals from the given selection of models and associated mesh indices.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. The order is maintained.
* @return Combined normals data of all specified model + mesh-indices tuples.
*/
extern std::vector<glm::vec3> get_normals_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
/** Get a buffer containing normals from the given input data.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffer is created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the normals. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_normals_buffer(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
return create_buffer<std::vector<glm::vec3>, Metas...>(get_normals(aModelsAndSelectedMeshes), avk::content_description::normal, aUsageFlags);
}
/** Get a buffer containing normals from the given input data.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the normals. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_normals_buffer_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
std::vector<glm::vec3> normalsData;
if (aSerializer.mode() == avk::serializer::mode::serialize) {
normalsData = get_normals(aModelsAndSelectedMeshes);
}
return create_buffer_cached<std::vector<glm::vec3>, Metas...>(aSerializer, normalsData, avk::content_description::normal, aUsageFlags);
}
/** Get tangents from the given selection of models and associated mesh indices.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @return Combined tangents data of all specified model + mesh-indices.
*/
extern std::vector<glm::vec3> get_tangents(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
/** Get tangents from the given selection of models and associated mesh indices.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. The order is maintained.
* @return Combined tangents data of all specified model + mesh-indices tuples.
*/
extern std::vector<glm::vec3> get_tangents_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
/** Get a buffer containing tangents from the given input data.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffer is created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the tangents. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_tangents_buffer(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
return create_buffer<std::vector<glm::vec3>, Metas...>(get_tangents(aModelsAndSelectedMeshes), avk::content_description::tangent, aUsageFlags);
}
/** Get a buffer containing tangents from the given input data.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the tangents. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_tangents_buffer_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
std::vector<glm::vec3> tangentsData;
if (aSerializer.mode() == avk::serializer::mode::serialize) {
tangentsData = get_tangents(aModelsAndSelectedMeshes);
}
return create_buffer_cached<std::vector<glm::vec3>, Metas...>(aSerializer, tangentsData, avk::content_description::tangent, aUsageFlags);
}
/** Get bitangents from the given selection of models and associated mesh indices.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @return Combined bitangents data of all specified model + mesh-indices.
*/
extern std::vector<glm::vec3> get_bitangents(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
/** Get bitangents from the given selection of models and associated mesh indices.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. The order is maintained.
* @return Combined bitangents data of all specified model + mesh-indices tuples.
*/
extern std::vector<glm::vec3> get_bitangents_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes);
/** Get a buffer containing bitangents from the given input data.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffer is created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the bitangents. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_bitangents_buffer(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
return create_buffer<std::vector<glm::vec3>, Metas...>(get_bitangents(aModelsAndSelectedMeshes), avk::content_description::bitangent, aUsageFlags);
}
/** Get a buffer containing bitangents from the given input data.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aUsageFlags Additional usage flags that the buffers are created with.
* @tparam Metas A list of buffer meta data types which shall be added to the creation of the buffer.
* The additional meta data declarations will always refer to the whole data in the buffer; specifying subranges is not supported.
* @return A tuple containing the following values:
* <0>: A buffer in device memory which will contain the given input data. Attention: The user of this function must ensure that it is not destroyed before the returned commands (at tuple index <1>) have completed execution.
* <1>: Commands that need to be executed on a queue to complete the operation
*/
template <typename... Metas>
std::tuple<avk::buffer, avk::command::action_type_command> create_bitangents_buffer_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, vk::BufferUsageFlags aUsageFlags = {})
{
std::vector<glm::vec3> bitangentsData;
if (aSerializer.mode() == avk::serializer::mode::serialize) {
bitangentsData = get_bitangents(aModelsAndSelectedMeshes);
}
return create_buffer_cached<std::vector<glm::vec3>, Metas...>(aSerializer, bitangentsData, avk::content_description::bitangent, aUsageFlags);
}
/** Get colors from the given selection of models and associated mesh indices.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.
* @param aColorsSet The zero-based set of vertex colors to get
* @return Combined colors data of all specified model + mesh-indices.
*/
extern std::vector<glm::vec4> get_colors(const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, int aColorsSet = 0);
/** Get colors from the given selection of models and associated mesh indices.
* @param aSerializer The serializer used to store the data to or load the data from a cache file, depending on its mode.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. The order is maintained.
* @param aColorsSet The zero-based set of vertex colors to get
* @return Combined colors data of all specified model + mesh-indices tuples.
*/
extern std::vector<glm::vec4> get_colors_cached(avk::serializer& aSerializer, const std::vector<std::tuple<const avk::model_t&, std::vector<avk::mesh_index_t>>>& aModelsAndSelectedMeshes, int aColorsSet = 0);
/** Get a buffer containing colors from the given input data.
* @param aModelsAndSelectedMeshes A collection where every entry consists of a model-reference + associated mesh indices.
* All the data they refer to is combined into a a common result. Their order is maintained.