gl: accomodate for viewport x and y

This commit is contained in:
chyyran 2022-11-27 02:10:11 -05:00
parent f0bc2d92af
commit 0806114e12
7 changed files with 28 additions and 39 deletions

View file

@ -4,7 +4,7 @@ use crate::framebuffer::{Framebuffer, GlImage, Viewport};
use crate::quad_render::DrawQuad; use crate::quad_render::DrawQuad;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::util; use crate::util;
use crate::util::{gl_get_version, InlineRingBuffer, Texture}; use crate::util::{gl_get_version, InlineRingBuffer};
use crate::error::{FilterChainError, Result}; use crate::error::{FilterChainError, Result};
use gl::types::{GLenum, GLint, GLsizei, GLsizeiptr, GLuint}; 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::back::{CompilerBackend, CompileShader, FromCompilation};
use librashader_reflect::front::shaderc::GlslangCompilation; use librashader_reflect::front::shaderc::GlslangCompilation;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::Texture;
pub struct FilterChain { pub struct FilterChain {
passes: Box<[FilterPass]>, passes: Box<[FilterPass]>,
@ -658,7 +659,7 @@ impl FilterChain {
viewport, viewport,
&original, &original,
&source, &source,
RenderTarget::new(target, None), RenderTarget::new(target, None, 0, 0),
); );
let target = target.as_texture(pass.config.filter, pass.config.wrap_mode); let target = target.as_texture(pass.config.filter, pass.config.wrap_mode);
@ -683,7 +684,7 @@ impl FilterChain {
viewport, viewport,
&original, &original,
&source, &source,
RenderTarget::new(viewport.output, viewport.mvp), RenderTarget::new(viewport.output, viewport.mvp, viewport.x, viewport.y),
); );
} }

View file

@ -14,7 +14,8 @@ use crate::filter_chain::FilterCommon;
use crate::framebuffer::Viewport; use crate::framebuffer::Viewport;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::util::{InlineRingBuffer, RingBuffer, Texture}; use crate::texture::Texture;
use crate::util::{InlineRingBuffer, RingBuffer};
pub struct FilterPass { pub struct FilterPass {
pub reflection: ShaderReflection, pub reflection: ShaderReflection,
@ -97,26 +98,6 @@ impl FilterPass {
gl::BindTexture(gl::TEXTURE_2D, texture.image.handle); gl::BindTexture(gl::TEXTURE_2D, texture.image.handle);
gl::BindSampler(binding.binding, gl::BindSampler(binding.binding,
samplers.get(texture.wrap_mode, texture.filter, texture.mip_filter)); 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 { unsafe {
gl::ColorMask(gl::TRUE, gl::TRUE, gl::TRUE, gl::TRUE); gl::ColorMask(gl::TRUE, gl::TRUE, gl::TRUE, gl::TRUE);
gl::ClearColor(0.0f32, 0.0f32, 0.0f32, 0.0f32); gl::ClearColor(0.0f32, 0.0f32, 0.0f32, 0.0f32);
gl::Clear(gl::COLOR_BUFFER_BIT); gl::Clear(gl::COLOR_BUFFER_BIT);
// //
gl::Viewport( gl::Viewport(
0, output.x,
0, output.y,
framebuffer.size.width as GLsizei, framebuffer.size.width as GLsizei,
framebuffer.size.height as GLsizei, framebuffer.size.height as GLsizei,
); );

View file

@ -1,5 +1,5 @@
use crate::util; use crate::util;
use crate::util::Texture; use crate::texture::Texture;
use gl::types::{GLenum, GLint, GLsizei, GLuint}; use gl::types::{GLenum, GLint, GLsizei, GLuint};
use librashader_common::{FilterMode, ShaderFormat, Size, WrapMode}; use librashader_common::{FilterMode, ShaderFormat, Size, WrapMode};
use librashader_presets::{Scale2D, ScaleType, Scaling}; use librashader_presets::{Scale2D, ScaleType, Scaling};

View file

@ -19,6 +19,7 @@ pub use framebuffer::Viewport;
#[cfg(test)] #[cfg(test)]
mod hello_triangle; mod hello_triangle;
mod texture;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -12,19 +12,25 @@ static DEFAULT_MVP: &[f32] = &[
pub struct RenderTarget<'a> { pub struct RenderTarget<'a> {
pub mvp: &'a [f32], pub mvp: &'a [f32],
pub framebuffer: &'a Framebuffer, pub framebuffer: &'a Framebuffer,
pub x: i32,
pub y: i32
} }
impl<'a> RenderTarget<'a> { 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 { if let Some(mvp) = mvp {
RenderTarget { RenderTarget {
framebuffer: backbuffer, framebuffer: backbuffer,
x,
mvp, mvp,
y,
} }
} else { } else {
RenderTarget { RenderTarget {
framebuffer: backbuffer, framebuffer: backbuffer,
x,
mvp: DEFAULT_MVP, mvp: DEFAULT_MVP,
y,
} }
} }
} }
@ -32,6 +38,6 @@ impl<'a> RenderTarget<'a> {
impl<'a> From<&Viewport<'a>> for RenderTarget<'a> { impl<'a> From<&Viewport<'a>> for RenderTarget<'a> {
fn from(value: &Viewport<'a>) -> Self { fn from(value: &Viewport<'a>) -> Self {
RenderTarget::new(value.output, value.mvp) RenderTarget::new(value.output, value.mvp, value.x, value.y)
} }
} }

View file

@ -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,
}

View file

@ -14,14 +14,6 @@ pub fn calc_miplevel(size: Size<u32>) -> u32 {
levels 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<T> { pub trait RingBuffer<T> {
fn current(&self) -> &T; fn current(&self) -> &T;
fn current_mut(&mut self) -> &mut T; fn current_mut(&mut self) -> &mut T;