mirror of
https://github.com/opus-tango/IntroductionToVulkan.git
synced 2026-03-20 03:55:26 +00:00
Added license.txt file.
Added Project folder with source code examples Part 1, Part 2, Part 3 and Part 4.
This commit is contained in:
BIN
Project/Tutorial03/Data03/frag.spv
Normal file
BIN
Project/Tutorial03/Data03/frag.spv
Normal file
Binary file not shown.
35
Project/Tutorial03/Data03/frag.spv.txt
Normal file
35
Project/Tutorial03/Data03/frag.spv.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
shader.frag
|
||||
Warning, version 400 is not yet complete; most version-specific features are present, but some are missing.
|
||||
|
||||
|
||||
Linked fragment stage:
|
||||
|
||||
|
||||
// Module Version 10000
|
||||
// Generated by (magic number): 80001
|
||||
// Id's are bound by 14
|
||||
|
||||
Capability Shader
|
||||
1: ExtInstImport "GLSL.std.450"
|
||||
MemoryModel Logical GLSL450
|
||||
EntryPoint Fragment 4 "main" 9
|
||||
ExecutionMode 4 OriginLowerLeft
|
||||
Source GLSL 400
|
||||
Name 4 "main"
|
||||
Name 9 "out_Color"
|
||||
Decorate 9(out_Color) Location 0
|
||||
2: TypeVoid
|
||||
3: TypeFunction 2
|
||||
6: TypeFloat 32
|
||||
7: TypeVector 6(float) 4
|
||||
8: TypePointer Output 7(fvec4)
|
||||
9(out_Color): 8(ptr) Variable Output
|
||||
10: 6(float) Constant 0
|
||||
11: 6(float) Constant 1053609165
|
||||
12: 6(float) Constant 1065353216
|
||||
13: 7(fvec4) ConstantComposite 10 11 12 12
|
||||
4(main): 2 Function None 3
|
||||
5: Label
|
||||
Store 9(out_Color) 13
|
||||
Return
|
||||
FunctionEnd
|
||||
17
Project/Tutorial03/Data03/shader.frag
Normal file
17
Project/Tutorial03/Data03/shader.frag
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2016 Intel Corporation All Rights Reserved
|
||||
//
|
||||
// Intel makes no representations about the suitability of this software for any purpose.
|
||||
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
|
||||
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
|
||||
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// Intel does not assume any responsibility for any errors which may appear in this software
|
||||
// nor any responsibility to update it.
|
||||
|
||||
#version 400
|
||||
|
||||
layout(location = 0) out vec4 out_Color;
|
||||
|
||||
void main() {
|
||||
out_Color = vec4( 0.0, 0.4, 1.0, 1.0 );
|
||||
}
|
||||
16
Project/Tutorial03/Data03/shader.vert
Normal file
16
Project/Tutorial03/Data03/shader.vert
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2016 Intel Corporation All Rights Reserved
|
||||
//
|
||||
// Intel makes no representations about the suitability of this software for any purpose.
|
||||
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
|
||||
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
|
||||
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// Intel does not assume any responsibility for any errors which may appear in this software
|
||||
// nor any responsibility to update it.
|
||||
|
||||
#version 400
|
||||
|
||||
void main() {
|
||||
vec2 pos[3] = vec2[3]( vec2(-0.7, 0.7), vec2(0.7, 0.7), vec2(0.0, -0.7) );
|
||||
gl_Position = vec4( pos[gl_VertexIndex], 0.0, 1.0 );
|
||||
}
|
||||
BIN
Project/Tutorial03/Data03/vert.spv
Normal file
BIN
Project/Tutorial03/Data03/vert.spv
Normal file
Binary file not shown.
72
Project/Tutorial03/Data03/vert.spv.txt
Normal file
72
Project/Tutorial03/Data03/vert.spv.txt
Normal file
@@ -0,0 +1,72 @@
|
||||
shader.vert
|
||||
Warning, version 400 is not yet complete; most version-specific features are present, but some are missing.
|
||||
|
||||
|
||||
Linked vertex stage:
|
||||
|
||||
|
||||
// Module Version 10000
|
||||
// Generated by (magic number): 80001
|
||||
// Id's are bound by 40
|
||||
|
||||
Capability Shader
|
||||
Capability ClipDistance
|
||||
1: ExtInstImport "GLSL.std.450"
|
||||
MemoryModel Logical GLSL450
|
||||
EntryPoint Vertex 4 "main" 25 29
|
||||
Source GLSL 400
|
||||
Name 4 "main"
|
||||
Name 12 "pos"
|
||||
Name 23 "gl_PerVertex"
|
||||
MemberName 23(gl_PerVertex) 0 "gl_Position"
|
||||
MemberName 23(gl_PerVertex) 1 "gl_PointSize"
|
||||
MemberName 23(gl_PerVertex) 2 "gl_ClipDistance"
|
||||
Name 25 ""
|
||||
Name 29 "gl_VertexIndex"
|
||||
MemberDecorate 23(gl_PerVertex) 0 BuiltIn Position
|
||||
MemberDecorate 23(gl_PerVertex) 1 BuiltIn PointSize
|
||||
MemberDecorate 23(gl_PerVertex) 2 BuiltIn ClipDistance
|
||||
Decorate 23(gl_PerVertex) Block
|
||||
Decorate 29(gl_VertexIndex) BuiltIn VertexIndex
|
||||
2: TypeVoid
|
||||
3: TypeFunction 2
|
||||
6: TypeFloat 32
|
||||
7: TypeVector 6(float) 2
|
||||
8: TypeInt 32 0
|
||||
9: 8(int) Constant 3
|
||||
10: TypeArray 7(fvec2) 9
|
||||
11: TypePointer Function 10
|
||||
13: 6(float) Constant 3207803699
|
||||
14: 6(float) Constant 1060320051
|
||||
15: 7(fvec2) ConstantComposite 13 14
|
||||
16: 7(fvec2) ConstantComposite 14 14
|
||||
17: 6(float) Constant 0
|
||||
18: 7(fvec2) ConstantComposite 17 13
|
||||
19: 10 ConstantComposite 15 16 18
|
||||
20: TypeVector 6(float) 4
|
||||
21: 8(int) Constant 1
|
||||
22: TypeArray 6(float) 21
|
||||
23(gl_PerVertex): TypeStruct 20(fvec4) 6(float) 22
|
||||
24: TypePointer Output 23(gl_PerVertex)
|
||||
25: 24(ptr) Variable Output
|
||||
26: TypeInt 32 1
|
||||
27: 26(int) Constant 0
|
||||
28: TypePointer Input 26(int)
|
||||
29(gl_VertexIndex): 28(ptr) Variable Input
|
||||
31: TypePointer Function 7(fvec2)
|
||||
34: 6(float) Constant 1065353216
|
||||
38: TypePointer Output 20(fvec4)
|
||||
4(main): 2 Function None 3
|
||||
5: Label
|
||||
12(pos): 11(ptr) Variable Function
|
||||
Store 12(pos) 19
|
||||
30: 26(int) Load 29(gl_VertexIndex)
|
||||
32: 31(ptr) AccessChain 12(pos) 30
|
||||
33: 7(fvec2) Load 32
|
||||
35: 6(float) CompositeExtract 33 0
|
||||
36: 6(float) CompositeExtract 33 1
|
||||
37: 20(fvec4) CompositeConstruct 35 36 17 34
|
||||
39: 38(ptr) AccessChain 25 27
|
||||
Store 39 37
|
||||
Return
|
||||
FunctionEnd
|
||||
596
Project/Tutorial03/Tutorial03.cpp
Normal file
596
Project/Tutorial03/Tutorial03.cpp
Normal file
@@ -0,0 +1,596 @@
|
||||
// Copyright 2016 Intel Corporation All Rights Reserved
|
||||
//
|
||||
// Intel makes no representations about the suitability of this software for any purpose.
|
||||
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
|
||||
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
|
||||
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// Intel does not assume any responsibility for any errors which may appear in this software
|
||||
// nor any responsibility to update it.
|
||||
|
||||
#include "Tutorial03.h"
|
||||
#include "VulkanFunctions.h"
|
||||
|
||||
namespace Tutorial {
|
||||
|
||||
Tutorial03::Tutorial03() :
|
||||
Vulkan() {
|
||||
}
|
||||
|
||||
bool Tutorial03::CreateRenderPass() {
|
||||
VkAttachmentDescription attachment_descriptions[] = {
|
||||
{
|
||||
0, // VkAttachmentDescriptionFlags flags
|
||||
GetSwapChain().Format, // VkFormat format
|
||||
VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples
|
||||
VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp
|
||||
VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp
|
||||
VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp
|
||||
VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // VkImageLayout initialLayout;
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR // VkImageLayout finalLayout
|
||||
}
|
||||
};
|
||||
|
||||
VkAttachmentReference color_attachment_references[] = {
|
||||
{
|
||||
0, // uint32_t attachment
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout
|
||||
}
|
||||
};
|
||||
|
||||
VkSubpassDescription subpass_descriptions[] = {
|
||||
{
|
||||
0, // VkSubpassDescriptionFlags flags
|
||||
VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint
|
||||
0, // uint32_t inputAttachmentCount
|
||||
nullptr, // const VkAttachmentReference *pInputAttachments
|
||||
1, // uint32_t colorAttachmentCount
|
||||
color_attachment_references, // const VkAttachmentReference *pColorAttachments
|
||||
nullptr, // const VkAttachmentReference *pResolveAttachments
|
||||
nullptr, // const VkAttachmentReference *pDepthStencilAttachment
|
||||
0, // uint32_t preserveAttachmentCount
|
||||
nullptr // const uint32_t* pPreserveAttachments
|
||||
}
|
||||
};
|
||||
|
||||
VkRenderPassCreateInfo render_pass_create_info = {
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkRenderPassCreateFlags flags
|
||||
1, // uint32_t attachmentCount
|
||||
attachment_descriptions, // const VkAttachmentDescription *pAttachments
|
||||
1, // uint32_t subpassCount
|
||||
subpass_descriptions, // const VkSubpassDescription *pSubpasses
|
||||
0, // uint32_t dependencyCount
|
||||
nullptr // const VkSubpassDependency *pDependencies
|
||||
};
|
||||
|
||||
if( vkCreateRenderPass( GetDevice(), &render_pass_create_info, nullptr, &Vulkan.RenderPass ) != VK_SUCCESS ) {
|
||||
printf( "Could not create render pass!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tutorial03::CreateFramebuffers() {
|
||||
const std::vector<VkImage> &swap_chain_images = GetSwapChain().Images;
|
||||
Vulkan.FramebufferObjects.resize( swap_chain_images.size() );
|
||||
|
||||
for( size_t i = 0; i < swap_chain_images.size(); ++i ) {
|
||||
VkImageViewCreateInfo image_view_create_info = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkImageViewCreateFlags flags
|
||||
swap_chain_images[i], // VkImage image
|
||||
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType
|
||||
GetSwapChain().Format, // VkFormat format
|
||||
{ // VkComponentMapping components
|
||||
VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle r
|
||||
VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle g
|
||||
VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle b
|
||||
VK_COMPONENT_SWIZZLE_IDENTITY // VkComponentSwizzle a
|
||||
},
|
||||
{ // VkImageSubresourceRange subresourceRange
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
|
||||
0, // uint32_t baseMipLevel
|
||||
1, // uint32_t levelCount
|
||||
0, // uint32_t baseArrayLayer
|
||||
1 // uint32_t layerCount
|
||||
}
|
||||
};
|
||||
|
||||
if( vkCreateImageView( GetDevice(), &image_view_create_info, nullptr, &Vulkan.FramebufferObjects[i].ImageView ) != VK_SUCCESS ) {
|
||||
printf( "Could not create image view for framebuffer!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
VkFramebufferCreateInfo framebuffer_create_info = {
|
||||
VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkFramebufferCreateFlags flags
|
||||
Vulkan.RenderPass, // VkRenderPass renderPass
|
||||
1, // uint32_t attachmentCount
|
||||
&Vulkan.FramebufferObjects[i].ImageView, // const VkImageView *pAttachments
|
||||
300, // uint32_t width
|
||||
300, // uint32_t height
|
||||
1 // uint32_t layers
|
||||
};
|
||||
|
||||
if( vkCreateFramebuffer( GetDevice(), &framebuffer_create_info, nullptr, &Vulkan.FramebufferObjects[i].Handle ) != VK_SUCCESS ) {
|
||||
printf( "Could not create a framebuffer!\n" );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> Tutorial03::CreateShaderModule( const char* filename ) {
|
||||
const std::vector<char> code = Tools::GetBinaryFileContents( filename );
|
||||
if( code.size() == 0 ) {
|
||||
return Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule>();
|
||||
}
|
||||
|
||||
VkShaderModuleCreateInfo shader_module_create_info = {
|
||||
VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkShaderModuleCreateFlags flags
|
||||
code.size(), // size_t codeSize
|
||||
reinterpret_cast<const uint32_t*>(&code[0]) // const uint32_t *pCode
|
||||
};
|
||||
|
||||
VkShaderModule shader_module;
|
||||
if( vkCreateShaderModule( GetDevice(), &shader_module_create_info, nullptr, &shader_module ) != VK_SUCCESS ) {
|
||||
printf( "Could not create shader module from a %s file!\n", filename );
|
||||
return Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule>();
|
||||
}
|
||||
|
||||
return Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule>( shader_module, vkDestroyShaderModule, GetDevice() );
|
||||
}
|
||||
|
||||
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> Tutorial03::CreatePipelineLayout() {
|
||||
VkPipelineLayoutCreateInfo layout_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineLayoutCreateFlags flags
|
||||
0, // uint32_t setLayoutCount
|
||||
nullptr, // const VkDescriptorSetLayout *pSetLayouts
|
||||
0, // uint32_t pushConstantRangeCount
|
||||
nullptr // const VkPushConstantRange *pPushConstantRanges
|
||||
};
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
if( vkCreatePipelineLayout( GetDevice(), &layout_create_info, nullptr, &pipeline_layout ) != VK_SUCCESS ) {
|
||||
printf( "Could not create pipeline layout!\n" );
|
||||
return Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout>();
|
||||
}
|
||||
|
||||
return Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout>( pipeline_layout, vkDestroyPipelineLayout, GetDevice() );
|
||||
}
|
||||
|
||||
bool Tutorial03::CreatePipeline() {
|
||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> vertex_shader_module = CreateShaderModule( "Data03/vert.spv" );
|
||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> fragment_shader_module = CreateShaderModule( "Data03/frag.spv" );
|
||||
|
||||
if( !vertex_shader_module || !fragment_shader_module ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<VkPipelineShaderStageCreateInfo> shader_stage_create_infos = {
|
||||
// Vertex shader
|
||||
{
|
||||
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineShaderStageCreateFlags flags
|
||||
VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage
|
||||
vertex_shader_module.Get(), // VkShaderModule module
|
||||
"main", // const char *pName
|
||||
nullptr // const VkSpecializationInfo *pSpecializationInfo
|
||||
},
|
||||
// Fragment shader
|
||||
{
|
||||
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineShaderStageCreateFlags flags
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage
|
||||
fragment_shader_module.Get(), // VkShaderModule module
|
||||
"main", // const char *pName
|
||||
nullptr // const VkSpecializationInfo *pSpecializationInfo
|
||||
}
|
||||
};
|
||||
|
||||
VkPipelineVertexInputStateCreateInfo vertex_input_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineVertexInputStateCreateFlags flags;
|
||||
0, // uint32_t vertexBindingDescriptionCount
|
||||
nullptr, // const VkVertexInputBindingDescription *pVertexBindingDescriptions
|
||||
0, // uint32_t vertexAttributeDescriptionCount
|
||||
nullptr // const VkVertexInputAttributeDescription *pVertexAttributeDescriptions
|
||||
};
|
||||
|
||||
VkPipelineInputAssemblyStateCreateInfo input_assembly_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineInputAssemblyStateCreateFlags flags
|
||||
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology
|
||||
VK_FALSE // VkBool32 primitiveRestartEnable
|
||||
};
|
||||
|
||||
VkViewport viewport = {
|
||||
0.0f, // float x
|
||||
0.0f, // float y
|
||||
300.0f, // float width
|
||||
300.0f, // float height
|
||||
0.0f, // float minDepth
|
||||
1.0f // float maxDepth
|
||||
};
|
||||
|
||||
VkRect2D scissor = {
|
||||
{ // VkOffset2D offset
|
||||
0, // int32_t x
|
||||
0 // int32_t y
|
||||
},
|
||||
{ // VkExtent2D extent
|
||||
300, // int32_t width
|
||||
300 // int32_t height
|
||||
}
|
||||
};
|
||||
|
||||
VkPipelineViewportStateCreateInfo viewport_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineViewportStateCreateFlags flags
|
||||
1, // uint32_t viewportCount
|
||||
&viewport, // const VkViewport *pViewports
|
||||
1, // uint32_t scissorCount
|
||||
&scissor // const VkRect2D *pScissors
|
||||
};
|
||||
|
||||
VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineRasterizationStateCreateFlags flags
|
||||
VK_FALSE, // VkBool32 depthClampEnable
|
||||
VK_FALSE, // VkBool32 rasterizerDiscardEnable
|
||||
VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode
|
||||
VK_CULL_MODE_BACK_BIT, // VkCullModeFlags cullMode
|
||||
VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace
|
||||
VK_FALSE, // VkBool32 depthBiasEnable
|
||||
0.0f, // float depthBiasConstantFactor
|
||||
0.0f, // float depthBiasClamp
|
||||
0.0f, // float depthBiasSlopeFactor
|
||||
1.0f // float lineWidth
|
||||
};
|
||||
|
||||
VkPipelineMultisampleStateCreateInfo multisample_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineMultisampleStateCreateFlags flags
|
||||
VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples
|
||||
VK_FALSE, // VkBool32 sampleShadingEnable
|
||||
1.0f, // float minSampleShading
|
||||
nullptr, // const VkSampleMask *pSampleMask
|
||||
VK_FALSE, // VkBool32 alphaToCoverageEnable
|
||||
VK_FALSE // VkBool32 alphaToOneEnable
|
||||
};
|
||||
|
||||
VkPipelineColorBlendAttachmentState color_blend_attachment_state = {
|
||||
VK_FALSE, // VkBool32 blendEnable
|
||||
VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor
|
||||
VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor
|
||||
VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp
|
||||
VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor
|
||||
VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor
|
||||
VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp
|
||||
VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask
|
||||
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
|
||||
};
|
||||
|
||||
VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineColorBlendStateCreateFlags flags
|
||||
VK_FALSE, // VkBool32 logicOpEnable
|
||||
VK_LOGIC_OP_COPY, // VkLogicOp logicOp
|
||||
1, // uint32_t attachmentCount
|
||||
&color_blend_attachment_state, // const VkPipelineColorBlendAttachmentState *pAttachments
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4]
|
||||
};
|
||||
|
||||
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> pipeline_layout = CreatePipelineLayout();
|
||||
if( !pipeline_layout ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VkGraphicsPipelineCreateInfo pipeline_create_info = {
|
||||
VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkPipelineCreateFlags flags
|
||||
static_cast<uint32_t>(shader_stage_create_infos.size()), // uint32_t stageCount
|
||||
&shader_stage_create_infos[0], // const VkPipelineShaderStageCreateInfo *pStages
|
||||
&vertex_input_state_create_info, // const VkPipelineVertexInputStateCreateInfo *pVertexInputState;
|
||||
&input_assembly_state_create_info, // const VkPipelineInputAssemblyStateCreateInfo *pInputAssemblyState
|
||||
nullptr, // const VkPipelineTessellationStateCreateInfo *pTessellationState
|
||||
&viewport_state_create_info, // const VkPipelineViewportStateCreateInfo *pViewportState
|
||||
&rasterization_state_create_info, // const VkPipelineRasterizationStateCreateInfo *pRasterizationState
|
||||
&multisample_state_create_info, // const VkPipelineMultisampleStateCreateInfo *pMultisampleState
|
||||
nullptr, // const VkPipelineDepthStencilStateCreateInfo *pDepthStencilState
|
||||
&color_blend_state_create_info, // const VkPipelineColorBlendStateCreateInfo *pColorBlendState
|
||||
nullptr, // const VkPipelineDynamicStateCreateInfo *pDynamicState
|
||||
pipeline_layout.Get(), // VkPipelineLayout layout
|
||||
Vulkan.RenderPass, // VkRenderPass renderPass
|
||||
0, // uint32_t subpass
|
||||
VK_NULL_HANDLE, // VkPipeline basePipelineHandle
|
||||
-1 // int32_t basePipelineIndex
|
||||
};
|
||||
|
||||
if( vkCreateGraphicsPipelines( GetDevice(), VK_NULL_HANDLE, 1, &pipeline_create_info, nullptr, &Vulkan.GraphicsPipeline ) != VK_SUCCESS ) {
|
||||
printf( "Could not create graphics pipeline!\n" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tutorial03::CreateCommandBuffers() {
|
||||
if( !CreateCommandPool( GetGraphicsQueue().FamilyIndex, &Vulkan.GraphicsCommandPool ) ) {
|
||||
printf( "Could not create command pool!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t image_count = static_cast<uint32_t>(GetSwapChain().Images.size());
|
||||
Vulkan.GraphicsCommandBuffers.resize( image_count, VK_NULL_HANDLE );
|
||||
|
||||
if( !AllocateCommandBuffers( Vulkan.GraphicsCommandPool, image_count, &Vulkan.GraphicsCommandBuffers[0] ) ) {
|
||||
printf( "Could not allocate command buffers!\n" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tutorial03::CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool ) {
|
||||
VkCommandPoolCreateInfo cmd_pool_create_info = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
0, // VkCommandPoolCreateFlags flags
|
||||
queue_family_index // uint32_t queueFamilyIndex
|
||||
};
|
||||
|
||||
if( vkCreateCommandPool( GetDevice(), &cmd_pool_create_info, nullptr, pool ) != VK_SUCCESS ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tutorial03::AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers ) {
|
||||
VkCommandBufferAllocateInfo command_buffer_allocate_info = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
pool, // VkCommandPool commandPool
|
||||
VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level
|
||||
count // uint32_t bufferCount
|
||||
};
|
||||
|
||||
if( vkAllocateCommandBuffers( GetDevice(), &command_buffer_allocate_info, command_buffers ) != VK_SUCCESS ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tutorial03::RecordCommandBuffers() {
|
||||
VkCommandBufferBeginInfo graphics_commandd_buffer_begin_info = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, // VkCommandBufferUsageFlags flags
|
||||
nullptr // const VkCommandBufferInheritanceInfo *pInheritanceInfo
|
||||
};
|
||||
|
||||
VkImageSubresourceRange image_subresource_range = {
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
|
||||
0, // uint32_t baseMipLevel
|
||||
1, // uint32_t levelCount
|
||||
0, // uint32_t baseArrayLayer
|
||||
1 // uint32_t layerCount
|
||||
};
|
||||
|
||||
VkClearValue clear_value = {
|
||||
{ 1.0f, 0.8f, 0.4f, 0.0f }, // VkClearColorValue color
|
||||
};
|
||||
|
||||
const std::vector<VkImage>& swap_chain_images = GetSwapChain().Images;
|
||||
|
||||
for( size_t i = 0; i < Vulkan.GraphicsCommandBuffers.size(); ++i ) {
|
||||
vkBeginCommandBuffer( Vulkan.GraphicsCommandBuffers[i], &graphics_commandd_buffer_begin_info );
|
||||
|
||||
if( GetPresentQueue().Handle != GetGraphicsQueue().Handle ) {
|
||||
VkImageMemoryBarrier barrier_from_present_to_draw = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
VK_ACCESS_MEMORY_READ_BIT, // VkAccessFlags srcAccessMask
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // VkImageLayout oldLayout
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // VkImageLayout newLayout
|
||||
GetPresentQueue().FamilyIndex, // uint32_t srcQueueFamilyIndex
|
||||
GetGraphicsQueue().FamilyIndex, // uint32_t dstQueueFamilyIndex
|
||||
swap_chain_images[i], // VkImage image
|
||||
image_subresource_range // VkImageSubresourceRange subresourceRange
|
||||
};
|
||||
vkCmdPipelineBarrier( Vulkan.GraphicsCommandBuffers[i], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier_from_present_to_draw );
|
||||
}
|
||||
|
||||
VkRenderPassBeginInfo render_pass_begin_info = {
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
Vulkan.RenderPass, // VkRenderPass renderPass
|
||||
Vulkan.FramebufferObjects[i].Handle, // VkFramebuffer framebuffer
|
||||
{ // VkRect2D renderArea
|
||||
{ // VkOffset2D offset
|
||||
0, // int32_t x
|
||||
0 // int32_t y
|
||||
},
|
||||
{ // VkExtent2D extent
|
||||
300, // int32_t width
|
||||
300, // int32_t height
|
||||
}
|
||||
},
|
||||
1, // uint32_t clearValueCount
|
||||
&clear_value // const VkClearValue *pClearValues
|
||||
};
|
||||
|
||||
vkCmdBeginRenderPass( Vulkan.GraphicsCommandBuffers[i], &render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE );
|
||||
|
||||
vkCmdBindPipeline( Vulkan.GraphicsCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, Vulkan.GraphicsPipeline );
|
||||
|
||||
vkCmdDraw( Vulkan.GraphicsCommandBuffers[i], 3, 1, 0, 0 );
|
||||
|
||||
vkCmdEndRenderPass( Vulkan.GraphicsCommandBuffers[i] );
|
||||
|
||||
if( GetGraphicsQueue().Handle != GetPresentQueue().Handle ) {
|
||||
VkImageMemoryBarrier barrier_from_draw_to_present = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags srcAccessMask
|
||||
VK_ACCESS_MEMORY_READ_BIT, // VkAccessFlags dstAccessMask
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // VkImageLayout oldLayout
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // VkImageLayout newLayout
|
||||
GetGraphicsQueue().FamilyIndex, // uint32_t srcQueueFamilyIndex
|
||||
GetPresentQueue( ).FamilyIndex, // uint32_t dstQueueFamilyIndex
|
||||
swap_chain_images[i], // VkImage image
|
||||
image_subresource_range // VkImageSubresourceRange subresourceRange
|
||||
};
|
||||
vkCmdPipelineBarrier( Vulkan.GraphicsCommandBuffers[i], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier_from_draw_to_present );
|
||||
}
|
||||
if( vkEndCommandBuffer( Vulkan.GraphicsCommandBuffers[i] ) != VK_SUCCESS ) {
|
||||
printf( "Could not record command buffer!\n" );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tutorial03::ChildOnWindowSizeChanged() {
|
||||
if( !CreateRenderPass() ) {
|
||||
return false;
|
||||
}
|
||||
if( !CreateFramebuffers() ) {
|
||||
return false;
|
||||
}
|
||||
if( !CreatePipeline() ) {
|
||||
return false;
|
||||
}
|
||||
if( !CreateCommandBuffers() ) {
|
||||
return false;
|
||||
}
|
||||
if( !RecordCommandBuffers() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tutorial03::Draw() {
|
||||
VkSemaphore image_available_semaphore = GetImageAvailableSemaphore();
|
||||
VkSemaphore rendering_finished_semaphore = GetRenderingFinishedSemaphore();
|
||||
VkSwapchainKHR swap_chain = GetSwapChain().Handle;
|
||||
uint32_t image_index;
|
||||
|
||||
VkResult result = vkAcquireNextImageKHR( GetDevice(), swap_chain, UINT64_MAX, image_available_semaphore, VK_NULL_HANDLE, &image_index );
|
||||
switch( result ) {
|
||||
case VK_SUCCESS:
|
||||
case VK_SUBOPTIMAL_KHR:
|
||||
break;
|
||||
case VK_ERROR_OUT_OF_DATE_KHR:
|
||||
return OnWindowSizeChanged();
|
||||
default:
|
||||
printf( "Problem occurred during swap chain image acquisition!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
VkPipelineStageFlags wait_dst_stage_mask = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
VkSubmitInfo submit_info = {
|
||||
VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
1, // uint32_t waitSemaphoreCount
|
||||
&image_available_semaphore, // const VkSemaphore *pWaitSemaphores
|
||||
&wait_dst_stage_mask, // const VkPipelineStageFlags *pWaitDstStageMask;
|
||||
1, // uint32_t commandBufferCount
|
||||
&Vulkan.GraphicsCommandBuffers[image_index], // const VkCommandBuffer *pCommandBuffers
|
||||
1, // uint32_t signalSemaphoreCount
|
||||
&rendering_finished_semaphore // const VkSemaphore *pSignalSemaphores
|
||||
};
|
||||
|
||||
if( vkQueueSubmit( GetGraphicsQueue().Handle, 1, &submit_info, VK_NULL_HANDLE ) != VK_SUCCESS ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VkPresentInfoKHR present_info = {
|
||||
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
1, // uint32_t waitSemaphoreCount
|
||||
&rendering_finished_semaphore, // const VkSemaphore *pWaitSemaphores
|
||||
1, // uint32_t swapchainCount
|
||||
&swap_chain, // const VkSwapchainKHR *pSwapchains
|
||||
&image_index, // const uint32_t *pImageIndices
|
||||
nullptr // VkResult *pResults
|
||||
};
|
||||
result = vkQueuePresentKHR( GetPresentQueue().Handle, &present_info );
|
||||
|
||||
switch( result ) {
|
||||
case VK_SUCCESS:
|
||||
break;
|
||||
case VK_ERROR_OUT_OF_DATE_KHR:
|
||||
case VK_SUBOPTIMAL_KHR:
|
||||
return OnWindowSizeChanged();
|
||||
default:
|
||||
printf( "Problem occurred during image presentation!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Tutorial03::ChildClear() {
|
||||
if( GetDevice() != VK_NULL_HANDLE ) {
|
||||
vkDeviceWaitIdle( GetDevice() );
|
||||
|
||||
if( (Vulkan.GraphicsCommandBuffers.size() > 0) && (Vulkan.GraphicsCommandBuffers[0] != VK_NULL_HANDLE) ) {
|
||||
vkFreeCommandBuffers( GetDevice(), Vulkan.GraphicsCommandPool, static_cast<uint32_t>(Vulkan.GraphicsCommandBuffers.size()), &Vulkan.GraphicsCommandBuffers[0] );
|
||||
Vulkan.GraphicsCommandBuffers.clear();
|
||||
}
|
||||
|
||||
if( Vulkan.GraphicsCommandPool != VK_NULL_HANDLE ) {
|
||||
vkDestroyCommandPool( GetDevice(), Vulkan.GraphicsCommandPool, nullptr );
|
||||
Vulkan.GraphicsCommandPool = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
if( Vulkan.GraphicsPipeline != VK_NULL_HANDLE ) {
|
||||
vkDestroyPipeline( GetDevice(), Vulkan.GraphicsPipeline, nullptr );
|
||||
Vulkan.GraphicsPipeline = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
if( Vulkan.RenderPass != VK_NULL_HANDLE ) {
|
||||
vkDestroyRenderPass( GetDevice(), Vulkan.RenderPass, nullptr );
|
||||
Vulkan.RenderPass = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
for( size_t i = 0; i < Vulkan.FramebufferObjects.size(); ++i ) {
|
||||
if( Vulkan.FramebufferObjects[i].Handle != VK_NULL_HANDLE ) {
|
||||
vkDestroyFramebuffer( GetDevice(), Vulkan.FramebufferObjects[i].Handle, nullptr );
|
||||
Vulkan.FramebufferObjects[i].Handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
if( Vulkan.FramebufferObjects[i].ImageView != VK_NULL_HANDLE ) {
|
||||
vkDestroyImageView( GetDevice(), Vulkan.FramebufferObjects[i].ImageView, nullptr );
|
||||
Vulkan.FramebufferObjects[i].ImageView = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
Vulkan.FramebufferObjects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Tutorial03::~Tutorial03() {
|
||||
ChildClear();
|
||||
}
|
||||
|
||||
} // namespace Tutorial
|
||||
82
Project/Tutorial03/Tutorial03.h
Normal file
82
Project/Tutorial03/Tutorial03.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 2016 Intel Corporation All Rights Reserved
|
||||
//
|
||||
// Intel makes no representations about the suitability of this software for any purpose.
|
||||
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
|
||||
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
|
||||
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// Intel does not assume any responsibility for any errors which may appear in this software
|
||||
// nor any responsibility to update it.
|
||||
|
||||
#if !defined(TUTORIAL_03_HEADER)
|
||||
#define TUTORIAL_03_HEADER
|
||||
|
||||
#include "VulkanCommon.h"
|
||||
#include "Tools.h"
|
||||
|
||||
namespace Tutorial {
|
||||
|
||||
// ************************************************************ //
|
||||
// FramebufferObject //
|
||||
// //
|
||||
// Vulkan Framebuffer's parameters container class //
|
||||
// ************************************************************ //
|
||||
struct FramebufferParameters {
|
||||
VkImageView ImageView;
|
||||
VkFramebuffer Handle;
|
||||
};
|
||||
|
||||
// ************************************************************ //
|
||||
// VulkanTutorial03Parameters //
|
||||
// //
|
||||
// Vulkan specific parameters //
|
||||
// ************************************************************ //
|
||||
struct VulkanTutorial03Parameters {
|
||||
VkRenderPass RenderPass;
|
||||
std::vector<FramebufferParameters> FramebufferObjects;
|
||||
VkCommandPool GraphicsCommandPool;
|
||||
std::vector<VkCommandBuffer> GraphicsCommandBuffers;
|
||||
VkPipeline GraphicsPipeline;
|
||||
|
||||
VulkanTutorial03Parameters() :
|
||||
RenderPass( VK_NULL_HANDLE ),
|
||||
FramebufferObjects(),
|
||||
GraphicsCommandPool( VK_NULL_HANDLE ),
|
||||
GraphicsCommandBuffers(),
|
||||
GraphicsPipeline( VK_NULL_HANDLE ) {
|
||||
}
|
||||
};
|
||||
|
||||
// ************************************************************ //
|
||||
// Tutorial03 //
|
||||
// //
|
||||
// Class for presenting Vulkan usage topics //
|
||||
// ************************************************************ //
|
||||
class Tutorial03 : public VulkanCommon {
|
||||
public:
|
||||
Tutorial03();
|
||||
~Tutorial03();
|
||||
|
||||
bool CreateRenderPass();
|
||||
bool CreateFramebuffers();
|
||||
bool CreatePipeline();
|
||||
bool CreateCommandBuffers();
|
||||
bool RecordCommandBuffers();
|
||||
|
||||
bool Draw() override;
|
||||
|
||||
private:
|
||||
VulkanTutorial03Parameters Vulkan;
|
||||
|
||||
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
|
||||
Tools::AutoDeleter<VkPipelineLayout, PFN_vkDestroyPipelineLayout> CreatePipelineLayout();
|
||||
bool CreateCommandPool( uint32_t queue_family_index, VkCommandPool *pool );
|
||||
bool AllocateCommandBuffers( VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers );
|
||||
|
||||
void ChildClear() override;
|
||||
bool ChildOnWindowSizeChanged() override;
|
||||
};
|
||||
|
||||
} // namespace Tutorial
|
||||
|
||||
#endif // TUTORIAL_03_HEADER
|
||||
50
Project/Tutorial03/main.cpp
Normal file
50
Project/Tutorial03/main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2016 Intel Corporation All Rights Reserved
|
||||
//
|
||||
// Intel makes no representations about the suitability of this software for any purpose.
|
||||
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
|
||||
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
|
||||
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// Intel does not assume any responsibility for any errors which may appear in this software
|
||||
// nor any responsibility to update it.
|
||||
|
||||
#include "Tutorial03.h"
|
||||
|
||||
int main( int argc, char **argv ) {
|
||||
OS::Window window;
|
||||
Tutorial::Tutorial03 tutorial03;
|
||||
|
||||
// Window creation
|
||||
if( !window.Create( "03 - First Triangle" ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Vulkan preparations and initialization
|
||||
if( !tutorial03.PrepareVulkan( window.GetParameters() ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Tutorial 03
|
||||
if( !tutorial03.CreateRenderPass() ) {
|
||||
return -1;
|
||||
}
|
||||
if( !tutorial03.CreateFramebuffers() ) {
|
||||
return -1;
|
||||
}
|
||||
if( !tutorial03.CreatePipeline() ) {
|
||||
return -1;
|
||||
}
|
||||
if( !tutorial03.CreateCommandBuffers() ) {
|
||||
return -1;
|
||||
}
|
||||
if( !tutorial03.RecordCommandBuffers() ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Rendering loop
|
||||
if( !window.RenderingLoop( tutorial03 ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user