Skip to content

Commit

Permalink
graphics server capabilities + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Oct 4, 2024
1 parent 5250397 commit c8cdee5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
36 changes: 36 additions & 0 deletions fyrox-graphics/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use glutin_winit::{DisplayBuilder, GlWindow};
use raw_window_handle::HasRawWindowHandle;
use std::any::Any;
use std::cell::RefCell;
use std::fmt::{Display, Formatter};
use std::ops::DerefMut;
use std::rc::{Rc, Weak};
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -1052,6 +1053,27 @@ impl GlGraphicsServer {
}
}

pub struct ServerCapabilities {
pub max_uniform_block_size: usize,
pub uniform_buffer_offset_alignment: usize,
}

impl Display for ServerCapabilities {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(
f,
"\tMax Uniform Block Size: {}",
self.max_uniform_block_size
)?;
writeln!(
f,
"\tUniform Block Offset Alignment: {}",
self.uniform_buffer_offset_alignment
)?;
Ok(())
}
}

pub trait GraphicsServer: Any {
fn create_buffer(
&self,
Expand Down Expand Up @@ -1084,6 +1106,7 @@ pub trait GraphicsServer: Any {
fn pipeline_statistics(&self) -> PipelineStatistics;
fn swap_buffers(&self) -> Result<(), FrameworkError>;
fn set_frame_size(&self, new_size: (u32, u32));
fn capabilities(&self) -> ServerCapabilities;
}

impl GraphicsServer for GlGraphicsServer {
Expand Down Expand Up @@ -1202,4 +1225,17 @@ impl GraphicsServer for GlGraphicsServer {
);
}
}

fn capabilities(&self) -> ServerCapabilities {
unsafe {
ServerCapabilities {
max_uniform_block_size: self.gl.get_parameter_i32(glow::MAX_UNIFORM_BLOCK_SIZE)
as usize,
uniform_buffer_offset_alignment: self
.gl
.get_parameter_i32(glow::UNIFORM_BUFFER_OFFSET_ALIGNMENT)
as usize,
}
}
}
}
4 changes: 3 additions & 1 deletion fyrox-impl/src/material/shader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ mod test {
PropertyDefinition, PropertyKind, RenderPassDefinition, SamplerFallback, ShaderDefinition,
ShaderResource, ShaderResourceExtension,
};
use fyrox_graphics::gpu_program::SamplerKind;

#[test]
fn test_shader_load() {
Expand Down Expand Up @@ -670,9 +671,10 @@ mod test {
let reference_definition = ShaderDefinition {
name: "TestShader".to_owned(),
properties: vec![PropertyDefinition {
name: "diffuseTexture".to_string(),
name: "diffuseTexture".into(),
kind: PropertyKind::Sampler {
default: None,
kind: SamplerKind::Sampler2D,
fallback: SamplerFallback::White,
},
}],
Expand Down
7 changes: 7 additions & 0 deletions fyrox-impl/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ use winit::{
window::{Window, WindowBuilder},
};

/// Maximum amount of bone matrices per shader.
pub const MAX_BONE_MATRICES: usize = 256;

lazy_static! {
Expand Down Expand Up @@ -692,6 +693,7 @@ pub struct Renderer {
// TextureId -> FrameBuffer mapping. This mapping is used for temporal frame buffers
// like ones used to render UI instances.
ui_frame_buffers: FxHashMap<u64, Box<dyn FrameBuffer>>,
/// A stub uniform buffer for situation when there's no actual bone matrices.
pub bone_matrices_stub_uniform_buffer: Box<dyn Buffer>,
/// Visibility cache based on occlusion query.
pub visibility_cache: VisibilityCache,
Expand Down Expand Up @@ -964,6 +966,11 @@ impl Renderer {
window_builder,
)?;

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

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

let mut shader_cache = ShaderCache::default();
Expand Down

0 comments on commit c8cdee5

Please sign in to comment.