diff --git a/examples/HelloTriangle.cpp b/examples/HelloTriangle.cpp index a35b4d65a1..20767243a3 100644 --- a/examples/HelloTriangle.cpp +++ b/examples/HelloTriangle.cpp @@ -56,16 +56,8 @@ void initTextures() { .SetAllowedUsage(nxt::TextureUsageBit::TransferDst | nxt::TextureUsageBit::Sampled) .GetResult(); - { - nxt::SamplerDescriptor desc; - desc.minFilter = nxt::FilterMode::Linear; - desc.magFilter = nxt::FilterMode::Linear; - desc.mipmapFilter = nxt::FilterMode::Linear; - desc.addressModeU = nxt::AddressMode::Repeat; - desc.addressModeV = nxt::AddressMode::Repeat; - desc.addressModeW = nxt::AddressMode::Repeat; - sampler = device.CreateSampler(&desc); - } + nxt::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); + sampler = device.CreateSampler(&samplerDesc); // Initialize the texture with arbitrary data until we can load images std::vector data(4 * 1024 * 1024, 0); diff --git a/examples/RenderToTexture.cpp b/examples/RenderToTexture.cpp index c2be03469f..41cd131f65 100644 --- a/examples/RenderToTexture.cpp +++ b/examples/RenderToTexture.cpp @@ -64,16 +64,8 @@ void initTextures() { .GetResult(); renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult(); - { - nxt::SamplerDescriptor desc; - desc.minFilter = nxt::FilterMode::Linear; - desc.magFilter = nxt::FilterMode::Linear; - desc.mipmapFilter = nxt::FilterMode::Linear; - desc.addressModeU = nxt::AddressMode::Repeat; - desc.addressModeV = nxt::AddressMode::Repeat; - desc.addressModeW = nxt::AddressMode::Repeat; - samplerPost = device.CreateSampler(&desc); - } + nxt::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); + samplerPost = device.CreateSampler(&samplerDesc); } void initPipeline() { diff --git a/examples/glTFViewer/glTFViewer.cpp b/examples/glTFViewer/glTFViewer.cpp index 610ec3f145..bb00f357f1 100644 --- a/examples/glTFViewer/glTFViewer.cpp +++ b/examples/glTFViewer/glTFViewer.cpp @@ -336,14 +336,8 @@ namespace { const auto& iSamplerID = s.first; const auto& iSampler = s.second; - nxt::SamplerDescriptor desc; - desc.magFilter = nxt::FilterMode::Nearest; - desc.minFilter = nxt::FilterMode::Nearest; - desc.mipmapFilter = nxt::FilterMode::Nearest; + nxt::SamplerDescriptor desc = utils::GetDefaultSamplerDescriptor(); // TODO: wrap modes - desc.addressModeU = nxt::AddressMode::Repeat; - desc.addressModeV = nxt::AddressMode::Repeat; - desc.addressModeW = nxt::AddressMode::Repeat; switch (iSampler.magFilter) { case gl::Nearest: diff --git a/src/utils/NXTHelpers.cpp b/src/utils/NXTHelpers.cpp index 7edcc9af24..e2de02b3a8 100644 --- a/src/utils/NXTHelpers.cpp +++ b/src/utils/NXTHelpers.cpp @@ -137,4 +137,17 @@ namespace utils { return result; } + nxt::SamplerDescriptor GetDefaultSamplerDescriptor() { + nxt::SamplerDescriptor desc; + + desc.minFilter = nxt::FilterMode::Linear; + desc.magFilter = nxt::FilterMode::Linear; + desc.mipmapFilter = nxt::FilterMode::Linear; + desc.addressModeU = nxt::AddressMode::Repeat; + desc.addressModeV = nxt::AddressMode::Repeat; + desc.addressModeW = nxt::AddressMode::Repeat; + + return desc; + } + } // namespace utils diff --git a/src/utils/NXTHelpers.h b/src/utils/NXTHelpers.h index e2a9bc704a..67959c0a9c 100644 --- a/src/utils/NXTHelpers.h +++ b/src/utils/NXTHelpers.h @@ -48,4 +48,6 @@ namespace utils { uint32_t width, uint32_t height); + nxt::SamplerDescriptor GetDefaultSamplerDescriptor(); + } // namespace utils