gl: overall cleanup
This commit is contained in:
parent
873814b03b
commit
cbfe76928e
|
@ -1,7 +1,7 @@
|
|||
use crate::binding::{UniformLocation, VariableLocation};
|
||||
use crate::error::{FilterChainError, Result};
|
||||
use crate::filter_pass::FilterPass;
|
||||
use crate::framebuffer::{GLImage, Viewport};
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::render_target::RenderTarget;
|
||||
use crate::util;
|
||||
use crate::util::{gl_get_version, gl_u16_to_version};
|
||||
|
@ -13,6 +13,7 @@ use crate::gl::{DrawQuad, Framebuffer, FramebufferInterface, GLInterface, LoadLu
|
|||
use crate::options::{FilterChainOptions, FrameOptions};
|
||||
use crate::samplers::SamplerSet;
|
||||
use crate::texture::Texture;
|
||||
use crate::viewport::Viewport;
|
||||
use librashader_common::{FilterMode, WrapMode};
|
||||
use librashader_preprocess::ShaderSource;
|
||||
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
|
||||
|
@ -31,7 +32,7 @@ use std::collections::VecDeque;
|
|||
use std::path::Path;
|
||||
|
||||
pub struct FilterChain {
|
||||
filter: FilterChainInner
|
||||
filter: FilterChainInner,
|
||||
}
|
||||
|
||||
impl FilterChain {
|
||||
|
@ -41,11 +42,13 @@ impl FilterChain {
|
|||
) -> Result<Self> {
|
||||
if let Some(options) = options && options.use_dsa {
|
||||
return Ok(Self {
|
||||
filter: FilterChainInner::DSA(FilterChainImpl::load_from_preset(preset, Some(options))?)
|
||||
filter: FilterChainInner::DirectStateAccess(FilterChainImpl::load_from_preset(preset, Some(options))?)
|
||||
})
|
||||
}
|
||||
return Ok(Self {
|
||||
filter: FilterChainInner::Compatibility(FilterChainImpl::load_from_preset(preset, options)?)
|
||||
Ok(Self {
|
||||
filter: FilterChainInner::Compatibility(FilterChainImpl::load_from_preset(
|
||||
preset, options,
|
||||
)?),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -64,25 +67,23 @@ impl FilterChain {
|
|||
/// When this frame returns, GL_FRAMEBUFFER is bound to 0.
|
||||
pub fn frame(
|
||||
&mut self,
|
||||
count: usize,
|
||||
viewport: &Viewport,
|
||||
input: &GLImage,
|
||||
viewport: &Viewport,
|
||||
frame_count: usize,
|
||||
options: Option<&FrameOptions>,
|
||||
) -> Result<()> {
|
||||
match &mut self.filter {
|
||||
FilterChainInner::DSA(p) => {
|
||||
p.frame(count, viewport, input, options)
|
||||
}
|
||||
FilterChainInner::Compatibility(p) => {
|
||||
p.frame(count, viewport, input, options)
|
||||
FilterChainInner::DirectStateAccess(p) => {
|
||||
p.frame(frame_count, viewport, input, options)
|
||||
}
|
||||
FilterChainInner::Compatibility(p) => p.frame(frame_count, viewport, input, options),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum FilterChainInner {
|
||||
DSA(FilterChainImpl<crate::gl::gl46::DirectStateAccessGL>),
|
||||
Compatibility(FilterChainImpl<crate::gl::gl3::CompatibilityGL>)
|
||||
DirectStateAccess(FilterChainImpl<crate::gl::gl46::DirectStateAccessGL>),
|
||||
Compatibility(FilterChainImpl<crate::gl::gl3::CompatibilityGL>),
|
||||
}
|
||||
|
||||
struct FilterChainImpl<T: GLInterface> {
|
||||
|
@ -595,7 +596,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
viewport,
|
||||
&original,
|
||||
&source,
|
||||
RenderTarget::new(viewport.output, viewport.mvp, viewport.x, viewport.y),
|
||||
viewport.into(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ use rustc_hash::FxHashMap;
|
|||
|
||||
use crate::binding::{BufferStorage, UniformLocation, VariableLocation};
|
||||
use crate::filter_chain::FilterCommon;
|
||||
use crate::framebuffer::Viewport;
|
||||
use crate::gl::{BindTexture, FramebufferInterface, GLInterface, UboRing};
|
||||
use crate::render_target::RenderTarget;
|
||||
use crate::viewport::Viewport;
|
||||
|
||||
use crate::texture::Texture;
|
||||
|
||||
|
@ -71,7 +71,6 @@ impl<T: GLInterface> FilterPass<T> {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
// can't use framebuffer.clear because it will unbind.
|
||||
framebuffer.clear::<T::FramebufferInterface, false>();
|
||||
|
||||
let framebuffer_size = framebuffer.size;
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
use gl::types::{GLenum, GLuint};
|
||||
use librashader_common::Size;
|
||||
|
||||
use crate::gl::{Framebuffer, FramebufferInterface};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Viewport<'a> {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub output: &'a Framebuffer,
|
||||
pub mvp: Option<&'a [f32; 16]>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone)]
|
||||
pub struct GLImage {
|
||||
pub handle: GLuint,
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::error::Result;
|
|||
use crate::framebuffer::GLImage;
|
||||
use crate::gl::FramebufferInterface;
|
||||
use crate::texture::Texture;
|
||||
use crate::Viewport;
|
||||
use crate::viewport::Viewport;
|
||||
use gl::types::{GLenum, GLuint};
|
||||
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
|
||||
use librashader_presets::Scale2D;
|
||||
|
@ -34,7 +34,7 @@ impl Framebuffer {
|
|||
}
|
||||
|
||||
pub fn clear<T: FramebufferInterface, const REBIND: bool>(&self) {
|
||||
T::clear::<REBIND>(&self)
|
||||
T::clear::<REBIND>(self)
|
||||
}
|
||||
|
||||
pub fn scale<T: FramebufferInterface>(
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::error::{FilterChainError, Result};
|
||||
use crate::framebuffer::{GLImage, Viewport};
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::gl::framebuffer::Framebuffer;
|
||||
use crate::gl::FramebufferInterface;
|
||||
use crate::texture::Texture;
|
||||
use crate::viewport::Viewport;
|
||||
use gl::types::{GLenum, GLint, GLsizei, GLuint};
|
||||
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
|
||||
use librashader_common::{ImageFormat, Size};
|
||||
use librashader_presets::Scale2D;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -96,8 +97,7 @@ impl FramebufferInterface for Gl3Framebuffer {
|
|||
fn copy_from(fb: &mut Framebuffer, image: &GLImage) -> Result<()> {
|
||||
// todo: may want to use a shader and draw a quad to be faster.
|
||||
if image.size != fb.size || image.format != fb.format {
|
||||
Self::init(
|
||||
fb,image.size, image.format)?;
|
||||
Self::init(fb, image.size, image.format)?;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -8,9 +8,10 @@ use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
|
|||
use librashader_common::Size;
|
||||
|
||||
use crate::filter_chain::FilterChain;
|
||||
use crate::framebuffer::{GLImage, Viewport};
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::gl::gl3::CompatibilityGL;
|
||||
use crate::gl::{FramebufferInterface, GLInterface};
|
||||
use crate::viewport::Viewport;
|
||||
|
||||
const WIDTH: u32 = 900;
|
||||
const HEIGHT: u32 = 700;
|
||||
|
@ -503,8 +504,8 @@ void main()
|
|||
}
|
||||
|
||||
let viewport = Viewport {
|
||||
x: 0,
|
||||
y: 0,
|
||||
x: 0f32,
|
||||
y: 0f32,
|
||||
output: &output,
|
||||
mvp: None,
|
||||
};
|
||||
|
@ -520,7 +521,7 @@ void main()
|
|||
};
|
||||
|
||||
filter
|
||||
.frame(framecount, &viewport, &rendered, None)
|
||||
.frame(&rendered, &viewport, framecount, None)
|
||||
.unwrap();
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::error::{FilterChainError, Result};
|
||||
use crate::framebuffer::{GLImage, Viewport};
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::gl::framebuffer::Framebuffer;
|
||||
use crate::gl::FramebufferInterface;
|
||||
use crate::texture::Texture;
|
||||
use crate::viewport::Viewport;
|
||||
use gl::types::{GLenum, GLint, GLsizei, GLuint};
|
||||
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
|
||||
use librashader_common::{ImageFormat, Size};
|
||||
use librashader_presets::Scale2D;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -91,14 +92,12 @@ impl FramebufferInterface for Gl46Framebuffer {
|
|||
fn copy_from(fb: &mut Framebuffer, image: &GLImage) -> Result<()> {
|
||||
// todo: confirm this behaviour for unbound image.
|
||||
if image.handle == 0 {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// todo: may want to use a shader and draw a quad to be faster.
|
||||
if image.size != fb.size || image.format != fb.format {
|
||||
Self::init(
|
||||
fb,
|
||||
image.size, image.format)?;
|
||||
Self::init(fb, image.size, image.format)?;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -8,9 +8,10 @@ use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
|
|||
use librashader_common::Size;
|
||||
|
||||
use crate::filter_chain::FilterChain;
|
||||
use crate::framebuffer::{GLImage, Viewport};
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::gl::gl46::DirectStateAccessGL;
|
||||
use crate::gl::{FramebufferInterface, GLInterface};
|
||||
use crate::viewport::Viewport;
|
||||
|
||||
const WIDTH: u32 = 900;
|
||||
const HEIGHT: u32 = 700;
|
||||
|
@ -497,8 +498,8 @@ void main()
|
|||
}
|
||||
|
||||
let viewport = Viewport {
|
||||
x: 0,
|
||||
y: 0,
|
||||
x: 0f32,
|
||||
y: 0f32,
|
||||
output: &output,
|
||||
mvp: None,
|
||||
};
|
||||
|
@ -514,7 +515,7 @@ void main()
|
|||
};
|
||||
|
||||
filter
|
||||
.frame(framecount, &viewport, &rendered, None)
|
||||
.frame(&rendered, &viewport, framecount, None)
|
||||
.unwrap();
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -4,12 +4,13 @@ pub(crate) mod gl46;
|
|||
|
||||
use crate::binding::UniformLocation;
|
||||
use crate::error::Result;
|
||||
use crate::framebuffer::{GLImage, Viewport};
|
||||
use crate::framebuffer::GLImage;
|
||||
use crate::samplers::SamplerSet;
|
||||
use crate::texture::Texture;
|
||||
use crate::viewport::Viewport;
|
||||
pub use framebuffer::Framebuffer;
|
||||
use gl::types::{GLenum, GLuint};
|
||||
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
|
||||
use librashader_common::{ImageFormat, Size};
|
||||
use librashader_presets::{Scale2D, TextureConfig};
|
||||
use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection};
|
||||
use librashader_runtime::uniforms::UniformStorageAccess;
|
||||
|
|
|
@ -13,11 +13,13 @@ mod gl;
|
|||
mod samplers;
|
||||
mod texture;
|
||||
|
||||
pub mod options;
|
||||
pub mod error;
|
||||
pub mod options;
|
||||
mod viewport;
|
||||
|
||||
pub use filter_chain::FilterChain;
|
||||
pub use framebuffer::Viewport;
|
||||
pub use framebuffer::GLImage;
|
||||
pub use viewport::Viewport;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -28,26 +30,30 @@ mod tests {
|
|||
#[test]
|
||||
fn triangle_gl() {
|
||||
let (glfw, window, events, shader, vao) = gl::gl3::hello_triangle::setup();
|
||||
let mut filter =
|
||||
FilterChain::load_from_path("../test/slang-shaders/vhs/VHSPro.slangp", Some(&FilterChainOptions {
|
||||
let mut filter = FilterChain::load_from_path(
|
||||
"../test/slang-shaders/vhs/VHSPro.slangp",
|
||||
Some(&FilterChainOptions {
|
||||
gl_version: 0,
|
||||
use_dsa: false,
|
||||
}))
|
||||
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
|
||||
.unwrap();
|
||||
}),
|
||||
)
|
||||
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
|
||||
.unwrap();
|
||||
gl::gl3::hello_triangle::do_loop(glfw, window, events, shader, vao, &mut filter);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn triangle_gl46() {
|
||||
let (glfw, window, events, shader, vao) = gl::gl46::hello_triangle::setup();
|
||||
let mut filter =
|
||||
FilterChain::load_from_path("../test/slang-shaders/vhs/VHSPro.slangp", Some(&FilterChainOptions {
|
||||
let mut filter = FilterChain::load_from_path(
|
||||
"../test/slang-shaders/vhs/VHSPro.slangp",
|
||||
Some(&FilterChainOptions {
|
||||
gl_version: 0,
|
||||
use_dsa: true,
|
||||
}))
|
||||
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
|
||||
.unwrap();
|
||||
}),
|
||||
)
|
||||
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
|
||||
.unwrap();
|
||||
gl::gl46::hello_triangle::do_loop(glfw, window, events, shader, vao, &mut filter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,5 +8,5 @@ pub struct FrameOptions {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct FilterChainOptions {
|
||||
pub gl_version: u16,
|
||||
pub use_dsa: bool
|
||||
pub use_dsa: bool,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::framebuffer::Viewport;
|
||||
use crate::gl::{Framebuffer, FramebufferInterface};
|
||||
use crate::viewport::Viewport;
|
||||
|
||||
#[rustfmt::skip]
|
||||
static DEFAULT_MVP: &[f32; 16] = &[
|
||||
|
@ -39,6 +39,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, value.x, value.y)
|
||||
RenderTarget::new(value.output, value.mvp, value.x as i32, value.y as i32)
|
||||
}
|
||||
}
|
||||
|
|
9
librashader-runtime-gl/src/viewport.rs
Normal file
9
librashader-runtime-gl/src/viewport.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use crate::gl::Framebuffer;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Viewport<'a> {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub output: &'a Framebuffer,
|
||||
pub mvp: Option<&'a [f32; 16]>,
|
||||
}
|
Loading…
Reference in a new issue