use wgpu::BindGroupLayout;
use crate::errors::AleaticoResult;
use crate::renderer::ctx::Gpu;
use crate::renderer::resources::pipelines::{Pipeline, PipelineDescriptor, PipelineId, PipelineStore};
use crate::renderer::vertex::{ColoredVertex, TexturedVertex};

const COLORED_SHADER: &str = include_str!("../../shaders/colored_vertex.wgsl");
const TEXTURED_SHADER: &str = include_str!("../../shaders/textured_vertex.wgsl");

#[derive(Default, Clone, Copy)] // clone&copy should be cheap, u32!!!!
pub(crate) struct BuiltinPipelines {
    #[allow(dead_code)]
    pub colored: PipelineId,
    pub textured: PipelineId,
}

impl BuiltinPipelines {
    pub(crate) fn create(
        gpu: &mut Gpu,
        pipelines: &mut PipelineStore,
        format: wgpu::TextureFormat,
        camera_layout: &BindGroupLayout
    ) -> AleaticoResult<Self> {
        let colored = pipelines.insert(
            Pipeline::new(
                gpu.device(),
                PipelineDescriptor::from_wgsl::<ColoredVertex>(
                    format,
                    COLORED_SHADER,
                ),
                camera_layout
            )?,
        );

        let textured = pipelines.insert(
            Pipeline::new(
                gpu.device(),
                PipelineDescriptor::from_wgsl::<TexturedVertex>(
                    format,
                    TEXTURED_SHADER,
                ),
                camera_layout
            )?,
        );

        Ok(Self { colored, textured })
    }
}