From 9051af4502103a3b6f37ffd8eb743062d0668d5d Mon Sep 17 00:00:00 2001 From: saschawillems Date: Sat, 4 Feb 2017 15:00:45 +0100 Subject: [PATCH] Use new texture and model classes, fragment shader inputs (Refs #277) --- data/shaders/textoverlay/mesh.frag | 1 - data/shaders/textoverlay/mesh.frag.spv | Bin 1976 -> 1920 bytes textoverlay/textoverlay.cpp | 61 ++++++++++++------------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/data/shaders/textoverlay/mesh.frag b/data/shaders/textoverlay/mesh.frag index 802d3862..6527eba9 100644 --- a/data/shaders/textoverlay/mesh.frag +++ b/data/shaders/textoverlay/mesh.frag @@ -9,7 +9,6 @@ layout (location = 0) in vec3 inNormal; layout (location = 1) in vec2 inUV; layout (location = 2) in vec3 inViewVec; layout (location = 3) in vec3 inLightVec; -layout (location = 4) in vec3 inEyeNormal; layout (location = 0) out vec4 outFragColor; diff --git a/data/shaders/textoverlay/mesh.frag.spv b/data/shaders/textoverlay/mesh.frag.spv index dce04049cfb3b5e95a6a83569a7d94e782c40ac9..6877f0e4de5411edc57131311a73698d6e355ef0 100644 GIT binary patch delta 44 zcmdnN-@wny%%sfDz`zKE91I>4c}*F)COWHb%n4wee1WlGa{$u>#?2p?PcQ=jyXXrA delta 94 zcmZqR-@(tz%%sfDz`zKE91NZlc}*F)CpxP#dTdM$W)x;+U}f-NU|`71bFEDE%P-1J o%$dBMv5?oDfdwos2b5#ktjaW*k=Gh1Bo5?)lrwJL%6ys`02?e33IG5A diff --git a/textoverlay/textoverlay.cpp b/textoverlay/textoverlay.cpp index 6a61cdf7..5a19a715 100644 --- a/textoverlay/textoverlay.cpp +++ b/textoverlay/textoverlay.cpp @@ -25,22 +25,14 @@ #include "vulkanexamplebase.h" #include "vulkandevice.hpp" #include "vulkanbuffer.hpp" +#include "VulkanModel.hpp" +#include "VulkanTexture.hpp" #include "../external/stb/stb_font_consolas_24_latin1.inl" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false -// Vertex layout for this example -std::vector vertexLayout = -{ - vkMeshLoader::VERTEX_LAYOUT_POSITION, - vkMeshLoader::VERTEX_LAYOUT_NORMAL, - vkMeshLoader::VERTEX_LAYOUT_UV, - vkMeshLoader::VERTEX_LAYOUT_COLOR, -}; - - // Defines for the STB font used // STB font files can be found at http://nothings.org/stb/font/ #define STB_FONT_NAME stb_font_consolas_24_latin1 @@ -698,21 +690,29 @@ class VulkanExample : public VulkanExampleBase public: 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 { - vkTools::VulkanTexture background; - vkTools::VulkanTexture cube; + vks::Texture2D background; + vks::Texture2D cube; } textures; + struct { + vks::Model cube; + } models; + struct { VkPipelineVertexInputStateCreateInfo inputState; std::vector bindingDescriptions; std::vector attributeDescriptions; } vertices; - struct { - vkMeshLoader::MeshBuffer cube; - } meshes; - vk::Buffer uniformBuffer; struct UBOVS { @@ -751,9 +751,9 @@ public: vkDestroyPipeline(device, pipelines.background, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); - vkMeshLoader::freeMeshBufferResources(device, &meshes.cube); - textureLoader->destroyTexture(textures.background); - textureLoader->destroyTexture(textures.cube); + models.cube.destroy(); + textures.background.destroy(); + textures.cube.destroy(); uniformBuffer.destroy(); delete(textOverlay); } @@ -792,8 +792,8 @@ public: vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.background, 0, NULL); VkDeviceSize offsets[1] = { 0 }; - vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &meshes.cube.vertices.buf, offsets); - vkCmdBindIndexBuffer(drawCmdBuffers[i], meshes.cube.indices.buf, 0, VK_INDEX_TYPE_UINT32); + vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.cube.vertices.buffer, offsets); + vkCmdBindIndexBuffer(drawCmdBuffers[i], models.cube.indices.buffer, 0, VK_INDEX_TYPE_UINT32); // Background vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.background); @@ -803,7 +803,7 @@ public: // Cube 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); - vkCmdDrawIndexed(drawCmdBuffers[i], meshes.cube.indexCount, 1, 0, 0, 0); + vkCmdDrawIndexed(drawCmdBuffers[i], models.cube.indexCount, 1, 0, 0, 0); vkCmdEndRenderPass(drawCmdBuffers[i]); @@ -865,15 +865,11 @@ public: textOverlay->endTextUpdate(); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.background); - textureLoader->loadTexture(getAssetPath() + "textures/round_window_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.cube); - } - - void loadMeshes() - { - loadMesh(getAssetPath() + "models/cube.dae", &meshes.cube, vertexLayout, 1.0f); + textures.background.loadFromFile(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + 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 setupVertexDescriptions() @@ -883,7 +879,7 @@ public: vertices.bindingDescriptions[0] = vkTools::initializers::vertexInputBindingDescription( VERTEX_BUFFER_BIND_ID, - vkMeshLoader::vertexSize(vertexLayout), + vertexLayout.stride(), VK_VERTEX_INPUT_RATE_VERTEX); // Attribute descriptions @@ -1175,8 +1171,7 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); - loadMeshes(); + loadAssets(); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout();