MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Resize

Method Resize

Source/Engine/GraphicsDevice/WebGPU/GPUSwapChainWebGPU.cpp:111–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111bool GPUSwapChainWebGPU::Resize(int32 width, int32 height)
112{
113 if (width == _width && height == _height)
114 return false;
115 _device->WaitForGPU();
116 GPUDeviceLock lock(_device);
117#if GPU_ENABLE_DIAGNOSTICS
118 LOG(Info, "Resizing WebGPU surface to: {}x{}", width, height);
119#endif
120
121 // Ensure to have a surface
122 if (!Surface)
123 {
124 WGPUEmscriptenSurfaceSourceCanvasHTMLSelector canvasDesc = WGPU_EMSCRIPTEN_SURFACE_SOURCE_CANVAS_HTML_SELECTOR_INIT;
125 canvasDesc.selector = WEBGPU_STR(WEB_CANVAS_ID);
126 WGPUSurfaceDescriptor surfaceDesc = WGPU_SURFACE_DESCRIPTOR_INIT;
127 surfaceDesc.nextInChain = &canvasDesc.chain;
128#if GPU_ENABLE_RESOURCE_NAMING
129 surfaceDesc.label = WEBGPU_STR("Flax Surface");
130#endif
131 Surface = wgpuInstanceCreateSurface(_device->WebGPUInstance, &surfaceDesc);
132 if (!Surface)
133 {
134 LOG(Fatal, "Failed to create WebGPU surface for the HTML selector '{}'", TEXT(WEB_CANVAS_ID));
135 return true;
136 }
137 }
138
139 // Setup surface configuration (based on capabilities)
140 WGPUSurfaceCapabilities capabilities = WGPU_SURFACE_CAPABILITIES_INIT;
141 wgpuSurfaceGetCapabilities(Surface, _device->Adapter->Adapter, &capabilities);
142 auto formats = ToSpan(capabilities.formats, capabilities.formatCount);
143 auto presentModes = ToSpan(capabilities.presentModes, capabilities.presentModeCount);
144 auto alphaModes = ToSpan(capabilities.alphaModes, capabilities.alphaModeCount);
145 WGPUSurfaceConfiguration configuration = WGPU_SURFACE_CONFIGURATION_INIT;
146 configuration.device = _device->Device;
147 configuration.usage = WGPUTextureUsage_RenderAttachment;
148#if GPU_USE_WINDOW_SRV
149 configuration.usage |= WGPUTextureUsage_TextureBinding;
150#endif
151 configuration.width = width;
152 configuration.height = height;
153 configuration.format = WGPUTextureFormat_RGBA8Unorm;
154 configuration.viewFormats = &configuration.format;
155 configuration.viewFormatCount = 1;
156 _format = PixelFormat::R8G8B8A8_UNorm;
157 if (SpanContains(formats, RenderToolsWebGPU::ToTextureFormat(GPU_BACK_BUFFER_PIXEL_FORMAT)))
158 {
159 _format = GPU_BACK_BUFFER_PIXEL_FORMAT;
160 configuration.format = RenderToolsWebGPU::ToTextureFormat(_format);
161 }
162 else if (formats.Length() != 0)
163 {
164 configuration.format = formats[0];
165 _format = RenderToolsWebGPU::ToPixelFormat(configuration.format);
166 }
167 if (_window->GetSettings().SupportsTransparency && SpanContains(alphaModes, WGPUCompositeAlphaMode_Premultiplied))
168 configuration.alphaMode = WGPUCompositeAlphaMode_Premultiplied;

Callers 5

OnInitMethod · 0.45
OnReleaseGPUMethod · 0.45
InitHandlesMethod · 0.45
GetPipelineMethod · 0.45
InitLayoutMethod · 0.45

Calls 6

SpanContainsFunction · 0.85
GetSettingsMethod · 0.80
ToSpanFunction · 0.50
WaitForGPUMethod · 0.45
LengthMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected