Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/renderer/wg_engine/tvgWgCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ void WgContext::initialize(WGPUInstance instance, WGPUDevice device)
assert(queue);

// create shared webgpu assets
samplerNearestRepeat = createSampler(WGPUFilterMode_Nearest, WGPUMipmapFilterMode_Nearest, WGPUAddressMode_Repeat);
samplerLinearRepeat = createSampler(WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_Repeat, 4);
samplerLinearMirror = createSampler(WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_MirrorRepeat, 4);
samplerLinearClamp = createSampler(WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_ClampToEdge, 4);
samplerImages = createSampler(WGPUFilterMode_Nearest, WGPUFilterMode_Linear, WGPUMipmapFilterMode_Nearest, WGPUAddressMode_ClampToEdge);
samplerNearestRepeat = createSampler(WGPUFilterMode_Nearest, WGPUFilterMode_Nearest, WGPUMipmapFilterMode_Nearest, WGPUAddressMode_Repeat);
samplerLinearRepeat = createSampler(WGPUFilterMode_Linear, WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_Repeat, 4);
samplerLinearMirror = createSampler(WGPUFilterMode_Linear, WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_MirrorRepeat, 4);
samplerLinearClamp = createSampler(WGPUFilterMode_Linear, WGPUFilterMode_Linear, WGPUMipmapFilterMode_Linear, WGPUAddressMode_ClampToEdge, 4);
assert(samplerImages);
assert(samplerNearestRepeat);
assert(samplerLinearRepeat);
assert(samplerLinearMirror);
Expand All @@ -60,15 +62,16 @@ void WgContext::release()
releaseSampler(samplerLinearMirror);
releaseSampler(samplerLinearRepeat);
releaseSampler(samplerNearestRepeat);
releaseSampler(samplerImages);
releaseQueue(queue);
}


WGPUSampler WgContext::createSampler(WGPUFilterMode filter, WGPUMipmapFilterMode mipmapFilter, WGPUAddressMode addrMode, uint16_t anisotropy)
WGPUSampler WgContext::createSampler(WGPUFilterMode minFilter, WGPUFilterMode magFilter, WGPUMipmapFilterMode mipmapFilter, WGPUAddressMode addrMode, uint16_t anisotropy)
{
const WGPUSamplerDescriptor samplerDesc {
.addressModeU = addrMode, .addressModeV = addrMode, .addressModeW = addrMode,
.magFilter = filter, .minFilter = filter, .mipmapFilter = mipmapFilter,
.magFilter = magFilter, .minFilter = minFilter, .mipmapFilter = mipmapFilter,
.lodMinClamp = 0.0f, .lodMaxClamp = 32.0f, .maxAnisotropy = anisotropy
};
return wgpuDeviceCreateSampler(device, &samplerDesc);
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/wg_engine/tvgWgCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct WgContext {
WGPUQueue queue{};
WGPUTextureFormat preferredFormat{};
// shared webgpu assets
WGPUSampler samplerImages{};
WGPUSampler samplerNearestRepeat{};
WGPUSampler samplerLinearRepeat{};
WGPUSampler samplerLinearMirror{};
Expand All @@ -45,7 +46,7 @@ struct WgContext {
void release();

// create common objects
WGPUSampler createSampler(WGPUFilterMode filter, WGPUMipmapFilterMode mipmapFilter, WGPUAddressMode addrMode, uint16_t anisotropy = 1);
WGPUSampler createSampler(WGPUFilterMode minFilter, WGPUFilterMode magFilter, WGPUMipmapFilterMode mipmapFilter, WGPUAddressMode addrMode, uint16_t anisotropy = 1);
WGPUTexture createTexture(uint32_t width, uint32_t height, WGPUTextureFormat format);
WGPUTexture createTexStorage(uint32_t width, uint32_t height, WGPUTextureFormat format);
WGPUTexture createTexAttachement(uint32_t width, uint32_t height, WGPUTextureFormat format, uint32_t sc);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/wg_engine/tvgWgRenderData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void WgImageData::update(WgContext& context, const RenderSurface* surface)
textureView = context.createTextureView(texture);
// update bind group
context.layouts.releaseBindGroup(bindGroup);
bindGroup = context.layouts.createBindGroupTexSampled(context.samplerLinearClamp, textureView);
bindGroup = context.layouts.createBindGroupTexSampled(context.samplerImages, textureView);
}
};

Expand Down
Loading