Use vulkan result check macro
This commit is contained in:
parent
fb053a5011
commit
72af27a49a
1 changed files with 21 additions and 25 deletions
|
|
@ -104,7 +104,10 @@ public:
|
||||||
// Bone transformations
|
// Bone transformations
|
||||||
std::vector<aiMatrix4x4> boneTransforms;
|
std::vector<aiMatrix4x4> boneTransforms;
|
||||||
|
|
||||||
|
// Modifier for the animation
|
||||||
float animationSpeed = 0.75f;
|
float animationSpeed = 0.75f;
|
||||||
|
// Currently active animation
|
||||||
|
aiAnimation* pAnimation;
|
||||||
|
|
||||||
// Vulkan buffers
|
// Vulkan buffers
|
||||||
vkMeshLoader::MeshBuffer meshBuffer;
|
vkMeshLoader::MeshBuffer meshBuffer;
|
||||||
|
|
@ -112,6 +115,13 @@ public:
|
||||||
// Required for animation
|
// Required for animation
|
||||||
VulkanMeshLoader *meshLoader;
|
VulkanMeshLoader *meshLoader;
|
||||||
|
|
||||||
|
// Set active animation by index
|
||||||
|
void setAnimation(uint32_t animationIndex)
|
||||||
|
{
|
||||||
|
assert(animationIndex < meshLoader->pScene->mNumAnimations);
|
||||||
|
pAnimation = meshLoader->pScene->mAnimations[animationIndex];
|
||||||
|
}
|
||||||
|
|
||||||
// Load bone information from ASSIMP mesh
|
// Load bone information from ASSIMP mesh
|
||||||
void loadBones(uint32_t meshIndex, const aiMesh* pMesh, std::vector<VertexBoneData>& Bones)
|
void loadBones(uint32_t meshIndex, const aiMesh* pMesh, std::vector<VertexBoneData>& Bones)
|
||||||
{
|
{
|
||||||
|
|
@ -295,8 +305,6 @@ private:
|
||||||
{
|
{
|
||||||
std::string NodeName(pNode->mName.data);
|
std::string NodeName(pNode->mName.data);
|
||||||
|
|
||||||
const aiAnimation* pAnimation = meshLoader->pScene->mAnimations[0];
|
|
||||||
|
|
||||||
aiMatrix4x4 NodeTransformation(pNode->mTransformation);
|
aiMatrix4x4 NodeTransformation(pNode->mTransformation);
|
||||||
|
|
||||||
const aiNodeAnim* pNodeAnim = findNodeAnim(pAnimation, NodeName);
|
const aiNodeAnim* pNodeAnim = findNodeAnim(pAnimation, NodeName);
|
||||||
|
|
@ -313,7 +321,6 @@ private:
|
||||||
|
|
||||||
aiMatrix4x4 GlobalTransformation = ParentTransform * NodeTransformation;
|
aiMatrix4x4 GlobalTransformation = ParentTransform * NodeTransformation;
|
||||||
|
|
||||||
// todo : replace name lookup with hash or index
|
|
||||||
if (boneMapping.find(NodeName) != boneMapping.end())
|
if (boneMapping.find(NodeName) != boneMapping.end())
|
||||||
{
|
{
|
||||||
uint32_t BoneIndex = boneMapping[NodeName];
|
uint32_t BoneIndex = boneMapping[NodeName];
|
||||||
|
|
@ -471,11 +478,8 @@ public:
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
VkResult err;
|
|
||||||
|
|
||||||
// Get next image in the swap chain (back/front buffer)
|
// Get next image in the swap chain (back/front buffer)
|
||||||
err = swapChain.acquireNextImage(semaphores.presentComplete, ¤tBuffer);
|
VK_CHECK_RESULT(swapChain.acquireNextImage(semaphores.presentComplete, ¤tBuffer));
|
||||||
assert(!err);
|
|
||||||
|
|
||||||
submitPostPresentBarrier(swapChain.buffers[currentBuffer].image);
|
submitPostPresentBarrier(swapChain.buffers[currentBuffer].image);
|
||||||
|
|
||||||
|
|
@ -484,16 +488,13 @@ public:
|
||||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||||
|
|
||||||
// Submit to queue
|
// Submit to queue
|
||||||
err = vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||||
assert(!err);
|
|
||||||
|
|
||||||
submitPrePresentBarrier(swapChain.buffers[currentBuffer].image);
|
submitPrePresentBarrier(swapChain.buffers[currentBuffer].image);
|
||||||
|
|
||||||
err = swapChain.queuePresent(queue, currentBuffer, semaphores.renderComplete);
|
VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, semaphores.renderComplete));
|
||||||
assert(!err);
|
|
||||||
|
|
||||||
err = vkQueueWaitIdle(queue);
|
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
||||||
assert(!err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a mesh based on data read via assimp
|
// Load a mesh based on data read via assimp
|
||||||
|
|
@ -506,6 +507,7 @@ public:
|
||||||
skinnedMesh->meshLoader->assetManager = androidApp->activity->assetManager;
|
skinnedMesh->meshLoader->assetManager = androidApp->activity->assetManager;
|
||||||
#endif
|
#endif
|
||||||
skinnedMesh->meshLoader->LoadMesh(getAssetPath() + "models/goblin.dae", 0);
|
skinnedMesh->meshLoader->LoadMesh(getAssetPath() + "models/goblin.dae", 0);
|
||||||
|
skinnedMesh->setAnimation(0);
|
||||||
|
|
||||||
// Setup bones
|
// Setup bones
|
||||||
// One vertex bone info structure per vertex
|
// One vertex bone info structure per vertex
|
||||||
|
|
@ -754,8 +756,7 @@ public:
|
||||||
poolSizes.data(),
|
poolSizes.data(),
|
||||||
2);
|
2);
|
||||||
|
|
||||||
VkResult vkRes = vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool);
|
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
||||||
assert(!vkRes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupDescriptorSetLayout()
|
void setupDescriptorSetLayout()
|
||||||
|
|
@ -779,16 +780,14 @@ public:
|
||||||
setLayoutBindings.data(),
|
setLayoutBindings.data(),
|
||||||
setLayoutBindings.size());
|
setLayoutBindings.size());
|
||||||
|
|
||||||
VkResult err = vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &descriptorSetLayout);
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &descriptorSetLayout));
|
||||||
assert(!err);
|
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo =
|
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo =
|
||||||
vkTools::initializers::pipelineLayoutCreateInfo(
|
vkTools::initializers::pipelineLayoutCreateInfo(
|
||||||
&descriptorSetLayout,
|
&descriptorSetLayout,
|
||||||
1);
|
1);
|
||||||
|
|
||||||
err = vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, nullptr, &pipelineLayout);
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, nullptr, &pipelineLayout));
|
||||||
assert(!err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupDescriptorSet()
|
void setupDescriptorSet()
|
||||||
|
|
@ -799,8 +798,7 @@ public:
|
||||||
&descriptorSetLayout,
|
&descriptorSetLayout,
|
||||||
1);
|
1);
|
||||||
|
|
||||||
VkResult vkRes = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet);
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
||||||
assert(!vkRes);
|
|
||||||
|
|
||||||
VkDescriptorImageInfo texDescriptor =
|
VkDescriptorImageInfo texDescriptor =
|
||||||
vkTools::initializers::descriptorImageInfo(
|
vkTools::initializers::descriptorImageInfo(
|
||||||
|
|
@ -924,13 +922,11 @@ public:
|
||||||
pipelineCreateInfo.stageCount = shaderStages.size();
|
pipelineCreateInfo.stageCount = shaderStages.size();
|
||||||
pipelineCreateInfo.pStages = shaderStages.data();
|
pipelineCreateInfo.pStages = shaderStages.data();
|
||||||
|
|
||||||
VkResult err = vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.skinning);
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.skinning));
|
||||||
assert(!err);
|
|
||||||
|
|
||||||
shaderStages[0] = loadShader(getAssetPath() + "shaders/skeletalanimation/texture.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/skeletalanimation/texture.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/skeletalanimation/texture.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/skeletalanimation/texture.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
vkTools::checkResult(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.texture));
|
vkTools::checkResult(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.texture));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare and initialize uniform buffer containing shader uniforms
|
// Prepare and initialize uniform buffer containing shader uniforms
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue