TexConv/TextureFileCreaterR.cpp

44 lines
1.1 KiB
C++
Raw Normal View History

2020-03-06 23:29:16 +08:00
#include"TextureFileCreater.h"
2019-12-02 22:10:49 +08:00
#include"ILImage.h"
2021-11-29 15:28:37 +08:00
#include<iostream>
2019-12-02 22:10:49 +08:00
class TextureFileCreaterR:public TextureFileCreater
{
2020-10-25 21:22:18 +08:00
ILuint type;
2019-12-02 22:10:49 +08:00
public:
using TextureFileCreater::TextureFileCreater;
public:
bool InitFormat(ILImage *img) override
2020-10-25 21:22:18 +08:00
{
image=img;
2020-10-25 21:22:18 +08:00
if(!ToILType(type,pixel_format->bits[0],pixel_format->type))
return(false);
return image->ConvertToR(type);
}
uint32 Write() override
2019-12-02 22:10:49 +08:00
{
2020-10-25 21:22:18 +08:00
const uint total_bytes=(pixel_format->total_bits*image->pixel_total())>>3;
2019-12-02 22:10:49 +08:00
2020-10-25 21:22:18 +08:00
std::cout<<"Convert Image To: "<<image->width()<<"x"<<image->height()<<" "<<total_bytes<<" bytes."<<std::endl;
2019-12-02 22:10:49 +08:00
void *data=image->GetR(type);
if(!data)
2020-10-25 21:22:18 +08:00
return(0);
2019-12-02 22:10:49 +08:00
//目前仅有R8UN,R16UN,R16F,R32U,R32I,R32F几种都是8的整倍数所以直接写
2020-10-25 21:22:18 +08:00
return TextureFileCreater::Write(data,total_bytes);
2019-12-02 22:10:49 +08:00
}
};//class TextureFileCreaterR:public TextureFileCreater
TextureFileCreater *CreateTextureFileCreaterR(const PixelFormat *pf)
2019-12-02 22:10:49 +08:00
{
return(new TextureFileCreaterR(pf));
2019-12-02 22:10:49 +08:00
}