ULRE/src/SceneGraph/Vulkan/VKTileData.cpp

102 lines
2.5 KiB
C++
Raw Normal View History

#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKPhysicalDevice.h>
2020-06-21 02:23:11 +08:00
#include<hgl/graph/TileData.h>
2024-11-05 00:04:36 +08:00
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/RenderFramework.h>
2020-06-21 02:23:11 +08:00
namespace
{
2020-07-31 18:01:28 +08:00
using namespace hgl;
2020-06-21 02:23:11 +08:00
void AnalyseSize(uint &fw,uint &fh,const uint w,const uint h,const uint count,const uint32_t max_texture_size)
2020-07-31 18:01:28 +08:00
{
uint total,tw,th,t;
2020-07-31 18:01:28 +08:00
fw=fh=0;
tw=max_texture_size;
while(tw>=w)
{
th=max_texture_size;
while(th>=h)
{
t=(tw/w)*(th/h);
if(!fw)
{
fw=tw;
fh=th;
total=t;
}
else
{
if(t==count)
{
//正好,就要这么大的
fw=tw;
fh=th;
return;
}
else
if(t>count) //要比要求的最大值大
{
if(t<total) //找到最接近最大值的
{
//比现在选中的更节省
fw=tw;
fh=th;
total=t;
}
}
}
th>>=1;
}
tw>>=1;
}
}//void AnalyseSize
2020-06-21 02:23:11 +08:00
}//namespace
VK_NAMESPACE_BEGIN
2024-11-05 00:04:36 +08:00
TileData *RenderFramework::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
2020-06-21 02:23:11 +08:00
{
if(!CheckVulkanFormat(format))
return(nullptr);
if(width<=0||height<=0||count<=0)
return(nullptr);
2024-11-05 00:04:36 +08:00
const uint32_t max_2d_texture=device->GetPhysicalDevice()->GetMaxImage2D();
2020-06-21 02:23:11 +08:00
uint tex_width,tex_height;
2020-07-31 18:01:28 +08:00
AnalyseSize(tex_width,tex_height,width,height,count,max_2d_texture);
2020-06-21 02:23:11 +08:00
2020-07-31 18:01:28 +08:00
const VulkanFormat *vf=GetVulkanFormat(format);
2020-06-21 02:23:11 +08:00
2020-07-31 18:01:28 +08:00
if(!vf)return(nullptr);
2020-06-21 02:23:11 +08:00
2020-07-31 18:01:28 +08:00
Texture2D *tex=nullptr;
VkExtent2D extent={tex_width,tex_height};
2020-06-21 02:23:11 +08:00
2022-06-24 11:42:20 +08:00
if(RangeCheck(vf->color))
2020-07-31 18:01:28 +08:00
{
2024-11-05 00:04:36 +08:00
tex=texture_manager->CreateTexture2D(new ColorTextureCreateInfo(format,extent));
2020-07-31 18:01:28 +08:00
}
else
2022-06-24 11:42:20 +08:00
if(RangeCheck(vf->depth))
2020-07-31 18:01:28 +08:00
{
2024-11-05 00:04:36 +08:00
tex=texture_manager->CreateTexture2D(new DepthTextureCreateInfo(format,extent));
2020-07-31 18:01:28 +08:00
}
else
return(nullptr);
2020-06-21 02:23:11 +08:00
2024-11-05 00:04:36 +08:00
return(new TileData(texture_manager,tex,width,height));
2020-06-21 02:23:11 +08:00
}
VK_NAMESPACE_END