2021-12-06 12:07:38 +08:00
|
|
|
|
#include<iostream>
|
|
|
|
|
#include<hgl/util/cmd/CmdParse.h>
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
2021-12-06 15:28:01 +08:00
|
|
|
|
#include<hgl/type/StringList.h>
|
2021-12-07 18:18:22 +08:00
|
|
|
|
#include<hgl/log/LogInfo.h>
|
2021-12-06 12:07:38 +08:00
|
|
|
|
#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;
|
|
|
|
|
|
2021-12-06 15:28:01 +08:00
|
|
|
|
bool ConvertCubemap(const OSString &filename,const OSStringList &file_list,const ImageConvertConfig *cfg)
|
2021-12-06 12:07:38 +08:00
|
|
|
|
{
|
2021-12-06 15:28:01 +08:00
|
|
|
|
ILImage image[6];
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
2021-12-06 15:28:01 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
|
|
|
|
int miplevel=1;
|
|
|
|
|
|
|
|
|
|
if(cfg->gen_mipmaps)
|
2021-12-06 15:28:01 +08:00
|
|
|
|
miplevel=hgl::GetMipLevel(width,height);
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
2021-12-06 15:28:01 +08:00
|
|
|
|
if(channels<=0||channels>4)
|
2021-12-06 12:07:38 +08:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2021-12-07 18:18:22 +08:00
|
|
|
|
AutoDelete<TextureFileCreater> tex_file_creater=CreateTFC(fmt,channels);
|
|
|
|
|
|
2021-12-13 13:47:08 +08:00
|
|
|
|
if (!tex_file_creater->CreateTexFile(filename, VK_IMAGE_VIEW_TYPE_CUBE))
|
2021-12-06 12:07:38 +08:00
|
|
|
|
{
|
2021-12-07 18:18:22 +08:00
|
|
|
|
LOG_ERROR(OS_TEXT("Create Texture failed."));
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
2021-12-13 13:47:08 +08:00
|
|
|
|
if (!tex_file_creater->WriteSize2D(width, height))
|
2021-12-07 18:18:22 +08:00
|
|
|
|
{
|
|
|
|
|
LOG_ERROR(OS_TEXT("Write size failed."));
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 13:47:08 +08:00
|
|
|
|
if (!tex_file_creater->WritePixelFormat(miplevel))
|
2021-12-07 18:18:22 +08:00
|
|
|
|
{
|
|
|
|
|
LOG_ERROR(OS_TEXT("Write format failed."));
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 18:16:23 +08:00
|
|
|
|
for(int i=0;i<miplevel;i++)
|
2021-12-07 18:18:22 +08:00
|
|
|
|
{
|
2021-12-13 18:16:23 +08:00
|
|
|
|
for(uint face=0;face<6;face++)
|
2021-12-06 12:07:38 +08:00
|
|
|
|
{
|
2021-12-13 18:16:23 +08:00
|
|
|
|
image[face].Bind();
|
|
|
|
|
width=image[face].width();
|
|
|
|
|
height=image[face].height();
|
|
|
|
|
|
|
|
|
|
if (!tex_file_creater->InitFormat(&image[face]))
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR(OS_TEXT("Init texture format failed."));
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
2021-12-06 15:28:01 +08:00
|
|
|
|
bytes=tex_file_creater->Write();
|
|
|
|
|
|
|
|
|
|
if(bytes<=0)
|
|
|
|
|
{
|
|
|
|
|
tex_file_creater->Delete();
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
2021-12-06 15:28:01 +08:00
|
|
|
|
total+=bytes;
|
2021-12-13 18:16:23 +08:00
|
|
|
|
}
|
2021-12-06 15:28:01 +08:00
|
|
|
|
|
2021-12-13 18:16:23 +08:00
|
|
|
|
if(miplevel>1&&i<miplevel)
|
|
|
|
|
{
|
|
|
|
|
if(width>1)width>>=1;
|
|
|
|
|
if(height>1)height>>=1;
|
|
|
|
|
}
|
2021-12-06 15:28:01 +08:00
|
|
|
|
|
2021-12-13 18:16:23 +08:00
|
|
|
|
for(uint face=0;face<6;face++)
|
|
|
|
|
{
|
|
|
|
|
image[face].Bind();
|
|
|
|
|
image[face].Resize(width,height);
|
2021-12-06 12:07:38 +08:00
|
|
|
|
}
|
2021-12-06 15:28:01 +08:00
|
|
|
|
}
|
2021-12-07 18:18:22 +08:00
|
|
|
|
|
|
|
|
|
tex_file_creater->Close();
|
|
|
|
|
|
2023-02-07 23:03:26 +08:00
|
|
|
|
LOG_INFO(OS_TEXT("pixel total length: ")+OSString::numberOf(total)+OS_TEXT(" bytes."));
|
2021-12-06 12:07:38 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMP_RegisterHostPlugins();
|
|
|
|
|
|
|
|
|
|
bool ConvertImage(const OSString &filename,const ImageConvertConfig *cfg);
|
|
|
|
|
|
|
|
|
|
int os_main(int argc,os_char **argv)
|
|
|
|
|
{
|
2021-12-13 13:47:08 +08:00
|
|
|
|
std::cout<<"Cubemap to Texture Convert tools 1.3"<<std::endl<<std::endl;
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
2021-12-06 15:28:01 +08:00
|
|
|
|
if(argc<=7)
|
2021-12-06 12:07:38 +08:00
|
|
|
|
{
|
|
|
|
|
std::cout<< "Command format:\n"
|
2021-12-07 18:18:22 +08:00
|
|
|
|
"\tCubemapConv [/R:][/RG:][/RGB:][/RGBA:] [/mip] <output texture filename> <pos x>,<neg x>,<pos y>,<neg y>,<pos z>,<neg z>\n\n";
|
2021-12-06 12:07:38 +08:00
|
|
|
|
|
|
|
|
|
PrintFormatList();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CmdParse cp(argc,argv);
|
|
|
|
|
|
|
|
|
|
ImageConvertConfig icc;
|
|
|
|
|
|
|
|
|
|
if(cp.Find(OS_TEXT("/mip"))!=-1)icc.gen_mipmaps=true; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>mipmaps
|
|
|
|
|
|
|
|
|
|
ParseParamColorKey(&icc,cp);
|
|
|
|
|
ParseParamFormat(&icc,cp); //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD>ʽ
|
|
|
|
|
|
|
|
|
|
ilInit();
|
|
|
|
|
|
|
|
|
|
CMP_RegisterHostPlugins();
|
|
|
|
|
CMP_InitializeBCLibrary();
|
|
|
|
|
|
2021-12-07 18:18:22 +08:00
|
|
|
|
OSString out_filename=argv[argc-7];
|
2021-12-06 15:28:01 +08:00
|
|
|
|
OSStringList file_list;
|
|
|
|
|
|
2021-12-07 18:18:22 +08:00
|
|
|
|
for(int i=argc-6;i<argc;i++)
|
2021-12-06 12:07:38 +08:00
|
|
|
|
{
|
2021-12-06 15:28:01 +08:00
|
|
|
|
if(filesystem::FileCanRead(argv[i]))
|
|
|
|
|
file_list.Add(argv[i]);
|
2021-12-07 18:18:22 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR(OS_TEXT("Can't check file ")+OSString(argv[i]));
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
2021-12-06 15:28:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(file_list.GetCount()==6)
|
|
|
|
|
{
|
2021-12-07 18:18:22 +08:00
|
|
|
|
constexpr os_char face_name[6][3]=
|
|
|
|
|
{
|
|
|
|
|
OS_TEXT("+X"),
|
|
|
|
|
OS_TEXT("-X"),
|
|
|
|
|
OS_TEXT("+Y"),
|
|
|
|
|
OS_TEXT("-Y"),
|
|
|
|
|
OS_TEXT("+Z"),
|
|
|
|
|
OS_TEXT("-Z")
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-06 15:28:01 +08:00
|
|
|
|
for(int i=0;i<6;i++)
|
2021-12-07 18:18:22 +08:00
|
|
|
|
os_out<<OS_TEXT(" ")<<face_name[i]<<OS_TEXT(": ")<<file_list[i].c_str()<<std::endl;
|
|
|
|
|
|
|
|
|
|
os_out<<OS_TEXT("output: ")<<out_filename.c_str()<<std::endl;
|
2021-12-06 15:28:01 +08:00
|
|
|
|
|
|
|
|
|
ConvertCubemap(out_filename,file_list,&icc);
|
2021-12-06 12:07:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMP_ShutdownBCLibrary();
|
|
|
|
|
ilShutDown();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|