Skip to content

Commit c47d060

Browse files
authored
WebGPU: Swapchain getCurrentTexture (#21271)
* WebGPU: added GetCurrentTexture method to swapchain. * WebGPU: fix for GetCurrentTexture signature.
1 parent 288d475 commit c47d060

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

src/library_sigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ sigs = {
17151715
wgpuSurfaceGetPreferredFormat__sig: 'ipp',
17161716
wgpuSurfaceReference__sig: 'vp',
17171717
wgpuSurfaceRelease__sig: 'vp',
1718+
wgpuSwapChainGetCurrentTexture__sig: 'pp',
17181719
wgpuSwapChainGetCurrentTextureView__sig: 'pp',
17191720
wgpuSwapChainPresent__sig: 'vp',
17201721
wgpuSwapChainReference__sig: 'vp',

src/library_webgpu.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,10 @@ var LibraryWebGPU = {
27102710
return WebGPU.mgrSwapChain.create(context);
27112711
},
27122712

2713+
wgpuSwapChainGetCurrentTexture: (swapChainId) => {
2714+
var context = WebGPU.mgrSwapChain.get(swapChainId);
2715+
return WebGPU.mgrTexture.create(context["getCurrentTexture"]());
2716+
},
27132717
wgpuSwapChainGetCurrentTextureView: (swapChainId) => {
27142718
var context = WebGPU.mgrSwapChain.get(swapChainId);
27152719
return WebGPU.mgrTextureView.create(context["getCurrentTexture"]()["createView"]());

system/include/webgpu/webgpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,7 @@ typedef void (*WGPUProcSurfaceReference)(WGPUSurface surface) WGPU_FUNCTION_ATTR
15371537
typedef void (*WGPUProcSurfaceRelease)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE;
15381538

15391539
// Procs of SwapChain
1540+
typedef WGPUTexture (*WGPUProcSwapChainGetCurrentTexture)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
15401541
typedef WGPUTextureView (*WGPUProcSwapChainGetCurrentTextureView)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
15411542
typedef void (*WGPUProcSwapChainPresent)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
15421543
typedef void (*WGPUProcSwapChainReference)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
@@ -1775,6 +1776,7 @@ WGPU_EXPORT void wgpuSurfaceReference(WGPUSurface surface) WGPU_FUNCTION_ATTRIBU
17751776
WGPU_EXPORT void wgpuSurfaceRelease(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE;
17761777

17771778
// Methods of SwapChain
1779+
WGPU_EXPORT WGPUTexture wgpuSwapChainGetCurrentTexture(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
17781780
WGPU_EXPORT WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
17791781
WGPU_EXPORT void wgpuSwapChainPresent(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
17801782
WGPU_EXPORT void wgpuSwapChainReference(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;

system/include/webgpu/webgpu_cpp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ namespace wgpu {
11371137
using ObjectBase::ObjectBase;
11381138
using ObjectBase::operator=;
11391139

1140+
Texture GetCurrentTexture() const;
11401141
TextureView GetCurrentTextureView() const;
11411142
void Present() const;
11421143

system/lib/webgpu/webgpu_cpp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,10 @@ template <typename T>
25852585
static_assert(sizeof(SwapChain) == sizeof(WGPUSwapChain), "sizeof mismatch for SwapChain");
25862586
static_assert(alignof(SwapChain) == alignof(WGPUSwapChain), "alignof mismatch for SwapChain");
25872587

2588+
Texture SwapChain::GetCurrentTexture() const {
2589+
auto result = wgpuSwapChainGetCurrentTexture(Get());
2590+
return Texture::Acquire(result);
2591+
}
25882592
TextureView SwapChain::GetCurrentTextureView() const {
25892593
auto result = wgpuSwapChainGetCurrentTextureView(Get());
25902594
return TextureView::Acquire(result);

0 commit comments

Comments
 (0)