#ifndef _API_H #define _API_H #include #include typedef int Error; #define ERROR_NONE 0 #define ERROR_OUT_OF_MEMORY 1 #define ERROR_OUT_OF_BLOCKS 2 #define ERROR_OUT_OF_MATERIALS 3 #define ERROR_OUT_OF_TEXTURES 4 typedef int Orientation; #define ORIENTATION_NEGATIVE_X ~0 #define ORIENTATION_POSITIVE_X 0 #define ORIENTATION_NEGATIVE_Y ~1 #define ORIENTATION_POSITIVE_Y 1 #define ORIENTATION_NEGATIVE_Z ~2 #define ORIENTATION_POSITIVE_Z 2 #define ORIENTATION_INIT_SIGN_INDEX(sign, index) ((sign) > 0 ? (index) : ~(index)) #define ORIENTATION_GET_INDEX(orientation) ((orientation) & 0x4 ? ~(orientation) : (orientation)) #define ORIENTATION_GET_SIGN(orientation) ((oritentation) & 0x4 ? -1 : 1) typedef int Transform; #define TRANSFORM_IDENTITY 0 #define TRANSFORM_ROTATE_CW 1 #define TRANSFORM_ROTATE_CCW 2 #define TRANSFORM_ROTATE_180 3 #define TRANSFORM_MIRROR 4 #define TRANSFORM_MIRROR_ROTATE_CW 5 #define TRANSFORM_MIRROR_ROTATE_CCW 6 #define TRANSFORM_MIRROR_ROTATE_180 7 typedef unsigned short BlockId; #define BLOCK_ID_AIR 0 typedef unsigned short MaterialId; #define MATERIAL_ID_EMPTY 0 typedef unsigned short TextureId; #define TEXTURE_ID_EMPTY_BASE_COLOR 0 #define TEXTURE_ID_EMPTY_EMISSIVE 1 #define TEXTURE_ID_EMPTY_NORMAL 2 #define TEXTURE_ID_EMPTY_OCCLUSION_ROUGHNESS_METALLIC 3 typedef int TextureUsage; #define TEXTURE_USAGE_BASE_COLOR 0 #define TEXTURE_USAGE_NORMAL 1 #define TEXTURE_USAGE_OCCLUSION_ROUGHNESS_METALLIC 2 #define TEXTURE_USAGE_EMISSIVE 3 typedef struct String { const char* ptr; size_t len; } String; #define STRING_NULL (String){ .ptr = NULL, .len = 0 } typedef struct BlockDefinitionWall { MaterialId material; Transform transform; } BlockDefinitionWall; typedef struct BlockDefinitionWalls { BlockDefinitionWall negative_x; BlockDefinitionWall positive_x; BlockDefinitionWall negative_y; BlockDefinitionWall positive_y; BlockDefinitionWall negative_z; BlockDefinitionWall positive_z; } BlockDefinitionWalls; typedef struct BlockDefinition { BlockDefinitionWalls walls; } BlockDefinition; typedef struct MaterialDefinition { vec3_t base_color; vec3_t emissive; float ior; float metallic; float normal_scale; float occlusion_texture_strength; float roughness; TextureId base_color_texture; TextureId emissive_texture; TextureId normal_texture; TextureId occlusion_roughness_metallic_texture; } MaterialDefinition; typedef struct TextureData { TextureUsage usage; unsigned int width; unsigned int height; const char *data; } TextureData; typedef struct TextureDataMutable { TextureUsage usage; unsigned int width; unsigned int height; char *data; } TextureDataMutable; Error BlockIdFromName(String name, bool *exists, BlockId *out); Error BlockDefinitionFromId(BlockId id, const BlockDefinition **out); Error BlockDefine(String name, const BlockDefinition *definition, BlockId *out); Error MaterialIdFromName(String name, bool *exists, MaterialId *out); Error MaterialDefinitionFromId(MaterialId, const MaterialDefinition **out); Error MaterialDefine(String name, const MaterialDefinition *definition, MaterialId *out); Error TextureIdFromName(String name, TextureUsage usage, bool *exists, TextureId *out); Error TextureDefine(String name, const TextureData *texture_data, TextureId *out); Error TextureResize(TextureDataMutable *texture_data, unsigned int width, unsigned int height); // --- CALLBACKS --- void PreInit(); void PostInit(); void Deinit(); void FilterBlock(BlockId id, String name, bool *exists, BlockDefinition *definition); void FilterMaterial(MaterialId id, String name, bool *exists, MaterialDefinition *definition); void FilterTexture(TextureId id, String name, bool *exists, TextureDataMutable *texture_data); #endif