Use new texture and model classes, fragment shader inputs (Refs #277)
This commit is contained in:
parent
5a50dfdc1c
commit
9051af4502
3 changed files with 28 additions and 34 deletions
|
|
@ -9,7 +9,6 @@ layout (location = 0) in vec3 inNormal;
|
||||||
layout (location = 1) in vec2 inUV;
|
layout (location = 1) in vec2 inUV;
|
||||||
layout (location = 2) in vec3 inViewVec;
|
layout (location = 2) in vec3 inViewVec;
|
||||||
layout (location = 3) in vec3 inLightVec;
|
layout (location = 3) in vec3 inLightVec;
|
||||||
layout (location = 4) in vec3 inEyeNormal;
|
|
||||||
|
|
||||||
layout (location = 0) out vec4 outFragColor;
|
layout (location = 0) out vec4 outFragColor;
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -25,22 +25,14 @@
|
||||||
#include "vulkanexamplebase.h"
|
#include "vulkanexamplebase.h"
|
||||||
#include "vulkandevice.hpp"
|
#include "vulkandevice.hpp"
|
||||||
#include "vulkanbuffer.hpp"
|
#include "vulkanbuffer.hpp"
|
||||||
|
#include "VulkanModel.hpp"
|
||||||
|
#include "VulkanTexture.hpp"
|
||||||
|
|
||||||
#include "../external/stb/stb_font_consolas_24_latin1.inl"
|
#include "../external/stb/stb_font_consolas_24_latin1.inl"
|
||||||
|
|
||||||
#define VERTEX_BUFFER_BIND_ID 0
|
#define VERTEX_BUFFER_BIND_ID 0
|
||||||
#define ENABLE_VALIDATION false
|
#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,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Defines for the STB font used
|
// Defines for the STB font used
|
||||||
// STB font files can be found at http://nothings.org/stb/font/
|
// STB font files can be found at http://nothings.org/stb/font/
|
||||||
#define STB_FONT_NAME stb_font_consolas_24_latin1
|
#define STB_FONT_NAME stb_font_consolas_24_latin1
|
||||||
|
|
@ -698,21 +690,29 @@ class VulkanExample : public VulkanExampleBase
|
||||||
public:
|
public:
|
||||||
TextOverlay *textOverlay = nullptr;
|
TextOverlay *textOverlay = nullptr;
|
||||||
|
|
||||||
|
// 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 {
|
struct {
|
||||||
vkTools::VulkanTexture background;
|
vks::Texture2D background;
|
||||||
vkTools::VulkanTexture cube;
|
vks::Texture2D cube;
|
||||||
} textures;
|
} textures;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
vks::Model cube;
|
||||||
|
} models;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
VkPipelineVertexInputStateCreateInfo inputState;
|
VkPipelineVertexInputStateCreateInfo inputState;
|
||||||
std::vector<VkVertexInputBindingDescription> bindingDescriptions;
|
std::vector<VkVertexInputBindingDescription> bindingDescriptions;
|
||||||
std::vector<VkVertexInputAttributeDescription> attributeDescriptions;
|
std::vector<VkVertexInputAttributeDescription> attributeDescriptions;
|
||||||
} vertices;
|
} vertices;
|
||||||
|
|
||||||
struct {
|
|
||||||
vkMeshLoader::MeshBuffer cube;
|
|
||||||
} meshes;
|
|
||||||
|
|
||||||
vk::Buffer uniformBuffer;
|
vk::Buffer uniformBuffer;
|
||||||
|
|
||||||
struct UBOVS {
|
struct UBOVS {
|
||||||
|
|
@ -751,9 +751,9 @@ public:
|
||||||
vkDestroyPipeline(device, pipelines.background, nullptr);
|
vkDestroyPipeline(device, pipelines.background, nullptr);
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
||||||
vkMeshLoader::freeMeshBufferResources(device, &meshes.cube);
|
models.cube.destroy();
|
||||||
textureLoader->destroyTexture(textures.background);
|
textures.background.destroy();
|
||||||
textureLoader->destroyTexture(textures.cube);
|
textures.cube.destroy();
|
||||||
uniformBuffer.destroy();
|
uniformBuffer.destroy();
|
||||||
delete(textOverlay);
|
delete(textOverlay);
|
||||||
}
|
}
|
||||||
|
|
@ -792,8 +792,8 @@ public:
|
||||||
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.background, 0, NULL);
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.background, 0, NULL);
|
||||||
|
|
||||||
VkDeviceSize offsets[1] = { 0 };
|
VkDeviceSize offsets[1] = { 0 };
|
||||||
vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &meshes.cube.vertices.buf, offsets);
|
vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.cube.vertices.buffer, offsets);
|
||||||
vkCmdBindIndexBuffer(drawCmdBuffers[i], meshes.cube.indices.buf, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdBindIndexBuffer(drawCmdBuffers[i], models.cube.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.background);
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.background);
|
||||||
|
|
@ -803,7 +803,7 @@ public:
|
||||||
// Cube
|
// Cube
|
||||||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
|
||||||
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.cube, 0, NULL);
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.cube, 0, NULL);
|
||||||
vkCmdDrawIndexed(drawCmdBuffers[i], meshes.cube.indexCount, 1, 0, 0, 0);
|
vkCmdDrawIndexed(drawCmdBuffers[i], models.cube.indexCount, 1, 0, 0, 0);
|
||||||
|
|
||||||
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
||||||
|
|
||||||
|
|
@ -865,15 +865,11 @@ public:
|
||||||
textOverlay->endTextUpdate();
|
textOverlay->endTextUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadTextures()
|
void loadAssets()
|
||||||
{
|
{
|
||||||
textureLoader->loadTexture(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.background);
|
textures.background.loadFromFile(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
|
||||||
textureLoader->loadTexture(getAssetPath() + "textures/round_window_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.cube);
|
textures.cube.loadFromFile(getAssetPath() + "textures/round_window_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
|
||||||
}
|
models.cube.loadFromFile(getAssetPath() + "models/cube.dae", vertexLayout, 1.0f, vulkanDevice, queue);
|
||||||
|
|
||||||
void loadMeshes()
|
|
||||||
{
|
|
||||||
loadMesh(getAssetPath() + "models/cube.dae", &meshes.cube, vertexLayout, 1.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupVertexDescriptions()
|
void setupVertexDescriptions()
|
||||||
|
|
@ -883,7 +879,7 @@ public:
|
||||||
vertices.bindingDescriptions[0] =
|
vertices.bindingDescriptions[0] =
|
||||||
vkTools::initializers::vertexInputBindingDescription(
|
vkTools::initializers::vertexInputBindingDescription(
|
||||||
VERTEX_BUFFER_BIND_ID,
|
VERTEX_BUFFER_BIND_ID,
|
||||||
vkMeshLoader::vertexSize(vertexLayout),
|
vertexLayout.stride(),
|
||||||
VK_VERTEX_INPUT_RATE_VERTEX);
|
VK_VERTEX_INPUT_RATE_VERTEX);
|
||||||
|
|
||||||
// Attribute descriptions
|
// Attribute descriptions
|
||||||
|
|
@ -1175,8 +1171,7 @@ public:
|
||||||
void prepare()
|
void prepare()
|
||||||
{
|
{
|
||||||
VulkanExampleBase::prepare();
|
VulkanExampleBase::prepare();
|
||||||
loadTextures();
|
loadAssets();
|
||||||
loadMeshes();
|
|
||||||
setupVertexDescriptions();
|
setupVertexDescriptions();
|
||||||
prepareUniformBuffers();
|
prepareUniformBuffers();
|
||||||
setupDescriptorSetLayout();
|
setupDescriptorSetLayout();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue