diff --git a/librashader-runtime-gl/src/filter_chain.rs b/librashader-runtime-gl/src/filter_chain.rs index acd897a..c67ffe4 100644 --- a/librashader-runtime-gl/src/filter_chain.rs +++ b/librashader-runtime-gl/src/filter_chain.rs @@ -1,13 +1,13 @@ use std::collections::VecDeque; use crate::binding::{UniformBinding, UniformLocation, VariableLocation}; use crate::filter_pass::FilterPass; -use crate::framebuffer::{Framebuffer, GlImage, Size, Viewport}; +use crate::framebuffer::{Framebuffer, GlImage, Viewport}; use crate::render_target::RenderTarget; use crate::util; use crate::util::{InlineRingBuffer, Texture}; use gl::types::{GLenum, GLint, GLsizei, GLsizeiptr, GLuint}; use librashader::image::Image; -use librashader::{FilterMode, ShaderSource, WrapMode}; +use librashader::{FilterMode, ShaderSource, Size, WrapMode}; use librashader_presets::{ScaleType, ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_reflect::back::cross::{GlslangGlslContext, GlVersion}; use librashader_reflect::back::targets::{CompilerBackend, FromCompilation, GLSL}; diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index 4d65379..3445e4d 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -3,7 +3,7 @@ use librashader_reflect::back::cross::GlslangGlslContext; use librashader_reflect::back::ShaderCompilerOutput; use librashader_reflect::reflect::ShaderReflection; -use librashader::{ShaderFormat, ShaderSource}; +use librashader::{ShaderFormat, ShaderSource, Size}; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{ MemberOffset, TextureImage, TextureSemantics, VariableSemantics, @@ -12,7 +12,7 @@ use rustc_hash::FxHashMap; use crate::binding::{UniformBinding, UniformLocation, VariableLocation}; use crate::filter_chain::FilterCommon; -use crate::framebuffer::{Size, Viewport}; +use crate::framebuffer::Viewport; use crate::render_target::RenderTarget; use crate::util::{InlineRingBuffer, RingBuffer, Texture}; @@ -35,7 +35,7 @@ impl FilterPass { buffer.copy_from_slice(mvp); } - fn build_vec4(location: UniformLocation, buffer: &mut [u8], size: Size) { + fn build_vec4(location: UniformLocation, buffer: &mut [u8], size: Size) { let vec4 = [ size.width as f32, size.height as f32, @@ -264,7 +264,7 @@ impl FilterPass { mvp: &[f32], frame_count: u32, frame_direction: i32, - fb_size: Size, + fb_size: Size, viewport: &Viewport, original: &Texture, source: &Texture, diff --git a/librashader-runtime-gl/src/framebuffer.rs b/librashader-runtime-gl/src/framebuffer.rs index 0a357b8..3b5cdf9 100644 --- a/librashader-runtime-gl/src/framebuffer.rs +++ b/librashader-runtime-gl/src/framebuffer.rs @@ -1,14 +1,14 @@ use crate::util; use crate::util::Texture; use gl::types::{GLenum, GLint, GLsizei, GLuint}; -use librashader::{FilterMode, ShaderFormat, WrapMode}; +use librashader::{FilterMode, ShaderFormat, Size, WrapMode}; use librashader_presets::{Scale2D, ScaleType, Scaling}; #[derive(Debug)] pub struct Framebuffer { pub image: GLuint, pub handle: GLuint, - pub size: Size, + pub size: Size, pub format: GLenum, pub max_levels: u32, pub levels: u32, @@ -42,7 +42,7 @@ impl Framebuffer { texture: GLuint, handle: GLuint, format: GLenum, - size: Size, + size: Size, miplevels: u32, ) -> Framebuffer { Framebuffer { @@ -77,7 +77,7 @@ impl Framebuffer { viewport: &Viewport, _original: &Texture, source: &Texture, - ) -> Size { + ) -> Size { if self.is_raw { return self.size; } @@ -192,7 +192,7 @@ impl Framebuffer { } // todo: fix panic - pub(crate) fn init(&mut self, mut size: Size, format: impl Into) { + pub(crate) fn init(&mut self, mut size: Size, format: impl Into) { if self.is_raw { return; } @@ -320,16 +320,10 @@ pub struct Viewport<'a> { pub mvp: Option<&'a [f32]>, } -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] -pub struct Size { - pub width: u32, - pub height: u32, -} - #[derive(Default, Debug, Copy, Clone)] pub struct GlImage { pub handle: GLuint, pub format: GLenum, - pub size: Size, - pub padded_size: Size, + pub size: Size, + pub padded_size: Size, } diff --git a/librashader-runtime-gl/src/hello_triangle.rs b/librashader-runtime-gl/src/hello_triangle.rs index 10b8580..1abaab0 100644 --- a/librashader-runtime-gl/src/hello_triangle.rs +++ b/librashader-runtime-gl/src/hello_triangle.rs @@ -5,9 +5,10 @@ use std::sync::mpsc::Receiver; use glfw::{Context, Glfw, Window, WindowEvent}; use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint}; +use librashader::Size; use crate::filter_chain::FilterChain; -use crate::framebuffer::{Framebuffer, GlImage, Size, Viewport}; +use crate::framebuffer::{Framebuffer, GlImage, Viewport}; const WIDTH: u32 = 900; const HEIGHT: u32 = 700; @@ -467,10 +468,7 @@ void main() output_texture, output_framebuffer_handle, gl::RGBA8, - Size { - width: vp_width as u32, - height: vp_height as u32, - }, + Size::new(vp_width as u32, vp_height as u32), 1, ); diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index 0a6b38a..227a4b1 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -13,7 +13,6 @@ mod quad_render; pub use filter_chain::FilterChain; pub use framebuffer::Viewport; pub use framebuffer::GlImage; -pub use framebuffer::Size; pub use framebuffer::Framebuffer; #[cfg(test)] diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index 8c18506..166b9d8 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -147,3 +147,18 @@ impl FromStr for ShaderFormat { }) } } + +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +pub struct Size { + pub width: T, + pub height: T, +} + +impl Size { + pub fn new(width: T, height: T) -> Self { + Size { + width, + height + } + } +} \ No newline at end of file