ULRE/src/RenderDevice/Vulkan/VKTileData.cpp

101 lines
2.4 KiB
C++
Raw Normal View History

2020-06-21 02:23:11 +08:00
#include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
#include<hgl/graph/TileData.h>
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
{
int total,tw,th,t;
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
TileData *Device::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
{
if(!CheckVulkanFormat(format))
return(nullptr);
if(width<=0||height<=0||count<=0)
return(nullptr);
const uint32_t max_2d_texture=attr->physical_device->GetMaxImage2D();
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;
2020-06-21 02:23:11 +08:00
2020-07-31 18:01:28 +08:00
if(vf->color>VulkanDataType::NONE
&&vf->color<VulkanDataType::END)
{
tex=CreateTexture2DColor(format,tex_width,tex_height);
}
else
if(vf->depth>VulkanDataType::NONE
&&vf->depth<VulkanDataType::END)
{
tex=CreateTexture2DDepth(format,tex_width,tex_height);
}
else
return(nullptr);
2020-06-21 02:23:11 +08:00
2020-07-31 18:01:28 +08:00
return(new TileData(this,tex,width,height));
2020-06-21 02:23:11 +08:00
}
VK_NAMESPACE_END