ULRE/example/Texture/texture_format_list.cpp

104 lines
2.8 KiB
C++
Raw Normal View History

#include<iostream>
2023-05-12 00:31:20 +08:00
#include<iomanip>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKInstance.h>
using namespace hgl;
using namespace hgl::graph;
VK_NAMESPACE_USING;
2019-08-14 16:36:02 +08:00
2020-10-21 12:47:06 +08:00
VulkanInstance *InitVulkanInstance()
{
#ifdef _DEBUG
if(!CheckStrideBytesByFormat())
{
std::cerr<<"check stride bytes by format failed."<<std::endl;
return(nullptr);
}
#endif//_DEBUG
InitNativeWindowSystem();
2020-11-05 14:18:05 +08:00
//InitVulkanProperties();
2019-11-06 20:52:09 +08:00
CreateInstanceLayerInfo cili;
memset(&cili,0,sizeof(CreateInstanceLayerInfo));
cili.lunarg.standard_validation=true;
cili.khronos.validation=true;
2020-10-21 12:47:06 +08:00
return CreateInstance("VulkanTest",nullptr,&cili);
}
int main(int,char **)
{
2020-11-05 14:18:05 +08:00
Window * win =nullptr;
VulkanInstance * inst =nullptr;
VulkanDevice * device =nullptr;
const VulkanPhyDevice * physical_device =nullptr;
inst=InitVulkanInstance();
if(!inst)
{
std::cerr<<"[VULKAN FATAL ERROR] Create Vulkan Instance failed.";
return(false);
}
physical_device=inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU);
if(!physical_device)
physical_device=inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU);
2019-08-14 16:36:02 +08:00
uint32_t count;
const VulkanFormat *vf=GetVulkanFormatList(count);
if(!count)return(255);
for(uint32_t i=0;i<count;i++)
{
2023-05-12 00:31:20 +08:00
std::cout<<std::setw(4)<<i<<". ";
2019-08-14 16:36:02 +08:00
2023-05-12 00:31:20 +08:00
std::cout<<"Format [ID:"<<std::setw(10)<<vf->format<<"]["<<std::setw(16)<<vf->name<<"]";
2019-08-14 16:36:02 +08:00
2023-05-12 00:31:20 +08:00
if(vf->depth!=VulkanBaseType::NONE)
2024-07-27 20:52:58 +08:00
std::cout<<"[ Depth:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->depth)]<<"]";
2019-08-14 16:36:02 +08:00
2023-05-12 00:31:20 +08:00
if(vf->stencil!=VulkanBaseType::NONE)
2024-07-27 20:52:58 +08:00
std::cout<<"[Stencil:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->stencil)]<<"]";
2019-08-14 16:36:02 +08:00
2023-05-12 00:31:20 +08:00
if((vf->depth==VulkanBaseType::NONE)
&&(vf->stencil==VulkanBaseType::NONE))
2024-07-27 20:52:58 +08:00
std::cout<<"[ Color:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->color)]<<"]";
{
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
2023-05-12 00:31:20 +08:00
char olb[]="[ ]";
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[1]='O';
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='L';
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='B';
2023-05-12 00:31:20 +08:00
std::cout<<olb;
}
2023-05-12 00:31:20 +08:00
if(vf->compress_type!=TextureCompressType::NONE)
2024-07-27 20:52:58 +08:00
std::cout<<" use "<<TextureCompressTypeName[size_t(vf->compress_type)]<<" compress.";
2023-05-12 00:31:20 +08:00
else
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";
2019-08-14 16:36:02 +08:00
std::cout<<std::endl;
2019-08-14 16:36:02 +08:00
++vf;
}
delete inst;
return 0;
}