update uint2float convert

This commit is contained in:
hyzboy 2019-09-05 20:49:53 +08:00
parent c691fce56b
commit fd02d2f4ee
2 changed files with 8 additions and 7 deletions

View File

@ -109,8 +109,11 @@ namespace
} }
template<typename T,typename S> template<typename T,typename S>
void UInteger2Float(T *tar,S *src,uint size,const T max_value) void UInteger2Float(void *ptr,uint size,const T max_value)
{ {
T *tar=(T *)ptr;
S *src=(S *)ptr;
for(uint i=0;i<size;i++) for(uint i=0;i<size;i++)
*tar++=T(*src++)/max_value; *tar++=T(*src++)/max_value;
} }
@ -158,7 +161,7 @@ Texture2D *LoadTGATexture(const OSString &filename,Device *device)
if(fis->Read(&header,sizeof(tga::Header))!=sizeof(tga::Header)) if(fis->Read(&header,sizeof(tga::Header))!=sizeof(tga::Header))
return(false); return(false);
const uint pixel_count =header.width*header.height; //象素数量 const uint pixel_count =header.width*header.height; //象素数量
const uint pixel_byte =header.bit>>3; //单个象素字节数 const uint pixel_byte =header.bit>>3; //单个象素字节数
const uint line_bytes =header.width*pixel_byte; //每行字节数 const uint line_bytes =header.width*pixel_byte; //每行字节数
@ -240,7 +243,7 @@ Texture2D *LoadTGATexture(const OSString &filename,Device *device)
fis->Read(pixel_data,total_bytes); fis->Read(pixel_data,total_bytes);
if(header.image_type==tga::ImageType::Grayscale&&header.bit==32) if(header.image_type==tga::ImageType::Grayscale&&header.bit==32)
UInteger2Float<float,uint32>((float *)pixel_data,(uint32 *)pixel_data,pixel_count,(float)HGL_U32_MAX); UInteger2Float<float,uint32>(pixel_data,pixel_count,(float)HGL_U32_MAX);
if(image_desc.vertical_direction==tga::VerticalDirection::BottomToTop) if(image_desc.vertical_direction==tga::VerticalDirection::BottomToTop)
SwapRow((uint8 *)pixel_data,line_bytes,header.height); SwapRow((uint8 *)pixel_data,line_bytes,header.height);

View File

@ -173,10 +173,10 @@ namespace
const VulkanFormat *vulkan_yuv_format_list=vulkan_color_format_list+FMT_RANGE_SIZE; const VulkanFormat *vulkan_yuv_format_list=vulkan_color_format_list+FMT_RANGE_SIZE;
const VulkanFormat *vulkan_pvrtc_format_list=vulkan_color_format_list+FMT_RANGE_SIZE+FMT_YUV_RANGE_SIZE; const VulkanFormat *vulkan_pvrtc_format_list=vulkan_color_format_list+FMT_RANGE_SIZE+FMT_YUV_RANGE_SIZE;
#ifdef _DEBUG
constexpr size_t TEXTURE_FORMAT_COUNT=sizeof(vulkan_color_format_list)/sizeof(VulkanFormat); constexpr size_t TEXTURE_FORMAT_COUNT=sizeof(vulkan_color_format_list)/sizeof(VulkanFormat);
#ifdef _DEBUG
uint32_t GetStrideBytesByFormat(const VkFormat &format) uint32_t GetStrideBytesByFormat(const VkFormat &format)
{ {
if(format<=VK_FORMAT_UNDEFINED) if(format<=VK_FORMAT_UNDEFINED)
@ -225,8 +225,6 @@ namespace
return(0); return(0);
} }
#else
constexpr uint32_t STRIDE_FORMAT_COUNT=sizeof(stride_list)/sizeof(uint32);
#endif//_DEBUG #endif//_DEBUG
}//namespace }//namespace