From 63d8a67845b81ed72b5c6dec2a182f8327457811 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 26 Sep 2022 23:34:05 -0400 Subject: [PATCH] disable anisotropic filtering on chunks --- engine/xe_engine.cpp | 4 ++-- engine/xe_engine.hpp | 2 +- engine/xe_image.cpp | 8 ++++---- engine/xe_image.hpp | 4 ++-- src/chunk.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/xe_engine.cpp b/engine/xe_engine.cpp index 56222a9..44e5a4e 100644 --- a/engine/xe_engine.cpp +++ b/engine/xe_engine.cpp @@ -46,8 +46,8 @@ std::shared_ptr Engine::loadModelFromData(std::vector vert return std::make_shared(xeDevice, builder); } -Image* Engine::loadImageFromFile(const std::string &filename) { - return new Image(xeDevice, filename); +Image* Engine::loadImageFromFile(const std::string &filename, bool anisotropic) { + return new Image(xeDevice, filename, anisotropic); } bool Engine::poll() { diff --git a/engine/xe_engine.hpp b/engine/xe_engine.hpp index 9555574..1a208d6 100644 --- a/engine/xe_engine.hpp +++ b/engine/xe_engine.hpp @@ -33,7 +33,7 @@ class Engine { std::shared_ptr loadModelFromFile(const std::string &filename); std::shared_ptr loadModelFromData(std::vector vertexData, uint32_t vertexSize, std::vector indices); - Image* loadImageFromFile(const std::string &filename); + Image* loadImageFromFile(const std::string &filename, bool anisotropic = true); bool beginFrame() { return xeRenderer.beginFrame(); } void endFrame() { xeRenderer.endFrame(); } diff --git a/engine/xe_image.cpp b/engine/xe_image.cpp index 2580384..cabcea3 100644 --- a/engine/xe_image.cpp +++ b/engine/xe_image.cpp @@ -10,10 +10,10 @@ namespace xe { -Image::Image(Device &xeDevice, const std::string &filename) : xeDevice{xeDevice} { +Image::Image(Device &xeDevice, const std::string &filename, bool anisotropic) : xeDevice{xeDevice} { createTextureImage(filename); createTextureImageView(); - createTextureSampler(); + createTextureSampler(anisotropic); } Image::~Image() { @@ -217,7 +217,7 @@ void Image::createTextureImageView() { textureImageView = createImageView(xeDevice, textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_ASPECT_COLOR_BIT, mipLevels); } -void Image::createTextureSampler() { +void Image::createTextureSampler(bool anisotropic) { VkSamplerCreateInfo samplerInfo{}; samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; @@ -226,7 +226,7 @@ void Image::createTextureSampler() { samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - samplerInfo.anisotropyEnable = VK_TRUE; + samplerInfo.anisotropyEnable = anisotropic ? VK_TRUE : VK_FALSE; samplerInfo.maxAnisotropy = xeDevice.getAnisotropy(); samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; samplerInfo.unnormalizedCoordinates = VK_FALSE; diff --git a/engine/xe_image.hpp b/engine/xe_image.hpp index 1b92e2a..6520a95 100644 --- a/engine/xe_image.hpp +++ b/engine/xe_image.hpp @@ -10,7 +10,7 @@ class Image { public: - Image(Device &xeDevice, const std::string &filename); + Image(Device &xeDevice, const std::string &filename, bool anisotropic); ~Image(); Image(const Image&) = delete; @@ -23,7 +23,7 @@ class Image { void generateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels); void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height); void createTextureImageView(); - void createTextureSampler(); + void createTextureSampler(bool anisotropic); static void createImage(Device& device, uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory); static VkImageView createImageView(Device& device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels); diff --git a/src/chunk.cpp b/src/chunk.cpp index 2db7312..1c15fa7 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -61,7 +61,7 @@ static std::map texturesIds{}; static std::vector textures{}; void loadTexture(const std::string& filePath) { - xe::Image* image = xe::Engine::getInstance()->loadImageFromFile(filePath); + xe::Image* image = xe::Engine::getInstance()->loadImageFromFile(filePath, false); texturesIds[filePath] = static_cast(textures.size()); textures.push_back(image); }