Removed old mesh loader, replaced with new model loader and vertex layout class in all examples (Refs #260)

This commit is contained in:
saschawillems 2017-02-11 14:18:24 +01:00
parent f326b3ec77
commit 7e43a55a76
35 changed files with 843 additions and 1715 deletions

View file

@ -21,17 +21,11 @@
#include <vulkan/vulkan.h>
#include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanMeshLoader.hpp"
#include "VulkanModel.hpp"
#include "vulkanbuffer.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
};
class VulkanExample : public VulkanExampleBase
{
@ -49,9 +43,16 @@ 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,
});
struct {
vkMeshLoader::MeshBuffer object;
} meshes;
vks::Model object;
} models;
struct {
vk::Buffer tessControl, tessEval;
@ -103,14 +104,13 @@ public:
uniformBuffers.tessControl.destroy();
uniformBuffers.tessEval.destroy();
vkMeshLoader::freeMeshBufferResources(device, &meshes.object);
models.object.destroy();
textures.colorHeightMap.destroy();
}
void loadAssets()
{
loadMesh(getAssetPath() + "models/plane.obj", &meshes.object, vertexLayout, 0.25f);
models.object.loadFromFile(getAssetPath() + "models/plane.obj", vertexLayout, 0.25f, vulkanDevice, queue);
textures.colorHeightMap.loadFromFile(getAssetPath() + "textures/pattern_36_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
}
@ -161,19 +161,19 @@ public:
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);
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);
if (splitScreen)
{
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.wireframe);
vkCmdDrawIndexed(drawCmdBuffers[i], meshes.object.indexCount, 1, 0, 0, 0);
vkCmdDrawIndexed(drawCmdBuffers[i], models.object.indexCount, 1, 0, 0, 0);
scissor.offset.x = width / 2;
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
}
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
vkCmdDrawIndexed(drawCmdBuffers[i], meshes.object.indexCount, 1, 0, 0, 0);
vkCmdDrawIndexed(drawCmdBuffers[i], models.object.indexCount, 1, 0, 0, 0);
vkCmdEndRenderPass(drawCmdBuffers[i]);
@ -188,7 +188,7 @@ public:
vertices.bindingDescriptions[0] =
vkTools::initializers::vertexInputBindingDescription(
VERTEX_BUFFER_BIND_ID,
vkMeshLoader::vertexSize(vertexLayout),
vertexLayout.stride(),
VK_VERTEX_INPUT_RATE_VERTEX);
// Attribute descriptions