Merge branch 'master' of https://github.com/SaschaWillems/Vulkan
This commit is contained in:
commit
e75f2ae739
3 changed files with 57 additions and 54 deletions
|
|
@ -85,7 +85,7 @@ public:
|
||||||
|
|
||||||
~VulkanExample()
|
~VulkanExample()
|
||||||
{
|
{
|
||||||
// Clean up used Vulkan resources
|
// Clean up used Vulkan resources
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
// Note : Inherited destructor cleans up resources stored in base class
|
||||||
|
|
||||||
destroyTextureImage(texture);
|
destroyTextureImage(texture);
|
||||||
|
|
@ -100,7 +100,7 @@ public:
|
||||||
uniformBufferVS.destroy();
|
uniformBufferVS.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable physical device features required for this example
|
// Enable physical device features required for this example
|
||||||
virtual void getEnabledFeatures()
|
virtual void getEnabledFeatures()
|
||||||
{
|
{
|
||||||
// Enable anisotropic filtering if supported
|
// Enable anisotropic filtering if supported
|
||||||
|
|
@ -121,14 +121,14 @@ public:
|
||||||
|
|
||||||
Optimal tiled images:
|
Optimal tiled images:
|
||||||
These are stored in an implementation specific layout matching the capability of the hardware. They usually support more formats and features and are much faster.
|
These are stored in an implementation specific layout matching the capability of the hardware. They usually support more formats and features and are much faster.
|
||||||
Optimal tiled images are stored on the device and not accessible by the host. So they can't be written directly to (like liner tiled images) and always require
|
Optimal tiled images are stored on the device and not accessible by the host. So they can't be written directly to (like liner tiled images) and always require
|
||||||
some sort of data copy, either from a buffer or a linear tiled image.
|
some sort of data copy, either from a buffer or a linear tiled image.
|
||||||
|
|
||||||
In Short: Always use optimal tiled images for rendering.
|
In Short: Always use optimal tiled images for rendering.
|
||||||
*/
|
*/
|
||||||
void loadTexture()
|
void loadTexture()
|
||||||
{
|
{
|
||||||
// We use the Khronos texture format (https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/)
|
// We use the Khronos texture format (https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/)
|
||||||
std::string filename = getAssetPath() + "textures/metalplate01_rgba.ktx";
|
std::string filename = getAssetPath() + "textures/metalplate01_rgba.ktx";
|
||||||
// Texture data contains 4 channels (RGBA) with unnormalized 8-bit values, this is the most commonly supported format
|
// Texture data contains 4 channels (RGBA) with unnormalized 8-bit values, this is the most commonly supported format
|
||||||
VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
|
VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
|
@ -156,7 +156,7 @@ public:
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
}
|
}
|
||||||
result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
||||||
#endif
|
#endif
|
||||||
assert(result == KTX_SUCCESS);
|
assert(result == KTX_SUCCESS);
|
||||||
|
|
||||||
// Get properties required for using and upload texture data from the ktx texture object
|
// Get properties required for using and upload texture data from the ktx texture object
|
||||||
|
|
@ -195,7 +195,7 @@ public:
|
||||||
bufferCreateInfo.size = ktxTextureSize;
|
bufferCreateInfo.size = ktxTextureSize;
|
||||||
// This buffer is used as a transfer source for the buffer copy
|
// This buffer is used as a transfer source for the buffer copy
|
||||||
bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||||
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
VK_CHECK_RESULT(vkCreateBuffer(device, &bufferCreateInfo, nullptr, &stagingBuffer));
|
VK_CHECK_RESULT(vkCreateBuffer(device, &bufferCreateInfo, nullptr, &stagingBuffer));
|
||||||
|
|
||||||
// Get memory requirements for the staging buffer (alignment, memory type bits)
|
// Get memory requirements for the staging buffer (alignment, memory type bits)
|
||||||
|
|
@ -219,7 +219,8 @@ public:
|
||||||
for (uint32_t i = 0; i < texture.mipLevels; i++) {
|
for (uint32_t i = 0; i < texture.mipLevels; i++) {
|
||||||
// Calculate offset into staging buffer for the current mip level
|
// Calculate offset into staging buffer for the current mip level
|
||||||
ktx_size_t offset;
|
ktx_size_t offset;
|
||||||
assert(ktxTexture_GetImageOffset(ktxTexture, i, 0, 0, &offset) == KTX_SUCCESS);
|
KTX_error_code ret = ktxTexture_GetImageOffset(ktxTexture, i, 0, 0, &offset);
|
||||||
|
assert(ret == KTX_SUCCESS);
|
||||||
// Setup a buffer image copy structure for the current mip level
|
// Setup a buffer image copy structure for the current mip level
|
||||||
VkBufferImageCopy bufferCopyRegion = {};
|
VkBufferImageCopy bufferCopyRegion = {};
|
||||||
bufferCopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
bufferCopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
|
@ -278,9 +279,9 @@ public:
|
||||||
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||||
|
|
||||||
// Insert a memory dependency at the proper pipeline stages that will execute the image layout transition
|
// Insert a memory dependency at the proper pipeline stages that will execute the image layout transition
|
||||||
// Source pipeline stage is host write/read exection (VK_PIPELINE_STAGE_HOST_BIT)
|
// Source pipeline stage is host write/read execution (VK_PIPELINE_STAGE_HOST_BIT)
|
||||||
// Destination pipeline stage is copy command exection (VK_PIPELINE_STAGE_TRANSFER_BIT)
|
// Destination pipeline stage is copy command execution (VK_PIPELINE_STAGE_TRANSFER_BIT)
|
||||||
vkCmdPipelineBarrier(
|
vkCmdPipelineBarrier(
|
||||||
copyCmd,
|
copyCmd,
|
||||||
VK_PIPELINE_STAGE_HOST_BIT,
|
VK_PIPELINE_STAGE_HOST_BIT,
|
||||||
|
|
@ -305,7 +306,7 @@ public:
|
||||||
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||||
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
|
||||||
// Insert a memory dependency at the proper pipeline stages that will execute the image layout transition
|
// Insert a memory dependency at the proper pipeline stages that will execute the image layout transition
|
||||||
// Source pipeline stage stage is copy command exection (VK_PIPELINE_STAGE_TRANSFER_BIT)
|
// Source pipeline stage stage is copy command exection (VK_PIPELINE_STAGE_TRANSFER_BIT)
|
||||||
// Destination pipeline stage fragment shader access (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT)
|
// Destination pipeline stage fragment shader access (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT)
|
||||||
vkCmdPipelineBarrier(
|
vkCmdPipelineBarrier(
|
||||||
|
|
@ -365,7 +366,7 @@ public:
|
||||||
texture.image = mappableImage;
|
texture.image = mappableImage;
|
||||||
texture.deviceMemory = mappableMemory;
|
texture.deviceMemory = mappableMemory;
|
||||||
texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
|
||||||
// Setup image memory barrier transfer image to shader read layout
|
// Setup image memory barrier transfer image to shader read layout
|
||||||
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
|
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
|
||||||
|
|
||||||
|
|
@ -385,7 +386,7 @@ public:
|
||||||
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
|
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
|
||||||
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
|
||||||
// Insert a memory dependency at the proper pipeline stages that will execute the image layout transition
|
// Insert a memory dependency at the proper pipeline stages that will execute the image layout transition
|
||||||
// Source pipeline stage is host write/read exection (VK_PIPELINE_STAGE_HOST_BIT)
|
// Source pipeline stage is host write/read exection (VK_PIPELINE_STAGE_HOST_BIT)
|
||||||
// Destination pipeline stage fragment shader access (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT)
|
// Destination pipeline stage fragment shader access (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT)
|
||||||
vkCmdPipelineBarrier(
|
vkCmdPipelineBarrier(
|
||||||
|
|
@ -565,8 +566,8 @@ public:
|
||||||
vertices.bindingDescriptions.resize(1);
|
vertices.bindingDescriptions.resize(1);
|
||||||
vertices.bindingDescriptions[0] =
|
vertices.bindingDescriptions[0] =
|
||||||
vks::initializers::vertexInputBindingDescription(
|
vks::initializers::vertexInputBindingDescription(
|
||||||
VERTEX_BUFFER_BIND_ID,
|
VERTEX_BUFFER_BIND_ID,
|
||||||
sizeof(Vertex),
|
sizeof(Vertex),
|
||||||
VK_VERTEX_INPUT_RATE_VERTEX);
|
VK_VERTEX_INPUT_RATE_VERTEX);
|
||||||
|
|
||||||
// Attribute descriptions
|
// Attribute descriptions
|
||||||
|
|
@ -578,7 +579,7 @@ public:
|
||||||
VERTEX_BUFFER_BIND_ID,
|
VERTEX_BUFFER_BIND_ID,
|
||||||
0,
|
0,
|
||||||
VK_FORMAT_R32G32B32_SFLOAT,
|
VK_FORMAT_R32G32B32_SFLOAT,
|
||||||
offsetof(Vertex, pos));
|
offsetof(Vertex, pos));
|
||||||
// Location 1 : Texture coordinates
|
// Location 1 : Texture coordinates
|
||||||
vertices.attributeDescriptions[1] =
|
vertices.attributeDescriptions[1] =
|
||||||
vks::initializers::vertexInputAttributeDescription(
|
vks::initializers::vertexInputAttributeDescription(
|
||||||
|
|
@ -610,7 +611,7 @@ public:
|
||||||
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1)
|
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDescriptorPoolCreateInfo descriptorPoolInfo =
|
VkDescriptorPoolCreateInfo descriptorPoolInfo =
|
||||||
vks::initializers::descriptorPoolCreateInfo(
|
vks::initializers::descriptorPoolCreateInfo(
|
||||||
static_cast<uint32_t>(poolSizes.size()),
|
static_cast<uint32_t>(poolSizes.size()),
|
||||||
poolSizes.data(),
|
poolSizes.data(),
|
||||||
|
|
@ -621,21 +622,21 @@ public:
|
||||||
|
|
||||||
void setupDescriptorSetLayout()
|
void setupDescriptorSetLayout()
|
||||||
{
|
{
|
||||||
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings =
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings =
|
||||||
{
|
{
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
// Binding 0 : Vertex shader uniform buffer
|
||||||
vks::initializers::descriptorSetLayoutBinding(
|
vks::initializers::descriptorSetLayoutBinding(
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
VK_SHADER_STAGE_VERTEX_BIT,
|
VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
0),
|
0),
|
||||||
// Binding 1 : Fragment shader image sampler
|
// Binding 1 : Fragment shader image sampler
|
||||||
vks::initializers::descriptorSetLayoutBinding(
|
vks::initializers::descriptorSetLayoutBinding(
|
||||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
1)
|
1)
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDescriptorSetLayoutCreateInfo descriptorLayout =
|
VkDescriptorSetLayoutCreateInfo descriptorLayout =
|
||||||
vks::initializers::descriptorSetLayoutCreateInfo(
|
vks::initializers::descriptorSetLayoutCreateInfo(
|
||||||
setLayoutBindings.data(),
|
setLayoutBindings.data(),
|
||||||
static_cast<uint32_t>(setLayoutBindings.size()));
|
static_cast<uint32_t>(setLayoutBindings.size()));
|
||||||
|
|
@ -652,7 +653,7 @@ public:
|
||||||
|
|
||||||
void setupDescriptorSet()
|
void setupDescriptorSet()
|
||||||
{
|
{
|
||||||
VkDescriptorSetAllocateInfo allocInfo =
|
VkDescriptorSetAllocateInfo allocInfo =
|
||||||
vks::initializers::descriptorSetAllocateInfo(
|
vks::initializers::descriptorSetAllocateInfo(
|
||||||
descriptorPool,
|
descriptorPool,
|
||||||
&descriptorSetLayout,
|
&descriptorSetLayout,
|
||||||
|
|
@ -670,14 +671,14 @@ public:
|
||||||
{
|
{
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
// Binding 0 : Vertex shader uniform buffer
|
||||||
vks::initializers::writeDescriptorSet(
|
vks::initializers::writeDescriptorSet(
|
||||||
descriptorSet,
|
descriptorSet,
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
0,
|
0,
|
||||||
&uniformBufferVS.descriptor),
|
&uniformBufferVS.descriptor),
|
||||||
// Binding 1 : Fragment shader texture sampler
|
// Binding 1 : Fragment shader texture sampler
|
||||||
// Fragment shader: layout (binding = 1) uniform sampler2D samplerColor;
|
// Fragment shader: layout (binding = 1) uniform sampler2D samplerColor;
|
||||||
vks::initializers::writeDescriptorSet(
|
vks::initializers::writeDescriptorSet(
|
||||||
descriptorSet,
|
descriptorSet,
|
||||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, // The descriptor set will use a combined image sampler (sampler and image could be split)
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, // The descriptor set will use a combined image sampler (sampler and image could be split)
|
||||||
1, // Shader binding point 1
|
1, // Shader binding point 1
|
||||||
&textureDescriptor) // Pointer to the descriptor image for our texture
|
&textureDescriptor) // Pointer to the descriptor image for our texture
|
||||||
|
|
@ -708,7 +709,7 @@ public:
|
||||||
|
|
||||||
VkPipelineColorBlendStateCreateInfo colorBlendState =
|
VkPipelineColorBlendStateCreateInfo colorBlendState =
|
||||||
vks::initializers::pipelineColorBlendStateCreateInfo(
|
vks::initializers::pipelineColorBlendStateCreateInfo(
|
||||||
1,
|
1,
|
||||||
&blendAttachmentState);
|
&blendAttachmentState);
|
||||||
|
|
||||||
VkPipelineDepthStencilStateCreateInfo depthStencilState =
|
VkPipelineDepthStencilStateCreateInfo depthStencilState =
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define GLM_FORCE_RADIANS
|
#define GLM_FORCE_RADIANS
|
||||||
|
|
@ -62,7 +62,7 @@ public:
|
||||||
glm::mat4 view;
|
glm::mat4 view;
|
||||||
} matrices;
|
} matrices;
|
||||||
// Seperate data for each instance
|
// Seperate data for each instance
|
||||||
UboInstanceData *instance;
|
UboInstanceData *instance;
|
||||||
} uboVS;
|
} uboVS;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ public:
|
||||||
|
|
||||||
~VulkanExample()
|
~VulkanExample()
|
||||||
{
|
{
|
||||||
// Clean up used Vulkan resources
|
// Clean up used Vulkan resources
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
// Note : Inherited destructor cleans up resources stored in base class
|
||||||
|
|
||||||
vkDestroyImageView(device, textureArray.view, nullptr);
|
vkDestroyImageView(device, textureArray.view, nullptr);
|
||||||
|
|
@ -129,7 +129,7 @@ public:
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
}
|
}
|
||||||
result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
||||||
#endif
|
#endif
|
||||||
assert(result == KTX_SUCCESS);
|
assert(result == KTX_SUCCESS);
|
||||||
|
|
||||||
// Get properties required for using and upload texture data from the ktx texture object
|
// Get properties required for using and upload texture data from the ktx texture object
|
||||||
|
|
@ -178,7 +178,8 @@ public:
|
||||||
{
|
{
|
||||||
// Calculate offset into staging buffer for the current array layer
|
// Calculate offset into staging buffer for the current array layer
|
||||||
ktx_size_t offset;
|
ktx_size_t offset;
|
||||||
assert(ktxTexture_GetImageOffset(ktxTexture, 0, layer, 0, &offset) == KTX_SUCCESS);
|
KTX_error_code ret = ktxTexture_GetImageOffset(ktxTexture, 0, layer, 0, &offset);
|
||||||
|
assert(ret == KTX_SUCCESS);
|
||||||
// Setup a buffer image copy structure for the current array layer
|
// Setup a buffer image copy structure for the current array layer
|
||||||
VkBufferImageCopy bufferCopyRegion = {};
|
VkBufferImageCopy bufferCopyRegion = {};
|
||||||
bufferCopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
bufferCopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
|
@ -464,7 +465,7 @@ public:
|
||||||
{
|
{
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
||||||
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
||||||
VkPipelineColorBlendAttachmentState blendAttachmentState = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
VkPipelineColorBlendAttachmentState blendAttachmentState = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
||||||
VkPipelineColorBlendStateCreateInfo colorBlendStateCI = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentState);
|
VkPipelineColorBlendStateCreateInfo colorBlendStateCI = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentState);
|
||||||
VkPipelineDepthStencilStateCreateInfo depthStencilStateCI = vks::initializers::pipelineDepthStencilStateCreateInfo(VK_TRUE, VK_TRUE, VK_COMPARE_OP_LESS_OR_EQUAL);
|
VkPipelineDepthStencilStateCreateInfo depthStencilStateCI = vks::initializers::pipelineDepthStencilStateCreateInfo(VK_TRUE, VK_TRUE, VK_COMPARE_OP_LESS_OR_EQUAL);
|
||||||
VkPipelineViewportStateCreateInfo viewportStateCI = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
|
VkPipelineViewportStateCreateInfo viewportStateCI = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ public:
|
||||||
|
|
||||||
~VulkanExample()
|
~VulkanExample()
|
||||||
{
|
{
|
||||||
// Clean up used Vulkan resources
|
// Clean up used Vulkan resources
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
// Note : Inherited destructor cleans up resources stored in base class
|
||||||
|
|
||||||
// Clean up texture resources
|
// Clean up texture resources
|
||||||
|
|
@ -108,7 +108,7 @@ public:
|
||||||
uniformBuffers.skybox.destroy();
|
uniformBuffers.skybox.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable physical device features required for this example
|
// Enable physical device features required for this example
|
||||||
virtual void getEnabledFeatures()
|
virtual void getEnabledFeatures()
|
||||||
{
|
{
|
||||||
if (deviceFeatures.samplerAnisotropy) {
|
if (deviceFeatures.samplerAnisotropy) {
|
||||||
|
|
@ -150,7 +150,7 @@ public:
|
||||||
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
vks::tools::exitFatal("Could not load texture from " + filename + "\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
|
||||||
}
|
}
|
||||||
result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
result = ktxTexture_CreateFromNamedFile(filename.c_str(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &ktxTexture);
|
||||||
#endif
|
#endif
|
||||||
assert(result == KTX_SUCCESS);
|
assert(result == KTX_SUCCESS);
|
||||||
|
|
||||||
// Get properties required for using and upload texture data from the ktx texture object
|
// Get properties required for using and upload texture data from the ktx texture object
|
||||||
|
|
@ -227,7 +227,8 @@ public:
|
||||||
{
|
{
|
||||||
// Calculate offset into staging buffer for the current mip level and face
|
// Calculate offset into staging buffer for the current mip level and face
|
||||||
ktx_size_t offset;
|
ktx_size_t offset;
|
||||||
assert(ktxTexture_GetImageOffset(ktxTexture, level, 0, face, &offset) == KTX_SUCCESS);
|
KTX_error_code ret = ktxTexture_GetImageOffset(ktxTexture, level, 0, face, &offset);
|
||||||
|
assert(ret == KTX_SUCCESS);
|
||||||
VkBufferImageCopy bufferCopyRegion = {};
|
VkBufferImageCopy bufferCopyRegion = {};
|
||||||
bufferCopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
bufferCopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
bufferCopyRegion.imageSubresource.mipLevel = level;
|
bufferCopyRegion.imageSubresource.mipLevel = level;
|
||||||
|
|
@ -424,7 +425,7 @@ public:
|
||||||
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2)
|
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDescriptorPoolCreateInfo descriptorPoolInfo =
|
VkDescriptorPoolCreateInfo descriptorPoolInfo =
|
||||||
vks::initializers::descriptorPoolCreateInfo(
|
vks::initializers::descriptorPoolCreateInfo(
|
||||||
poolSizes.size(),
|
poolSizes.size(),
|
||||||
poolSizes.data(),
|
poolSizes.data(),
|
||||||
|
|
@ -435,21 +436,21 @@ public:
|
||||||
|
|
||||||
void setupDescriptorSetLayout()
|
void setupDescriptorSetLayout()
|
||||||
{
|
{
|
||||||
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings =
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings =
|
||||||
{
|
{
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
// Binding 0 : Vertex shader uniform buffer
|
||||||
vks::initializers::descriptorSetLayoutBinding(
|
vks::initializers::descriptorSetLayoutBinding(
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
VK_SHADER_STAGE_VERTEX_BIT,
|
VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
0),
|
0),
|
||||||
// Binding 1 : Fragment shader image sampler
|
// Binding 1 : Fragment shader image sampler
|
||||||
vks::initializers::descriptorSetLayoutBinding(
|
vks::initializers::descriptorSetLayoutBinding(
|
||||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
1)
|
1)
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDescriptorSetLayoutCreateInfo descriptorLayout =
|
VkDescriptorSetLayoutCreateInfo descriptorLayout =
|
||||||
vks::initializers::descriptorSetLayoutCreateInfo(
|
vks::initializers::descriptorSetLayoutCreateInfo(
|
||||||
setLayoutBindings.data(),
|
setLayoutBindings.data(),
|
||||||
setLayoutBindings.size());
|
setLayoutBindings.size());
|
||||||
|
|
@ -486,15 +487,15 @@ public:
|
||||||
{
|
{
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
// Binding 0 : Vertex shader uniform buffer
|
||||||
vks::initializers::writeDescriptorSet(
|
vks::initializers::writeDescriptorSet(
|
||||||
descriptorSets.object,
|
descriptorSets.object,
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
0,
|
0,
|
||||||
&uniformBuffers.object.descriptor),
|
&uniformBuffers.object.descriptor),
|
||||||
// Binding 1 : Fragment shader cubemap sampler
|
// Binding 1 : Fragment shader cubemap sampler
|
||||||
vks::initializers::writeDescriptorSet(
|
vks::initializers::writeDescriptorSet(
|
||||||
descriptorSets.object,
|
descriptorSets.object,
|
||||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
1,
|
1,
|
||||||
&textureDescriptor)
|
&textureDescriptor)
|
||||||
};
|
};
|
||||||
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
||||||
|
|
@ -542,7 +543,7 @@ public:
|
||||||
|
|
||||||
VkPipelineColorBlendStateCreateInfo colorBlendState =
|
VkPipelineColorBlendStateCreateInfo colorBlendState =
|
||||||
vks::initializers::pipelineColorBlendStateCreateInfo(
|
vks::initializers::pipelineColorBlendStateCreateInfo(
|
||||||
1,
|
1,
|
||||||
&blendAttachmentState);
|
&blendAttachmentState);
|
||||||
|
|
||||||
VkPipelineDepthStencilStateCreateInfo depthStencilState =
|
VkPipelineDepthStencilStateCreateInfo depthStencilState =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue