use std::ffi::c_void;

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PtexFilterType {
    Point = 0,
    Bilinear = 1,
    Box = 2,
    Gaussian = 3,
    Bicubic = 4,
    BSpline = 5,
    CatmullRom = 6,
    Mitchell = 7,
}

#[repr(C)]
#[derive(Debug, Clone)]
pub struct PtexFilterOptions {
    pub filter: PtexFilterType,
    pub lerp: i32,
    pub sharpness: f32,
    pub noedgeblend: i32,
}

impl Default for PtexFilterOptions {
    fn default() -> Self {
        Self {
            filter: PtexFilterType::BSpline,
            lerp: 1,
            sharpness: 0.0,
            noedgeblend: 0,
        }
    }
}

extern "C" {
    pub fn ptex_filter_create(texture: *mut c_void, opts: *const PtexFilterOptions) -> *mut c_void;

    pub fn ptex_filter_eval(
        filter: *mut c_void,
        result: *mut f32,
        first_channel: i32,
        num_channels: i32,
        face_id: i32,
        u: f32,
        v: f32,
        dudx: f32,
        dvdx: f32,
        dudy: f32,
        dvdy: f32,
    );

    pub fn ptex_filter_release(filter: *mut c_void);
    pub fn ptex_texture_open(
        filename: *const std::ffi::c_char,
        error_str: *mut *mut std::ffi::c_char,
    ) -> *mut c_void;
    pub fn ptex_texture_release(texture: *mut c_void);
    pub fn ptex_texture_num_channels(texture: *mut c_void) -> i32;
}
