diff --git a/librashader-runtime-gl/src/filter_chain.rs b/librashader-runtime-gl/src/filter_chain.rs index 6a17039..d2d0f71 100644 --- a/librashader-runtime-gl/src/filter_chain.rs +++ b/librashader-runtime-gl/src/filter_chain.rs @@ -4,7 +4,7 @@ use crate::framebuffer::{Framebuffer, GlImage, Viewport}; use crate::quad_render::DrawQuad; use crate::render_target::RenderTarget; use crate::util; -use crate::util::{gl_get_version, InlineRingBuffer, Texture}; +use crate::util::{gl_get_version, InlineRingBuffer}; use crate::error::{FilterChainError, Result}; use gl::types::{GLenum, GLint, GLsizei, GLsizeiptr, GLuint}; @@ -23,6 +23,7 @@ use std::path::Path; use librashader_reflect::back::{CompilerBackend, CompileShader, FromCompilation}; use librashader_reflect::front::shaderc::GlslangCompilation; use crate::samplers::SamplerSet; +use crate::texture::Texture; pub struct FilterChain { passes: Box<[FilterPass]>, @@ -658,7 +659,7 @@ impl FilterChain { viewport, &original, &source, - RenderTarget::new(target, None), + RenderTarget::new(target, None, 0, 0), ); let target = target.as_texture(pass.config.filter, pass.config.wrap_mode); @@ -683,7 +684,7 @@ impl FilterChain { viewport, &original, &source, - RenderTarget::new(viewport.output, viewport.mvp), + RenderTarget::new(viewport.output, viewport.mvp, viewport.x, viewport.y), ); } diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index 7b75ec0..20dc805 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -14,7 +14,8 @@ use crate::filter_chain::FilterCommon; use crate::framebuffer::Viewport; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; -use crate::util::{InlineRingBuffer, RingBuffer, Texture}; +use crate::texture::Texture; +use crate::util::{InlineRingBuffer, RingBuffer}; pub struct FilterPass { pub reflection: ShaderReflection, @@ -97,26 +98,6 @@ impl FilterPass { gl::BindTexture(gl::TEXTURE_2D, texture.image.handle); gl::BindSampler(binding.binding, samplers.get(texture.wrap_mode, texture.filter, texture.mip_filter)); - // gl::TexParameteri( - // gl::TEXTURE_2D, - // gl::TEXTURE_MAG_FILTER, - // GLenum::from(texture.filter) as GLint, - // ); - // gl::TexParameteri( - // gl::TEXTURE_2D, - // gl::TEXTURE_MIN_FILTER, - // texture.filter.gl_mip(texture.mip_filter) as GLint, - // ); - // gl::TexParameteri( - // gl::TEXTURE_2D, - // gl::TEXTURE_WRAP_S, - // GLenum::from(texture.wrap_mode) as GLint, - // ); - // gl::TexParameteri( - // gl::TEXTURE_2D, - // gl::TEXTURE_WRAP_T, - // GLenum::from(texture.wrap_mode) as GLint, - // ); } } @@ -190,16 +171,14 @@ impl FilterPass { } } - // todo: final pass? - unsafe { gl::ColorMask(gl::TRUE, gl::TRUE, gl::TRUE, gl::TRUE); gl::ClearColor(0.0f32, 0.0f32, 0.0f32, 0.0f32); gl::Clear(gl::COLOR_BUFFER_BIT); // gl::Viewport( - 0, - 0, + output.x, + output.y, framebuffer.size.width as GLsizei, framebuffer.size.height as GLsizei, ); diff --git a/librashader-runtime-gl/src/framebuffer.rs b/librashader-runtime-gl/src/framebuffer.rs index 4e9065a..960a7b7 100644 --- a/librashader-runtime-gl/src/framebuffer.rs +++ b/librashader-runtime-gl/src/framebuffer.rs @@ -1,5 +1,5 @@ use crate::util; -use crate::util::Texture; +use crate::texture::Texture; use gl::types::{GLenum, GLint, GLsizei, GLuint}; use librashader_common::{FilterMode, ShaderFormat, Size, WrapMode}; use librashader_presets::{Scale2D, ScaleType, Scaling}; diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index 10686c3..2a4337f 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -19,6 +19,7 @@ pub use framebuffer::Viewport; #[cfg(test)] mod hello_triangle; +mod texture; #[cfg(test)] mod tests { diff --git a/librashader-runtime-gl/src/render_target.rs b/librashader-runtime-gl/src/render_target.rs index 987f9d2..d3db5e5 100644 --- a/librashader-runtime-gl/src/render_target.rs +++ b/librashader-runtime-gl/src/render_target.rs @@ -12,19 +12,25 @@ static DEFAULT_MVP: &[f32] = &[ pub struct RenderTarget<'a> { pub mvp: &'a [f32], pub framebuffer: &'a Framebuffer, + pub x: i32, + pub y: i32 } impl<'a> RenderTarget<'a> { - pub fn new(backbuffer: &'a Framebuffer, mvp: Option<&'a [f32]>) -> Self { + pub fn new(backbuffer: &'a Framebuffer, mvp: Option<&'a [f32]>, x: i32, y: i32) -> Self { if let Some(mvp) = mvp { RenderTarget { framebuffer: backbuffer, + x, mvp, + y, } } else { RenderTarget { framebuffer: backbuffer, + x, mvp: DEFAULT_MVP, + y, } } } @@ -32,6 +38,6 @@ impl<'a> RenderTarget<'a> { impl<'a> From<&Viewport<'a>> for RenderTarget<'a> { fn from(value: &Viewport<'a>) -> Self { - RenderTarget::new(value.output, value.mvp) + RenderTarget::new(value.output, value.mvp, value.x, value.y) } } diff --git a/librashader-runtime-gl/src/texture.rs b/librashader-runtime-gl/src/texture.rs new file mode 100644 index 0000000..c621f55 --- /dev/null +++ b/librashader-runtime-gl/src/texture.rs @@ -0,0 +1,10 @@ +use librashader_common::{FilterMode, WrapMode}; +use crate::GlImage; + +#[derive(Default, Debug, Copy, Clone)] +pub struct Texture { + pub image: GlImage, + pub filter: FilterMode, + pub mip_filter: FilterMode, + pub wrap_mode: WrapMode, +} diff --git a/librashader-runtime-gl/src/util.rs b/librashader-runtime-gl/src/util.rs index cadf4b1..46afd3c 100644 --- a/librashader-runtime-gl/src/util.rs +++ b/librashader-runtime-gl/src/util.rs @@ -14,14 +14,6 @@ pub fn calc_miplevel(size: Size) -> u32 { levels } -#[derive(Default, Debug, Copy, Clone)] -pub struct Texture { - pub image: GlImage, - pub filter: FilterMode, - pub mip_filter: FilterMode, - pub wrap_mode: WrapMode, -} - pub trait RingBuffer { fn current(&self) -> &T; fn current_mut(&mut self) -> &mut T;