#include #include #include #include #include #include"ILImage.h" #include"TextureFileCreater.h" #include"ImageConvertConfig.h" #include"CMP_CompressonatorLib/Compressonator.h" #include"ParamParse.h" using namespace hgl; using namespace hgl::filesystem; using namespace hgl::util; bool ConvertCubemap(const OSString &filename,const OSStringList &file_list,const ImageConvertConfig *cfg) { ILImage image[6]; uint width,height,channels,bits; for(int i=0;i<6;i++) { if(!image[i].LoadFile(file_list[i])) return(false); if(i==0) { width=image[0].width(); height=image[0].height(); channels=image[0].channels(); bits=image[0].bit(); } else { if(width!=image[i].width() ||height!=image[i].height() ||channels!=image[i].channels() ||bits!=image[i].bit()) { LOG_ERROR(OS_TEXT("image formats can't batch")); return(false); } } } int miplevel=1; if(cfg->gen_mipmaps) miplevel=hgl::GetMipLevel(width,height); if(channels<=0||channels>4) { LOG_ERROR(OS_TEXT("image format don't support ")); return(false); } const PixelFormat *fmt=cfg->pixel_fmt[channels-1]; uint total=0; uint bytes=0; AutoDelete tex_file_creater=CreateTFC(fmt,channels); if (!tex_file_creater->CreateTexFile(filename, VK_IMAGE_VIEW_TYPE_CUBE)) { LOG_ERROR(OS_TEXT("Create Texture failed.")); return(false); } if (!tex_file_creater->WriteSize2D(width, height)) { LOG_ERROR(OS_TEXT("Write size failed.")); return(false); } if (!tex_file_creater->WritePixelFormat(miplevel)) { LOG_ERROR(OS_TEXT("Write format failed.")); return(false); } for(int i=0;iInitFormat(&image[face])) { LOG_ERROR(OS_TEXT("Init texture format failed.")); return(false); } bytes=tex_file_creater->Write(); if(bytes<=0) { tex_file_creater->Delete(); return(false); } total+=bytes; } if(miplevel>1&&i1)width>>=1; if(height>1)height>>=1; } for(uint face=0;face<6;face++) { image[face].Bind(); image[face].Resize(width,height); } } tex_file_creater->Close(); LOG_INFO(OS_TEXT("pixel total length: ")+OSString::numberOf(total)+OS_TEXT(" bytes.")); return(true); } void CMP_RegisterHostPlugins(); bool ConvertImage(const OSString &filename,const ImageConvertConfig *cfg); int os_main(int argc,os_char **argv) { std::cout<<"Cubemap to Texture Convert tools 1.3"< ,,,,,\n\n"; PrintFormatList(); return 0; } CmdParse cp(argc,argv); ImageConvertConfig icc; if(cp.Find(OS_TEXT("/mip"))!=-1)icc.gen_mipmaps=true; //检测是否生成mipmaps ParseParamColorKey(&icc,cp); ParseParamFormat(&icc,cp); //检测推荐格式 ilInit(); CMP_RegisterHostPlugins(); CMP_InitializeBCLibrary(); OSString out_filename=argv[argc-7]; OSStringList file_list; for(int i=argc-6;i