@@ -35,14 +35,15 @@ namespace mrover {
35
35
}
36
36
37
37
auto Simulator::makeFramebuffers (int width, int height) -> void {
38
- wgpu::SwapChainDescriptor descriptor;
39
- descriptor.usage = wgpu::TextureUsage::RenderAttachment;
40
- descriptor.format = COLOR_FORMAT;
41
- descriptor.width = width;
42
- descriptor.height = height;
43
- descriptor.presentMode = wgpu::PresentMode::Immediate;
44
- mSwapChain = mDevice .createSwapChain (mSurface , descriptor);
45
- if (!mSwapChain ) throw std::runtime_error (" Failed to create WGPU swap chain" );
38
+ wgpu::SurfaceConfiguration surfaceConfiguration;
39
+ surfaceConfiguration.device = mDevice ;
40
+ surfaceConfiguration.format = COLOR_FORMAT;
41
+ surfaceConfiguration.usage = wgpu::TextureUsage::RenderAttachment;
42
+ surfaceConfiguration.width = width;
43
+ surfaceConfiguration.height = height;
44
+ surfaceConfiguration.alphaMode = wgpu::CompositeAlphaMode::Auto;
45
+ surfaceConfiguration.presentMode = wgpu::PresentMode::Immediate;
46
+ mSurface .configure (surfaceConfiguration);
46
47
std::tie (mNormalTexture , mNormalTextureView ) = makeTextureAndView (width, height, NORMAL_FORMAT, wgpu::TextureUsage::RenderAttachment, wgpu::TextureAspect::All);
47
48
std::tie (mDepthTexture , mDepthTextureView ) = makeTextureAndView (width, height, DEPTH_FORMAT, wgpu::TextureUsage::RenderAttachment, wgpu::TextureAspect::DepthOnly);
48
49
}
@@ -203,7 +204,9 @@ namespace mrover {
203
204
constexpr auto WINDOW_NAME = " MRover Simulator (DEBUG BUILD, MAY BE SLOW)" ;
204
205
#endif
205
206
glfwWindowHint (GLFW_CLIENT_API, GLFW_NO_API);
206
- glfwWindowHint (GLFW_RESIZABLE, GLFW_FALSE);
207
+ // There is still an off-by-one error on Vulkan with resizing windows and ImGui.
208
+ // See: https://matrix.to/#/!ZSOHTEPDbwuEgSJwYw:matrix.org
209
+ glfwWindowHint (GLFW_RESIZABLE, GLFW_TRUE);
207
210
glfwWindowHint (GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE);
208
211
mWindow = GlfwPointer<GLFWwindow, glfwCreateWindow, glfwDestroyWindow>{w, h, WINDOW_NAME, nullptr , nullptr };
209
212
RCLCPP_INFO_STREAM (get_logger (), std::format (" Created window of size: {}x{}" , w, h));
@@ -258,7 +261,7 @@ namespace mrover {
258
261
mNormalTextureView .release ();
259
262
mNormalTexture .destroy ();
260
263
mNormalTexture .release ();
261
- mSwapChain . release ();
264
+ mSurface . unconfigure ();
262
265
263
266
makeFramebuffers (width, height);
264
267
}
@@ -492,7 +495,7 @@ namespace mrover {
492
495
for (int i = 0 ; i < compound ->getNumChildShapes (); ++i) {
493
496
SE3d modelInLink = btTransformToSe3 (urdfPoseToBtTransform (link ->collision_array .at (i)->origin ));
494
497
SE3d modelInWorld = linkToWorld * modelInLink;
495
- auto * shape = compound ->getChildShape (i);
498
+ btCollisionShape * shape = compound ->getChildShape (i);
496
499
if (auto * box = dynamic_cast <btBoxShape const *>(shape)) {
497
500
btVector3 extents = box->getHalfExtentsWithoutMargin () * 2 ;
498
501
SIM3 modelToWorld{modelInWorld, R3d{extents.x (), extents.y (), extents.z ()}};
@@ -723,10 +726,20 @@ namespace mrover {
723
726
camerasUpdate (encoder, colorAttachment, normalAttachment, depthStencilAttachment, renderPassDescriptor);
724
727
725
728
if (!mIsHeadless ) {
726
- wgpu::TextureView nextTexture = mSwapChain .getCurrentTextureView ();
727
- if (!nextTexture) throw std::runtime_error (" Failed to get WGPU next texture view" );
728
-
729
- colorAttachment.view = nextTexture;
729
+ wgpu::SurfaceTexture surfaceTexture;
730
+ mSurface .getCurrentTexture (&surfaceTexture);
731
+ if (surfaceTexture.status != wgpu::SurfaceGetCurrentTextureStatus::Success)
732
+ throw std::runtime_error{" Failed to get WGPU surface texture" };
733
+
734
+ wgpu::TextureViewDescriptor nextTextureViewDescriptor;
735
+ nextTextureViewDescriptor.format = COLOR_FORMAT;
736
+ nextTextureViewDescriptor.dimension = wgpu::TextureViewDimension::_2D;
737
+ nextTextureViewDescriptor.mipLevelCount = 1 ;
738
+ nextTextureViewDescriptor.arrayLayerCount = 1 ;
739
+ nextTextureViewDescriptor.aspect = wgpu::TextureAspect::All;
740
+ wgpu::TextureView nextTextureView = wgpu::Texture{surfaceTexture.texture }.createView (nextTextureViewDescriptor);
741
+
742
+ colorAttachment.view = nextTextureView;
730
743
normalAttachment.view = mNormalTextureView ;
731
744
depthStencilAttachment.view = mDepthTextureView ;
732
745
@@ -768,7 +781,7 @@ namespace mrover {
768
781
769
782
bindGroup.release ();
770
783
771
- nextTexture .release ();
784
+ nextTextureView .release ();
772
785
}
773
786
774
787
wgpu::CommandBuffer commands = encoder.finish ();
@@ -791,7 +804,7 @@ namespace mrover {
791
804
}
792
805
#endif
793
806
794
- if (!mIsHeadless ) mSwapChain .present ();
807
+ if (!mIsHeadless ) mSurface .present ();
795
808
796
809
// TODO(quintin): Remote duplicate code
797
810
for (StereoCamera& stereoCamera: mStereoCameras ) {
0 commit comments