gl: move Size to librashader core

This commit is contained in:
chyyran 2022-11-21 03:01:26 -05:00
parent 4124ae3955
commit e0b66c2c60
6 changed files with 31 additions and 25 deletions

View file

@ -1,13 +1,13 @@
use std::collections::VecDeque; use std::collections::VecDeque;
use crate::binding::{UniformBinding, UniformLocation, VariableLocation}; use crate::binding::{UniformBinding, UniformLocation, VariableLocation};
use crate::filter_pass::FilterPass; 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::render_target::RenderTarget;
use crate::util; use crate::util;
use crate::util::{InlineRingBuffer, Texture}; use crate::util::{InlineRingBuffer, Texture};
use gl::types::{GLenum, GLint, GLsizei, GLsizeiptr, GLuint}; use gl::types::{GLenum, GLint, GLsizei, GLsizeiptr, GLuint};
use librashader::image::Image; use librashader::image::Image;
use librashader::{FilterMode, ShaderSource, WrapMode}; use librashader::{FilterMode, ShaderSource, Size, WrapMode};
use librashader_presets::{ScaleType, ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_presets::{ScaleType, ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::cross::{GlslangGlslContext, GlVersion}; use librashader_reflect::back::cross::{GlslangGlslContext, GlVersion};
use librashader_reflect::back::targets::{CompilerBackend, FromCompilation, GLSL}; use librashader_reflect::back::targets::{CompilerBackend, FromCompilation, GLSL};

View file

@ -3,7 +3,7 @@ use librashader_reflect::back::cross::GlslangGlslContext;
use librashader_reflect::back::ShaderCompilerOutput; use librashader_reflect::back::ShaderCompilerOutput;
use librashader_reflect::reflect::ShaderReflection; use librashader_reflect::reflect::ShaderReflection;
use librashader::{ShaderFormat, ShaderSource}; use librashader::{ShaderFormat, ShaderSource, Size};
use librashader_presets::ShaderPassConfig; use librashader_presets::ShaderPassConfig;
use librashader_reflect::reflect::semantics::{ use librashader_reflect::reflect::semantics::{
MemberOffset, TextureImage, TextureSemantics, VariableSemantics, MemberOffset, TextureImage, TextureSemantics, VariableSemantics,
@ -12,7 +12,7 @@ use rustc_hash::FxHashMap;
use crate::binding::{UniformBinding, UniformLocation, VariableLocation}; use crate::binding::{UniformBinding, UniformLocation, VariableLocation};
use crate::filter_chain::FilterCommon; use crate::filter_chain::FilterCommon;
use crate::framebuffer::{Size, Viewport}; use crate::framebuffer::Viewport;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::util::{InlineRingBuffer, RingBuffer, Texture}; use crate::util::{InlineRingBuffer, RingBuffer, Texture};
@ -35,7 +35,7 @@ impl FilterPass {
buffer.copy_from_slice(mvp); buffer.copy_from_slice(mvp);
} }
fn build_vec4(location: UniformLocation<GLint>, buffer: &mut [u8], size: Size) { fn build_vec4(location: UniformLocation<GLint>, buffer: &mut [u8], size: Size<u32>) {
let vec4 = [ let vec4 = [
size.width as f32, size.width as f32,
size.height as f32, size.height as f32,
@ -264,7 +264,7 @@ impl FilterPass {
mvp: &[f32], mvp: &[f32],
frame_count: u32, frame_count: u32,
frame_direction: i32, frame_direction: i32,
fb_size: Size, fb_size: Size<u32>,
viewport: &Viewport, viewport: &Viewport,
original: &Texture, original: &Texture,
source: &Texture, source: &Texture,

View file

@ -1,14 +1,14 @@
use crate::util; use crate::util;
use crate::util::Texture; use crate::util::Texture;
use gl::types::{GLenum, GLint, GLsizei, GLuint}; use gl::types::{GLenum, GLint, GLsizei, GLuint};
use librashader::{FilterMode, ShaderFormat, WrapMode}; use librashader::{FilterMode, ShaderFormat, Size, WrapMode};
use librashader_presets::{Scale2D, ScaleType, Scaling}; use librashader_presets::{Scale2D, ScaleType, Scaling};
#[derive(Debug)] #[derive(Debug)]
pub struct Framebuffer { pub struct Framebuffer {
pub image: GLuint, pub image: GLuint,
pub handle: GLuint, pub handle: GLuint,
pub size: Size, pub size: Size<u32>,
pub format: GLenum, pub format: GLenum,
pub max_levels: u32, pub max_levels: u32,
pub levels: u32, pub levels: u32,
@ -42,7 +42,7 @@ impl Framebuffer {
texture: GLuint, texture: GLuint,
handle: GLuint, handle: GLuint,
format: GLenum, format: GLenum,
size: Size, size: Size<u32>,
miplevels: u32, miplevels: u32,
) -> Framebuffer { ) -> Framebuffer {
Framebuffer { Framebuffer {
@ -77,7 +77,7 @@ impl Framebuffer {
viewport: &Viewport, viewport: &Viewport,
_original: &Texture, _original: &Texture,
source: &Texture, source: &Texture,
) -> Size { ) -> Size<u32> {
if self.is_raw { if self.is_raw {
return self.size; return self.size;
} }
@ -192,7 +192,7 @@ impl Framebuffer {
} }
// todo: fix panic // todo: fix panic
pub(crate) fn init(&mut self, mut size: Size, format: impl Into<GLenum>) { pub(crate) fn init(&mut self, mut size: Size<u32>, format: impl Into<GLenum>) {
if self.is_raw { if self.is_raw {
return; return;
} }
@ -320,16 +320,10 @@ pub struct Viewport<'a> {
pub mvp: Option<&'a [f32]>, 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)] #[derive(Default, Debug, Copy, Clone)]
pub struct GlImage { pub struct GlImage {
pub handle: GLuint, pub handle: GLuint,
pub format: GLenum, pub format: GLenum,
pub size: Size, pub size: Size<u32>,
pub padded_size: Size, pub padded_size: Size<u32>,
} }

View file

@ -5,9 +5,10 @@ use std::sync::mpsc::Receiver;
use glfw::{Context, Glfw, Window, WindowEvent}; use glfw::{Context, Glfw, Window, WindowEvent};
use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint}; use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
use librashader::Size;
use crate::filter_chain::FilterChain; use crate::filter_chain::FilterChain;
use crate::framebuffer::{Framebuffer, GlImage, Size, Viewport}; use crate::framebuffer::{Framebuffer, GlImage, Viewport};
const WIDTH: u32 = 900; const WIDTH: u32 = 900;
const HEIGHT: u32 = 700; const HEIGHT: u32 = 700;
@ -467,10 +468,7 @@ void main()
output_texture, output_texture,
output_framebuffer_handle, output_framebuffer_handle,
gl::RGBA8, gl::RGBA8,
Size { Size::new(vp_width as u32, vp_height as u32),
width: vp_width as u32,
height: vp_height as u32,
},
1, 1,
); );

View file

@ -13,7 +13,6 @@ mod quad_render;
pub use filter_chain::FilterChain; pub use filter_chain::FilterChain;
pub use framebuffer::Viewport; pub use framebuffer::Viewport;
pub use framebuffer::GlImage; pub use framebuffer::GlImage;
pub use framebuffer::Size;
pub use framebuffer::Framebuffer; pub use framebuffer::Framebuffer;
#[cfg(test)] #[cfg(test)]

View file

@ -147,3 +147,18 @@ impl FromStr for ShaderFormat {
}) })
} }
} }
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct Size<T> {
pub width: T,
pub height: T,
}
impl <T> Size<T> {
pub fn new(width: T, height: T) -> Self {
Size {
width,
height
}
}
}