2021-11-04 19:26:49 -03:00
|
|
|
mod compatibility;
|
|
|
|
|
mod core;
|
|
|
|
|
|
2022-01-19 22:04:53 -03:00
|
|
|
use crate::program;
|
2020-05-20 20:28:35 +02:00
|
|
|
use crate::Transformation;
|
2020-05-19 14:23:28 +02:00
|
|
|
use glow::HasContext;
|
2020-05-19 22:55:12 +02:00
|
|
|
use iced_graphics::layer;
|
2020-05-19 14:23:28 +02:00
|
|
|
use iced_native::Rectangle;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2021-11-04 19:26:49 -03:00
|
|
|
pub enum Pipeline {
|
|
|
|
|
Core(core::Pipeline),
|
|
|
|
|
Compatibility(compatibility::Pipeline),
|
2020-05-19 14:23:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Pipeline {
|
2021-11-11 01:10:47 -03:00
|
|
|
pub fn new(
|
|
|
|
|
gl: &glow::Context,
|
2022-01-19 22:04:53 -03:00
|
|
|
shader_version: &program::Version,
|
2021-11-11 01:10:47 -03:00
|
|
|
) -> Pipeline {
|
2022-01-19 22:04:53 -03:00
|
|
|
let gl_version = gl.version();
|
2021-11-11 01:10:47 -03:00
|
|
|
|
|
|
|
|
// OpenGL 3.0+ and OpenGL ES 3.0+ have instancing (which is what separates `core` from `compatibility`)
|
2022-01-19 22:04:53 -03:00
|
|
|
if gl_version.major >= 3 {
|
2021-11-10 11:18:57 -03:00
|
|
|
log::info!("Mode: core");
|
2021-11-11 01:10:47 -03:00
|
|
|
Pipeline::Core(core::Pipeline::new(gl, shader_version))
|
|
|
|
|
} else {
|
|
|
|
|
log::info!("Mode: compatibility");
|
|
|
|
|
Pipeline::Compatibility(compatibility::Pipeline::new(
|
|
|
|
|
gl,
|
|
|
|
|
shader_version,
|
|
|
|
|
))
|
2020-05-19 14:23:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn draw(
|
|
|
|
|
&mut self,
|
|
|
|
|
gl: &glow::Context,
|
2020-05-20 20:28:35 +02:00
|
|
|
target_height: u32,
|
2020-05-19 22:55:12 +02:00
|
|
|
instances: &[layer::Quad],
|
2020-05-19 14:23:28 +02:00
|
|
|
transformation: Transformation,
|
|
|
|
|
scale: f32,
|
|
|
|
|
bounds: Rectangle<u32>,
|
|
|
|
|
) {
|
2021-11-04 19:26:49 -03:00
|
|
|
match self {
|
|
|
|
|
Pipeline::Core(pipeline) => {
|
|
|
|
|
pipeline.draw(
|
|
|
|
|
gl,
|
|
|
|
|
target_height,
|
|
|
|
|
instances,
|
|
|
|
|
transformation,
|
|
|
|
|
scale,
|
|
|
|
|
bounds,
|
2020-05-22 05:52:11 +02:00
|
|
|
);
|
2020-05-21 01:01:47 +02:00
|
|
|
}
|
2021-11-04 19:26:49 -03:00
|
|
|
Pipeline::Compatibility(pipeline) => {
|
|
|
|
|
pipeline.draw(
|
|
|
|
|
gl,
|
|
|
|
|
target_height,
|
|
|
|
|
instances,
|
|
|
|
|
transformation,
|
|
|
|
|
scale,
|
|
|
|
|
bounds,
|
2020-05-19 14:23:28 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|