mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
vulkan: properly implement samplers
This commit is contained in:
@@ -83,7 +83,7 @@ bool Texture::loadVolatile() {
|
||||
}
|
||||
}
|
||||
createTextureImageView();
|
||||
createTextureSampler();
|
||||
textureSampler = vgfx->getCachedSampler(samplerState);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -94,12 +94,10 @@ void Texture::unloadVolatile() {
|
||||
|
||||
vgfx->queueCleanUp([
|
||||
device = device,
|
||||
textureSampler = textureSampler,
|
||||
textureImageView = textureImageView,
|
||||
allocator = allocator,
|
||||
textureImage = textureImage,
|
||||
textureImageAllocation = textureImageAllocation] () {
|
||||
vkDestroySampler(device, textureSampler, nullptr);
|
||||
vkDestroyImageView(device, textureImageView, nullptr);
|
||||
vmaDestroyImage(allocator, textureImage, textureImageAllocation);
|
||||
});
|
||||
@@ -111,6 +109,11 @@ Texture::~Texture() {
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
void Texture::setSamplerState(const SamplerState &s) {
|
||||
love::graphics::Texture::setSamplerState(s);
|
||||
textureSampler = vgfx->getCachedSampler(s);
|
||||
}
|
||||
|
||||
void Texture::createTextureImageView() {
|
||||
auto vulkanFormat = Vulkan::getTextureFormat(format);
|
||||
|
||||
@@ -134,34 +137,6 @@ void Texture::createTextureImageView() {
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::createTextureSampler() {
|
||||
auto physicalDevice = vgfx->getPhysicalDevice();
|
||||
VkPhysicalDeviceProperties properties{};
|
||||
vkGetPhysicalDeviceProperties(physicalDevice, &properties);
|
||||
|
||||
VkSamplerCreateInfo samplerInfo{};
|
||||
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
samplerInfo.magFilter = VK_FILTER_LINEAR;
|
||||
samplerInfo.minFilter = VK_FILTER_LINEAR;
|
||||
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.anisotropyEnable = VK_TRUE;
|
||||
samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy;
|
||||
samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
|
||||
samplerInfo.unnormalizedCoordinates = VK_FALSE;
|
||||
samplerInfo.compareEnable = VK_FALSE;
|
||||
samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||
samplerInfo.mipLodBias = 0.0f;
|
||||
samplerInfo.minLod = 0.0f;
|
||||
samplerInfo.maxLod = 0.0f;
|
||||
|
||||
if (vkCreateSampler(device, &samplerInfo, nullptr, &textureSampler) != VK_SUCCESS) {
|
||||
throw love::Exception("failed to create texture sampler");
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::clear(bool white) {
|
||||
auto commandBuffer = vgfx->beginSingleTimeCommands();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user