载入中...
搜索中...
未找到
GraphicsSampler.cpp
浏览该文件的文档.
1// eve-hot-path
2#include <algorithm>
3#include <iterator>
4#include "graphics/Texture.h"
6
7namespace eve::graphics::webgpu {
9 if (!texture || texture->sampler == sampler) return;
10 if (std::none_of(ownedTextures.begin(), ownedTextures.end(),
11 [texture](const auto &owned) { return owned.get() == texture; }))
12 return;
13 texture->sampler = sampler;
14 samplerChangesPending_ = true;
15}
16
17void Graphics::applyPendingResourceChanges() {
18 if (!samplerChangesPending_) return;
19 bool changed = false;
20 for (auto &texture : ownedTextures) {
21 if (!texture->gpuHandle) continue;
22 auto *gpu = static_cast<GpuTexture *>(texture->gpuHandle);
23 if (gpu->samplerState == texture->sampler) continue;
24 auto found = std::find_if(cachedSamplers_.begin(), cachedSamplers_.end(), [&](const CachedSampler &entry) {
25 return entry.mipLevels == gpu->mipLevels && entry.state == texture->sampler;
26 });
27 if (found == cachedSamplers_.end()) {
28 cachedSamplers_.push_back(
29 {texture->sampler, gpu->mipLevels, makeSampler(texture->sampler, gpu->mipLevels)});
30 found = std::prev(cachedSamplers_.end());
31 }
32 gpu->sampler = found->sampler;
33 gpu->samplerState = texture->sampler;
34 changed = true;
35 }
36 samplerChangesPending_ = false;
37 if (changed) clearMeshBindGroupCache();
38}
39} // namespace eve::graphics::webgpu
ActiveSource owned
bool changed
vk::UniqueSampler sampler
std::shared_ptr< OceanGpuSpectrum > gpu
Texture * texture
bool found
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
void setTextureSampler(Texture *texture, const TextureSampler &sampler) override
Sets the texture sampler.
Sampler state for a Texture (filter, wrap, mip LOD, anisotropy). Defaults match historical engine beh...
Texture resources backed by a wgpu texture + view + sampler + bind groups.
Definition Graphics.h:137