diff --git a/bloom/bloom.cpp b/bloom/bloom.cpp index f8edb693..88bae9fc 100644 --- a/bloom/bloom.cpp +++ b/bloom/bloom.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -43,7 +44,7 @@ public: bool bloom = true; struct { - vkTools::VulkanTexture cubemap; + vks::TextureCubeMap cubemap; } textures; struct { @@ -183,7 +184,7 @@ public: uniformBuffers.skyBox.destroy(); uniformBuffers.blurParams.destroy(); - textureLoader->destroyTexture(textures.cubemap); + textures.cubemap.destroy(); } // Setup the offscreen framebuffer for rendering the mirrored scene @@ -524,7 +525,7 @@ public: loadMesh(getAssetPath() + "models/retroufo.dae", &meshes.ufo, vertexLayout, 0.05f); loadMesh(getAssetPath() + "models/retroufo_glow.dae", &meshes.ufoGlow, vertexLayout, 0.05f); loadMesh(getAssetPath() + "models/cube.obj", &meshes.skyBox, vertexLayout, 1.0f); - textureLoader->loadCubemap(getAssetPath() + "textures/cubemap_space.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.cubemap); + textures.cubemap.loadFromFile(getAssetPath() + "textures/cubemap_space.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void setupVertexDescriptions() diff --git a/computenbody/computenbody.cpp b/computenbody/computenbody.cpp index a83176cf..04eac1e3 100644 --- a/computenbody/computenbody.cpp +++ b/computenbody/computenbody.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -36,8 +37,8 @@ public: uint32_t numParticles; struct { - vkTools::VulkanTexture particle; - vkTools::VulkanTexture gradient; + vks::Texture2D particle; + vks::Texture2D gradient; } textures; struct { @@ -121,14 +122,14 @@ public: vkDestroyFence(device, compute.fence, nullptr); vkDestroyCommandPool(device, compute.commandPool, nullptr); - textureLoader->destroyTexture(textures.particle); - textureLoader->destroyTexture(textures.gradient); + textures.particle.destroy(); + textures.gradient.destroy(); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.particle, false); - textureLoader->loadTexture(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.gradient, false); + textures.particle.loadFromFile(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); + textures.gradient.loadFromFile(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void buildCommandBuffers() @@ -735,7 +736,7 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); + loadAssets(); prepareStorageBuffers(); prepareUniformBuffers(); setupDescriptorSetLayout(); diff --git a/computeparticles/computeparticles.cpp b/computeparticles/computeparticles.cpp index 21053ba5..0865d786 100644 --- a/computeparticles/computeparticles.cpp +++ b/computeparticles/computeparticles.cpp @@ -22,6 +22,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -40,8 +41,8 @@ public: bool animate = true; struct { - vkTools::VulkanTexture particle; - vkTools::VulkanTexture gradient; + vks::Texture2D particle; + vks::Texture2D gradient; } textures; struct { @@ -107,14 +108,14 @@ public: vkDestroyFence(device, compute.fence, nullptr); vkDestroyCommandPool(device, compute.commandPool, nullptr); - textureLoader->destroyTexture(textures.particle); - textureLoader->destroyTexture(textures.gradient); + textures.particle.destroy(); + textures.gradient.destroy(); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.particle, false); - textureLoader->loadTexture(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.gradient, false); + textures.particle.loadFromFile(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); + textures.gradient.loadFromFile(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void buildCommandBuffers() @@ -627,7 +628,7 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); + loadAssets(); prepareStorageBuffers(); prepareUniformBuffers(); setupDescriptorSetLayout(); diff --git a/computeshader/computeshader.cpp b/computeshader/computeshader.cpp index a7818aa1..418caf93 100644 --- a/computeshader/computeshader.cpp +++ b/computeshader/computeshader.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -33,8 +34,8 @@ struct Vertex { class VulkanExample : public VulkanExampleBase { private: - vkTools::VulkanTexture textureColorMap; - vkTools::VulkanTexture textureComputeTarget; + vks::Texture2D textureColorMap; + vks::Texture2D textureComputeTarget; public: struct { VkPipelineVertexInputStateCreateInfo inputState; @@ -109,12 +110,12 @@ public: indexBuffer.destroy(); uniformBufferVS.destroy(); - textureLoader->destroyTexture(textureColorMap); - textureLoader->destroyTexture(textureComputeTarget); + textureColorMap.destroy(); + textureComputeTarget.destroy(); } // Prepare a texture target that is used to store compute shader calculations - void prepareTextureTarget(vkTools::VulkanTexture *tex, uint32_t width, uint32_t height, VkFormat format) + void prepareTextureTarget(vks::Texture *tex, uint32_t width, uint32_t height, VkFormat format) { VkFormatProperties formatProperties; @@ -193,15 +194,16 @@ public: tex->descriptor.imageLayout = tex->imageLayout; tex->descriptor.imageView = tex->view; tex->descriptor.sampler = tex->sampler; + tex->device = vulkanDevice; } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture( - getAssetPath() + "textures/het_kanonschot_rgba8.ktx", - VK_FORMAT_R8G8B8A8_UNORM, - &textureColorMap, - false, + textureColorMap.loadFromFile( + getAssetPath() + "textures/het_kanonschot_rgba8.ktx", + VK_FORMAT_R8G8B8A8_UNORM, + vulkanDevice, + queue, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL); } @@ -764,7 +766,7 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); + loadAssets(); generateQuad(); setupVertexDescriptions(); prepareUniformBuffers(); diff --git a/deferred/deferred.cpp b/deferred/deferred.cpp index 5d762c06..47024178 100644 --- a/deferred/deferred.cpp +++ b/deferred/deferred.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -48,12 +49,12 @@ public: struct { struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture normalMap; + vks::Texture2D colorMap; + vks::Texture2D normalMap; } model; struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture normalMap; + vks::Texture2D colorMap; + vks::Texture2D normalMap; } floor; } textures; @@ -201,10 +202,10 @@ public: vkDestroyRenderPass(device, offScreenFrameBuf.renderPass, nullptr); - textureLoader->destroyTexture(textures.model.colorMap); - textureLoader->destroyTexture(textures.model.normalMap); - textureLoader->destroyTexture(textures.floor.colorMap); - textureLoader->destroyTexture(textures.floor.normalMap); + textures.model.colorMap.destroy(); + textures.model.normalMap.destroy(); + textures.floor.colorMap.destroy(); + textures.floor.normalMap.destroy(); vkDestroySemaphore(device, offscreenSemaphore, nullptr); } @@ -473,13 +474,21 @@ public: VK_CHECK_RESULT(vkEndCommandBuffer(offScreenCmdBuffer)); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.colorMap); - textureLoader->loadTexture(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.normalMap); + loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f); - textureLoader->loadTexture(getAssetPath() + "textures/pattern_35_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor.colorMap); - textureLoader->loadTexture(getAssetPath() + "textures/pattern_35_normalmap_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor.normalMap); + vkMeshLoader::MeshCreateInfo meshCreateInfo; + meshCreateInfo.scale = glm::vec3(2.0f); + meshCreateInfo.uvscale = glm::vec2(4.0f); + meshCreateInfo.center = glm::vec3(0.0f, 2.35f, 0.0f); + loadMesh(getAssetPath() + "models/plane.obj", &meshes.floor, vertexLayout, &meshCreateInfo); + + textures.model.colorMap.loadFromFile(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.model.normalMap.loadFromFile(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + + textures.floor.colorMap.loadFromFile(getAssetPath() + "textures/pattern_35_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.floor.normalMap.loadFromFile(getAssetPath() + "textures/pattern_35_normalmap_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void reBuildCommandBuffers() @@ -553,17 +562,6 @@ public: } } - void loadMeshes() - { - loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f); - - vkMeshLoader::MeshCreateInfo meshCreateInfo; - meshCreateInfo.scale = glm::vec3(2.0f); - meshCreateInfo.uvscale = glm::vec2(4.0f); - meshCreateInfo.center = glm::vec3(0.0f, 2.35f, 0.0f); - loadMesh(getAssetPath() + "models/plane.obj", &meshes.floor, vertexLayout, &meshCreateInfo); - } - void generateQuads() { // Setup vertices for multiple screen aligned quads @@ -1130,9 +1128,8 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); + loadAssets(); generateQuads(); - loadMeshes(); setupVertexDescriptions(); prepareOffscreenFramebuffer(); prepareUniformBuffers(); diff --git a/deferredmultisampling/deferredmultisampling.cpp b/deferredmultisampling/deferredmultisampling.cpp index ab69ac1f..84116154 100644 --- a/deferredmultisampling/deferredmultisampling.cpp +++ b/deferredmultisampling/deferredmultisampling.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -45,12 +46,12 @@ public: struct { struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture normalMap; + vks::Texture2D colorMap; + vks::Texture2D normalMap; } model; struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture normalMap; + vks::Texture2D colorMap; + vks::Texture2D normalMap; } floor; } textures; @@ -206,10 +207,10 @@ public: vkDestroyRenderPass(device, offScreenFrameBuf.renderPass, nullptr); - textureLoader->destroyTexture(textures.model.colorMap); - textureLoader->destroyTexture(textures.model.normalMap); - textureLoader->destroyTexture(textures.floor.colorMap); - textureLoader->destroyTexture(textures.floor.normalMap); + textures.model.colorMap.destroy(); + textures.model.normalMap.destroy(); + textures.floor.colorMap.destroy(); + textures.floor.normalMap.destroy(); vkDestroySemaphore(device, offscreenSemaphore, nullptr); } @@ -565,11 +566,11 @@ public: void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.colorMap); - textureLoader->loadTexture(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.normalMap); + textures.model.colorMap.loadFromFile(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.model.normalMap.loadFromFile(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); - textureLoader->loadTexture(getAssetPath() + "textures/pattern_57_diffuse_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor.colorMap); - textureLoader->loadTexture(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor.normalMap); + textures.floor.colorMap.loadFromFile(getAssetPath() + "textures/pattern_57_diffuse_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.floor.normalMap.loadFromFile(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f); diff --git a/deferredshadows/deferredshadows.cpp b/deferredshadows/deferredshadows.cpp index 1ba93f07..11c26b69 100644 --- a/deferredshadows/deferredshadows.cpp +++ b/deferredshadows/deferredshadows.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanframebuffer.hpp" #include "vulkanbuffer.hpp" @@ -74,12 +75,12 @@ public: struct { struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture normalMap; + vks::Texture2D colorMap; + vks::Texture2D normalMap; } model; struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture normalMap; + vks::Texture2D colorMap; + vks::Texture2D normalMap; } background; } textures; @@ -224,10 +225,10 @@ public: vkFreeCommandBuffers(device, cmdPool, 1, &commandBuffers.deferred); // Textures - textureLoader->destroyTexture(textures.model.colorMap); - textureLoader->destroyTexture(textures.model.normalMap); - textureLoader->destroyTexture(textures.background.colorMap); - textureLoader->destroyTexture(textures.background.normalMap); + textures.model.colorMap.destroy(); + textures.model.normalMap.destroy(); + textures.background.colorMap.destroy(); + textures.background.normalMap.destroy(); vkDestroySemaphore(device, offscreenSemaphore, nullptr); } @@ -417,12 +418,20 @@ public: VK_CHECK_RESULT(vkEndCommandBuffer(commandBuffers.deferred)); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.colorMap); - textureLoader->loadTexture(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.normalMap); - textureLoader->loadTexture(getAssetPath() + "textures/pattern_57_diffuse_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.background.colorMap); - textureLoader->loadTexture(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.background.normalMap); + loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f); + + vkMeshLoader::MeshCreateInfo meshCreateInfo; + meshCreateInfo.scale = glm::vec3(15.0f); + meshCreateInfo.uvscale = glm::vec2(1.0f, 1.5f); + meshCreateInfo.center = glm::vec3(0.0f, 2.3f, 0.0f); + loadMesh(getAssetPath() + "models/openbox.dae", &meshes.background, vertexLayout, &meshCreateInfo); + + textures.model.colorMap.loadFromFile(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.model.normalMap.loadFromFile(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.background.colorMap.loadFromFile(getAssetPath() + "textures/pattern_57_diffuse_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.background.normalMap.loadFromFile(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void reBuildCommandBuffers() @@ -489,17 +498,6 @@ public: } } - void loadMeshes() - { - loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f); - - vkMeshLoader::MeshCreateInfo meshCreateInfo; - meshCreateInfo.scale = glm::vec3(15.0f); - meshCreateInfo.uvscale = glm::vec2(1.0f, 1.5f); - meshCreateInfo.center = glm::vec3(0.0f, 2.3f, 0.0f); - loadMesh(getAssetPath() + "models/openbox.dae", &meshes.background, vertexLayout, &meshCreateInfo); - } - /** @brief Create a single quad for fullscreen deferred pass and debug passes (debug pass uses instancing for light visualization) */ void generateQuads() { @@ -1079,9 +1077,8 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); + loadAssets(); generateQuads(); - loadMeshes(); setupVertexDescriptions(); deferredSetup(); shadowSetup(); diff --git a/displacement/displacement.cpp b/displacement/displacement.cpp index 4a3ca74e..0dd6ea18 100644 --- a/displacement/displacement.cpp +++ b/displacement/displacement.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanMeshLoader.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -36,7 +37,7 @@ class VulkanExample : public VulkanExampleBase { private: struct { - vkTools::VulkanTexture colorHeightMap; + vks::Texture2D colorHeightMap; } textures; public: bool splitScreen = true; @@ -104,15 +105,13 @@ public: uniformBuffers.tessEval.destroy(); vkMeshLoader::freeMeshBufferResources(device, &meshes.object); - textureLoader->destroyTexture(textures.colorHeightMap); + textures.colorHeightMap.destroy(); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture( - getAssetPath() + "textures/pattern_36_bc3.ktx", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.colorHeightMap); + loadMesh(getAssetPath() + "models/plane.obj", &meshes.object, vertexLayout, 0.25f); + textures.colorHeightMap.loadFromFile(getAssetPath() + "textures/pattern_36_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void reBuildCommandBuffers() @@ -182,11 +181,6 @@ public: } } - void loadMeshes() - { - loadMesh(getAssetPath() + "models/plane.obj", &meshes.object, vertexLayout, 0.25f); - } - void setupVertexDescriptions() { // Binding description @@ -498,8 +492,7 @@ public: } VulkanExampleBase::prepare(); - loadMeshes(); - loadTextures(); + loadAssets(); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout(); diff --git a/distancefieldfonts/distancefieldfonts.cpp b/distancefieldfonts/distancefieldfonts.cpp index 98719cfc..8e45fa06 100644 --- a/distancefieldfonts/distancefieldfonts.cpp +++ b/distancefieldfonts/distancefieldfonts.cpp @@ -23,6 +23,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -65,8 +66,8 @@ public: bool splitScreen = true; struct { - vkTools::VulkanTexture fontSDF; - vkTools::VulkanTexture fontBitmap; + vks::Texture2D fontSDF; + vks::Texture2D fontBitmap; } textures; struct { @@ -121,8 +122,8 @@ public: // Note : Inherited destructor cleans up resources stored in base class // Clean up texture resources - textureLoader->destroyTexture(textures.fontSDF); - textureLoader->destroyTexture(textures.fontBitmap); + textures.fontSDF.destroy(); + textures.fontBitmap.destroy(); vkDestroyPipeline(device, pipelines.sdf, nullptr); vkDestroyPipeline(device, pipelines.bitmap, nullptr); @@ -196,16 +197,10 @@ public: } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture( - getAssetPath() + "textures/font_sdf_rgba.ktx", - VK_FORMAT_R8G8B8A8_UNORM, - &textures.fontSDF); - textureLoader->loadTexture( - getAssetPath() + "textures/font_bitmap_rgba.ktx", - VK_FORMAT_R8G8B8A8_UNORM, - &textures.fontBitmap); + textures.fontSDF.loadFromFile(getAssetPath() + "textures/font_sdf_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); + textures.fontBitmap.loadFromFile(getAssetPath() + "textures/font_bitmap_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void reBuildCommandBuffers() @@ -659,7 +654,7 @@ public: { VulkanExampleBase::prepare(); parsebmFont(); - loadTextures(); + loadAssets(); generateText("Vulkan"); setupVertexDescriptions(); prepareUniformBuffers(); diff --git a/indirectdraw/indirectdraw.cpp b/indirectdraw/indirectdraw.cpp index 670262c1..72c8f3dd 100644 --- a/indirectdraw/indirectdraw.cpp +++ b/indirectdraw/indirectdraw.cpp @@ -34,6 +34,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -76,8 +77,8 @@ public: } meshes; struct { - vkTools::VulkanTexture plants; - vkTools::VulkanTexture ground; + vks::Texture2DArray plants; + vks::Texture2D ground; } textures; // Per-instance data block @@ -141,8 +142,8 @@ public: vkMeshLoader::freeMeshBufferResources(device, &meshes.plants); vkMeshLoader::freeMeshBufferResources(device, &meshes.ground); vkMeshLoader::freeMeshBufferResources(device, &meshes.skysphere); - textureLoader->destroyTexture(textures.plants); - textureLoader->destroyTexture(textures.ground); + textures.plants.destroy(); + textures.ground.destroy(); instanceBuffer.destroy(); indirectCommandsBuffer.destroy(); uniformData.scene.destroy(); @@ -239,8 +240,8 @@ public: loadMesh(getAssetPath() + "models/plane_circle.dae", &meshes.ground, vertexLayout, PLANT_RADIUS + 1.0f); loadMesh(getAssetPath() + "models/skysphere.dae", &meshes.skysphere, vertexLayout, 512.0f / 10.0f); - textureLoader->loadTextureArray(getAssetPath() + "textures/texturearray_plants_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.plants); - textureLoader->loadTexture(getAssetPath() + "textures/ground_dry_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.ground); + textures.plants.loadFromFile(getAssetPath() + "textures/texturearray_plants_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.ground.loadFromFile(getAssetPath() + "textures/ground_dry_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void setupVertexDescriptions() diff --git a/instancing/instancing.cpp b/instancing/instancing.cpp index 05491903..9b3c71ff 100644 --- a/instancing/instancing.cpp +++ b/instancing/instancing.cpp @@ -21,6 +21,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -46,8 +47,8 @@ public: } meshes; struct { - vkTools::VulkanTexture rocks; - vkTools::VulkanTexture planet; + vks::Texture2DArray rocks; + vks::Texture2D planet; } textures; // Per-instance data block @@ -184,8 +185,8 @@ public: { loadMesh(getAssetPath() + "models/rock01.dae", &meshes.rock, vertexLayout, 0.1f); loadMesh(getAssetPath() + "models/sphere.obj", &meshes.planet, vertexLayout, 0.2f); - textureLoader->loadTextureArray(getAssetPath() + "textures/texturearray_rocks_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.rocks); - textureLoader->loadTexture(getAssetPath() + "textures/lavaplanet_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.planet); + textures.rocks.loadFromFile(getAssetPath() + "textures/texturearray_rocks_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.planet.loadFromFile(getAssetPath() + "textures/lavaplanet_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void setupDescriptorPool() diff --git a/mesh/mesh.cpp b/mesh/mesh.cpp index f4ca04cf..a0420968 100644 --- a/mesh/mesh.cpp +++ b/mesh/mesh.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -37,7 +38,7 @@ public: bool wireframe = false; struct { - vkTools::VulkanTexture colorMap; + vks::Texture2D colorMap; } textures; struct { @@ -113,8 +114,7 @@ public: vkDestroyBuffer(device, mesh.indices.buf, nullptr); vkFreeMemory(device, mesh.indices.mem, nullptr); - textureLoader->destroyTexture(textures.colorMap); - + textures.colorMap.destroy(); uniformBuffers.scene.destroy(); } @@ -317,12 +317,9 @@ public: delete(meshLoader); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture( - getAssetPath() + "models/voyager/voyager.ktx", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.colorMap); + textures.colorMap.loadFromFile(getAssetPath() + "models/voyager/voyager.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void setupVertexDescriptions() @@ -586,7 +583,7 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); + loadAssets(); loadMesh(); setupVertexDescriptions(); prepareUniformBuffers(); diff --git a/multisampling/multisampling.cpp b/multisampling/multisampling.cpp index 1be6eab8..f38672bf 100644 --- a/multisampling/multisampling.cpp +++ b/multisampling/multisampling.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -53,7 +54,7 @@ public: bool useSampleShading = false; struct { - vkTools::VulkanTexture colorMap; + vks::Texture2D colorMap; } textures; struct { @@ -112,7 +113,7 @@ public: vkDestroyImageView(device, multisampleTarget.depth.view, nullptr); vkFreeMemory(device, multisampleTarget.depth.memory, nullptr); - textureLoader->destroyTexture(textures.colorMap); + textures.colorMap.destroy(); uniformBuffer.destroy(); } @@ -415,7 +416,7 @@ public: void loadAssets() { loadMesh(getAssetPath() + "models/voyager/voyager.dae", &meshes.example, vertexLayout, 1.0f); - textureLoader->loadTexture(getAssetPath() + "models/voyager/voyager.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.colorMap); + textures.colorMap.loadFromFile(getAssetPath() + "models/voyager/voyager.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void setupVertexDescriptions() diff --git a/offscreen/offscreen.cpp b/offscreen/offscreen.cpp index 8f357425..93a28660 100644 --- a/offscreen/offscreen.cpp +++ b/offscreen/offscreen.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -43,7 +44,7 @@ public: bool debugDisplay = false; struct { - vkTools::VulkanTexture colorMap; + vks::Texture2D colorMap; } textures; struct { @@ -133,7 +134,7 @@ public: // Note : Inherited destructor cleans up resources stored in base class // Textures - textureLoader->destroyTexture(textures.colorMap); + textures.colorMap.destroy(); // Frame buffer @@ -480,7 +481,7 @@ public: { loadMesh(getAssetPath() + "models/plane.obj", &meshes.plane, vertexLayout, 0.5f); loadMesh(getAssetPath() + "models/chinesedragon.dae", &meshes.example, vertexLayout, 0.3f); - textureLoader->loadTexture(getAssetPath() + "textures/darkmetal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.colorMap); + textures.colorMap.loadFromFile(getAssetPath() + "textures/darkmetal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void generateQuad() diff --git a/parallaxmapping/parallaxmapping.cpp b/parallaxmapping/parallaxmapping.cpp index 84c1bea9..0c233054 100644 --- a/parallaxmapping/parallaxmapping.cpp +++ b/parallaxmapping/parallaxmapping.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -41,9 +42,9 @@ public: bool splitScreen = false; struct { - vkTools::VulkanTexture colorMap; + vks::Texture2D colorMap; // Normals and height are combined in one texture (height = alpha channel) - vkTools::VulkanTexture normalHeightMap; + vks::Texture2D normalHeightMap; } textures; struct { @@ -119,20 +120,15 @@ public: uniformBuffers.vertexShader.destroy(); uniformBuffers.fragmentShader.destroy(); - textureLoader->destroyTexture(textures.colorMap); - textureLoader->destroyTexture(textures.normalHeightMap); + textures.colorMap.destroy(); + textures.normalHeightMap.destroy(); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture( - getAssetPath() + "textures/rocks_color_bc3.dds", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.colorMap); - textureLoader->loadTexture( - getAssetPath() + "textures/rocks_normal_height_rgba.dds", - VK_FORMAT_R8G8B8A8_UNORM, - &textures.normalHeightMap); + loadMesh(getAssetPath() + "models/plane_z.obj", &meshes.quad, vertexLayout, 0.1f); + textures.colorMap.loadFromFile(getAssetPath() + "textures/rocks_color_bc3.dds", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.normalHeightMap.loadFromFile(getAssetPath() + "textures/rocks_normal_height_rgba.dds", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void reBuildCommandBuffers() @@ -203,11 +199,6 @@ public: } } - void loadMeshes() - { - loadMesh(getAssetPath() + "models/plane_z.obj", &meshes.quad, vertexLayout, 0.1f); - } - void setupVertexDescriptions() { // Binding description @@ -513,8 +504,7 @@ public: void prepare() { VulkanExampleBase::prepare(); - loadTextures(); - loadMeshes(); + loadAssets(); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout(); diff --git a/particlefire/particlefire.cpp b/particlefire/particlefire.cpp index cce4ad83..dab46a47 100644 --- a/particlefire/particlefire.cpp +++ b/particlefire/particlefire.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -59,16 +60,16 @@ class VulkanExample : public VulkanExampleBase public: struct { struct { - vkTools::VulkanTexture smoke; - vkTools::VulkanTexture fire; + vks::Texture2D smoke; + vks::Texture2D fire; // We use a custom sampler to change some sampler // attributes required for rotation the uv coordinates // inside the shader for alpha blended textures VkSampler sampler; } particles; struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture normalMap; + vks::Texture2D colorMap; + vks::Texture2D normalMap; } floor; } textures; @@ -139,10 +140,10 @@ public: // Clean up used Vulkan resources // Note : Inherited destructor cleans up resources stored in base class - textureLoader->destroyTexture(textures.particles.smoke); - textureLoader->destroyTexture(textures.particles.fire); - textureLoader->destroyTexture(textures.floor.colorMap); - textureLoader->destroyTexture(textures.floor.normalMap); + textures.particles.smoke.destroy(); + textures.particles.fire.destroy(); + textures.floor.colorMap.destroy(); + textures.floor.normalMap.destroy(); vkDestroyPipeline(device, pipelines.particles, nullptr); vkDestroyPipeline(device, pipelines.environment, nullptr); @@ -323,24 +324,12 @@ public: void loadTextures() { // Particles - textureLoader->loadTexture( - getAssetPath() + "textures/particle_smoke.ktx", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.particles.smoke); - textureLoader->loadTexture( - getAssetPath() + "textures/particle_fire.ktx", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.particles.fire); + textures.particles.smoke.loadFromFile(getAssetPath() + "textures/particle_smoke.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.particles.fire.loadFromFile(getAssetPath() + "textures/particle_fire.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); // Floor - textureLoader->loadTexture( - getAssetPath() + "textures/fireplace_colormap_bc3.ktx", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.floor.colorMap); - textureLoader->loadTexture( - getAssetPath() + "textures/fireplace_normalmap_bc3.ktx", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.floor.normalMap); + textures.floor.colorMap.loadFromFile(getAssetPath() + "textures/fireplace_colormap_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.floor.normalMap.loadFromFile(getAssetPath() + "textures/fireplace_normalmap_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); // Create a custom sampler to be used with the particle textures // Create sampler diff --git a/radialblur/radialblur.cpp b/radialblur/radialblur.cpp index 98c43938..f0805c64 100644 --- a/radialblur/radialblur.cpp +++ b/radialblur/radialblur.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -48,7 +49,7 @@ public: } meshes; struct { - vkTools::VulkanTexture gradient; + vks::Texture2D gradient; } textures; struct { @@ -165,7 +166,7 @@ public: vkFreeCommandBuffers(device, cmdPool, 1, &offscreenPass.commandBuffer); vkDestroySemaphore(device, offscreenPass.semaphore, nullptr); - textureLoader->destroyTexture(textures.gradient); + textures.gradient.destroy(); } // Setup the offscreen framebuffer for rendering the blurred scene @@ -456,7 +457,7 @@ public: void loadAssets() { loadMesh(getAssetPath() + "models/glowsphere.dae", &meshes.example, vertexLayout, 0.05f); - textureLoader->loadTexture(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.gradient, false); + textures.gradient.loadFromFile(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void setupVertexDescriptions() diff --git a/raytracing/raytracing.cpp b/raytracing/raytracing.cpp index 12d43917..3e2366c2 100644 --- a/raytracing/raytracing.cpp +++ b/raytracing/raytracing.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -32,7 +33,7 @@ class VulkanExample : public VulkanExampleBase { public: - vkTools::VulkanTexture textureComputeTarget; + vks::Texture textureComputeTarget; // Resources for the graphics part of the example struct { @@ -122,11 +123,11 @@ public: compute.storageBuffers.spheres.destroy(); compute.storageBuffers.planes.destroy(); - textureLoader->destroyTexture(textureComputeTarget); + textureComputeTarget.destroy(); } // Prepare a texture target that is used to store compute shader calculations - void prepareTextureTarget(vkTools::VulkanTexture *tex, uint32_t width, uint32_t height, VkFormat format) + void prepareTextureTarget(vks::Texture *tex, uint32_t width, uint32_t height, VkFormat format) { // Get device properties for the requested texture format VkFormatProperties formatProperties; @@ -202,6 +203,7 @@ public: tex->descriptor.imageLayout = tex->imageLayout; tex->descriptor.imageView = tex->view; tex->descriptor.sampler = tex->sampler; + tex->device = vulkanDevice; } void buildCommandBuffers() diff --git a/scenerendering/scenerendering.cpp b/scenerendering/scenerendering.cpp index f8c7f532..454195a8 100644 --- a/scenerendering/scenerendering.cpp +++ b/scenerendering/scenerendering.cpp @@ -35,6 +35,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkandevice.hpp" #include "vulkanbuffer.hpp" @@ -68,7 +69,7 @@ struct SceneMaterial // Material properties SceneMaterialProperites properties; // The example only uses a diffuse channel - vkTools::VulkanTexture diffuse; + vks::Texture2D diffuse; // The material's descriptor contains the material descriptors VkDescriptorSet descriptorSet; // Pointer to the pipeline used by this material @@ -111,8 +112,6 @@ private: VkDescriptorSet descriptorSetScene; - vkTools::VulkanTextureLoader *textureLoader; - const aiScene* aScene; // Get materials from the assimp scene and map to our scene structures @@ -152,13 +151,13 @@ private: std::cout << " Diffuse: \"" << texturefile.C_Str() << "\"" << std::endl; std::string fileName = std::string(texturefile.C_Str()); std::replace(fileName.begin(), fileName.end(), '\\', '/'); - textureLoader->loadTexture(assetPath + fileName, VK_FORMAT_BC3_UNORM_BLOCK, &materials[i].diffuse); + materials[i].diffuse.loadFromFile(assetPath + fileName, VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } else { std::cout << " Material has no diffuse, using dummy texture!" << std::endl; // todo : separate pipeline and layout - textureLoader->loadTexture(assetPath + "dummy.ktx", VK_FORMAT_BC2_UNORM_BLOCK, &materials[i].diffuse); + materials[i].diffuse.loadFromFile(assetPath + "dummy.ktx", VK_FORMAT_BC2_UNORM_BLOCK, vulkanDevice, queue); } // For scenes with multiple textures per material we would need to check for additional texture types, e.g.: @@ -421,11 +420,10 @@ public: uint32_t scenePartIndex = 0; // Default constructor - Scene(vk::VulkanDevice *vulkanDevice, VkQueue queue, vkTools::VulkanTextureLoader *textureloader) + Scene(vk::VulkanDevice *vulkanDevice, VkQueue queue) { this->vulkanDevice = vulkanDevice; this->queue = queue; - this->textureLoader = textureloader; // Prepare uniform buffer for global matrices VkMemoryRequirements memReqs; @@ -451,7 +449,7 @@ public: indexBuffer.destroy(); for (auto material : materials) { - textureLoader->destroyTexture(material.diffuse); + material.diffuse.destroy(); } vkDestroyPipelineLayout(vulkanDevice->logicalDevice, pipelineLayout, nullptr); vkDestroyDescriptorSetLayout(vulkanDevice->logicalDevice, descriptorSetLayouts.material, nullptr); @@ -797,7 +795,7 @@ public: void loadScene() { VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false); - scene = new Scene(vulkanDevice, queue, textureLoader); + scene = new Scene(vulkanDevice, queue); #if defined(__ANDROID__) scene->assetManager = androidApp->activity->assetManager; diff --git a/shadowmappingomni/shadowmappingomni.cpp b/shadowmappingomni/shadowmappingomni.cpp index 906ff164..1595c88a 100644 --- a/shadowmappingomni/shadowmappingomni.cpp +++ b/shadowmappingomni/shadowmappingomni.cpp @@ -19,6 +19,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -99,7 +100,7 @@ public: VkDescriptorSetLayout descriptorSetLayout; - vkTools::VulkanTexture shadowCubeMap; + vks::Texture shadowCubeMap; // Framebuffer for offscreen rendering struct FrameBufferAttachment { diff --git a/skeletalanimation/skeletalanimation.cpp b/skeletalanimation/skeletalanimation.cpp index f548b6d5..03bdd535 100644 --- a/skeletalanimation/skeletalanimation.cpp +++ b/skeletalanimation/skeletalanimation.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -339,8 +340,8 @@ class VulkanExample : public VulkanExampleBase { public: struct { - vkTools::VulkanTexture colorMap; - vkTools::VulkanTexture floor; + vks::Texture2D colorMap; + vks::Texture2D floor; } textures; struct { @@ -415,8 +416,8 @@ public: vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); - textureLoader->destroyTexture(textures.colorMap); - textureLoader->destroyTexture(textures.floor); + textures.colorMap.destroy(); + textures.floor.destroy(); uniformBuffers.mesh.destroy(); uniformBuffers.floor.destroy(); @@ -622,8 +623,8 @@ public: void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "textures/goblin_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.colorMap); - textureLoader->loadTexture(getAssetPath() + "textures/trail_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor); + textures.colorMap.loadFromFile(getAssetPath() + "textures/goblin_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + textures.floor.loadFromFile(getAssetPath() + "textures/trail_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); VulkanExampleBase::loadMesh(getAssetPath() + "models/plane_z.obj", &meshes.floor, vertexLayout, 512.0f); } diff --git a/specializationconstants/specializationconstants.cpp b/specializationconstants/specializationconstants.cpp index edf6d8ad..3eae6fbd 100644 --- a/specializationconstants/specializationconstants.cpp +++ b/specializationconstants/specializationconstants.cpp @@ -21,6 +21,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -49,7 +50,7 @@ public: } meshes; struct { - vkTools::VulkanTexture colormap; + vks::Texture2D colormap; } textures; vk::Buffer uniformBuffer; @@ -92,7 +93,7 @@ public: vkMeshLoader::freeMeshBufferResources(device, &meshes.cube); - textureLoader->destroyTexture(textures.colormap); + textures.colormap.destroy(); uniformBuffer.destroy(); } @@ -163,7 +164,7 @@ public: void loadAssets() { loadMesh(getAssetPath() + "models/color_teapot_spheres.dae", &meshes.cube, vertexLayout, 0.1f); - textureLoader->loadTexture(getAssetPath() + "textures/metalplate_nomips_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.colormap); + textures.colormap.loadFromFile(getAssetPath() + "textures/metalplate_nomips_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void setupVertexDescriptions() diff --git a/sphericalenvmapping/sphericalenvmapping.cpp b/sphericalenvmapping/sphericalenvmapping.cpp index b08eccc7..a14cfe34 100644 --- a/sphericalenvmapping/sphericalenvmapping.cpp +++ b/sphericalenvmapping/sphericalenvmapping.cpp @@ -24,6 +24,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -52,7 +53,7 @@ public: } meshes; struct { - vkTools::VulkanTexture matCapArray; + vks::Texture2DArray matCapArray; } textures; vk::Buffer uniformBuffer; @@ -92,8 +93,7 @@ public: vkMeshLoader::freeMeshBufferResources(device, &meshes.object); uniformBuffer.destroy(); - - textureLoader->destroyTexture(textures.matCapArray); + textures.matCapArray.destroy(); } void loadTextures() @@ -101,10 +101,7 @@ public: // 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 - textureLoader->loadTextureArray( - getAssetPath() + "textures/matcap_array_rgba.ktx", - VK_FORMAT_R8G8B8A8_UNORM, - &textures.matCapArray); + textures.matCapArray.loadFromFile(getAssetPath() + "textures/matcap_array_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void buildCommandBuffers() diff --git a/ssao/ssao.cpp b/ssao/ssao.cpp index 51b2d9a9..9ec944fe 100644 --- a/ssao/ssao.cpp +++ b/ssao/ssao.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -46,7 +47,7 @@ class VulkanExample : public VulkanExampleBase { public: struct { - vkTools::VulkanTexture ssaoNoise; + vks::Texture2D ssaoNoise; } textures; struct { @@ -213,7 +214,7 @@ public: // Misc vkFreeCommandBuffers(device, cmdPool, 1, &offScreenCmdBuffer); vkDestroySemaphore(device, offscreenSemaphore, nullptr); - textureLoader->destroyTexture(textures.ssaoNoise); + textures.ssaoNoise.destroy(); } // Create a frame buffer attachment @@ -1050,7 +1051,7 @@ public: ssaoNoise[i] = glm::vec4(rndDist(rndGen) * 2.0f - 1.0f, rndDist(rndGen) * 2.0f - 1.0f, 0.0f, 0.0f); } // Upload as texture - textureLoader->createTexture(ssaoNoise.data(), ssaoNoise.size() * sizeof(glm::vec4), VK_FORMAT_R32G32B32A32_SFLOAT, SSAO_NOISE_DIM, SSAO_NOISE_DIM, &textures.ssaoNoise, VK_FILTER_NEAREST); + textures.ssaoNoise.fromBuffer(ssaoNoise.data(), ssaoNoise.size() * sizeof(glm::vec4), VK_FORMAT_R32G32B32A32_SFLOAT, SSAO_NOISE_DIM, SSAO_NOISE_DIM, vulkanDevice, queue, VK_FILTER_NEAREST); } void updateUniformBufferMatrices() diff --git a/subpasses/subpasses.cpp b/subpasses/subpasses.cpp index acce07a3..d98e368a 100644 --- a/subpasses/subpasses.cpp +++ b/subpasses/subpasses.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -44,7 +45,7 @@ public: } meshes; struct { - vkTools::VulkanTexture glass; + vks::Texture2D glass; } textures; struct { @@ -487,7 +488,7 @@ public: { loadMesh(getAssetPath() + "models/samplebuilding.dae", &meshes.scene, vertexLayout, 1.0f); loadMesh(getAssetPath() + "models/samplebuilding_glass.dae", &meshes.transparent, vertexLayout, 1.0f); - textureLoader->loadTexture(getAssetPath() + "textures/colored_glass_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.glass); + textures.glass.loadFromFile(getAssetPath() + "textures/colored_glass_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void setupVertexDescriptions() diff --git a/terraintessellation/terraintessellation.cpp b/terraintessellation/terraintessellation.cpp index 6500eadd..4691d18c 100644 --- a/terraintessellation/terraintessellation.cpp +++ b/terraintessellation/terraintessellation.cpp @@ -21,6 +21,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #include "frustum.hpp" @@ -39,9 +40,9 @@ class VulkanExample : public VulkanExampleBase { private: struct { - vkTools::VulkanTexture heightMap; - vkTools::VulkanTexture skySphere; - vkTools::VulkanTexture terrainArray; + vks::Texture2D heightMap; + vks::Texture2D skySphere; + vks::Texture2DArray terrainArray; } textures; public: bool wireframe = false; @@ -151,9 +152,9 @@ public: uniformBuffers.skysphereVertex.destroy(); uniformBuffers.terrainTessellation.destroy(); - textureLoader->destroyTexture(textures.heightMap); - textureLoader->destroyTexture(textures.skySphere); - textureLoader->destroyTexture(textures.terrainArray); + textures.heightMap.destroy(); + textures.skySphere.destroy(); + textures.terrainArray.destroy(); vkDestroyQueryPool(device, queryPool, nullptr); @@ -208,13 +209,15 @@ public: VK_QUERY_RESULT_64_BIT); } - void loadTextures() + void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.skySphere); + loadMesh(getAssetPath() + "models/geosphere.obj", &meshes.skysphere, vertexLayout, 1.0f); + + textures.skySphere.loadFromFile(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); // Height data is stored in a one-channel texture - textureLoader->loadTexture(getAssetPath() + "textures/terrain_heightmap_r16.ktx", VK_FORMAT_R16_UNORM, &textures.heightMap); + textures.heightMap.loadFromFile(getAssetPath() + "textures/terrain_heightmap_r16.ktx", VK_FORMAT_R16_UNORM, vulkanDevice, queue); // Terrain textures are stored in a texture array with layers corresponding to terrain height - textureLoader->loadTextureArray(getAssetPath() + "textures/terrain_texturearray_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.terrainArray); + textures.terrainArray.loadFromFile(getAssetPath() + "textures/terrain_texturearray_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); VkSamplerCreateInfo samplerInfo = vkTools::initializers::samplerCreateInfo(); @@ -328,11 +331,6 @@ public: } } - void loadMeshes() - { - loadMesh(getAssetPath() + "models/geosphere.obj", &meshes.skysphere, vertexLayout, 1.0f); - } - // Encapsulate height map data for easy sampling struct HeightMap { @@ -883,8 +881,7 @@ public: } VulkanExampleBase::prepare(); - loadMeshes(); - loadTextures(); + loadAssets(); generateTerrain(); setupQueryResultBuffer(); setupVertexDescriptions(); diff --git a/tessellation/tessellation.cpp b/tessellation/tessellation.cpp index 9d284da2..7937fb6e 100644 --- a/tessellation/tessellation.cpp +++ b/tessellation/tessellation.cpp @@ -22,6 +22,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -41,7 +42,7 @@ public: bool splitScreen = true; struct { - vkTools::VulkanTexture colorMap; + vks::Texture2D colorMap; } textures; struct { @@ -111,8 +112,7 @@ public: uniformBuffers.tessControl.destroy(); uniformBuffers.tessEval.destroy(); - - textureLoader->destroyTexture(textures.colorMap); + textures.colorMap.destroy(); } void reBuildCommandBuffers() @@ -183,17 +183,10 @@ public: } } - void loadMeshes() + void loadAssets() { loadMesh(getAssetPath() + "models/lowpoly/deer.dae", &meshes.object, vertexLayout, 1.0f); - } - - void loadTextures() - { - textureLoader->loadTexture( - getAssetPath() + "textures/deer.ktx", - VK_FORMAT_BC3_UNORM_BLOCK, - &textures.colorMap); + textures.colorMap.loadFromFile(getAssetPath() + "textures/deer.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); } void setupVertexDescriptions() @@ -503,8 +496,7 @@ public: } VulkanExampleBase::prepare(); - loadTextures(); - loadMeshes(); + loadAssets(); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout(); diff --git a/texture/texture.cpp b/texture/texture.cpp index 45d2c444..6bcecf00 100644 --- a/texture/texture.cpp +++ b/texture/texture.cpp @@ -36,9 +36,7 @@ class VulkanExample : public VulkanExampleBase { public: // Contains all Vulkan objects that are required to store and use a texture - // Note that this repository contains a texture loader (vulkantextureloader.h) - // that encapsulates texture loading functionality in a class that is used - // in subsequent demos + // Note that this repository contains a texture class (VulkanTexture.hpp) that encapsulates texture loading functionality in a class that is used in subsequent demos struct Texture { VkSampler sampler; VkImage image; diff --git a/texturearray/texturearray.cpp b/texturearray/texturearray.cpp index a9e13f05..ff1bc9b9 100644 --- a/texturearray/texturearray.cpp +++ b/texturearray/texturearray.cpp @@ -20,6 +20,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -37,7 +38,7 @@ public: // Number of array layers in texture array // Also used as instance count uint32_t layerCount; - vkTools::VulkanTexture textureArray; + vks::Texture textureArray; struct { VkPipelineVertexInputStateCreateInfo inputState; diff --git a/texturecubemap/texturecubemap.cpp b/texturecubemap/texturecubemap.cpp index 4388b403..f66c1d1c 100644 --- a/texturecubemap/texturecubemap.cpp +++ b/texturecubemap/texturecubemap.cpp @@ -21,6 +21,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkanbuffer.hpp" #define VERTEX_BUFFER_BIND_ID 0 @@ -39,7 +40,7 @@ class VulkanExample : public VulkanExampleBase public: bool displaySkybox = true; - vkTools::VulkanTexture cubeMap; + vks::Texture cubeMap; struct { VkPipelineVertexInputStateCreateInfo inputState; diff --git a/texturesparseresidency/texturesparseresidency.cpp b/texturesparseresidency/texturesparseresidency.cpp index b7c1cc49..1c532ee8 100644 --- a/texturesparseresidency/texturesparseresidency.cpp +++ b/texturesparseresidency/texturesparseresidency.cpp @@ -30,6 +30,7 @@ todos: #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #include "vulkandevice.hpp" #include "vulkanbuffer.hpp" #include "vulkanheightmap.hpp" @@ -199,7 +200,7 @@ public: } texture; struct { - vkTools::VulkanTexture source; + vks::Texture2D source; } textures; vkTools::HeightMap *heightMap = nullptr; @@ -659,7 +660,7 @@ public: void loadAssets() { - textureLoader->loadTexture(getAssetPath() + "textures/ground_dry_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.source, false, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); + textures.source.loadFromFile(getAssetPath() + "textures/ground_dry_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); } // Generate a terrain quad patch for feeding to the tessellation control shader diff --git a/vulkanscene/vulkanscene.cpp b/vulkanscene/vulkanscene.cpp index 171bf14e..b1330680 100644 --- a/vulkanscene/vulkanscene.cpp +++ b/vulkanscene/vulkanscene.cpp @@ -24,6 +24,7 @@ #include #include "vulkanexamplebase.h" +#include "VulkanTexture.hpp" #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false @@ -76,7 +77,7 @@ public: struct { - vkTools::VulkanTexture skybox; + vks::TextureCubeMap skybox; } textures; struct { @@ -119,15 +120,12 @@ public: mesh.indexBuffer.destroy(); } - textureLoader->destroyTexture(textures.skybox); + textures.skybox.destroy(); } void loadTextures() { - textureLoader->loadCubemap( - getAssetPath() + "textures/cubemap_vulkan.ktx", - VK_FORMAT_R8G8B8A8_UNORM, - &textures.skybox); + textures.skybox.loadFromFile(getAssetPath() + "textures/cubemap_vulkan.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } void buildCommandBuffers()