/******************************************************************************
*
* Copyright (C) 2026  Brian Berlin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
#ifndef shader_bundle_h
#define shader_bundle_h

/* Sentinel shader name meaning "no shader / passthrough". */
#define SHADER_NONE "None"

typedef struct {
    char *name;
    char *target;
    char *resource;
    int offset;
    char *type;
} t_shader_bundle_uniform;

typedef struct {
    char *name;
    int slot;
} t_shader_bundle_sampler;

typedef struct {
    char *stage;
    char *entrypoint;
    char *spirv;
    char *msl;
    char *dxil;
    int samplers;
    int num_sampler_bindings;
    t_shader_bundle_sampler *sampler_bindings;
    int storage_textures;
    int storage_buffers;
    int uniform_buffers;
    int common_uniform_slot;
    int common_uniform_size;
    int param_uniform_slot;
    int param_uniform_size;
    int num_uniforms;
    t_shader_bundle_uniform *uniforms;
} t_shader_bundle_stage;

typedef struct {
    char *name;
    char *label;
    char *group;
    int divider;
    float def;
    float min;
    float max;
    float step;
    float val;
    char *stage;
    char *target;
    char *resource;
    int offset;
    char *type;
} t_shader_bundle_param;

typedef struct {
    int index;
    char *source;
    char *filter_linear;
    char *wrap_mode;
    char *mipmap_input;
    char *scale_type;
    char *scale_type_x;
    char *scale_type_y;
    char *scale;
    char *scale_x;
    char *scale_y;
    char *alias;
    char *float_framebuffer;
    char *srgb_framebuffer;
    int num_stages;
    t_shader_bundle_stage *stages;
    int num_params;
    t_shader_bundle_param *params;
} t_shader_bundle_pass;

typedef struct {
    char *name;
    char *file;
    char *filter_linear;
    char *wrap_mode;
    char *mipmap;
} t_shader_bundle_texture;

typedef struct {
    char *dir;
    char *id;
    char *source_hash;
    char *glsl_to_spirv;
    char *shadercross;
    char *spirv_cross;
    char *source_preset;
    int num_passes;
    t_shader_bundle_pass *passes;
    int num_textures;
    t_shader_bundle_texture *textures;
} t_shader_bundle;

void shader_bundle_init(t_shader_bundle *bundle);
void shader_bundle_free(t_shader_bundle *bundle);
int shader_bundle_load(const char *bundle_dir, t_shader_bundle *bundle);
t_shader_bundle_param * shader_bundle_find_param(t_shader_bundle *bundle,
        int pass_index, const char *name);
void shader_bundle_reset_params(t_shader_bundle *bundle);
void shader_bundle_clamp_params(t_shader_bundle *bundle);
int shader_bundle_param_is_default(const t_shader_bundle_param *param);

/* Pick a printf float format whose precision matches a parameter step size. */
const char * shader_get_float_format(float step);

#endif
