-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.cpp
executable file
·1767 lines (1456 loc) · 102 KB
/
main.cpp
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
#include "TDevice.h"
#include "TDeviceQueue.h"
#include "TEngine.h"
#include "TFormatInfo.h"
#include "TPhysicalDevice.h"
#include "TVulkanAllocator.h"
#include "TBuffer.h"
#include "TCommandBuffer.h"
#include "TCommandBufferPool.h"
#include "TImage.h"
#include "TImageView.h"
#include "TShader.h"
#include "TAttachment.h"
#include "TGraphicsPipeline.h"
#include "TRenderPass.h"
#include "TSubpass.h"
#include "TDescriptorPool.h"
#include "TDescriptorSet.h"
#include "TDescriptorSetLayout.h"
#include "TFramebuffer.h"
#include "TFence.h"
#include "TSemaphore.h"
#include <fstream>
#include <GLFW/glfw3.h>
#include "TSurface.h"
#include "TSwapchain.h"
#include <iostream>
#include <math.h>
#include "TPipelineDescriptorSet.h"
#include "TSampler.h"
#include <glm/ext.hpp>
#include "TVulkanLoader.h"
#include "glm/ext/matrix_transform.hpp"
#include "glm/fwd.hpp"
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
// #define TINYGLTF_NOEXCEPTION // optional. disable exception handling.
#include <tiny_gltf.h>
#include <ktx.h>
#include <imgui.h>
static bool g_MouseJustPressed[ImGuiMouseButton_COUNT] = {};
static GLFWcursor *g_MouseCursors[ImGuiMouseCursor_COUNT] = {};
void ImageSaveToPPM(Turbo::Core::TRefPtr<Turbo::Core::TImage> &image, Turbo::Core::TRefPtr<Turbo::Core::TCommandBufferPool> &commandBufferPool, Turbo::Core::TRefPtr<Turbo::Core::TDeviceQueue> &deviceQueue, std::string name)
{
std::string save_file_path = "./";
std::string save_file_name = name;
Turbo::Core::TRefPtr<Turbo::Core::TImage> source_image = image;
Turbo::Core::TRefPtr<Turbo::Core::TImage> temp_image = new Turbo::Core::TImage(image->GetDevice(), 0, Turbo::Core::TImageType::DIMENSION_2D, source_image->GetFormat(), source_image->GetWidth(), source_image->GetHeight(), 1, 1, 1, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, Turbo::Core::TImageTiling::LINEAR, Turbo::Core::TImageUsageBits::IMAGE_TRANSFER_DST, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE);
Turbo::Core::TRefPtr<Turbo::Core::TCommandBuffer> temp_command_buffer = commandBufferPool->Allocate();
temp_command_buffer->Begin();
temp_command_buffer->CmdTransformImageLayout(Turbo::Core::TPipelineStageBits::TOP_OF_PIPE_BIT, Turbo::Core::TPipelineStageBits::TRANSFER_BIT, 0, 0, Turbo::Core::TImageLayout::UNDEFINED, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, temp_image, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, 1, 0, 1);
temp_command_buffer->CmdTransformImageLayout(Turbo::Core::TPipelineStageBits::BOTTOM_OF_PIPE_BIT, Turbo::Core::TPipelineStageBits::TRANSFER_BIT, 0, 0, Turbo::Core::TImageLayout::PRESENT_SRC_KHR, Turbo::Core::TImageLayout::TRANSFER_SRC_OPTIMAL, source_image, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, 1, 0, 1);
temp_command_buffer->CmdCopyImage(source_image, Turbo::Core::TImageLayout::TRANSFER_SRC_OPTIMAL, temp_image, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, 0, 1, 0, 0, 0, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, 0, 1, 0, 0, 0, source_image->GetWidth(), source_image->GetHeight(), 1);
temp_command_buffer->CmdTransformImageLayout(Turbo::Core::TPipelineStageBits::TRANSFER_BIT, Turbo::Core::TPipelineStageBits::HOST_BIT, 0, 0, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, Turbo::Core::TImageLayout::GENERAL, temp_image, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, 1, 0, 1);
temp_command_buffer->End();
Turbo::Core::TRefPtr<Turbo::Core::TFence> gpu_copy_to_cpu_fence = new Turbo::Core::TFence(image->GetDevice());
deviceQueue->Submit(temp_command_buffer, gpu_copy_to_cpu_fence);
gpu_copy_to_cpu_fence->WaitUntil();
// delete gpu_copy_to_cpu_fence;
std::string filename;
filename.append(save_file_path);
filename.append(save_file_name);
filename.append(".ppm");
VkImageSubresource subres = {};
subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subres.mipLevel = 0;
subres.arrayLayer = 0;
VkSubresourceLayout sr_layout;
image->GetDevice()->GetDeviceDriver()->vkGetImageSubresourceLayout(image->GetDevice()->GetVkDevice(), temp_image->GetVkImage(), &subres, &sr_layout);
char *ptr = (char *)temp_image->Map();
ptr += sr_layout.offset;
std::ofstream file(filename.c_str(), std::ios::binary);
file << "P6\n";
file << source_image->GetWidth() << " ";
file << source_image->GetHeight() << "\n";
file << 255 << "\n";
int x = 0;
int y = 0;
for (y = 0; y < source_image->GetHeight(); y++)
{
const int *row = (const int *)ptr;
int swapped;
if (source_image->GetFormat().GetVkFormat() == VK_FORMAT_B8G8R8A8_UNORM || source_image->GetFormat().GetVkFormat() == VK_FORMAT_B8G8R8A8_SRGB)
{
for (x = 0; x < source_image->GetWidth(); x++)
{
swapped = (*row & 0xff00ff00) | (*row & 0x000000ff) << 16 | (*row & 0x00ff0000) >> 16;
file.write((char *)&swapped, 3);
row++;
}
}
else if (source_image->GetFormat().GetVkFormat() == VK_FORMAT_R8G8B8A8_UNORM)
{
for (x = 0; x < source_image->GetWidth(); x++)
{
file.write((char *)row, 3);
row++;
}
}
else
{
printf("Unrecognized image format - will not write image files");
break;
}
ptr += sr_layout.rowPitch;
}
file.close();
temp_image->Unmap();
// delete temp_image;
commandBufferPool->Free(temp_command_buffer);
}
bool read_ppm(char const *const filename, int &width, int &height, uint64_t rowPitch, unsigned char *dataPtr)
{
// PPM format expected from http://netpbm.sourceforge.net/doc/ppm.html
// 1. magic number
// 2. whitespace
// 3. width
// 4. whitespace
// 5. height
// 6. whitespace
// 7. max color value
// 8. whitespace
// 7. data
// Comments are not supported, but are detected and we kick out
// Only 8 bits per channel is supported
// If dataPtr is nullptr, only width and height are returned
// Read in values from the PPM file as characters to check for comments
char magicStr[3] = {}, heightStr[6] = {}, widthStr[6] = {}, formatStr[6] = {};
#ifndef __ANDROID__
FILE *fPtr = fopen(filename, "rb");
#else
FILE *fPtr = AndroidFopen(filename, "rb");
#endif
if (!fPtr)
{
printf("Bad filename in read_ppm: %s\n", filename);
return false;
}
// Read the four values from file, accounting with any and all whitepace
int count = fscanf(fPtr, "%s %s %s %s ", magicStr, widthStr, heightStr, formatStr);
// Kick out if comments present
if (magicStr[0] == '#' || widthStr[0] == '#' || heightStr[0] == '#' || formatStr[0] == '#')
{
printf("Unhandled comment in PPM file\n");
return false;
}
// Only one magic value is valid
if (strncmp(magicStr, "P6", sizeof(magicStr)))
{
printf("Unhandled PPM magic number: %s\n", magicStr);
return false;
}
width = atoi(widthStr);
height = atoi(heightStr);
// Ensure we got something sane for width/height
static const int saneDimension = 32768; //??
if (width <= 0 || width > saneDimension)
{
printf("Width seems wrong. Update read_ppm if not: %u\n", width);
return false;
}
if (height <= 0 || height > saneDimension)
{
printf("Height seems wrong. Update read_ppm if not: %u\n", height);
return false;
}
if (dataPtr == nullptr)
{
// If no destination pointer, caller only wanted dimensions
return true;
}
// Now read the data
for (int y = 0; y < height; y++)
{
unsigned char *rowPtr = dataPtr;
for (int x = 0; x < width; x++)
{
count = fread(rowPtr, 3, 1, fPtr);
rowPtr[3] = 255; /* Alpha of 1 */
rowPtr += 4;
}
dataPtr += rowPitch;
}
fclose(fPtr);
return true;
}
const std::string IMGUI_VERT_SHADER_STR = "#version 450\n"
"layout (location = 0) in vec2 inPos;\n"
"layout (location = 1) in vec2 inUV;\n"
"layout (location = 2) in vec4 inColor;\n"
"layout (push_constant) uniform PushConstants {\n"
" vec2 scale;\n"
" vec2 translate;\n"
"} pushConstants;\n"
"layout (location = 0) out vec2 outUV;\n"
"layout (location = 1) out vec4 outColor;\n"
"out gl_PerVertex \n"
"{\n"
" vec4 gl_Position; \n"
"};\n"
"void main() \n"
"{\n"
" outUV = inUV;\n"
" outColor = inColor;\n"
" gl_Position = vec4(inPos * pushConstants.scale + pushConstants.translate, 0.0, 1.0);\n"
"}\n";
const std::string IMGUI_FRAG_SHADER_STR = "#version 450\n"
"layout (binding = 0) uniform sampler2D fontSampler;\n"
"layout (location = 0) in vec2 inUV;\n"
"layout (location = 1) in vec4 inColor;\n"
"layout (location = 0) out vec4 outColor;\n"
"layout (location = 1) out vec4 outCustomColor;\n"
"void main() \n"
"{\n"
" outColor = inColor * texture(fontSampler, inUV);\n"
" outCustomColor = outColor;\n"
"}";
const std::string SKY_VERT_SHADER_STR = "#version 450\n"
"layout(set = 0, binding = 0) uniform UBO{\n"
" mat4 mvp;\n"
"}ubo;\n"
"layout(location = 0) in vec3 inPos;\n"
"layout(location = 0) out vec3 outUVW;\n"
"void main()\n"
"{\n"
" outUVW = inPos;\n"
" // Convert cubemap coordinates into Vulkan coordinate space\n"
" outUVW.xy *= -1.0;\n"
" gl_Position = ubo.mvp * vec4(inPos.xyz, 1.0);\n"
"}\n";
const std::string SKY_FRAG_SHADER_STR = "#version 450\n"
"layout(set = 0, binding = 1) uniform samplerCube samplerCubeMap;\n"
"layout(location = 0) in vec3 inUVW;\n"
"layout(location = 0) out vec4 outFragColor;\n"
"layout (location = 1) out vec4 outCustomColor;\n"
"void main()\n"
"{\n"
" outFragColor = texture(samplerCubeMap, inUVW);\n"
" outCustomColor = outFragColor;\n"
"}\n";
const std::string VERT_SHADER_STR = "#version 450 core\n"
"layout (set = 0, binding = 0) uniform bufferVals {\n"
" float scale;\n"
"} myBufferVals;\n"
"layout (set = 1, binding = 0) uniform mvpBuffer {\n"
" mat4 mvp;\n"
"} mvpBufferVals;\n"
"layout (location = 0) in vec3 pos;\n"
"layout (location = 1) in vec3 normal;\n"
"layout (location = 2) in vec2 inUV;"
"layout (location = 0) out vec4 outNormal;\n"
"layout (location = 1) out vec2 outUV;\n"
"layout (location = 2) out float outScale;\n"
"layout (location = 3) out vec4 outSunPosition;\n"
"layout (location = 4) out vec3 outPosition;\n"
"void main() {\n"
" outNormal = mvpBufferVals.mvp * vec4(normal.xyz,1);\n"
" gl_Position =mvpBufferVals.mvp * vec4(pos.xyz,1);\n"
" outPosition =gl_Position.xyz;\n"
" outUV = inUV;\n"
" outScale = myBufferVals.scale;\n"
" outSunPosition = mvpBufferVals.mvp * vec4(-100,-100,-100,1);\n"
"}\n";
const std::string FRAG_SHADER_STR = "#version 450 core\n"
"layout (set = 0, binding = 1) uniform texture2D myTexture;\n"
"layout (set = 1, binding = 1) uniform samplerCube samplerColor;\n"
"layout (set = 2, binding = 2) uniform sampler mySampler;\n"
"layout (location = 0) in vec4 normal;\n"
"layout (location = 1) in vec2 uv;\n"
"layout (location = 2) in float scale;\n"
"layout (location = 3) in vec4 sunPosition;\n"
"layout (location = 4) in vec3 inPosition;\n"
"layout (location = 0) out vec4 outColor;\n"
"layout (location = 1) out vec4 outCustomColor;\n"
"layout (push_constant) uniform my_push_constants_t\n"
"{"
" float alpha;\n"
"} my_push_constants;\n"
"void main() {\n"
" float load_bias = my_push_constants.alpha * 10;\n"
" vec3 normalize_position = normalize(inPosition);\n"
" vec3 reflect_dir = reflect(normalize_position, normalize(normal.xyz));\n"
" vec4 sky_cube_color = texture(samplerColor, reflect_dir, 0);\n"
" float lum = max(dot(normal.xyz, normalize(sunPosition.xyz)), 0.0)*0.4f;\n"
" vec3 sun_color = vec3(1,1,1);\n"
" vec4 _outColor = sky_cube_color * texture(sampler2D(myTexture, mySampler), uv, 0)* vec4((0.3 + lum) * sun_color, 1.0);\n"
" outColor = vec4(_outColor.xyz,my_push_constants.alpha);\n"
" outCustomColor = outColor;\n"
"}\n";
const std::string INPUT_ATTACHMENT_VERT_SHADER_STR = "#version 450\n"
"out gl_PerVertex {\n"
" vec4 gl_Position;\n"
"};\n"
"void main() \n"
"{\n"
" gl_Position = vec4(vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2) * 2.0f - 1.0f, 0.0f, 1.0f);\n"
"}";
const std::string INPUT_ATTACHMENT_FRAG_SHADER_STR = "#version 450\n"
"layout (input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput inputColor;\n"
"layout (input_attachment_index = 1, set = 0, binding = 1) uniform subpassInput inputDepth;\n"
"layout (push_constant) uniform my_push_constants_t\n"
"{"
" int isOutputDepth;\n"
"} my_push_constants;\n"
"layout (location = 0) out vec4 outColor;\n"
"void main() {\n"
" if(my_push_constants.isOutputDepth == 0)\n"
" {\n"
" outColor=subpassLoad(inputColor).rgba;\n"
" }\n"
" else\n"
" { \n"
" float alpha=subpassLoad(inputColor).a;\n"
" float depth=subpassLoad(inputDepth).r;\n"
" outColor=vec4(depth,depth,depth,alpha);\n"
" }\n"
"}\n";
typedef struct POSITION
{
float x;
float y;
float z;
} POSITION;
typedef struct NORMAL
{
float x;
float y;
float z;
} NORMAL;
typedef struct TEXCOORD
{
float u;
float v;
} TEXCOORD;
int main()
{
std::cout << "Vulkan Version:" << Turbo::Core::TVulkanLoader::Instance()->GetVulkanVersion().ToString() << std::endl;
float value = -10.0f;
float alpha = 1.0;
//<gltf for Suzanne>
std::vector<POSITION> POSITION_data;
std::vector<NORMAL> NORMAL_data;
std::vector<TEXCOORD> TEXCOORD_data;
std::vector<uint32_t> INDICES_data;
{
tinygltf::Model model;
tinygltf::TinyGLTF loader;
std::string err;
std::string warn;
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, "../asset/models/Suzanne.gltf");
const tinygltf::Scene &scene = model.scenes[model.defaultScene];
tinygltf::Node &node = model.nodes[scene.nodes[0]];
tinygltf::Mesh &mesh = model.meshes[node.mesh];
tinygltf::Primitive &primitive = mesh.primitives[0];
int mode = primitive.mode; // 4 is triangle
int position_accesser_index = primitive.attributes["POSITION"];
int normal_accesser_index = primitive.attributes["NORMAL"];
int texcoord_0_accesser_index = primitive.attributes["TEXCOORD_0"];
int indices_accesser_index = primitive.indices;
tinygltf::Accessor &position_accessor = model.accessors[position_accesser_index];
tinygltf::Accessor &normal_accessor = model.accessors[normal_accesser_index];
tinygltf::Accessor &texcoord_0_accessor = model.accessors[texcoord_0_accesser_index];
tinygltf::Accessor &indices_accessor = model.accessors[indices_accesser_index];
tinygltf::BufferView &position_buffer_view = model.bufferViews[position_accessor.bufferView];
tinygltf::BufferView &normal_buffer_view = model.bufferViews[normal_accessor.bufferView];
tinygltf::BufferView &texcoord_0_buffer_view = model.bufferViews[texcoord_0_accessor.bufferView];
tinygltf::BufferView &indices_buffer_view = model.bufferViews[indices_accessor.bufferView];
int position_buffer_index = position_buffer_view.buffer;
size_t position_buffer_byteLength = position_buffer_view.byteLength;
int position_buffer_byteOffset = position_buffer_view.byteOffset;
int position_type = position_accessor.type;
int normal_buffer_index = normal_buffer_view.buffer;
size_t normal_buffer_byteLength = normal_buffer_view.byteLength;
int normal_buffer_byteOffset = normal_buffer_view.byteOffset;
int normal_type = normal_accessor.type;
int texcoord_0_buffer_index = texcoord_0_buffer_view.buffer;
size_t texcoord_0_buffer_byteLength = texcoord_0_buffer_view.byteLength;
int texcoord_0_buffer_byteOffset = texcoord_0_buffer_view.byteOffset;
int texcoord_0_type = texcoord_0_accessor.type;
int indices_buffer_index = indices_buffer_view.buffer;
size_t indices_buffer_byteLength = indices_buffer_view.byteLength;
int indices_buffer_byteOffset = indices_buffer_view.byteOffset;
int indices_type = indices_accessor.type;
tinygltf::Buffer &position_buffer = model.buffers[position_buffer_index];
tinygltf::Buffer &normal_buffer = model.buffers[normal_buffer_index];
tinygltf::Buffer &texcoord_0_buffer = model.buffers[texcoord_0_buffer_index];
tinygltf::Buffer &indices_buffer = model.buffers[indices_buffer_index];
std::vector<unsigned char> &position_data = position_buffer.data;
std::vector<unsigned char> &normal_data = normal_buffer.data;
std::vector<unsigned char> &texcoord_0_data = texcoord_0_buffer.data;
std::vector<unsigned char> &indices_data = indices_buffer.data;
std::vector<unsigned short> temp_indices_data;
POSITION_data.resize(position_buffer_byteLength / sizeof(POSITION));
NORMAL_data.resize(normal_buffer_byteLength / sizeof(NORMAL));
TEXCOORD_data.resize(texcoord_0_buffer_byteLength / sizeof(TEXCOORD));
temp_indices_data.resize(indices_buffer_byteLength / sizeof(unsigned short));
memcpy(POSITION_data.data(), position_data.data() + position_buffer_byteOffset, position_buffer_byteLength);
memcpy(NORMAL_data.data(), normal_data.data() + normal_buffer_byteOffset, normal_buffer_byteLength);
memcpy(TEXCOORD_data.data(), texcoord_0_data.data() + texcoord_0_buffer_byteOffset, texcoord_0_buffer_byteLength);
memcpy(temp_indices_data.data(), indices_data.data() + indices_buffer_byteOffset, indices_buffer_byteLength);
for (unsigned short &temp_indices_item : temp_indices_data)
{
INDICES_data.push_back(temp_indices_item);
}
}
//</gltf for Suzanne>
//<gltf for sky cube>
std::vector<POSITION> SKY_CUBE_POSITION_data;
std::vector<NORMAL> SKY_CUBE_NORMAL_data;
std::vector<TEXCOORD> SKY_CUBE_TEXCOORD_data;
std::vector<uint32_t> SKY_CUBE_INDICES_data;
{
tinygltf::Model model;
tinygltf::TinyGLTF loader;
std::string err;
std::string warn;
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, "../asset/models/cube.gltf");
const tinygltf::Scene &scene = model.scenes[model.defaultScene];
tinygltf::Node &node = model.nodes[scene.nodes[2]];
tinygltf::Mesh &mesh = model.meshes[node.mesh];
tinygltf::Primitive &primitive = mesh.primitives[0];
int position_accesser_index = primitive.attributes["POSITION"];
int normal_accesser_index = primitive.attributes["NORMAL"];
int texcoord_0_accesser_index = primitive.attributes["TEXCOORD_0"];
int indices_accesser_index = primitive.indices;
tinygltf::Accessor &position_accessor = model.accessors[position_accesser_index];
tinygltf::Accessor &normal_accessor = model.accessors[normal_accesser_index];
tinygltf::Accessor &texcoord_0_accessor = model.accessors[texcoord_0_accesser_index];
tinygltf::Accessor &indices_accessor = model.accessors[indices_accesser_index];
tinygltf::BufferView &position_buffer_view = model.bufferViews[position_accessor.bufferView];
tinygltf::BufferView &normal_buffer_view = model.bufferViews[normal_accessor.bufferView];
tinygltf::BufferView &texcoord_0_buffer_view = model.bufferViews[texcoord_0_accessor.bufferView];
tinygltf::BufferView &indices_buffer_view = model.bufferViews[indices_accessor.bufferView];
int position_buffer_index = position_buffer_view.buffer;
size_t position_buffer_byteLength = position_buffer_view.byteLength;
int position_buffer_byteOffset = position_buffer_view.byteOffset;
int position_type = position_accessor.type;
int normal_buffer_index = normal_buffer_view.buffer;
size_t normal_buffer_byteLength = normal_buffer_view.byteLength;
int normal_buffer_byteOffset = normal_buffer_view.byteOffset;
int normal_type = normal_accessor.type;
int texcoord_0_buffer_index = texcoord_0_buffer_view.buffer;
size_t texcoord_0_buffer_byteLength = texcoord_0_buffer_view.byteLength;
int texcoord_0_buffer_byteOffset = texcoord_0_buffer_view.byteOffset;
int texcoord_0_type = texcoord_0_accessor.type;
int indices_buffer_index = indices_buffer_view.buffer;
size_t indices_buffer_byteLength = indices_buffer_view.byteLength;
int indices_buffer_byteOffset = indices_buffer_view.byteOffset;
int indices_type = indices_accessor.type;
tinygltf::Buffer &position_buffer = model.buffers[position_buffer_index];
tinygltf::Buffer &normal_buffer = model.buffers[normal_buffer_index];
tinygltf::Buffer &texcoord_0_buffer = model.buffers[texcoord_0_buffer_index];
tinygltf::Buffer &indices_buffer = model.buffers[indices_buffer_index];
std::vector<unsigned char> &position_data = position_buffer.data;
std::vector<unsigned char> &normal_data = normal_buffer.data;
std::vector<unsigned char> &texcoord_0_data = texcoord_0_buffer.data;
std::vector<unsigned char> &indices_data = indices_buffer.data;
std::vector<unsigned short> temp_indices_data;
SKY_CUBE_POSITION_data.resize(position_buffer_byteLength / sizeof(POSITION));
SKY_CUBE_NORMAL_data.resize(normal_buffer_byteLength / sizeof(NORMAL));
SKY_CUBE_TEXCOORD_data.resize(texcoord_0_buffer_byteLength / sizeof(TEXCOORD));
temp_indices_data.resize(indices_buffer_byteLength / sizeof(unsigned short));
memcpy(SKY_CUBE_POSITION_data.data(), position_data.data() + position_buffer_byteOffset, position_buffer_byteLength);
memcpy(SKY_CUBE_NORMAL_data.data(), normal_data.data() + normal_buffer_byteOffset, normal_buffer_byteLength);
memcpy(SKY_CUBE_TEXCOORD_data.data(), texcoord_0_data.data() + texcoord_0_buffer_byteOffset, texcoord_0_buffer_byteLength);
memcpy(temp_indices_data.data(), indices_data.data() + indices_buffer_byteOffset, indices_buffer_byteLength);
for (unsigned short &temp_indices_item : temp_indices_data)
{
SKY_CUBE_INDICES_data.push_back(temp_indices_item);
}
}
//</gltf for sky cube>
uint32_t sky_cube_indices_count = SKY_CUBE_INDICES_data.size();
uint32_t indices_count = INDICES_data.size();
Turbo::Core::TRefPtr<Turbo::Core::TInstance> temp_instance = new Turbo::Core::TInstance();
Turbo::Core::TLayerInfo khronos_validation;
std::vector<Turbo::Core::TLayerInfo> support_layers = temp_instance->GetSupportLayers();
for (Turbo::Core::TLayerInfo &layer : support_layers)
{
if (layer.GetLayerType() == Turbo::Core::TLayerType::VK_LAYER_KHRONOS_VALIDATION)
{
khronos_validation = layer;
break;
}
}
std::vector<Turbo::Core::TLayerInfo> enable_layer;
enable_layer.push_back(khronos_validation);
std::vector<Turbo::Core::TExtensionInfo> enable_instance_extensions;
std::vector<Turbo::Core::TExtensionInfo> instance_support_extensions = temp_instance->GetSupportExtensions();
for (Turbo::Core::TExtensionInfo &extension : instance_support_extensions)
{
if (extension.GetExtensionType() == Turbo::Core::TExtensionType::VK_KHR_SURFACE)
{
enable_instance_extensions.push_back(extension);
}
else if (extension.GetExtensionType() == Turbo::Core::TExtensionType::VK_KHR_WIN32_SURFACE)
{
enable_instance_extensions.push_back(extension);
}
else if (extension.GetExtensionType() == Turbo::Core::TExtensionType::VK_KHR_WAYLAND_SURFACE)
{
enable_instance_extensions.push_back(extension);
}
else if (extension.GetExtensionType() == Turbo::Core::TExtensionType::VK_KHR_XCB_SURFACE)
{
enable_instance_extensions.push_back(extension);
}
else if (extension.GetExtensionType() == Turbo::Core::TExtensionType::VK_KHR_XLIB_SURFACE)
{
enable_instance_extensions.push_back(extension);
}
}
temp_instance = nullptr; // After get layer and extension info we no longer need [temp_instance]
Turbo::Core::TVersion instance_version(1, 2, 0, 0);
Turbo::Core::TRefPtr<Turbo::Core::TInstance> instance = new Turbo::Core::TInstance(&enable_layer, &enable_instance_extensions, &instance_version);
Turbo::Core::TRefPtr<Turbo::Core::TPhysicalDevice> physical_device = instance->GetBestPhysicalDevice();
std::cout << "Physical Device:" << physical_device->GetDeviceName() << std::endl;
if (!glfwInit())
return -1;
GLFWwindow *window;
int window_width = 500;
int window_height = 500;
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
window = glfwCreateWindow(window_width, window_height, "Turbo", NULL, NULL);
VkSurfaceKHR vk_surface_khr = VK_NULL_HANDLE;
VkInstance vk_instance = instance->GetVkInstance();
glfwCreateWindowSurface(vk_instance, window, nullptr, &vk_surface_khr);
Turbo::Core::TPhysicalDeviceFeatures physical_device_features = {};
physical_device_features.sampleRateShading = true;
std::vector<Turbo::Core::TExtensionInfo> enable_device_extensions;
std::vector<Turbo::Core::TExtensionInfo> physical_device_support_extensions = physical_device->GetSupportExtensions();
for (Turbo::Core::TExtensionInfo &extension : physical_device_support_extensions)
{
if (extension.GetExtensionType() == Turbo::Core::TExtensionType::VK_KHR_SWAPCHAIN)
{
enable_device_extensions.push_back(extension);
}
}
Turbo::Core::TRefPtr<Turbo::Core::TDevice> device = new Turbo::Core::TDevice(physical_device, nullptr, &enable_device_extensions, &physical_device_features);
Turbo::Core::TRefPtr<Turbo::Core::TDeviceQueue> queue = device->GetBestGraphicsQueue();
Turbo::Core::TRefPtr<Turbo::Extension::TSurface> surface = new Turbo::Extension::TSurface(device, nullptr, vk_surface_khr);
uint32_t max_image_count = surface->GetMaxImageCount();
uint32_t min_image_count = surface->GetMinImageCount();
uint32_t swapchain_image_count = max_image_count <= min_image_count ? min_image_count : max_image_count - 1;
Turbo::Core::TRefPtr<Turbo::Extension::TSwapchain> swapchain = new Turbo::Extension::TSwapchain(surface, swapchain_image_count, Turbo::Core::TFormatType::B8G8R8A8_SRGB, 1, Turbo::Core::TImageUsageBits::IMAGE_COLOR_ATTACHMENT | Turbo::Core::TImageUsageBits::IMAGE_TRANSFER_SRC | Turbo::Core::TImageUsageBits::IMAGE_TRANSFER_DST, true);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TImage>> swapchain_images = swapchain->GetImages();
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TImageView>> swapchain_image_views;
for (Turbo::Core::TRefPtr<Turbo::Core::TImage> &swapchain_image_item : swapchain_images)
{
Turbo::Core::TRefPtr<Turbo::Core::TImageView> swapchain_view = new Turbo::Core::TImageView(swapchain_image_item, Turbo::Core::TImageViewType::IMAGE_VIEW_2D, Turbo::Core::TFormatType::B8G8R8A8_SRGB, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, 1, 0, 1);
swapchain_image_views.push_back(swapchain_view);
}
Turbo::Core::TRefPtr<Turbo::Core::TCommandBufferPool> command_pool = new Turbo::Core::TCommandBufferPool(queue);
Turbo::Core::TRefPtr<Turbo::Core::TCommandBuffer> command_buffer = command_pool->Allocate();
glm::mat4 model = glm::mat4(1.0f);
model = glm::rotate(model, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 view = glm::mat4(1.0f);
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -10.0f));
glm::mat4 projection = glm::mat4(1.0f);
projection = glm::perspective(glm::radians(45.0f), (float)swapchain->GetWidth() / (float)swapchain->GetHeight(), 0.1f, 100.0f);
glm::mat4 mvp = projection * view * model;
glm::mat4 sky_cube_view = glm::mat4(glm::mat3(view));
glm::mat4 sky_cube_mvp = projection * sky_cube_view * glm::mat4(1.0f);
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> mvp_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_UNIFORM_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(mvp));
void *mvp_ptr = mvp_buffer->Map();
memcpy(mvp_ptr, &mvp, sizeof(mvp));
mvp_buffer->Unmap();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> sky_cube_mvp_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_UNIFORM_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(sky_cube_mvp));
void *sky_cube_mvp_ptr = sky_cube_mvp_buffer->Map();
memcpy(sky_cube_mvp_ptr, &sky_cube_mvp, sizeof(sky_cube_mvp));
sky_cube_mvp_buffer->Unmap();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> value_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_UNIFORM_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(float));
void *value_ptr = value_buffer->Map();
memcpy(value_ptr, &value, sizeof(value));
value_buffer->Unmap();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> position_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_VERTEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(POSITION) * POSITION_data.size());
void *position_buffer_ptr = position_buffer->Map();
memcpy(position_buffer_ptr, POSITION_data.data(), sizeof(POSITION) * POSITION_data.size());
position_buffer->Unmap();
POSITION_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> sky_cube_position_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_VERTEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(POSITION) * SKY_CUBE_POSITION_data.size());
void *sky_cube_position_buffer_ptr = sky_cube_position_buffer->Map();
memcpy(sky_cube_position_buffer_ptr, SKY_CUBE_POSITION_data.data(), sizeof(POSITION) * SKY_CUBE_POSITION_data.size());
sky_cube_position_buffer->Unmap();
SKY_CUBE_POSITION_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> normal_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_VERTEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(NORMAL) * NORMAL_data.size());
void *normal_buffer_ptr = normal_buffer->Map();
memcpy(normal_buffer_ptr, NORMAL_data.data(), sizeof(NORMAL) * NORMAL_data.size());
normal_buffer->Unmap();
NORMAL_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> sky_cube_normal_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_VERTEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(NORMAL) * SKY_CUBE_NORMAL_data.size());
void *sky_cube_normal_buffer_ptr = sky_cube_normal_buffer->Map();
memcpy(sky_cube_normal_buffer_ptr, SKY_CUBE_NORMAL_data.data(), sizeof(NORMAL) * SKY_CUBE_NORMAL_data.size());
sky_cube_normal_buffer->Unmap();
SKY_CUBE_NORMAL_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> texcoord_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_VERTEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(TEXCOORD) * TEXCOORD_data.size());
void *texcoord_buffer_ptr = texcoord_buffer->Map();
memcpy(texcoord_buffer_ptr, TEXCOORD_data.data(), sizeof(TEXCOORD) * TEXCOORD_data.size());
texcoord_buffer->Unmap();
TEXCOORD_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> sky_cube_texcoord_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_VERTEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(TEXCOORD) * SKY_CUBE_TEXCOORD_data.size());
void *sky_cube_texcoord_buffer_ptr = sky_cube_texcoord_buffer->Map();
memcpy(sky_cube_texcoord_buffer_ptr, SKY_CUBE_TEXCOORD_data.data(), sizeof(TEXCOORD) * SKY_CUBE_TEXCOORD_data.size());
sky_cube_texcoord_buffer->Unmap();
SKY_CUBE_TEXCOORD_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> index_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_INDEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(uint32_t) * INDICES_data.size());
void *index_buffer_ptr = index_buffer->Map();
memcpy(index_buffer_ptr, INDICES_data.data(), sizeof(uint32_t) * INDICES_data.size());
index_buffer->Unmap();
INDICES_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> sky_cube_index_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_INDEX_BUFFER /*| Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_DST*/, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, sizeof(uint32_t) * SKY_CUBE_INDICES_data.size());
void *sky_cube_index_buffer_ptr = sky_cube_index_buffer->Map();
memcpy(sky_cube_index_buffer_ptr, SKY_CUBE_INDICES_data.data(), sizeof(uint32_t) * SKY_CUBE_INDICES_data.size());
sky_cube_index_buffer->Unmap();
SKY_CUBE_INDICES_data.clear();
Turbo::Core::TRefPtr<Turbo::Core::TImage> ktx_image = nullptr;
//<KTX Texture>
{
std::string ktx_filename = "../asset/images/metalplate01_rgba.ktx";
ktxTexture *ktx_texture;
KTX_error_code ktx_result;
ktx_result = ktxTexture_CreateFromNamedFile(ktx_filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktx_texture);
if (ktx_texture == nullptr)
{
throw std::runtime_error("Couldn't load texture");
}
uint32_t ktx_texture_width = ktx_texture->baseWidth;
uint32_t ktx_texture_height = ktx_texture->baseHeight;
uint32_t ktx_texture_mip_levels = ktx_texture->numLevels;
ktx_uint8_t *ktx_texture_data = ktx_texture->pData;
ktx_size_t ktx_texture_size = ktx_texture->dataSize;
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> ktx_staging_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_SRC, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, ktx_texture_size);
void *ktx_ptr = ktx_staging_buffer->Map();
memcpy(ktx_ptr, ktx_texture_data, ktx_texture_size);
ktx_staging_buffer->Unmap();
ktx_image = new Turbo::Core::TImage(device, 0, Turbo::Core::TImageType::DIMENSION_2D, Turbo::Core::TFormatType::R8G8B8A8_UNORM, ktx_texture_width, ktx_texture_height, 1, ktx_texture_mip_levels, 1, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, Turbo::Core::TImageTiling::OPTIMAL, Turbo::Core::TImageUsageBits::IMAGE_TRANSFER_DST | Turbo::Core::TImageUsageBits::IMAGE_SAMPLED, Turbo::Core::TMemoryFlagsBits::DEDICATED_MEMORY, Turbo::Core::TImageLayout::UNDEFINED);
Turbo::Core::TRefPtr<Turbo::Core::TCommandBuffer> ktx_command_buffer = command_pool->Allocate();
ktx_command_buffer->Begin();
ktx_command_buffer->CmdTransformImageLayout(Turbo::Core::TPipelineStageBits::HOST_BIT, Turbo::Core::TPipelineStageBits::TRANSFER_BIT, Turbo::Core::TAccessBits::HOST_WRITE_BIT, Turbo::Core::TAccessBits::TRANSFER_WRITE_BIT, Turbo::Core::TImageLayout::UNDEFINED, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, ktx_image, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, ktx_texture_mip_levels, 0, 1);
for (uint32_t mip_index = 0; mip_index < ktx_texture_mip_levels; mip_index++)
{
uint32_t copy_width = ktx_texture_width >> mip_index;
uint32_t copy_height = ktx_texture_height >> mip_index;
uint32_t copy_mip_level = mip_index;
ktx_size_t copy_buffer_offset = 0;
ktx_result = ktxTexture_GetImageOffset(ktx_texture, mip_index, 0, 0, ©_buffer_offset);
ktx_command_buffer->CmdCopyBufferToImage(ktx_staging_buffer, ktx_image, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, copy_buffer_offset, copy_width, copy_height, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, copy_mip_level, 0, 1, 0, 0, 0, copy_width, copy_height, 1);
}
ktx_command_buffer->CmdTransformImageLayout(Turbo::Core::TPipelineStageBits::TRANSFER_BIT, Turbo::Core::TPipelineStageBits::FRAGMENT_SHADER_BIT, Turbo::Core::TAccessBits::TRANSFER_WRITE_BIT, Turbo::Core::TAccessBits::SHADER_READ_BIT, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, Turbo::Core::TImageLayout::SHADER_READ_ONLY_OPTIMAL, ktx_image, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, ktx_texture_mip_levels, 0, 1);
ktx_command_buffer->End();
Turbo::Core::TRefPtr<Turbo::Core::TFence> ktx_fence = new Turbo::Core::TFence(device);
queue->Submit(ktx_command_buffer, ktx_fence);
ktx_fence->WaitUntil();
// delete ktx_fence;
// delete ktx_staging_buffer;
command_pool->Free(ktx_command_buffer);
ktxTexture_Destroy(ktx_texture);
}
//</KTX Texture>
Turbo::Core::TRefPtr<Turbo::Core::TImageView> ktx_texture_view = new Turbo::Core::TImageView(ktx_image, Turbo::Core::TImageViewType::IMAGE_VIEW_2D, ktx_image->GetFormat(), Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, ktx_image->GetMipLevels(), 0, 1);
Turbo::Core::TRefPtr<Turbo::Core::TSampler> sampler = new Turbo::Core::TSampler(device, Turbo::Core::TFilter::LINEAR, Turbo::Core::TFilter::LINEAR, Turbo::Core::TMipmapMode::LINEAR, Turbo::Core::TAddressMode::REPEAT, Turbo::Core::TAddressMode::REPEAT, Turbo::Core::TAddressMode::REPEAT, Turbo::Core::TBorderColor::FLOAT_OPAQUE_WHITE, 0.0f, 0.0f, ktx_image->GetMipLevels());
Turbo::Core::TRefPtr<Turbo::Core::TImage> ktx_sky_cube_image = nullptr;
//<KTX SkyCube Texture>
{
ktxResult result;
ktxTexture *ktx_texture;
result = ktxTexture_CreateFromNamedFile("../asset/images/cubemap_yokohama_rgba.ktx", KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktx_texture);
uint32_t ktx_texture_width = ktx_texture->baseWidth;
uint32_t ktx_texture_height = ktx_texture->baseHeight;
uint32_t ktx_texture_mip_levels = ktx_texture->numLevels;
ktx_uint8_t *ktx_texture_data = ktx_texture->pData;
ktx_size_t ktx_texture_size = ktx_texture->dataSize;
Turbo::Core::TRefPtr<Turbo::Core::TBuffer> ktx_staging_buffer = new Turbo::Core::TBuffer(device, 0, Turbo::Core::TBufferUsageBits::BUFFER_TRANSFER_SRC, Turbo::Core::TMemoryFlagsBits::HOST_ACCESS_SEQUENTIAL_WRITE, ktx_texture_size);
void *ktx_ptr = ktx_staging_buffer->Map();
memcpy(ktx_ptr, ktx_texture_data, ktx_texture_size);
ktx_staging_buffer->Unmap();
ktx_sky_cube_image = new Turbo::Core::TImage(device, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT /*for cubemap*/, Turbo::Core::TImageType::DIMENSION_2D, Turbo::Core::TFormatType::R8G8B8A8_UNORM, ktx_texture_width, ktx_texture_height, 1, ktx_texture_mip_levels, 6 /*for cubemap six faces*/, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, Turbo::Core::TImageTiling::OPTIMAL, Turbo::Core::TImageUsageBits::IMAGE_TRANSFER_DST | Turbo::Core::TImageUsageBits::IMAGE_SAMPLED, Turbo::Core::TMemoryFlagsBits::DEDICATED_MEMORY, Turbo::Core::TImageLayout::UNDEFINED);
Turbo::Core::TRefPtr<Turbo::Core::TCommandBuffer> ktx_command_buffer = command_pool->Allocate();
ktx_command_buffer->Begin();
ktx_command_buffer->CmdTransformImageLayout(Turbo::Core::TPipelineStageBits::HOST_BIT, Turbo::Core::TPipelineStageBits::TRANSFER_BIT, Turbo::Core::TAccessBits::HOST_WRITE_BIT, Turbo::Core::TAccessBits::TRANSFER_WRITE_BIT, Turbo::Core::TImageLayout::UNDEFINED, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, ktx_sky_cube_image, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, ktx_texture_mip_levels, 0, 6 /*for cubemap six faces*/);
for (uint32_t face = 0; face < 6; face++)
{
for (uint32_t mip_index = 0; mip_index < ktx_texture_mip_levels; mip_index++)
{
uint32_t copy_width = ktx_texture_width >> mip_index;
uint32_t copy_height = ktx_texture_height >> mip_index;
uint32_t copy_mip_level = mip_index;
uint32_t copy_base_array_layer = face;
ktx_size_t copy_buffer_offset = 0;
KTX_error_code ret = ktxTexture_GetImageOffset(ktx_texture, mip_index, 0, face, ©_buffer_offset);
assert(ret == KTX_SUCCESS);
ktx_command_buffer->CmdCopyBufferToImage(ktx_staging_buffer, ktx_sky_cube_image, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, copy_buffer_offset, copy_width, copy_height, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, copy_mip_level, copy_base_array_layer, 1, 0, 0, 0, copy_width, copy_height, 1);
}
}
ktx_command_buffer->CmdTransformImageLayout(Turbo::Core::TPipelineStageBits::TRANSFER_BIT, Turbo::Core::TPipelineStageBits::FRAGMENT_SHADER_BIT, Turbo::Core::TAccessBits::TRANSFER_WRITE_BIT, Turbo::Core::TAccessBits::SHADER_READ_BIT, Turbo::Core::TImageLayout::TRANSFER_DST_OPTIMAL, Turbo::Core::TImageLayout::SHADER_READ_ONLY_OPTIMAL, ktx_sky_cube_image, Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, ktx_texture_mip_levels, 0, 6 /*for cubemap six faces*/);
ktx_command_buffer->End();
Turbo::Core::TRefPtr<Turbo::Core::TFence> ktx_fence = new Turbo::Core::TFence(device);
queue->Submit(ktx_command_buffer, ktx_fence);
ktx_fence->WaitUntil();
// delete ktx_fence;
// delete ktx_staging_buffer;
command_pool->Free(ktx_command_buffer);
ktxTexture_Destroy(ktx_texture);
}
//</KTX SkyCube Texture>
Turbo::Core::TRefPtr<Turbo::Core::TImageView> ktx_sky_cube_image_view = new Turbo::Core::TImageView(ktx_sky_cube_image, Turbo::Core::TImageViewType::IMAGE_VIEW_CUBE, ktx_sky_cube_image->GetFormat(), Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, ktx_sky_cube_image->GetMipLevels(), 0, 6 /*for cubemap six faces*/);
Turbo::Core::TRefPtr<Turbo::Core::TSampler> sky_cube_sampler = new Turbo::Core::TSampler(device, Turbo::Core::TFilter::LINEAR, Turbo::Core::TFilter::LINEAR, Turbo::Core::TMipmapMode::LINEAR, Turbo::Core::TAddressMode::REPEAT, Turbo::Core::TAddressMode::REPEAT, Turbo::Core::TAddressMode::REPEAT, Turbo::Core::TBorderColor::FLOAT_OPAQUE_WHITE, 0.0f, 0.0f, ktx_sky_cube_image->GetMipLevels());
Turbo::Core::TRefPtr<Turbo::Core::TImage> color_image = new Turbo::Core::TImage(device, 0, Turbo::Core::TImageType::DIMENSION_2D, Turbo::Core::TFormatType::B8G8R8A8_SRGB, swapchain->GetWidth(), swapchain->GetHeight(), 1, 1, 1, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, Turbo::Core::TImageTiling::OPTIMAL, Turbo::Core::TImageUsageBits::IMAGE_COLOR_ATTACHMENT | Turbo::Core::TImageUsageBits::IMAGE_TRANSFER_SRC | Turbo::Core::TImageUsageBits::IMAGE_TRANSFER_DST | Turbo::Core::TImageUsageBits::IMAGE_INPUT_ATTACHMENT, Turbo::Core::TMemoryFlagsBits::DEDICATED_MEMORY, Turbo::Core::TImageLayout::UNDEFINED);
Turbo::Core::TRefPtr<Turbo::Core::TImageView> color_image_view = new Turbo::Core::TImageView(color_image, Turbo::Core::TImageViewType::IMAGE_VIEW_2D, color_image->GetFormat(), Turbo::Core::TImageAspectBits::ASPECT_COLOR_BIT, 0, 1, 0, 1);
Turbo::Core::TRefPtr<Turbo::Core::TImage> depth_image = new Turbo::Core::TImage(device, 0, Turbo::Core::TImageType::DIMENSION_2D, Turbo::Core::TFormatType::D32_SFLOAT, swapchain->GetWidth(), swapchain->GetHeight(), 1, 1, 1, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, Turbo::Core::TImageTiling::OPTIMAL, Turbo::Core::TImageUsageBits::IMAGE_DEPTH_STENCIL_ATTACHMENT | Turbo::Core::TImageUsageBits::IMAGE_INPUT_ATTACHMENT, Turbo::Core::TMemoryFlagsBits::DEDICATED_MEMORY, Turbo::Core::TImageLayout::UNDEFINED);
Turbo::Core::TRefPtr<Turbo::Core::TImageView> depth_image_view = new Turbo::Core::TImageView(depth_image, Turbo::Core::TImageViewType::IMAGE_VIEW_2D, depth_image->GetFormat(), Turbo::Core::TImageAspectBits::ASPECT_DEPTH_BIT, 0, 1, 0, 1);
Turbo::Core::TRefPtr<Turbo::Core::TShader> vertex_shader = new Turbo::Core::TShader(device, Turbo::Core::TShaderType::VERTEX, Turbo::Core::TShaderLanguage::GLSL, VERT_SHADER_STR);
Turbo::Core::TRefPtr<Turbo::Core::TShader> fragment_shader = new Turbo::Core::TShader(device, Turbo::Core::TShaderType::FRAGMENT, Turbo::Core::TShaderLanguage::GLSL, FRAG_SHADER_STR);
Turbo::Core::TRefPtr<Turbo::Core::TShader> input_attachment_vertex_shader = new Turbo::Core::TShader(device, Turbo::Core::TShaderType::VERTEX, Turbo::Core::TShaderLanguage::GLSL, INPUT_ATTACHMENT_VERT_SHADER_STR);
Turbo::Core::TRefPtr<Turbo::Core::TShader> input_attachment_fragment_shader = new Turbo::Core::TShader(device, Turbo::Core::TShaderType::FRAGMENT, Turbo::Core::TShaderLanguage::GLSL, INPUT_ATTACHMENT_FRAG_SHADER_STR);
Turbo::Core::TRefPtr<Turbo::Core::TShader> sky_vertex_shader = new Turbo::Core::TShader(device, Turbo::Core::TShaderType::VERTEX, Turbo::Core::TShaderLanguage::GLSL, SKY_VERT_SHADER_STR);
Turbo::Core::TRefPtr<Turbo::Core::TShader> sky_fragment_shader = new Turbo::Core::TShader(device, Turbo::Core::TShaderType::FRAGMENT, Turbo::Core::TShaderLanguage::GLSL, SKY_FRAG_SHADER_STR);
std::cout << vertex_shader->ToString() << std::endl;
std::cout << fragment_shader->ToString() << std::endl;
std::cout << sky_vertex_shader->ToString() << std::endl;
std::cout << sky_fragment_shader->ToString() << std::endl;
std::vector<Turbo::Core::TDescriptorSize> descriptor_sizes;
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::UNIFORM_BUFFER, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::COMBINED_IMAGE_SAMPLER, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::SAMPLER, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::SAMPLED_IMAGE, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::STORAGE_IMAGE, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::UNIFORM_TEXEL_BUFFER, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::STORAGE_TEXEL_BUFFER, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::STORAGE_BUFFER, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::UNIFORM_BUFFER_DYNAMIC, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::STORAGE_BUFFER_DYNAMIC, 1000));
descriptor_sizes.push_back(Turbo::Core::TDescriptorSize(Turbo::Core::TDescriptorType::INPUT_ATTACHMENT, 1000));
Turbo::Core::TRefPtr<Turbo::Core::TDescriptorPool> descriptor_pool = new Turbo::Core::TDescriptorPool(device, descriptor_sizes.size() * 1000, descriptor_sizes);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TBuffer>> buffers;
buffers.push_back(value_buffer);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TBuffer>> mvp_buffers;
mvp_buffers.push_back(mvp_buffer);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TBuffer>> sky_cube_mvp_buffers;
sky_cube_mvp_buffers.push_back(sky_cube_mvp_buffer);
Turbo::Core::TSubpass subpass(Turbo::Core::TPipelineType::Graphics);
subpass.AddColorAttachmentReference(0, Turbo::Core::TImageLayout::COLOR_ATTACHMENT_OPTIMAL); // swapchain color image
subpass.AddColorAttachmentReference(1, Turbo::Core::TImageLayout::COLOR_ATTACHMENT_OPTIMAL); // custom color image
subpass.SetDepthStencilAttachmentReference(2, Turbo::Core::TImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL); // depth image
Turbo::Core::TSubpass subpass1(Turbo::Core::TPipelineType::Graphics);
subpass1.AddColorAttachmentReference(0, Turbo::Core::TImageLayout::COLOR_ATTACHMENT_OPTIMAL); // swapchain color image
subpass1.AddInputAttachmentReference(1, Turbo::Core::TImageLayout::SHADER_READ_ONLY_OPTIMAL); // custom color image, input attachment
subpass1.AddInputAttachmentReference(2, Turbo::Core::TImageLayout::SHADER_READ_ONLY_OPTIMAL); // depth image, input attachment
std::vector<Turbo::Core::TSubpass> subpasses;
subpasses.push_back(subpass); // subpass 0
subpasses.push_back(subpass1); // subpass 1
Turbo::Core::TAttachment swapchain_color_attachment(swapchain_images[0]->GetFormat(), swapchain_images[0]->GetSampleCountBits(), Turbo::Core::TLoadOp::CLEAR, Turbo::Core::TStoreOp::STORE, Turbo::Core::TLoadOp::DONT_CARE, Turbo::Core::TStoreOp::DONT_CARE, Turbo::Core::TImageLayout::UNDEFINED, Turbo::Core::TImageLayout::PRESENT_SRC_KHR);
Turbo::Core::TAttachment color_attachment(color_image->GetFormat(), color_image->GetSampleCountBits(), Turbo::Core::TLoadOp::CLEAR, Turbo::Core::TStoreOp::STORE, Turbo::Core::TLoadOp::DONT_CARE, Turbo::Core::TStoreOp::DONT_CARE, Turbo::Core::TImageLayout::UNDEFINED, Turbo::Core::TImageLayout::PRESENT_SRC_KHR);
Turbo::Core::TAttachment depth_attachment(depth_image->GetFormat(), depth_image->GetSampleCountBits(), Turbo::Core::TLoadOp::CLEAR, Turbo::Core::TStoreOp::STORE, Turbo::Core::TLoadOp::DONT_CARE, Turbo::Core::TStoreOp::DONT_CARE, Turbo::Core::TImageLayout::UNDEFINED, Turbo::Core::TImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
std::vector<Turbo::Core::TAttachment> attachemts;
attachemts.push_back(swapchain_color_attachment);
attachemts.push_back(color_attachment);
attachemts.push_back(depth_attachment);
Turbo::Core::TRefPtr<Turbo::Core::TRenderPass> render_pass = new Turbo::Core::TRenderPass(device, attachemts, subpasses);
Turbo::Core::TVertexBinding position_binding(0, sizeof(POSITION), Turbo::Core::TVertexRate::VERTEX);
position_binding.AddAttribute(0, Turbo::Core::TFormatType::R32G32B32_SFLOAT, 0); // position
Turbo::Core::TVertexBinding normal_binding(1, sizeof(NORMAL), Turbo::Core::TVertexRate::VERTEX);
normal_binding.AddAttribute(1, Turbo::Core::TFormatType::R32G32B32_SFLOAT, 0); // normal
Turbo::Core::TVertexBinding texcoord_binding(2, sizeof(TEXCOORD), Turbo::Core::TVertexRate::VERTEX);
texcoord_binding.AddAttribute(2, Turbo::Core::TFormatType::R32G32_SFLOAT, 0); // texcoord/uv
std::vector<Turbo::Core::TVertexBinding> vertex_bindings;
vertex_bindings.push_back(position_binding);
vertex_bindings.push_back(normal_binding);
vertex_bindings.push_back(texcoord_binding);
Turbo::Core::TViewport viewport(0, 0, 500, 500, 0, 1);
Turbo::Core::TScissor scissor(0, 0, 500, 500);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TShader>> shaders{vertex_shader, fragment_shader};
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TShader>> sky_cube_shaders{sky_vertex_shader, sky_fragment_shader};
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TShader>> input_attachment_shaders{input_attachment_vertex_shader, input_attachment_fragment_shader};
Turbo::Core::TRefPtr<Turbo::Core::TGraphicsPipeline> pipeline = new Turbo::Core::TGraphicsPipeline(render_pass, 0, vertex_bindings, shaders, Turbo::Core::TTopologyType::TRIANGLE_LIST, false, false, false, Turbo::Core::TPolygonMode::FILL, Turbo::Core::TCullModeBits::MODE_BACK_BIT, Turbo::Core::TFrontFace::CLOCKWISE, false, 0, 0, 0, 1, false, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, true, true, Turbo::Core::TCompareOp::LESS_OR_EQUAL, false, false, Turbo::Core::TStencilOp::KEEP, Turbo::Core::TStencilOp::KEEP, Turbo::Core::TStencilOp::KEEP, Turbo::Core::TCompareOp::ALWAYS, 0, 0, 0, Turbo::Core::TStencilOp::KEEP, Turbo::Core::TStencilOp::KEEP, Turbo::Core::TStencilOp::KEEP, Turbo::Core::TCompareOp::ALWAYS, 0, 0, 0, 0, 0, false, Turbo::Core::TLogicOp::NO_OP, true, Turbo::Core::TBlendFactor::SRC_ALPHA, Turbo::Core::TBlendFactor::ONE_MINUS_SRC_ALPHA, Turbo::Core::TBlendOp::ADD, Turbo::Core::TBlendFactor::ONE_MINUS_SRC_ALPHA, Turbo::Core::TBlendFactor::ZERO, Turbo::Core::TBlendOp::ADD);
Turbo::Core::TRefPtr<Turbo::Core::TGraphicsPipeline> sky_cube_pipeline = new Turbo::Core::TGraphicsPipeline(render_pass, 0, vertex_bindings, sky_cube_shaders, Turbo::Core::TTopologyType::TRIANGLE_LIST, false, false, false, Turbo::Core::TPolygonMode::FILL, Turbo::Core::TCullModeBits::MODE_FRONT_BIT, Turbo::Core::TFrontFace::CLOCKWISE, false, 0, 0, 0, 1, false, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, false, false, Turbo::Core::TCompareOp::LESS_OR_EQUAL, false, false);
Turbo::Core::TRefPtr<Turbo::Core::TGraphicsPipeline> input_attachment_pipeline = new Turbo::Core::TGraphicsPipeline(render_pass, 1, vertex_bindings, input_attachment_shaders, Turbo::Core::TTopologyType::TRIANGLE_LIST, false, false, false, Turbo::Core::TPolygonMode::FILL, Turbo::Core::TCullModeBits::MODE_BACK_BIT, Turbo::Core::TFrontFace::CLOCKWISE, false, 0, 0, 0, 1, false, Turbo::Core::TSampleCountBits::SAMPLE_1_BIT, true, false, Turbo::Core::TCompareOp::LESS_OR_EQUAL);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TImageView>> my_textures;
my_textures.push_back(/*texture_view*/ ktx_texture_view);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TSampler>> my_samples;
my_samples.push_back(sampler);
std::vector<std::pair<Turbo::Core::TRefPtr<Turbo::Core::TImageView>, Turbo::Core::TRefPtr<Turbo::Core::TSampler>>> sky_cube_combined_images;
sky_cube_combined_images.push_back(std::make_pair(ktx_sky_cube_image_view, sky_cube_sampler));
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TImageView>> input_attachment_colors;
input_attachment_colors.push_back(color_image_view);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TImageView>> input_attachment_depths;
input_attachment_depths.push_back(depth_image_view);
Turbo::Core::TRefPtr<Turbo::Core::TPipelineDescriptorSet> pipeline_descriptor_set = descriptor_pool->Allocate(pipeline->GetPipelineLayout());
pipeline_descriptor_set->BindData(0, 0, 0, buffers);
pipeline_descriptor_set->BindData(0, 1, 0, my_textures);
pipeline_descriptor_set->BindData(1, 0, 0, mvp_buffers);
pipeline_descriptor_set->BindData(1, 1, 0, sky_cube_combined_images);
pipeline_descriptor_set->BindData(2, 2, 0, my_samples);
Turbo::Core::TRefPtr<Turbo::Core::TPipelineDescriptorSet> sky_cube_pipeline_descriptor_set = descriptor_pool->Allocate(sky_cube_pipeline->GetPipelineLayout());
sky_cube_pipeline_descriptor_set->BindData(0, 0, 0, sky_cube_mvp_buffers);
sky_cube_pipeline_descriptor_set->BindData(0, 1, 0, sky_cube_combined_images);
Turbo::Core::TRefPtr<Turbo::Core::TPipelineDescriptorSet> input_attachment_pipeline_descriptor_set = descriptor_pool->Allocate(input_attachment_pipeline->GetPipelineLayout());
input_attachment_pipeline_descriptor_set->BindData(0, 0, 0, input_attachment_colors);
input_attachment_pipeline_descriptor_set->BindData(0, 1, 0, input_attachment_depths);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TBuffer>> vertex_buffers;
vertex_buffers.push_back(position_buffer);
vertex_buffers.push_back(normal_buffer);
vertex_buffers.push_back(texcoord_buffer);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TBuffer>> sky_cube_vertex_buffers;
sky_cube_vertex_buffers.push_back(sky_cube_position_buffer);
sky_cube_vertex_buffers.push_back(sky_cube_normal_buffer);
sky_cube_vertex_buffers.push_back(sky_cube_texcoord_buffer);
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TFramebuffer>> swpachain_framebuffers;
for (Turbo::Core::TRefPtr<Turbo::Core::TImageView> &swapchain_image_view_item : swapchain_image_views)
{
std::vector<Turbo::Core::TRefPtr<Turbo::Core::TImageView>> image_views;
image_views.push_back(swapchain_image_view_item);
image_views.push_back(color_image_view);
image_views.push_back(depth_image_view);
Turbo::Core::TRefPtr<Turbo::Core::TFramebuffer> swapchain_framebuffer = new Turbo::Core::TFramebuffer(render_pass, image_views);
swpachain_framebuffers.push_back(swapchain_framebuffer);
}
//<IMGUI>
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
ImGui::StyleColorsDark();