Skip to content

Commit

Permalink
prevent the renderer from window creation + made Renderer::new public
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Dec 22, 2024
1 parent a0ff21f commit 0b46f44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
15 changes: 8 additions & 7 deletions fyrox-impl/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ use crate::{
};
use fxhash::{FxHashMap, FxHashSet};
use fyrox_animation::AnimationTracksData;
use fyrox_graphics::gl::server::GlGraphicsServer;
use fyrox_sound::{
buffer::{loader::SoundBufferLoader, SoundBuffer},
renderer::hrtf::{HrirSphereLoader, HrirSphereResourceData},
Expand Down Expand Up @@ -1408,18 +1409,18 @@ impl Engine {
.with_window_level(params.window_attributes.window_level)
.with_active(params.window_attributes.active);

let (window, renderer) = Renderer::new(
&self.resource_manager,
params,
let (window, server) = GlGraphicsServer::new(
params.vsync,
params.msaa_sample_count,
window_target,
window_builder,
)?;
let frame_size = (window.inner_size().width, window.inner_size().height);

let renderer = Renderer::new(server, frame_size, &self.resource_manager)?;

for ui in self.user_interfaces.iter_mut() {
ui.set_screen_size(Vector2::new(
window.inner_size().width as f32,
window.inner_size().height as f32,
));
ui.set_screen_size(Vector2::new(frame_size.0 as f32, frame_size.1 as f32));
}

self.graphics_context = GraphicsContext::Initialized(InitializedGraphicsContext {
Expand Down
33 changes: 9 additions & 24 deletions fyrox-impl/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use crate::{
sstorage::ImmutableString,
uuid_provider,
},
engine::{error::EngineError, GraphicsContextParams},
engine::error::EngineError,
graph::SceneGraph,
gui::draw::DrawingContext,
material::shader::{Shader, ShaderDefinition, ShaderResource, ShaderResourceExtension},
Expand All @@ -87,7 +87,6 @@ use crate::{
ResourceBinding,
},
geometry_buffer::{DrawCallStatistics, GeometryBuffer},
gl::server::GlGraphicsServer,
gpu_program::SamplerFallback,
gpu_texture::{GpuTexture, GpuTextureDescriptor, GpuTextureKind, PixelKind},
server::{GraphicsServer, SharedGraphicsServer},
Expand All @@ -110,10 +109,7 @@ use serde::{Deserialize, Serialize};
pub use stats::*;
use std::{any::TypeId, cell::RefCell, collections::hash_map::Entry, rc::Rc, sync::mpsc::Receiver};
use strum_macros::{AsRefStr, EnumString, VariantNames};
use winit::{
event_loop::EventLoopWindowTarget,
window::{Window, WindowBuilder},
};
use winit::window::Window;

lazy_static! {
static ref GBUFFER_PASS_NAME: ImmutableString = ImmutableString::new("GBuffer");
Expand Down Expand Up @@ -911,12 +907,12 @@ impl<const N: usize> Default for LightData<N> {
}

impl Renderer {
pub(crate) fn new(
/// Creates a new renderer with the given graphics server.
pub fn new(
server: Rc<dyn GraphicsServer>,
frame_size: (u32, u32),
resource_manager: &ResourceManager,
params: &GraphicsContextParams,
window_target: &EventLoopWindowTarget<()>,
window_builder: WindowBuilder,
) -> Result<(Window, Self), EngineError> {
) -> Result<Self, EngineError> {
let settings = QualitySettings::default();

let (texture_event_sender, texture_event_receiver) = std::sync::mpsc::channel();
Expand All @@ -933,18 +929,9 @@ impl Renderer {
.event_broadcaster
.add(shader_event_sender);

let (window, server) = GlGraphicsServer::new(
params.vsync,
params.msaa_sample_count,
window_target,
window_builder,
)?;

let caps = server.capabilities();
Log::info(format!("Graphics Server Capabilities\n{caps:?}",));

let frame_size = (window.inner_size().width, window.inner_size().height);

let mut shader_cache = ShaderCache::default();

for shader in ShaderResource::standard_shaders() {
Expand Down Expand Up @@ -1032,7 +1019,7 @@ impl Renderer {
},
};

let renderer = Self {
Ok(Self {
backbuffer: server.back_buffer(),
frame_size,
deferred_light_renderer: DeferredLightRenderer::new(&*server, frame_size, &settings)?,
Expand Down Expand Up @@ -1064,9 +1051,7 @@ impl Renderer {
server,
visibility_cache: Default::default(),
uniform_memory_allocator,
};

Ok((window, renderer))
})
}

/// Adds a custom render pass.
Expand Down

0 comments on commit 0b46f44

Please sign in to comment.