OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/vulkan/vulkan_sampler.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "gpu/vulkan/vulkan_device_queue.h" |
| 9 |
| 10 namespace gpu { |
| 11 |
| 12 VulkanSampler::SamplerOptions::SamplerOptions() = default; |
| 13 VulkanSampler::SamplerOptions::~SamplerOptions() = default; |
| 14 |
| 15 VulkanSampler::VulkanSampler(VulkanDeviceQueue* device_queue) |
| 16 : device_queue_(device_queue) {} |
| 17 |
| 18 VulkanSampler::~VulkanSampler() { |
| 19 DCHECK_EQ(static_cast<VkSampler>(VK_NULL_HANDLE), handle_); |
| 20 } |
| 21 |
| 22 bool VulkanSampler::Initialize(const SamplerOptions& options) { |
| 23 DCHECK_EQ(static_cast<VkSampler>(VK_NULL_HANDLE), handle_); |
| 24 |
| 25 VkSamplerCreateInfo sampler_create_info = {}; |
| 26 sampler_create_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 27 sampler_create_info.magFilter = options.mag_filter; |
| 28 sampler_create_info.minFilter = options.min_filter; |
| 29 sampler_create_info.mipmapMode = options.mipmap_mode; |
| 30 sampler_create_info.addressModeU = options.address_mode_u; |
| 31 sampler_create_info.addressModeV = options.address_mode_v; |
| 32 sampler_create_info.addressModeW = options.address_mode_w; |
| 33 sampler_create_info.mipLodBias = options.mip_lod_bias; |
| 34 sampler_create_info.anisotropyEnable = options.anisotropy_enable; |
| 35 sampler_create_info.maxAnisotropy = options.max_anisotropy; |
| 36 sampler_create_info.compareOp = options.compare_op; |
| 37 sampler_create_info.minLod = options.min_lod; |
| 38 sampler_create_info.maxLod = options.max_lod; |
| 39 sampler_create_info.borderColor = options.border_color; |
| 40 sampler_create_info.unnormalizedCoordinates = |
| 41 options.unnormalized_coordinates; |
| 42 |
| 43 VkResult result = vkCreateSampler(device_queue_->GetVulkanDevice(), |
| 44 &sampler_create_info, nullptr, &handle_); |
| 45 if (VK_SUCCESS != result) { |
| 46 DLOG(ERROR) << "vkCreateSampler() failed: " << result; |
| 47 return false; |
| 48 } |
| 49 |
| 50 return true; |
| 51 } |
| 52 |
| 53 void VulkanSampler::Destroy() { |
| 54 if (VK_NULL_HANDLE != handle_) { |
| 55 vkDestroySampler(device_queue_->GetVulkanDevice(), handle_, nullptr); |
| 56 handle_ = VK_NULL_HANDLE; |
| 57 } |
| 58 } |
| 59 |
| 60 } // namespace gpu |
OLD | NEW |