载入中...
搜索中...
未找到
SamplerBuilder.cpp
浏览该文件的文档.
2
3#include "common/Exception.h"
4
5#include <algorithm>
6
7namespace eve::graphics::webgpu {
8
10 uint32_t mipLevels, float maxDeviceAnisotropy) {
12 b.addrU_ = s.repeatU ? wgpu::AddressMode::Repeat : wgpu::AddressMode::ClampToEdge;
13 b.addrV_ = s.repeatV ? wgpu::AddressMode::Repeat : wgpu::AddressMode::ClampToEdge;
14 b.addrW_ = s.repeatW ? wgpu::AddressMode::Repeat : wgpu::AddressMode::ClampToEdge;
15 b.mag_ = s.mag == FilterMode::Nearest ? wgpu::FilterMode::Nearest : wgpu::FilterMode::Linear;
16 b.min_ = s.min == FilterMode::Nearest ? wgpu::FilterMode::Nearest : wgpu::FilterMode::Linear;
17 if (s.mipmap == MipmapMode::Disabled || mipLevels <= 1) {
18 b.mip_ = wgpu::MipmapFilterMode::Nearest;
19 b.lodMin_ = 0.f;
20 b.lodMax_ = 0.f;
21 } else {
22 b.mip_ = s.mipmap == MipmapMode::Nearest ? wgpu::MipmapFilterMode::Nearest
23 : wgpu::MipmapFilterMode::Linear;
24 b.lodMin_ = s.minLod;
25 b.lodMax_ = std::min(std::max(s.maxLod, 0.f), float(mipLevels - 1));
26 if (b.lodMax_ < b.lodMin_) b.lodMax_ = b.lodMin_;
27 }
28 float aniso = s.maxAnisotropy > 1.f ? s.maxAnisotropy : 1.f;
29 b.aniso_ = std::min(std::max(aniso, 1.f), std::max(maxDeviceAnisotropy, 1.f));
30 return b;
31}
32
33wgpu::Sampler SamplerBuilder::build(const wgpu::Device &device) const {
34 if (!device) throw Exception("SamplerBuilder::build: null device");
35
36 // Build the C++ wrapper descriptor directly: its zero-init already matches
37 // the WebGPU defaults (no reinterpret_cast, no hand-rolled default masks).
38 wgpu::SamplerDescriptor d{};
39 d.label = label_;
40 d.addressModeU = addrU_;
41 d.addressModeV = addrV_;
42 d.addressModeW = addrW_;
43 d.magFilter = mag_;
44 d.minFilter = min_;
45 d.mipmapFilter = mip_;
46 d.lodMinClamp = lodMin_;
47 d.lodMaxClamp = lodMax_;
48 d.maxAnisotropy = static_cast<uint16_t>(aniso_);
49 if (hasCompare_) d.compare = compare_;
50 return device.CreateSampler(&d);
51}
52
53} // namespace eve::graphics::webgpu
const std::string & s
vkb::Device & device
MeleePoint3 b
Definition MeleeHit.cpp:41
float d
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Fluent builder for wgpu::Sampler.
wgpu::Sampler build(const wgpu::Device &device) const
Create the sampler. Throws eve::graphics::Exception on null device.
static SamplerBuilder fromEngine(const eve::graphics::TextureSampler &s, uint32_t mipLevels, float maxDeviceAnisotropy)
Start from an engine TextureSampler (mirrors Graphics::makeSampler).
Sampler state for a Texture (filter, wrap, mip LOD, anisotropy). Defaults match historical engine beh...