@@ -15,7 +15,7 @@ namespace vksample {
1515 * @brief
1616 *
1717 */
18- class Cube : public VKWindow {
18+ class Cube : public VKBaseSampleWindow {
1919 private:
2020 VkBuffer vertexBuffer = VK_NULL_HANDLE;
2121 VkDeviceMemory vertexMemory = VK_NULL_HANDLE;
@@ -24,24 +24,21 @@ namespace vksample {
2424 VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
2525 VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
2626
27- VkDescriptorPool descpool = VK_NULL_HANDLE;
28-
2927 std::vector<VkDescriptorSet> descriptorSets;
28+
3029 VkBuffer uniformBuffer{};
30+ VkDeviceSize uniformMemSize{};
3131 VkDeviceMemory uniformBufferMemory{};
3232 std::vector<void *> mapMemory;
3333
34- VkDeviceSize uniformMemSize{};
3534 CameraController camera;
3635
37- const std::string vertexShaderPath = " Shaders/triangle-mvp .vert.spv" ;
38- const std::string fragmentShaderPath = " Shaders/triangle-mvp .frag.spv" ;
36+ const std::string vertexShaderPath = " Shaders/vertexinterpolation/VertexInterpolation .vert.spv" ;
37+ const std::string fragmentShaderPath = " Shaders/vertexinterpolation/VertexInterpolation .frag.spv" ;
3938
4039 struct UniformBufferBlock {
41- glm::mat4 model;
42- glm::mat4 view;
43- glm::mat4 proj;
44- } mvp{};
40+ glm::mat4 modelViewProjection;
41+ } StageBuffer{};
4542
4643 using Vertex = struct _vertex_t {
4744 float pos[3 ];
@@ -50,16 +47,21 @@ namespace vksample {
5047
5148 public:
5249 Cube (std::shared_ptr<VulkanCore> &core, std::shared_ptr<VKDevice> &device)
53- : VKWindow (core, device, -1 , -1 , -1 , -1 ) {
50+ : VKBaseSampleWindow (core, device, -1 , -1 , -1 , -1 ) {
5451 this ->setTitle (" Cube" );
5552 this ->show ();
5653
57- this ->camera .enableNavigation (false );
54+ /* Default camera position and orientation. */
55+ this ->camera .setPosition (glm::vec3 (-2 .5f ));
56+ this ->camera .lookAt (glm::vec3 (0 .f ));
57+
58+ this ->camera .enableNavigation (true );
59+ this ->camera .enableLook (true );
5860 }
5961
6062 void release () override {
6163
62- vkDestroyDescriptorPool (getDevice (), this ->descpool , nullptr );
64+ vkDestroyDescriptorPool (getDevice (), this ->getDescriptorPool () , nullptr );
6365
6466 vkDestroyBuffer (getDevice (), this ->vertexBuffer , nullptr );
6567 vkFreeMemory (getDevice (), this ->vertexMemory , nullptr );
@@ -116,9 +118,9 @@ namespace vksample {
116118 VkPipeline createGraphicPipeline () {
117119
118120 const auto vertShaderCode =
119- vksample ::IOUtil::readFileData<uint32_t >(this ->vertexShaderPath , this ->getFileSystem ());
121+ fragcore ::IOUtil::readFileData<uint32_t >(this ->vertexShaderPath , this ->getFileSystem ());
120122 const auto fragShaderCode =
121- vksample ::IOUtil::readFileData<uint32_t >(this ->fragmentShaderPath , this ->getFileSystem ());
123+ fragcore ::IOUtil::readFileData<uint32_t >(this ->fragmentShaderPath , this ->getFileSystem ());
122124
123125 VkShaderModule vertShaderModule = VKHelper::createShaderModule (getDevice (), vertShaderCode);
124126 VkShaderModule fragShaderModule = VKHelper::createShaderModule (getDevice (), fragShaderCode);
@@ -170,7 +172,7 @@ namespace vksample {
170172 uboLayoutBinding.pImmutableSamplers = nullptr ;
171173 uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
172174
173- VKHelper::createDescriptorSetLayout (this ->getDevice (), descriptorSetLayout, {uboLayoutBinding});
175+ VKHelper::createDescriptorSetLayout (this ->getDevice (), descriptorSetLayout, {uboLayoutBinding}, 0 );
174176
175177 VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
176178 inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
@@ -236,7 +238,7 @@ namespace vksample {
236238 depthStencil.depthBoundsTestEnable = VK_FALSE;
237239 depthStencil.stencilTestEnable = VK_FALSE;
238240
239- VKHelper::createPipelineLayout (getDevice (), pipelineLayout, {descriptorSetLayout});
241+ VKHelper::createPipelineLayout (getDevice (), pipelineLayout, 0 , {descriptorSetLayout});
240242
241243 VkDynamicState dynamicStateEnables[1 ];
242244 dynamicStateEnables[0 ] = VK_DYNAMIC_STATE_VIEWPORT;
@@ -276,8 +278,8 @@ namespace vksample {
276278
277279 this ->uniformMemSize = sizeof (UniformBufferBlock);
278280
279- this -> uniformMemSize +=
280- uniformMemSize % getVKDevice ()-> getPhysicalDevices ()[ 0 ]-> getDeviceLimits (). nonCoherentAtomSize ;
281+ const size_t uniform_align_size = getPhysicalDevice ()-> getDeviceLimits (). minUniformBufferOffsetAlignment ;
282+ this -> uniformMemSize = Math::align ( this -> uniformMemSize , uniform_align_size) ;
281283
282284 const VkDeviceSize uniformBufferSize = this ->getSwapChainImageCount () * uniformMemSize;
283285
@@ -298,26 +300,14 @@ namespace vksample {
298300 this ->mapMemory [i] = &_data[this ->uniformMemSize * i];
299301 }
300302
301- VkDescriptorPoolSize poolSize{};
302- poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
303- poolSize.descriptorCount = static_cast <uint32_t >(getSwapChainImageCount ());
304-
305- VkDescriptorPoolCreateInfo poolInfo{};
306- poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
307- poolInfo.poolSizeCount = 1 ;
308- poolInfo.pPoolSizes = &poolSize;
309- poolInfo.maxSets = static_cast <uint32_t >(getSwapChainImageCount ());
310-
311- VKS_VALIDATE (vkCreateDescriptorPool (getDevice (), &poolInfo, nullptr , &descpool));
312-
313303 /* Create pipeline. */
314304 this ->graphicsPipeline = createGraphicPipeline ();
315305
316306 /* */
317307 std::vector<VkDescriptorSetLayout> layouts (getSwapChainImageCount (), descriptorSetLayout);
318308 VkDescriptorSetAllocateInfo allocdescInfo{};
319309 allocdescInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
320- allocdescInfo.descriptorPool = descpool ;
310+ allocdescInfo.descriptorPool = getDescriptorPool () ;
321311 allocdescInfo.descriptorSetCount = static_cast <uint32_t >(getSwapChainImageCount ());
322312 allocdescInfo.pSetLayouts = layouts.data ();
323313
@@ -412,8 +402,12 @@ namespace vksample {
412402 renderPassInfo.clearValueCount = clearValues.size ();
413403 renderPassInfo.pClearValues = clearValues.data ();
414404
415- VkViewport viewport = {
416- .x = 0 , .y = 0 , .width = (float )width, .height = (float )height, .minDepth = 0 , .maxDepth = 1 .0f };
405+ const VkViewport viewport = {.x = 0 ,
406+ .y = static_cast <float >(height),
407+ .width = (float )width,
408+ .height = (float )-height,
409+ .minDepth = 0 ,
410+ .maxDepth = 1 .0f };
417411 vkCmdSetViewport (cmd, 0 , 1 , &viewport);
418412
419413 vkCmdBeginRenderPass (cmd, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
@@ -445,17 +439,12 @@ namespace vksample {
445439 this ->camera .update (this ->getTimer ().deltaTime <float >());
446440
447441 const float elapsedTime = this ->getTimer ().getElapsed <float >();
448-
449- this ->mvp .proj = this ->camera .getProjectionMatrix ();
450- this ->mvp .model = glm::mat4 (1 .0f );
451- this ->mvp .view = glm::mat4 (1 .0f );
452- this ->mvp .view = glm::translate (this ->mvp .view , glm::vec3 (0 , 0 , -5 ));
453- this ->mvp .model =
454- glm::rotate (this ->mvp .model , glm::radians (elapsedTime * 45 .0f ), glm::vec3 (0 .0f , 1 .0f , 0 .0f ));
455- this ->mvp .model = glm::scale (this ->mvp .model , glm::vec3 (0 .95f ));
442+ this ->StageBuffer .modelViewProjection =
443+ (camera.getProjectionMatrix () * camera.getViewMatrix () *
444+ glm::rotate (glm::mat4 (1 ), glm::radians (elapsedTime * 45 .0f ), glm::vec3 (0 .0f , 1 .0f , 0 .0f )));
456445
457446 /* Copy new uniform data. */
458- memcpy (this ->mapMemory [this ->getCurrentFrameIndex ()], &mvp , (size_t )sizeof (this ->mvp ));
447+ memcpy (this ->mapMemory [this ->getCurrentFrameIndex ()], &StageBuffer , (size_t )sizeof (this ->StageBuffer ));
459448
460449 // Setup the range
461450 VkMappedMemoryRange stagingRange{};
0 commit comments