@@ -90,6 +90,7 @@ use lambda_platform::gfx::{
9090
9191use self :: {
9292 command:: RenderCommand ,
93+ pipeline:: RenderPipeline ,
9394 render_pass:: RenderPass ,
9495} ;
9596
@@ -124,8 +125,9 @@ impl RenderContextBuilder {
124125
125126 let mut instance = internal:: InstanceBuilder :: new ( )
126127 . build :: < internal:: RenderBackend > ( name. as_str ( ) ) ;
127- let mut surface =
128- internal:: SurfaceBuilder :: new ( ) . build ( & instance, window. window_handle ( ) ) ;
128+ let mut surface = Rc :: new (
129+ internal:: SurfaceBuilder :: new ( ) . build ( & instance, window. window_handle ( ) ) ,
130+ ) ;
129131
130132 // Build a GPU with a 3D Render queue that can render to our surface.
131133 let mut gpu = internal:: GpuBuilder :: new ( )
@@ -151,21 +153,23 @@ impl RenderContextBuilder {
151153 . with_size ( dimensions[ 0 ] , dimensions[ 1 ] )
152154 . build ( & gpu, & surface) ;
153155
154- surface
155- . apply_swapchain ( & gpu, swapchain, 1_000_000_000 )
156+ Rc :: get_mut ( & mut surface)
157+ . expect ( "Failed to get mutable reference to surface." )
158+ . apply_swapchain ( & gpu, swapchain, self . render_timeout )
156159 . expect ( "Failed to apply the swapchain to the surface." ) ;
157160
158161 return RenderContext {
159162 name,
160163 instance,
161164 gpu,
162- surface : Rc :: new ( surface) ,
165+ surface : surface. clone ( ) ,
163166 frame_buffer : None ,
164167 submission_fence : Some ( submission_fence) ,
165168 render_semaphore : Some ( render_semaphore) ,
166169 command_pool : Some ( command_pool) ,
167170 viewports : vec ! [ ] ,
168171 render_passes : vec ! [ ] ,
172+ render_pipelines : vec ! [ ] ,
169173 } ;
170174 }
171175}
@@ -183,6 +187,7 @@ pub struct RenderContext {
183187 render_semaphore : Option < internal:: RenderSemaphore < internal:: RenderBackend > > ,
184188 command_pool : Option < internal:: CommandPool < internal:: RenderBackend > > ,
185189 render_passes : Vec < Option < RenderPass > > ,
190+ render_pipelines : Vec < Option < RenderPipeline > > ,
186191 viewports : Vec < ViewPort > ,
187192}
188193
@@ -195,13 +200,22 @@ impl RenderContext {
195200 self . submission_fence . take ( ) . unwrap ( ) . destroy ( & self . gpu ) ;
196201 self . render_semaphore . take ( ) . unwrap ( ) . destroy ( & self . gpu ) ;
197202
203+ // Destroy render passes.
198204 let mut render_passes = vec ! [ ] ;
199205 swap ( & mut self . render_passes , & mut render_passes) ;
200206
201207 for render_pass in & mut render_passes {
202208 render_pass. take ( ) . unwrap ( ) . destroy ( & self ) ;
203209 }
204210
211+ // Destroy render pipelines.
212+ let mut render_pipelines = vec ! [ ] ;
213+ swap ( & mut self . render_pipelines , & mut render_pipelines) ;
214+
215+ for render_pipeline in & mut render_pipelines {
216+ render_pipeline. take ( ) . unwrap ( ) . destroy ( & self ) ;
217+ }
218+
205219 // Takes the inner surface and destroys it.
206220 let mut surface = Rc :: try_unwrap ( self . surface ) . ok ( ) . unwrap ( ) ;
207221 surface. remove_swapchain ( & self . gpu ) ;
@@ -211,15 +225,12 @@ impl RenderContext {
211225 pub fn allocate_and_get_frame_buffer (
212226 & mut self ,
213227 render_pass : & internal:: RenderPass < internal:: RenderBackend > ,
214- ) -> Rc <
215- lambda_platform:: gfx:: framebuffer:: Framebuffer <
216- lambda_platform:: gfx:: api:: RenderingAPI :: Backend ,
217- > ,
218- > {
228+ ) -> Rc < lambda_platform:: gfx:: framebuffer:: Framebuffer < internal:: RenderBackend > >
229+ {
219230 let frame_buffer = FramebufferBuilder :: new ( ) . build (
220231 & mut self . gpu ,
221232 & render_pass,
222- & self . surface ,
233+ self . surface . as_ref ( ) ,
223234 ) ;
224235
225236 // TODO(vmarcella): Update the framebuffer allocation to not be so hacky.
@@ -231,6 +242,20 @@ impl RenderContext {
231242
232243 /// Allocates a command buffer and records commands to the GPU.
233244 pub fn render ( & mut self , commands : Vec < RenderCommand > ) {
245+ let dimensions = self
246+ . surface
247+ . size ( )
248+ . expect ( "Surface has no size configured." ) ;
249+
250+ let swapchain = SwapchainBuilder :: new ( )
251+ . with_size ( dimensions[ 0 ] , dimensions[ 1 ] )
252+ . build ( & self . gpu , & self . surface ) ;
253+
254+ Rc :: get_mut ( & mut self . surface )
255+ . expect ( "Failed to get mutable reference to surface." )
256+ . apply_swapchain ( & self . gpu , swapchain, 1_000_000_000 )
257+ . expect ( "Failed to apply the swapchain to the surface." ) ;
258+
234259 let platform_command_list = commands
235260 . into_iter ( )
236261 . map ( |command| command. into_platform_command ( self ) )
0 commit comments