From fd02d2f4ee344b22f0674f19eba4e79d1f60aacf Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 5 Sep 2019 20:49:53 +0800 Subject: [PATCH] update uint2float convert --- example/Vulkan/TGATexture.cpp | 9 ++++++--- src/RenderDevice/Vulkan/VKFormat.cpp | 6 ++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/example/Vulkan/TGATexture.cpp b/example/Vulkan/TGATexture.cpp index c463e6a1..c36f064c 100644 --- a/example/Vulkan/TGATexture.cpp +++ b/example/Vulkan/TGATexture.cpp @@ -109,8 +109,11 @@ namespace } template - 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;iRead(&header,sizeof(tga::Header))!=sizeof(tga::Header)) return(false); - + const uint pixel_count =header.width*header.height; //象素数量 const uint pixel_byte =header.bit>>3; //单个象素字节数 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); if(header.image_type==tga::ImageType::Grayscale&&header.bit==32) - UInteger2Float((float *)pixel_data,(uint32 *)pixel_data,pixel_count,(float)HGL_U32_MAX); + UInteger2Float(pixel_data,pixel_count,(float)HGL_U32_MAX); if(image_desc.vertical_direction==tga::VerticalDirection::BottomToTop) SwapRow((uint8 *)pixel_data,line_bytes,header.height); diff --git a/src/RenderDevice/Vulkan/VKFormat.cpp b/src/RenderDevice/Vulkan/VKFormat.cpp index fb1ef286..ea3742c2 100644 --- a/src/RenderDevice/Vulkan/VKFormat.cpp +++ b/src/RenderDevice/Vulkan/VKFormat.cpp @@ -173,10 +173,10 @@ namespace 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; - -#ifdef _DEBUG + constexpr size_t TEXTURE_FORMAT_COUNT=sizeof(vulkan_color_format_list)/sizeof(VulkanFormat); +#ifdef _DEBUG uint32_t GetStrideBytesByFormat(const VkFormat &format) { if(format<=VK_FORMAT_UNDEFINED) @@ -225,8 +225,6 @@ namespace return(0); } -#else - constexpr uint32_t STRIDE_FORMAT_COUNT=sizeof(stride_list)/sizeof(uint32); #endif//_DEBUG }//namespace