Use new Vulkan texture class (Refs #260)

This commit is contained in:
saschawillems 2017-02-09 21:55:35 +01:00
parent 83ad186ce5
commit 9822cde6e2
32 changed files with 232 additions and 273 deletions

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -43,7 +44,7 @@ public:
bool bloom = true; bool bloom = true;
struct { struct {
vkTools::VulkanTexture cubemap; vks::TextureCubeMap cubemap;
} textures; } textures;
struct { struct {
@ -183,7 +184,7 @@ public:
uniformBuffers.skyBox.destroy(); uniformBuffers.skyBox.destroy();
uniformBuffers.blurParams.destroy(); uniformBuffers.blurParams.destroy();
textureLoader->destroyTexture(textures.cubemap); textures.cubemap.destroy();
} }
// Setup the offscreen framebuffer for rendering the mirrored scene // 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.dae", &meshes.ufo, vertexLayout, 0.05f);
loadMesh(getAssetPath() + "models/retroufo_glow.dae", &meshes.ufoGlow, vertexLayout, 0.05f); loadMesh(getAssetPath() + "models/retroufo_glow.dae", &meshes.ufoGlow, vertexLayout, 0.05f);
loadMesh(getAssetPath() + "models/cube.obj", &meshes.skyBox, vertexLayout, 1.0f); 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() void setupVertexDescriptions()

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
@ -36,8 +37,8 @@ public:
uint32_t numParticles; uint32_t numParticles;
struct { struct {
vkTools::VulkanTexture particle; vks::Texture2D particle;
vkTools::VulkanTexture gradient; vks::Texture2D gradient;
} textures; } textures;
struct { struct {
@ -121,14 +122,14 @@ public:
vkDestroyFence(device, compute.fence, nullptr); vkDestroyFence(device, compute.fence, nullptr);
vkDestroyCommandPool(device, compute.commandPool, nullptr); vkDestroyCommandPool(device, compute.commandPool, nullptr);
textureLoader->destroyTexture(textures.particle); textures.particle.destroy();
textureLoader->destroyTexture(textures.gradient); textures.gradient.destroy();
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.particle, false); textures.particle.loadFromFile(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
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 buildCommandBuffers() void buildCommandBuffers()
@ -735,7 +736,7 @@ public:
void prepare() void prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
prepareStorageBuffers(); prepareStorageBuffers();
prepareUniformBuffers(); prepareUniformBuffers();
setupDescriptorSetLayout(); setupDescriptorSetLayout();

View file

@ -22,6 +22,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
@ -40,8 +41,8 @@ public:
bool animate = true; bool animate = true;
struct { struct {
vkTools::VulkanTexture particle; vks::Texture2D particle;
vkTools::VulkanTexture gradient; vks::Texture2D gradient;
} textures; } textures;
struct { struct {
@ -107,14 +108,14 @@ public:
vkDestroyFence(device, compute.fence, nullptr); vkDestroyFence(device, compute.fence, nullptr);
vkDestroyCommandPool(device, compute.commandPool, nullptr); vkDestroyCommandPool(device, compute.commandPool, nullptr);
textureLoader->destroyTexture(textures.particle); textures.particle.destroy();
textureLoader->destroyTexture(textures.gradient); textures.gradient.destroy();
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.particle, false); textures.particle.loadFromFile(getAssetPath() + "textures/particle01_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
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 buildCommandBuffers() void buildCommandBuffers()
@ -627,7 +628,7 @@ public:
void prepare() void prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
prepareStorageBuffers(); prepareStorageBuffers();
prepareUniformBuffers(); prepareUniformBuffers();
setupDescriptorSetLayout(); setupDescriptorSetLayout();

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -33,8 +34,8 @@ struct Vertex {
class VulkanExample : public VulkanExampleBase class VulkanExample : public VulkanExampleBase
{ {
private: private:
vkTools::VulkanTexture textureColorMap; vks::Texture2D textureColorMap;
vkTools::VulkanTexture textureComputeTarget; vks::Texture2D textureComputeTarget;
public: public:
struct { struct {
VkPipelineVertexInputStateCreateInfo inputState; VkPipelineVertexInputStateCreateInfo inputState;
@ -109,12 +110,12 @@ public:
indexBuffer.destroy(); indexBuffer.destroy();
uniformBufferVS.destroy(); uniformBufferVS.destroy();
textureLoader->destroyTexture(textureColorMap); textureColorMap.destroy();
textureLoader->destroyTexture(textureComputeTarget); textureComputeTarget.destroy();
} }
// Prepare a texture target that is used to store compute shader calculations // 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; VkFormatProperties formatProperties;
@ -193,15 +194,16 @@ public:
tex->descriptor.imageLayout = tex->imageLayout; tex->descriptor.imageLayout = tex->imageLayout;
tex->descriptor.imageView = tex->view; tex->descriptor.imageView = tex->view;
tex->descriptor.sampler = tex->sampler; tex->descriptor.sampler = tex->sampler;
tex->device = vulkanDevice;
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture( textureColorMap.loadFromFile(
getAssetPath() + "textures/het_kanonschot_rgba8.ktx", getAssetPath() + "textures/het_kanonschot_rgba8.ktx",
VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM,
&textureColorMap, vulkanDevice,
false, queue,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
VK_IMAGE_LAYOUT_GENERAL); VK_IMAGE_LAYOUT_GENERAL);
} }
@ -764,7 +766,7 @@ public:
void prepare() void prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
generateQuad(); generateQuad();
setupVertexDescriptions(); setupVertexDescriptions();
prepareUniformBuffers(); prepareUniformBuffers();

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -48,12 +49,12 @@ public:
struct { struct {
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture normalMap; vks::Texture2D normalMap;
} model; } model;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture normalMap; vks::Texture2D normalMap;
} floor; } floor;
} textures; } textures;
@ -201,10 +202,10 @@ public:
vkDestroyRenderPass(device, offScreenFrameBuf.renderPass, nullptr); vkDestroyRenderPass(device, offScreenFrameBuf.renderPass, nullptr);
textureLoader->destroyTexture(textures.model.colorMap); textures.model.colorMap.destroy();
textureLoader->destroyTexture(textures.model.normalMap); textures.model.normalMap.destroy();
textureLoader->destroyTexture(textures.floor.colorMap); textures.floor.colorMap.destroy();
textureLoader->destroyTexture(textures.floor.normalMap); textures.floor.normalMap.destroy();
vkDestroySemaphore(device, offscreenSemaphore, nullptr); vkDestroySemaphore(device, offscreenSemaphore, nullptr);
} }
@ -473,13 +474,21 @@ public:
VK_CHECK_RESULT(vkEndCommandBuffer(offScreenCmdBuffer)); VK_CHECK_RESULT(vkEndCommandBuffer(offScreenCmdBuffer));
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.colorMap); loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f);
textureLoader->loadTexture(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.normalMap);
textureLoader->loadTexture(getAssetPath() + "textures/pattern_35_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor.colorMap); vkMeshLoader::MeshCreateInfo meshCreateInfo;
textureLoader->loadTexture(getAssetPath() + "textures/pattern_35_normalmap_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor.normalMap); 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() 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() void generateQuads()
{ {
// Setup vertices for multiple screen aligned quads // Setup vertices for multiple screen aligned quads
@ -1130,9 +1128,8 @@ public:
void prepare() void prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
generateQuads(); generateQuads();
loadMeshes();
setupVertexDescriptions(); setupVertexDescriptions();
prepareOffscreenFramebuffer(); prepareOffscreenFramebuffer();
prepareUniformBuffers(); prepareUniformBuffers();

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -45,12 +46,12 @@ public:
struct { struct {
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture normalMap; vks::Texture2D normalMap;
} model; } model;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture normalMap; vks::Texture2D normalMap;
} floor; } floor;
} textures; } textures;
@ -206,10 +207,10 @@ public:
vkDestroyRenderPass(device, offScreenFrameBuf.renderPass, nullptr); vkDestroyRenderPass(device, offScreenFrameBuf.renderPass, nullptr);
textureLoader->destroyTexture(textures.model.colorMap); textures.model.colorMap.destroy();
textureLoader->destroyTexture(textures.model.normalMap); textures.model.normalMap.destroy();
textureLoader->destroyTexture(textures.floor.colorMap); textures.floor.colorMap.destroy();
textureLoader->destroyTexture(textures.floor.normalMap); textures.floor.normalMap.destroy();
vkDestroySemaphore(device, offscreenSemaphore, nullptr); vkDestroySemaphore(device, offscreenSemaphore, nullptr);
} }
@ -565,11 +566,11 @@ public:
void loadAssets() void loadAssets()
{ {
textureLoader->loadTexture(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.colorMap); textures.model.colorMap.loadFromFile(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
textureLoader->loadTexture(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.model.normalMap); 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); textures.floor.colorMap.loadFromFile(getAssetPath() + "textures/pattern_57_diffuse_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
textureLoader->loadTexture(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor.normalMap); 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); loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f);

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanframebuffer.hpp" #include "vulkanframebuffer.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
@ -74,12 +75,12 @@ public:
struct { struct {
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture normalMap; vks::Texture2D normalMap;
} model; } model;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture normalMap; vks::Texture2D normalMap;
} background; } background;
} textures; } textures;
@ -224,10 +225,10 @@ public:
vkFreeCommandBuffers(device, cmdPool, 1, &commandBuffers.deferred); vkFreeCommandBuffers(device, cmdPool, 1, &commandBuffers.deferred);
// Textures // Textures
textureLoader->destroyTexture(textures.model.colorMap); textures.model.colorMap.destroy();
textureLoader->destroyTexture(textures.model.normalMap); textures.model.normalMap.destroy();
textureLoader->destroyTexture(textures.background.colorMap); textures.background.colorMap.destroy();
textureLoader->destroyTexture(textures.background.normalMap); textures.background.normalMap.destroy();
vkDestroySemaphore(device, offscreenSemaphore, nullptr); vkDestroySemaphore(device, offscreenSemaphore, nullptr);
} }
@ -417,12 +418,20 @@ public:
VK_CHECK_RESULT(vkEndCommandBuffer(commandBuffers.deferred)); 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); loadMesh(getAssetPath() + "models/armor/armor.dae", &meshes.model, vertexLayout, 1.0f);
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); vkMeshLoader::MeshCreateInfo meshCreateInfo;
textureLoader->loadTexture(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.background.normalMap); 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() 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) */ /** @brief Create a single quad for fullscreen deferred pass and debug passes (debug pass uses instancing for light visualization) */
void generateQuads() void generateQuads()
{ {
@ -1079,9 +1077,8 @@ public:
void prepare() void prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
generateQuads(); generateQuads();
loadMeshes();
setupVertexDescriptions(); setupVertexDescriptions();
deferredSetup(); deferredSetup();
shadowSetup(); shadowSetup();

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanMeshLoader.hpp" #include "vulkanMeshLoader.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -36,7 +37,7 @@ class VulkanExample : public VulkanExampleBase
{ {
private: private:
struct { struct {
vkTools::VulkanTexture colorHeightMap; vks::Texture2D colorHeightMap;
} textures; } textures;
public: public:
bool splitScreen = true; bool splitScreen = true;
@ -104,15 +105,13 @@ public:
uniformBuffers.tessEval.destroy(); uniformBuffers.tessEval.destroy();
vkMeshLoader::freeMeshBufferResources(device, &meshes.object); vkMeshLoader::freeMeshBufferResources(device, &meshes.object);
textureLoader->destroyTexture(textures.colorHeightMap); textures.colorHeightMap.destroy();
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture( loadMesh(getAssetPath() + "models/plane.obj", &meshes.object, vertexLayout, 0.25f);
getAssetPath() + "textures/pattern_36_bc3.ktx", textures.colorHeightMap.loadFromFile(getAssetPath() + "textures/pattern_36_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
VK_FORMAT_BC3_UNORM_BLOCK,
&textures.colorHeightMap);
} }
void reBuildCommandBuffers() void reBuildCommandBuffers()
@ -182,11 +181,6 @@ public:
} }
} }
void loadMeshes()
{
loadMesh(getAssetPath() + "models/plane.obj", &meshes.object, vertexLayout, 0.25f);
}
void setupVertexDescriptions() void setupVertexDescriptions()
{ {
// Binding description // Binding description
@ -498,8 +492,7 @@ public:
} }
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadMeshes(); loadAssets();
loadTextures();
setupVertexDescriptions(); setupVertexDescriptions();
prepareUniformBuffers(); prepareUniformBuffers();
setupDescriptorSetLayout(); setupDescriptorSetLayout();

View file

@ -23,6 +23,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -65,8 +66,8 @@ public:
bool splitScreen = true; bool splitScreen = true;
struct { struct {
vkTools::VulkanTexture fontSDF; vks::Texture2D fontSDF;
vkTools::VulkanTexture fontBitmap; vks::Texture2D fontBitmap;
} textures; } textures;
struct { struct {
@ -121,8 +122,8 @@ public:
// Note : Inherited destructor cleans up resources stored in base class // Note : Inherited destructor cleans up resources stored in base class
// Clean up texture resources // Clean up texture resources
textureLoader->destroyTexture(textures.fontSDF); textures.fontSDF.destroy();
textureLoader->destroyTexture(textures.fontBitmap); textures.fontBitmap.destroy();
vkDestroyPipeline(device, pipelines.sdf, nullptr); vkDestroyPipeline(device, pipelines.sdf, nullptr);
vkDestroyPipeline(device, pipelines.bitmap, nullptr); vkDestroyPipeline(device, pipelines.bitmap, nullptr);
@ -196,16 +197,10 @@ public:
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture( textures.fontSDF.loadFromFile(getAssetPath() + "textures/font_sdf_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
getAssetPath() + "textures/font_sdf_rgba.ktx", textures.fontBitmap.loadFromFile(getAssetPath() + "textures/font_bitmap_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
VK_FORMAT_R8G8B8A8_UNORM,
&textures.fontSDF);
textureLoader->loadTexture(
getAssetPath() + "textures/font_bitmap_rgba.ktx",
VK_FORMAT_R8G8B8A8_UNORM,
&textures.fontBitmap);
} }
void reBuildCommandBuffers() void reBuildCommandBuffers()
@ -659,7 +654,7 @@ public:
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
parsebmFont(); parsebmFont();
loadTextures(); loadAssets();
generateText("Vulkan"); generateText("Vulkan");
setupVertexDescriptions(); setupVertexDescriptions();
prepareUniformBuffers(); prepareUniformBuffers();

View file

@ -34,6 +34,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -76,8 +77,8 @@ public:
} meshes; } meshes;
struct { struct {
vkTools::VulkanTexture plants; vks::Texture2DArray plants;
vkTools::VulkanTexture ground; vks::Texture2D ground;
} textures; } textures;
// Per-instance data block // Per-instance data block
@ -141,8 +142,8 @@ public:
vkMeshLoader::freeMeshBufferResources(device, &meshes.plants); vkMeshLoader::freeMeshBufferResources(device, &meshes.plants);
vkMeshLoader::freeMeshBufferResources(device, &meshes.ground); vkMeshLoader::freeMeshBufferResources(device, &meshes.ground);
vkMeshLoader::freeMeshBufferResources(device, &meshes.skysphere); vkMeshLoader::freeMeshBufferResources(device, &meshes.skysphere);
textureLoader->destroyTexture(textures.plants); textures.plants.destroy();
textureLoader->destroyTexture(textures.ground); textures.ground.destroy();
instanceBuffer.destroy(); instanceBuffer.destroy();
indirectCommandsBuffer.destroy(); indirectCommandsBuffer.destroy();
uniformData.scene.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/plane_circle.dae", &meshes.ground, vertexLayout, PLANT_RADIUS + 1.0f);
loadMesh(getAssetPath() + "models/skysphere.dae", &meshes.skysphere, vertexLayout, 512.0f / 10.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); textures.plants.loadFromFile(getAssetPath() + "textures/texturearray_plants_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
textureLoader->loadTexture(getAssetPath() + "textures/ground_dry_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.ground); textures.ground.loadFromFile(getAssetPath() + "textures/ground_dry_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
} }
void setupVertexDescriptions() void setupVertexDescriptions()

View file

@ -21,6 +21,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -46,8 +47,8 @@ public:
} meshes; } meshes;
struct { struct {
vkTools::VulkanTexture rocks; vks::Texture2DArray rocks;
vkTools::VulkanTexture planet; vks::Texture2D planet;
} textures; } textures;
// Per-instance data block // Per-instance data block
@ -184,8 +185,8 @@ public:
{ {
loadMesh(getAssetPath() + "models/rock01.dae", &meshes.rock, vertexLayout, 0.1f); loadMesh(getAssetPath() + "models/rock01.dae", &meshes.rock, vertexLayout, 0.1f);
loadMesh(getAssetPath() + "models/sphere.obj", &meshes.planet, vertexLayout, 0.2f); 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); textures.rocks.loadFromFile(getAssetPath() + "textures/texturearray_rocks_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
textureLoader->loadTexture(getAssetPath() + "textures/lavaplanet_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.planet); textures.planet.loadFromFile(getAssetPath() + "textures/lavaplanet_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
} }
void setupDescriptorPool() void setupDescriptorPool()

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
@ -37,7 +38,7 @@ public:
bool wireframe = false; bool wireframe = false;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
} textures; } textures;
struct { struct {
@ -113,8 +114,7 @@ public:
vkDestroyBuffer(device, mesh.indices.buf, nullptr); vkDestroyBuffer(device, mesh.indices.buf, nullptr);
vkFreeMemory(device, mesh.indices.mem, nullptr); vkFreeMemory(device, mesh.indices.mem, nullptr);
textureLoader->destroyTexture(textures.colorMap); textures.colorMap.destroy();
uniformBuffers.scene.destroy(); uniformBuffers.scene.destroy();
} }
@ -317,12 +317,9 @@ public:
delete(meshLoader); delete(meshLoader);
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture( textures.colorMap.loadFromFile(getAssetPath() + "models/voyager/voyager.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
getAssetPath() + "models/voyager/voyager.ktx",
VK_FORMAT_BC3_UNORM_BLOCK,
&textures.colorMap);
} }
void setupVertexDescriptions() void setupVertexDescriptions()
@ -586,7 +583,7 @@ public:
void prepare() void prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
loadMesh(); loadMesh();
setupVertexDescriptions(); setupVertexDescriptions();
prepareUniformBuffers(); prepareUniformBuffers();

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -53,7 +54,7 @@ public:
bool useSampleShading = false; bool useSampleShading = false;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
} textures; } textures;
struct { struct {
@ -112,7 +113,7 @@ public:
vkDestroyImageView(device, multisampleTarget.depth.view, nullptr); vkDestroyImageView(device, multisampleTarget.depth.view, nullptr);
vkFreeMemory(device, multisampleTarget.depth.memory, nullptr); vkFreeMemory(device, multisampleTarget.depth.memory, nullptr);
textureLoader->destroyTexture(textures.colorMap); textures.colorMap.destroy();
uniformBuffer.destroy(); uniformBuffer.destroy();
} }
@ -415,7 +416,7 @@ public:
void loadAssets() void loadAssets()
{ {
loadMesh(getAssetPath() + "models/voyager/voyager.dae", &meshes.example, vertexLayout, 1.0f); 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() void setupVertexDescriptions()

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -43,7 +44,7 @@ public:
bool debugDisplay = false; bool debugDisplay = false;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
} textures; } textures;
struct { struct {
@ -133,7 +134,7 @@ public:
// Note : Inherited destructor cleans up resources stored in base class // Note : Inherited destructor cleans up resources stored in base class
// Textures // Textures
textureLoader->destroyTexture(textures.colorMap); textures.colorMap.destroy();
// Frame buffer // Frame buffer
@ -480,7 +481,7 @@ public:
{ {
loadMesh(getAssetPath() + "models/plane.obj", &meshes.plane, vertexLayout, 0.5f); loadMesh(getAssetPath() + "models/plane.obj", &meshes.plane, vertexLayout, 0.5f);
loadMesh(getAssetPath() + "models/chinesedragon.dae", &meshes.example, vertexLayout, 0.3f); 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() void generateQuad()

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -41,9 +42,9 @@ public:
bool splitScreen = false; bool splitScreen = false;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
// Normals and height are combined in one texture (height = alpha channel) // Normals and height are combined in one texture (height = alpha channel)
vkTools::VulkanTexture normalHeightMap; vks::Texture2D normalHeightMap;
} textures; } textures;
struct { struct {
@ -119,20 +120,15 @@ public:
uniformBuffers.vertexShader.destroy(); uniformBuffers.vertexShader.destroy();
uniformBuffers.fragmentShader.destroy(); uniformBuffers.fragmentShader.destroy();
textureLoader->destroyTexture(textures.colorMap); textures.colorMap.destroy();
textureLoader->destroyTexture(textures.normalHeightMap); textures.normalHeightMap.destroy();
} }
void loadTextures() void loadAssets()
{ {
textureLoader->loadTexture( loadMesh(getAssetPath() + "models/plane_z.obj", &meshes.quad, vertexLayout, 0.1f);
getAssetPath() + "textures/rocks_color_bc3.dds", textures.colorMap.loadFromFile(getAssetPath() + "textures/rocks_color_bc3.dds", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
VK_FORMAT_BC3_UNORM_BLOCK, textures.normalHeightMap.loadFromFile(getAssetPath() + "textures/rocks_normal_height_rgba.dds", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
&textures.colorMap);
textureLoader->loadTexture(
getAssetPath() + "textures/rocks_normal_height_rgba.dds",
VK_FORMAT_R8G8B8A8_UNORM,
&textures.normalHeightMap);
} }
void reBuildCommandBuffers() void reBuildCommandBuffers()
@ -203,11 +199,6 @@ public:
} }
} }
void loadMeshes()
{
loadMesh(getAssetPath() + "models/plane_z.obj", &meshes.quad, vertexLayout, 0.1f);
}
void setupVertexDescriptions() void setupVertexDescriptions()
{ {
// Binding description // Binding description
@ -513,8 +504,7 @@ public:
void prepare() void prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
loadMeshes();
setupVertexDescriptions(); setupVertexDescriptions();
prepareUniformBuffers(); prepareUniformBuffers();
setupDescriptorSetLayout(); setupDescriptorSetLayout();

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -59,16 +60,16 @@ class VulkanExample : public VulkanExampleBase
public: public:
struct { struct {
struct { struct {
vkTools::VulkanTexture smoke; vks::Texture2D smoke;
vkTools::VulkanTexture fire; vks::Texture2D fire;
// We use a custom sampler to change some sampler // We use a custom sampler to change some sampler
// attributes required for rotation the uv coordinates // attributes required for rotation the uv coordinates
// inside the shader for alpha blended textures // inside the shader for alpha blended textures
VkSampler sampler; VkSampler sampler;
} particles; } particles;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture normalMap; vks::Texture2D normalMap;
} floor; } floor;
} textures; } textures;
@ -139,10 +140,10 @@ public:
// Clean up used Vulkan resources // Clean up used Vulkan resources
// Note : Inherited destructor cleans up resources stored in base class // Note : Inherited destructor cleans up resources stored in base class
textureLoader->destroyTexture(textures.particles.smoke); textures.particles.smoke.destroy();
textureLoader->destroyTexture(textures.particles.fire); textures.particles.fire.destroy();
textureLoader->destroyTexture(textures.floor.colorMap); textures.floor.colorMap.destroy();
textureLoader->destroyTexture(textures.floor.normalMap); textures.floor.normalMap.destroy();
vkDestroyPipeline(device, pipelines.particles, nullptr); vkDestroyPipeline(device, pipelines.particles, nullptr);
vkDestroyPipeline(device, pipelines.environment, nullptr); vkDestroyPipeline(device, pipelines.environment, nullptr);
@ -323,24 +324,12 @@ public:
void loadTextures() void loadTextures()
{ {
// Particles // Particles
textureLoader->loadTexture( textures.particles.smoke.loadFromFile(getAssetPath() + "textures/particle_smoke.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
getAssetPath() + "textures/particle_smoke.ktx", textures.particles.fire.loadFromFile(getAssetPath() + "textures/particle_fire.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
VK_FORMAT_BC3_UNORM_BLOCK,
&textures.particles.smoke);
textureLoader->loadTexture(
getAssetPath() + "textures/particle_fire.ktx",
VK_FORMAT_BC3_UNORM_BLOCK,
&textures.particles.fire);
// Floor // Floor
textureLoader->loadTexture( textures.floor.colorMap.loadFromFile(getAssetPath() + "textures/fireplace_colormap_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
getAssetPath() + "textures/fireplace_colormap_bc3.ktx", textures.floor.normalMap.loadFromFile(getAssetPath() + "textures/fireplace_normalmap_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
VK_FORMAT_BC3_UNORM_BLOCK,
&textures.floor.colorMap);
textureLoader->loadTexture(
getAssetPath() + "textures/fireplace_normalmap_bc3.ktx",
VK_FORMAT_BC3_UNORM_BLOCK,
&textures.floor.normalMap);
// Create a custom sampler to be used with the particle textures // Create a custom sampler to be used with the particle textures
// Create sampler // Create sampler

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -48,7 +49,7 @@ public:
} meshes; } meshes;
struct { struct {
vkTools::VulkanTexture gradient; vks::Texture2D gradient;
} textures; } textures;
struct { struct {
@ -165,7 +166,7 @@ public:
vkFreeCommandBuffers(device, cmdPool, 1, &offscreenPass.commandBuffer); vkFreeCommandBuffers(device, cmdPool, 1, &offscreenPass.commandBuffer);
vkDestroySemaphore(device, offscreenPass.semaphore, nullptr); vkDestroySemaphore(device, offscreenPass.semaphore, nullptr);
textureLoader->destroyTexture(textures.gradient); textures.gradient.destroy();
} }
// Setup the offscreen framebuffer for rendering the blurred scene // Setup the offscreen framebuffer for rendering the blurred scene
@ -456,7 +457,7 @@ public:
void loadAssets() void loadAssets()
{ {
loadMesh(getAssetPath() + "models/glowsphere.dae", &meshes.example, vertexLayout, 0.05f); 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() void setupVertexDescriptions()

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
@ -32,7 +33,7 @@
class VulkanExample : public VulkanExampleBase class VulkanExample : public VulkanExampleBase
{ {
public: public:
vkTools::VulkanTexture textureComputeTarget; vks::Texture textureComputeTarget;
// Resources for the graphics part of the example // Resources for the graphics part of the example
struct { struct {
@ -122,11 +123,11 @@ public:
compute.storageBuffers.spheres.destroy(); compute.storageBuffers.spheres.destroy();
compute.storageBuffers.planes.destroy(); compute.storageBuffers.planes.destroy();
textureLoader->destroyTexture(textureComputeTarget); textureComputeTarget.destroy();
} }
// Prepare a texture target that is used to store compute shader calculations // 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 // Get device properties for the requested texture format
VkFormatProperties formatProperties; VkFormatProperties formatProperties;
@ -202,6 +203,7 @@ public:
tex->descriptor.imageLayout = tex->imageLayout; tex->descriptor.imageLayout = tex->imageLayout;
tex->descriptor.imageView = tex->view; tex->descriptor.imageView = tex->view;
tex->descriptor.sampler = tex->sampler; tex->descriptor.sampler = tex->sampler;
tex->device = vulkanDevice;
} }
void buildCommandBuffers() void buildCommandBuffers()

View file

@ -35,6 +35,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkandevice.hpp" #include "vulkandevice.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
@ -68,7 +69,7 @@ struct SceneMaterial
// Material properties // Material properties
SceneMaterialProperites properties; SceneMaterialProperites properties;
// The example only uses a diffuse channel // The example only uses a diffuse channel
vkTools::VulkanTexture diffuse; vks::Texture2D diffuse;
// The material's descriptor contains the material descriptors // The material's descriptor contains the material descriptors
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
// Pointer to the pipeline used by this material // Pointer to the pipeline used by this material
@ -111,8 +112,6 @@ private:
VkDescriptorSet descriptorSetScene; VkDescriptorSet descriptorSetScene;
vkTools::VulkanTextureLoader *textureLoader;
const aiScene* aScene; const aiScene* aScene;
// Get materials from the assimp scene and map to our scene structures // 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::cout << " Diffuse: \"" << texturefile.C_Str() << "\"" << std::endl;
std::string fileName = std::string(texturefile.C_Str()); std::string fileName = std::string(texturefile.C_Str());
std::replace(fileName.begin(), fileName.end(), '\\', '/'); 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 else
{ {
std::cout << " Material has no diffuse, using dummy texture!" << std::endl; std::cout << " Material has no diffuse, using dummy texture!" << std::endl;
// todo : separate pipeline and layout // 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.: // 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; uint32_t scenePartIndex = 0;
// Default constructor // Default constructor
Scene(vk::VulkanDevice *vulkanDevice, VkQueue queue, vkTools::VulkanTextureLoader *textureloader) Scene(vk::VulkanDevice *vulkanDevice, VkQueue queue)
{ {
this->vulkanDevice = vulkanDevice; this->vulkanDevice = vulkanDevice;
this->queue = queue; this->queue = queue;
this->textureLoader = textureloader;
// Prepare uniform buffer for global matrices // Prepare uniform buffer for global matrices
VkMemoryRequirements memReqs; VkMemoryRequirements memReqs;
@ -451,7 +449,7 @@ public:
indexBuffer.destroy(); indexBuffer.destroy();
for (auto material : materials) for (auto material : materials)
{ {
textureLoader->destroyTexture(material.diffuse); material.diffuse.destroy();
} }
vkDestroyPipelineLayout(vulkanDevice->logicalDevice, pipelineLayout, nullptr); vkDestroyPipelineLayout(vulkanDevice->logicalDevice, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(vulkanDevice->logicalDevice, descriptorSetLayouts.material, nullptr); vkDestroyDescriptorSetLayout(vulkanDevice->logicalDevice, descriptorSetLayouts.material, nullptr);
@ -797,7 +795,7 @@ public:
void loadScene() void loadScene()
{ {
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false); VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
scene = new Scene(vulkanDevice, queue, textureLoader); scene = new Scene(vulkanDevice, queue);
#if defined(__ANDROID__) #if defined(__ANDROID__)
scene->assetManager = androidApp->activity->assetManager; scene->assetManager = androidApp->activity->assetManager;

View file

@ -19,6 +19,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -99,7 +100,7 @@ public:
VkDescriptorSetLayout descriptorSetLayout; VkDescriptorSetLayout descriptorSetLayout;
vkTools::VulkanTexture shadowCubeMap; vks::Texture shadowCubeMap;
// Framebuffer for offscreen rendering // Framebuffer for offscreen rendering
struct FrameBufferAttachment { struct FrameBufferAttachment {

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -339,8 +340,8 @@ class VulkanExample : public VulkanExampleBase
{ {
public: public:
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
vkTools::VulkanTexture floor; vks::Texture2D floor;
} textures; } textures;
struct { struct {
@ -415,8 +416,8 @@ public:
vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
textureLoader->destroyTexture(textures.colorMap); textures.colorMap.destroy();
textureLoader->destroyTexture(textures.floor); textures.floor.destroy();
uniformBuffers.mesh.destroy(); uniformBuffers.mesh.destroy();
uniformBuffers.floor.destroy(); uniformBuffers.floor.destroy();
@ -622,8 +623,8 @@ public:
void loadAssets() void loadAssets()
{ {
textureLoader->loadTexture(getAssetPath() + "textures/goblin_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.colorMap); textures.colorMap.loadFromFile(getAssetPath() + "textures/goblin_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
textureLoader->loadTexture(getAssetPath() + "textures/trail_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.floor); 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); VulkanExampleBase::loadMesh(getAssetPath() + "models/plane_z.obj", &meshes.floor, vertexLayout, 512.0f);
} }

View file

@ -21,6 +21,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -49,7 +50,7 @@ public:
} meshes; } meshes;
struct { struct {
vkTools::VulkanTexture colormap; vks::Texture2D colormap;
} textures; } textures;
vk::Buffer uniformBuffer; vk::Buffer uniformBuffer;
@ -92,7 +93,7 @@ public:
vkMeshLoader::freeMeshBufferResources(device, &meshes.cube); vkMeshLoader::freeMeshBufferResources(device, &meshes.cube);
textureLoader->destroyTexture(textures.colormap); textures.colormap.destroy();
uniformBuffer.destroy(); uniformBuffer.destroy();
} }
@ -163,7 +164,7 @@ public:
void loadAssets() void loadAssets()
{ {
loadMesh(getAssetPath() + "models/color_teapot_spheres.dae", &meshes.cube, vertexLayout, 0.1f); 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() void setupVertexDescriptions()

View file

@ -24,6 +24,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -52,7 +53,7 @@ public:
} meshes; } meshes;
struct { struct {
vkTools::VulkanTexture matCapArray; vks::Texture2DArray matCapArray;
} textures; } textures;
vk::Buffer uniformBuffer; vk::Buffer uniformBuffer;
@ -92,8 +93,7 @@ public:
vkMeshLoader::freeMeshBufferResources(device, &meshes.object); vkMeshLoader::freeMeshBufferResources(device, &meshes.object);
uniformBuffer.destroy(); uniformBuffer.destroy();
textures.matCapArray.destroy();
textureLoader->destroyTexture(textures.matCapArray);
} }
void loadTextures() void loadTextures()
@ -101,10 +101,7 @@ public:
// Several mat caps are stored in a single texture array // Several mat caps are stored in a single texture array
// so they can easily be switched inside the shader // so they can easily be switched inside the shader
// just by updating the index in a uniform buffer // just by updating the index in a uniform buffer
textureLoader->loadTextureArray( textures.matCapArray.loadFromFile(getAssetPath() + "textures/matcap_array_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
getAssetPath() + "textures/matcap_array_rgba.ktx",
VK_FORMAT_R8G8B8A8_UNORM,
&textures.matCapArray);
} }
void buildCommandBuffers() void buildCommandBuffers()

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
@ -46,7 +47,7 @@ class VulkanExample : public VulkanExampleBase
{ {
public: public:
struct { struct {
vkTools::VulkanTexture ssaoNoise; vks::Texture2D ssaoNoise;
} textures; } textures;
struct { struct {
@ -213,7 +214,7 @@ public:
// Misc // Misc
vkFreeCommandBuffers(device, cmdPool, 1, &offScreenCmdBuffer); vkFreeCommandBuffers(device, cmdPool, 1, &offScreenCmdBuffer);
vkDestroySemaphore(device, offscreenSemaphore, nullptr); vkDestroySemaphore(device, offscreenSemaphore, nullptr);
textureLoader->destroyTexture(textures.ssaoNoise); textures.ssaoNoise.destroy();
} }
// Create a frame buffer attachment // 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); ssaoNoise[i] = glm::vec4(rndDist(rndGen) * 2.0f - 1.0f, rndDist(rndGen) * 2.0f - 1.0f, 0.0f, 0.0f);
} }
// Upload as texture // 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() void updateUniformBufferMatrices()

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
@ -44,7 +45,7 @@ public:
} meshes; } meshes;
struct { struct {
vkTools::VulkanTexture glass; vks::Texture2D glass;
} textures; } textures;
struct { struct {
@ -487,7 +488,7 @@ public:
{ {
loadMesh(getAssetPath() + "models/samplebuilding.dae", &meshes.scene, vertexLayout, 1.0f); loadMesh(getAssetPath() + "models/samplebuilding.dae", &meshes.scene, vertexLayout, 1.0f);
loadMesh(getAssetPath() + "models/samplebuilding_glass.dae", &meshes.transparent, 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() void setupVertexDescriptions()

View file

@ -21,6 +21,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#include "frustum.hpp" #include "frustum.hpp"
@ -39,9 +40,9 @@ class VulkanExample : public VulkanExampleBase
{ {
private: private:
struct { struct {
vkTools::VulkanTexture heightMap; vks::Texture2D heightMap;
vkTools::VulkanTexture skySphere; vks::Texture2D skySphere;
vkTools::VulkanTexture terrainArray; vks::Texture2DArray terrainArray;
} textures; } textures;
public: public:
bool wireframe = false; bool wireframe = false;
@ -151,9 +152,9 @@ public:
uniformBuffers.skysphereVertex.destroy(); uniformBuffers.skysphereVertex.destroy();
uniformBuffers.terrainTessellation.destroy(); uniformBuffers.terrainTessellation.destroy();
textureLoader->destroyTexture(textures.heightMap); textures.heightMap.destroy();
textureLoader->destroyTexture(textures.skySphere); textures.skySphere.destroy();
textureLoader->destroyTexture(textures.terrainArray); textures.terrainArray.destroy();
vkDestroyQueryPool(device, queryPool, nullptr); vkDestroyQueryPool(device, queryPool, nullptr);
@ -208,13 +209,15 @@ public:
VK_QUERY_RESULT_64_BIT); 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 // 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 // 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(); 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 // Encapsulate height map data for easy sampling
struct HeightMap struct HeightMap
{ {
@ -883,8 +881,7 @@ public:
} }
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadMeshes(); loadAssets();
loadTextures();
generateTerrain(); generateTerrain();
setupQueryResultBuffer(); setupQueryResultBuffer();
setupVertexDescriptions(); setupVertexDescriptions();

View file

@ -22,6 +22,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -41,7 +42,7 @@ public:
bool splitScreen = true; bool splitScreen = true;
struct { struct {
vkTools::VulkanTexture colorMap; vks::Texture2D colorMap;
} textures; } textures;
struct { struct {
@ -111,8 +112,7 @@ public:
uniformBuffers.tessControl.destroy(); uniformBuffers.tessControl.destroy();
uniformBuffers.tessEval.destroy(); uniformBuffers.tessEval.destroy();
textures.colorMap.destroy();
textureLoader->destroyTexture(textures.colorMap);
} }
void reBuildCommandBuffers() void reBuildCommandBuffers()
@ -183,17 +183,10 @@ public:
} }
} }
void loadMeshes() void loadAssets()
{ {
loadMesh(getAssetPath() + "models/lowpoly/deer.dae", &meshes.object, vertexLayout, 1.0f); loadMesh(getAssetPath() + "models/lowpoly/deer.dae", &meshes.object, vertexLayout, 1.0f);
} textures.colorMap.loadFromFile(getAssetPath() + "textures/deer.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
void loadTextures()
{
textureLoader->loadTexture(
getAssetPath() + "textures/deer.ktx",
VK_FORMAT_BC3_UNORM_BLOCK,
&textures.colorMap);
} }
void setupVertexDescriptions() void setupVertexDescriptions()
@ -503,8 +496,7 @@ public:
} }
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadTextures(); loadAssets();
loadMeshes();
setupVertexDescriptions(); setupVertexDescriptions();
prepareUniformBuffers(); prepareUniformBuffers();
setupDescriptorSetLayout(); setupDescriptorSetLayout();

View file

@ -36,9 +36,7 @@ class VulkanExample : public VulkanExampleBase
{ {
public: public:
// Contains all Vulkan objects that are required to store and use a texture // Contains all Vulkan objects that are required to store and use a texture
// Note that this repository contains a texture loader (vulkantextureloader.h) // Note that this repository contains a texture class (VulkanTexture.hpp) that encapsulates texture loading functionality in a class that is used in subsequent demos
// that encapsulates texture loading functionality in a class that is used
// in subsequent demos
struct Texture { struct Texture {
VkSampler sampler; VkSampler sampler;
VkImage image; VkImage image;

View file

@ -20,6 +20,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -37,7 +38,7 @@ public:
// Number of array layers in texture array // Number of array layers in texture array
// Also used as instance count // Also used as instance count
uint32_t layerCount; uint32_t layerCount;
vkTools::VulkanTexture textureArray; vks::Texture textureArray;
struct { struct {
VkPipelineVertexInputStateCreateInfo inputState; VkPipelineVertexInputStateCreateInfo inputState;

View file

@ -21,6 +21,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
@ -39,7 +40,7 @@ class VulkanExample : public VulkanExampleBase
public: public:
bool displaySkybox = true; bool displaySkybox = true;
vkTools::VulkanTexture cubeMap; vks::Texture cubeMap;
struct { struct {
VkPipelineVertexInputStateCreateInfo inputState; VkPipelineVertexInputStateCreateInfo inputState;

View file

@ -30,6 +30,7 @@ todos:
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#include "vulkandevice.hpp" #include "vulkandevice.hpp"
#include "vulkanbuffer.hpp" #include "vulkanbuffer.hpp"
#include "vulkanheightmap.hpp" #include "vulkanheightmap.hpp"
@ -199,7 +200,7 @@ public:
} texture; } texture;
struct { struct {
vkTools::VulkanTexture source; vks::Texture2D source;
} textures; } textures;
vkTools::HeightMap *heightMap = nullptr; vkTools::HeightMap *heightMap = nullptr;
@ -659,7 +660,7 @@ public:
void loadAssets() 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 // Generate a terrain quad patch for feeding to the tessellation control shader

View file

@ -24,6 +24,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "VulkanTexture.hpp"
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
@ -76,7 +77,7 @@ public:
struct struct
{ {
vkTools::VulkanTexture skybox; vks::TextureCubeMap skybox;
} textures; } textures;
struct { struct {
@ -119,15 +120,12 @@ public:
mesh.indexBuffer.destroy(); mesh.indexBuffer.destroy();
} }
textureLoader->destroyTexture(textures.skybox); textures.skybox.destroy();
} }
void loadTextures() void loadTextures()
{ {
textureLoader->loadCubemap( textures.skybox.loadFromFile(getAssetPath() + "textures/cubemap_vulkan.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
getAssetPath() + "textures/cubemap_vulkan.ktx",
VK_FORMAT_R8G8B8A8_UNORM,
&textures.skybox);
} }
void buildCommandBuffers() void buildCommandBuffers()