MCPcopy Create free account
hub / github.com/AryanpurTech/BlueEngine / pre_render

Method pre_render

crates/blue_engine_core/src/render.rs:228–400  ·  view source on GitHub ↗

Render the scene. Returns the command encoder, the texture view, and the surface texture.

(
        &mut self,
        objects: &ObjectStorage,
        window_size: WindowSize,
        camera: &CameraContainer,
    )

Source from the content-addressed store, hash-verified

226
227 /// Render the scene. Returns the command encoder, the texture view, and the surface texture.
228 pub(crate) fn pre_render(
229 &mut self,
230 objects: &ObjectStorage,
231 window_size: WindowSize,
232 camera: &CameraContainer,
233 ) -> Result<
234 Option<(
235 wgpu::CommandEncoder,
236 wgpu::TextureView,
237 Option<wgpu::SurfaceTexture>,
238 Option<(wgpu::Buffer, wgpu::Texture)>,
239 )>,
240 wgpu::SurfaceError,
241 > {
242 #[cfg(not(feature = "headless"))]
243 let surface = if let Some(ref surface) = self.surface {
244 surface
245 } else {
246 return Ok(None);
247 };
248 #[cfg(not(feature = "headless"))]
249 let frame = if let Ok(frame) = surface.get_current_texture() {
250 frame
251 } else {
252 return Ok(None);
253 };
254
255 let mut encoder = self
256 .device
257 .create_command_encoder(&wgpu::CommandEncoderDescriptor {
258 label: Some("Render Encoder"),
259 });
260
261 #[cfg(feature = "headless")]
262 let render_target = self.device.create_texture(&wgpu::TextureDescriptor {
263 size: wgpu::Extent3d {
264 width: self.config.width,
265 height: self.config.height,
266 depth_or_array_layers: 1,
267 },
268 mip_level_count: 1,
269 sample_count: 1,
270 dimension: wgpu::TextureDimension::D2,
271 format: self.config.format,
272 usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT,
273 label: None,
274 view_formats: &[self.config.format],
275 });
276
277 // ? There might be a way to enable both headless and normal rendering,
278 // ? However the cost of it can increase a lot
279 #[cfg(feature = "headless")]
280 let view = render_target.create_view(&wgpu::TextureViewDescriptor::default());
281 #[cfg(not(feature = "headless"))]
282 let view = frame
283 .texture
284 .create_view(&wgpu::TextureViewDescriptor::default());
285

Callers 2

window_eventMethod · 0.80
update_loopMethod · 0.80

Calls 1

Tested by

no test coverage detected