Removed old mesh loader, replaced with new model loader and vertex layout class in all examples (Refs #260)
This commit is contained in:
parent
f326b3ec77
commit
7e43a55a76
35 changed files with 843 additions and 1715 deletions
|
|
@ -24,21 +24,13 @@
|
|||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "vulkanexamplebase.h"
|
||||
#include "VulkanTexture.hpp"
|
||||
#include "vulkanbuffer.hpp"
|
||||
#include "VulkanTexture.hpp"
|
||||
#include "VulkanModel.hpp"
|
||||
|
||||
#define VERTEX_BUFFER_BIND_ID 0
|
||||
#define ENABLE_VALIDATION false
|
||||
|
||||
// Vertex layout for this example
|
||||
std::vector<vkMeshLoader::VertexLayout> vertexLayout =
|
||||
{
|
||||
vkMeshLoader::VERTEX_LAYOUT_POSITION,
|
||||
vkMeshLoader::VERTEX_LAYOUT_NORMAL,
|
||||
vkMeshLoader::VERTEX_LAYOUT_UV,
|
||||
vkMeshLoader::VERTEX_LAYOUT_COLOR
|
||||
};
|
||||
|
||||
class VulkanExample : public VulkanExampleBase
|
||||
{
|
||||
public:
|
||||
|
|
@ -48,9 +40,17 @@ public:
|
|||
std::vector<VkVertexInputAttributeDescription> attributeDescriptions;
|
||||
} vertices;
|
||||
|
||||
// Vertex layout for the models
|
||||
vks::VertexLayout vertexLayout = vks::VertexLayout({
|
||||
vks::VERTEX_COMPONENT_POSITION,
|
||||
vks::VERTEX_COMPONENT_NORMAL,
|
||||
vks::VERTEX_COMPONENT_UV,
|
||||
vks::VERTEX_COMPONENT_COLOR,
|
||||
});
|
||||
|
||||
struct {
|
||||
vkMeshLoader::MeshBuffer object;
|
||||
} meshes;
|
||||
vks::Model object;
|
||||
} models;
|
||||
|
||||
struct {
|
||||
vks::Texture2DArray matCapArray;
|
||||
|
|
@ -90,17 +90,16 @@ public:
|
|||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
||||
|
||||
vkMeshLoader::freeMeshBufferResources(device, &meshes.object);
|
||||
models.object.destroy();
|
||||
|
||||
uniformBuffer.destroy();
|
||||
textures.matCapArray.destroy();
|
||||
}
|
||||
|
||||
void loadTextures()
|
||||
void loadAssets()
|
||||
{
|
||||
// Several mat caps are stored in a single texture array
|
||||
// so they can easily be switched inside the shader
|
||||
// just by updating the index in a uniform buffer
|
||||
models.object.loadFromFile(getAssetPath() + "models/chinesedragon.dae", vertexLayout, 0.05f, vulkanDevice, queue);
|
||||
// Multiple mat caps are stored in a single texture array so they can easily be switched inside the shader just by updating the index in a uniform buffer
|
||||
textures.matCapArray.loadFromFile(getAssetPath() + "textures/matcap_array_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
|
||||
}
|
||||
|
||||
|
|
@ -140,10 +139,10 @@ public:
|
|||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||
|
||||
VkDeviceSize offsets[1] = { 0 };
|
||||
vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &meshes.object.vertices.buf, offsets);
|
||||
vkCmdBindIndexBuffer(drawCmdBuffers[i], meshes.object.indices.buf, 0, VK_INDEX_TYPE_UINT32);
|
||||
vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.object.vertices.buffer, offsets);
|
||||
vkCmdBindIndexBuffer(drawCmdBuffers[i], models.object.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||
|
||||
vkCmdDrawIndexed(drawCmdBuffers[i], meshes.object.indexCount, 1, 0, 0, 0);
|
||||
vkCmdDrawIndexed(drawCmdBuffers[i], models.object.indexCount, 1, 0, 0, 0);
|
||||
|
||||
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
||||
|
||||
|
|
@ -151,11 +150,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void loadMeshes()
|
||||
{
|
||||
loadMesh(getAssetPath() + "models/chinesedragon.dae", &meshes.object, vertexLayout, 0.05f);
|
||||
}
|
||||
|
||||
void prepareVertices()
|
||||
{
|
||||
// Binding description
|
||||
|
|
@ -163,7 +157,7 @@ public:
|
|||
vertices.bindingDescriptions[0] =
|
||||
vkTools::initializers::vertexInputBindingDescription(
|
||||
VERTEX_BUFFER_BIND_ID,
|
||||
vkMeshLoader::vertexSize(vertexLayout),
|
||||
vertexLayout.stride(),
|
||||
VK_VERTEX_INPUT_RATE_VERTEX);
|
||||
|
||||
// Attribute descriptions
|
||||
|
|
@ -407,8 +401,7 @@ public:
|
|||
void prepare()
|
||||
{
|
||||
VulkanExampleBase::prepare();
|
||||
loadTextures();
|
||||
loadMeshes();
|
||||
loadAssets();
|
||||
prepareVertices();
|
||||
prepareUniformBuffers();
|
||||
setupDescriptorSetLayout();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue