#ifndef RENDER_TASK_H
#define RENDER_TASK_H
#include <render_type_def.h>
#include "render_lib_macro.h"

namespace TaskReturn {
struct TexbufferDesc {
    int index{};
    char name[256]{};
};
struct CbufferDesc {
    int index{};
    char name[256]{};

};
struct Ret_CompileShader_BufferDesc {
    CbufferDesc *ar_cb;
    int c_cb;

};
}

namespace Z {
enum struct CmdType:uint8_t {
    monostate = 0, AddRenderObj = 1, SetRenderObjMaterial = 2, SetMaterialProp = 3,
    AddTextureResource = 4, CompileShader = 5, CreateMaterial = 6, SetRenderObjMatrix = 7,
    AssignTextureToMaterial = 8,
};
enum struct ResultType : uint8_t {
    OK = 0, FAILED = 1,
};
struct ResultMessage {
    unsigned int id;
    ResultType res;
    unsigned char data[8];
};

//-blue
class RENDER_API Task {
public: // app -> renderer 的task
    struct AddRenderObj { // return data = int modelID; (-1 = failed)
        Model *model;
    };
    struct SetRenderObjMaterial {
        int objIndex;
        int meshIndex;
        const char *matName;
    };
    struct SetMaterialProp {
        const char *matName;
        int propIndex;
        Z::ShaderInfo::Value value{};
    };
    struct AddTextureResource {
        const char *texName;
        TextureType type;
        const void *dataptr;
        unsigned int bytesPerPixel;
        unsigned int rowPitch;
        unsigned int size;
        bool SRGB;
        bool bpp16;
    };
    struct CompileShader { // return data = int shaderID; (-1 = failed)
        const char *path;
    };
    struct CreateMaterial {
        const char *matName;
        const char *fileName; // shader 可以从完整path索引,也可以从fileName索引
    };
    struct SetRenderObjMatrix {
        int id;
        float matrix[16];
    };
    struct AssignTextureToMaterial {
        const char *matName;
        int matTexIdx;
        const char *texName; // texutre的path.stem的utf8,用于renderer索引texture
    };

    //----
    union Command {
        AddRenderObj add_render_obj;
        SetRenderObjMaterial set_render_obj_material;
        SetMaterialProp set_material_prop;
        AddTextureResource add_texture_resource;
        CompileShader compile_shader;
        CreateMaterial create_material;
        SetRenderObjMatrix set_render_obj_matrix;
        AssignTextureToMaterial assign_texture_to_material;
    };

public: // renderer -> app 的message



    //----


public:
    static void AddCommand(Task &task) noexcept;
    static bool TryGetCommand(Task &task);

public:
    unsigned int id;
    CmdType type;
    Command cmd;
    void (*fpCallBack)(ResultMessage msg){nullptr};

};

}













#endif //RENDER_TASK_H
