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