Skip to content

Commit

Permalink
move gl-specific graphics server parts into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Oct 4, 2024
1 parent 53bddd7 commit 6e44fbe
Show file tree
Hide file tree
Showing 50 changed files with 169 additions and 120 deletions.
3 changes: 2 additions & 1 deletion editor/src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ use crate::{
Attachment, AttachmentKind, FrameBuffer, ResourceBindGroup, ResourceBinding,
},
geometry_buffer::GeometryBuffer,
gl::server::GlGraphicsServer,
gpu_program::{GpuProgram, UniformLocation},
gpu_texture::{
Coordinate, GpuTextureKind, MagnificationFilter, MinificationFilter, PixelKind,
WrapMode,
},
state::{GlGraphicsServer, GraphicsServer},
server::GraphicsServer,
uniform::StaticUniformBuffer,
BlendFactor, BlendFunc, BlendParameters, CompareFunc, DrawParameters, ElementRange,
GeometryBufferExt,
Expand Down
2 changes: 1 addition & 1 deletion editor/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use crate::{
error::FrameworkError,
framebuffer::{ResourceBindGroup, ResourceBinding},
geometry_buffer::GeometryBuffer,
gl::server::GlGraphicsServer,
gpu_program::{GpuProgram, UniformLocation},
state::GlGraphicsServer,
uniform::StaticUniformBuffer,
BlendFactor, BlendFunc, BlendParameters, CompareFunc, DrawParameters, ElementRange,
GeometryBufferExt,
Expand Down
3 changes: 2 additions & 1 deletion fyrox-graphics/src/geometry_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::gl::server::GlGraphicsServer;
use crate::gl::ToGlConstant;
use crate::{
buffer::{Buffer, BufferKind, BufferUsage},
core::{array_as_u8_slice, math::TriangleDefinition},
error::FrameworkError,
gl::buffer::GlBuffer,
state::{GlGraphicsServer, ToGlConstant},
ElementKind, ElementRange,
};
use glow::HasContext;
Expand Down
3 changes: 2 additions & 1 deletion fyrox-graphics/src/gl/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::gl::server::GlGraphicsServer;
use crate::gl::ToGlConstant;
use crate::{
buffer::{Buffer, BufferKind, BufferUsage},
error::FrameworkError,
state::{GlGraphicsServer, ToGlConstant},
};
use glow::HasContext;
use std::any::Any;
Expand Down
3 changes: 2 additions & 1 deletion fyrox-graphics/src/gl/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// SOFTWARE.

use crate::framebuffer::ResourceBindGroup;
use crate::gl::server::GlGraphicsServer;
use crate::gl::ToGlConstant;
use crate::{
buffer::{Buffer, BufferKind},
core::{color::Color, math::Rect},
Expand All @@ -28,7 +30,6 @@ use crate::{
gl::{buffer::GlBuffer, texture::GlTexture},
gpu_program::{GpuProgram, GpuProgramBinding},
gpu_texture::{CubeMapFace, GpuTexture, GpuTextureKind, PixelElementKind},
state::{GlGraphicsServer, ToGlConstant},
ColorMask, DrawParameters, ElementRange,
};
use glow::HasContext;
Expand Down
5 changes: 5 additions & 0 deletions fyrox-graphics/src/gl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
pub mod buffer;
pub mod framebuffer;
pub mod query;
pub mod server;
pub mod texture;

pub trait ToGlConstant {
fn into_gl(self) -> u32;
}
2 changes: 1 addition & 1 deletion fyrox-graphics/src/gl/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::gl::server::GlGraphicsServer;
use crate::{
error::FrameworkError,
query::{Query, QueryKind, QueryResult},
state::GlGraphicsServer,
};
use glow::HasContext;
use std::any::Any;
Expand Down
63 changes: 2 additions & 61 deletions fyrox-graphics/src/state.rs → fyrox-graphics/src/gl/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::gl::ToGlConstant;
use crate::server::{GraphicsServer, ServerCapabilities};
use crate::{
buffer::{Buffer, BufferKind, BufferUsage},
core::{color::Color, log::Log, math::Rect},
Expand Down Expand Up @@ -47,7 +49,6 @@ 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 All @@ -57,10 +58,6 @@ use winit::{
window::{Window, WindowBuilder},
};

pub trait ToGlConstant {
fn into_gl(self) -> u32;
}

impl ToGlConstant for PolygonFace {
fn into_gl(self) -> u32 {
match self {
Expand Down Expand Up @@ -1053,62 +1050,6 @@ 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,
size: usize,
buffer_kind: BufferKind,
buffer_usage: BufferUsage,
) -> Result<Box<dyn Buffer>, FrameworkError>;
fn create_texture(
&self,
kind: GpuTextureKind,
pixel_kind: PixelKind,
min_filter: MinificationFilter,
mag_filter: MagnificationFilter,
mip_count: usize,
data: Option<&[u8]>,
) -> Result<Rc<RefCell<dyn GpuTexture>>, FrameworkError>;
fn create_frame_buffer(
&self,
depth_attachment: Option<Attachment>,
color_attachments: Vec<Attachment>,
) -> Result<Box<dyn FrameBuffer>, FrameworkError>;
fn back_buffer(&self) -> Box<dyn FrameBuffer>;
fn create_query(&self) -> Result<Box<dyn Query>, FrameworkError>;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn weak(self: Rc<Self>) -> Weak<dyn GraphicsServer>;
fn flush(&self);
fn finish(&self);
fn invalidate_resource_bindings_cache(&self);
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 {
fn create_buffer(
&self,
Expand Down
3 changes: 2 additions & 1 deletion fyrox-graphics/src/gl/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::gl::server::GlGraphicsServer;
use crate::gl::ToGlConstant;
use crate::gpu_texture::CubeMapFace;
use crate::{
core::color::Color,
Expand All @@ -26,7 +28,6 @@ use crate::{
image_1d_size_bytes, image_2d_size_bytes, image_3d_size_bytes, Coordinate, GpuTexture,
GpuTextureKind, MagnificationFilter, MinificationFilter, PixelKind, WrapMode,
},
state::{GlGraphicsServer, ToGlConstant},
};
use glow::{HasContext, PixelPackData, COMPRESSED_RED_RGTC1, COMPRESSED_RG_RGTC2};
use std::any::Any;
Expand Down
2 changes: 1 addition & 1 deletion fyrox-graphics/src/gpu_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::gl::server::{GlGraphicsServer, GlKind};
use crate::{
core::{
algebra::{Matrix2, Matrix3, Matrix4, Vector2, Vector3, Vector4},
Expand All @@ -28,7 +29,6 @@ use crate::{
visitor::prelude::*,
},
error::FrameworkError,
state::{GlGraphicsServer, GlKind},
};
use fxhash::FxHashMap;
use glow::HasContext;
Expand Down
2 changes: 1 addition & 1 deletion fyrox-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod gpu_program;
pub mod gpu_texture;
pub mod pixel_buffer;
pub mod query;
pub mod state;
pub mod server;
pub mod stats;
pub mod uniform;

Expand Down
3 changes: 2 additions & 1 deletion fyrox-graphics/src/pixel_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
// SOFTWARE.

use crate::gl::framebuffer::GlFrameBuffer;
use crate::gl::server::GlGraphicsServer;
use crate::gl::ToGlConstant;
use crate::{
buffer::{Buffer, BufferKind, BufferUsage},
core::{algebra::Vector2, math::Rect},
error::FrameworkError,
framebuffer::FrameBuffer,
gl::buffer::GlBuffer,
gpu_texture::{image_2d_size_bytes, GpuTextureKind},
state::{GlGraphicsServer, ToGlConstant},
};
use bytemuck::Pod;
use glow::{HasContext, PixelPackData};
Expand Down
90 changes: 90 additions & 0 deletions fyrox-graphics/src/server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::{
buffer::{Buffer, BufferKind, BufferUsage},
error::FrameworkError,
framebuffer::{Attachment, FrameBuffer},
gpu_texture::{GpuTexture, GpuTextureKind, MagnificationFilter, MinificationFilter, PixelKind},
query::Query,
stats::PipelineStatistics,
};
use std::{
any::Any,
cell::RefCell,
fmt::{Display, Formatter},
rc::{Rc, Weak},
};

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,
size: usize,
buffer_kind: BufferKind,
buffer_usage: BufferUsage,
) -> Result<Box<dyn Buffer>, FrameworkError>;
fn create_texture(
&self,
kind: GpuTextureKind,
pixel_kind: PixelKind,
min_filter: MinificationFilter,
mag_filter: MagnificationFilter,
mip_count: usize,
data: Option<&[u8]>,
) -> Result<Rc<RefCell<dyn GpuTexture>>, FrameworkError>;
fn create_frame_buffer(
&self,
depth_attachment: Option<Attachment>,
color_attachments: Vec<Attachment>,
) -> Result<Box<dyn FrameBuffer>, FrameworkError>;
fn back_buffer(&self) -> Box<dyn FrameBuffer>;
fn create_query(&self) -> Result<Box<dyn Query>, FrameworkError>;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn weak(self: Rc<Self>) -> Weak<dyn GraphicsServer>;
fn flush(&self);
fn finish(&self);
fn invalidate_resource_bindings_cache(&self);
fn pipeline_statistics(&self) -> PipelineStatistics;
fn swap_buffers(&self) -> Result<(), FrameworkError>;
fn set_frame_size(&self, new_size: (u32, u32));
fn capabilities(&self) -> ServerCapabilities;
}
3 changes: 2 additions & 1 deletion fyrox-impl/src/renderer/bloom/blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ use crate::{
Attachment, AttachmentKind, FrameBuffer, ResourceBindGroup, ResourceBinding,
},
geometry_buffer::GeometryBuffer,
gl::server::GlGraphicsServer,
gpu_program::{GpuProgram, UniformLocation},
gpu_texture::{
Coordinate, GpuTexture, GpuTextureKind, MagnificationFilter, MinificationFilter,
PixelKind, WrapMode,
},
state::{GlGraphicsServer, GraphicsServer},
server::GraphicsServer,
uniform::StaticUniformBuffer,
DrawParameters, ElementRange,
},
Expand Down
3 changes: 2 additions & 1 deletion fyrox-impl/src/renderer/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ use crate::{
Attachment, AttachmentKind, FrameBuffer, ResourceBindGroup, ResourceBinding,
},
geometry_buffer::GeometryBuffer,
gl::server::GlGraphicsServer,
gpu_program::{GpuProgram, UniformLocation},
gpu_texture::{
Coordinate, GpuTexture, GpuTextureKind, MagnificationFilter, MinificationFilter,
PixelKind, WrapMode,
},
state::{GlGraphicsServer, GraphicsServer},
server::GraphicsServer,
uniform::StaticUniformBuffer,
DrawParameters, ElementRange,
},
Expand Down
2 changes: 1 addition & 1 deletion fyrox-impl/src/renderer/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ use crate::{
framework::{
error::FrameworkError,
framebuffer::FrameBuffer,
gl::server::GlGraphicsServer,
gpu_program::{BuiltInUniform, BuiltInUniformBlock, GpuProgramBinding},
gpu_texture::GpuTexture,
state::GlGraphicsServer,
uniform::StaticUniformBuffer,
ElementRange,
},
Expand Down
2 changes: 1 addition & 1 deletion fyrox-impl/src/renderer/cache/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
renderer::{
cache::{TemporaryCache, TimeToLive},
framework::{
error::FrameworkError, geometry_buffer::GeometryBuffer, state::GlGraphicsServer,
error::FrameworkError, geometry_buffer::GeometryBuffer, gl::server::GlGraphicsServer,
},
},
scene::mesh::surface::{SurfaceData, SurfaceResource},
Expand Down
2 changes: 1 addition & 1 deletion fyrox-impl/src/renderer/cache/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::renderer::framework::error::FrameworkError;
use crate::{
core::sstorage::ImmutableString,
material::shader::{Shader, ShaderResource},
renderer::framework::{gpu_program::GpuProgram, state::GlGraphicsServer, DrawParameters},
renderer::framework::{gl::server::GlGraphicsServer, gpu_program::GpuProgram, DrawParameters},
};
use fxhash::FxHashMap;
use fyrox_core::log::Log;
Expand Down
Loading

0 comments on commit 6e44fbe

Please sign in to comment.