to improve Device::CreateTexture2D serial functions.
This commit is contained in:
parent
9f8cce3e4b
commit
ea2010a2c6
@ -122,8 +122,17 @@ public: //Image
|
|||||||
|
|
||||||
public: //Texture
|
public: //Texture
|
||||||
|
|
||||||
|
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal);
|
||||||
|
|
||||||
|
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal){return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
|
||||||
|
|
||||||
|
Texture2D *CreateTexture2D(TextureData *);
|
||||||
|
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
|
||||||
|
|
||||||
|
void Clear(TextureCreateInfo *);
|
||||||
|
|
||||||
Texture2D *CreateTexture2D(Memory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling);
|
Texture2D *CreateTexture2D(Memory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling);
|
||||||
Texture2D *CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlagBits aspectMask,VkImage image,VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
Texture2D *CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,VkImage image,VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
||||||
|
|
||||||
Texture2D *CreateTexture2D(const VkFormat format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
Texture2D *CreateTexture2D(const VkFormat format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
||||||
|
|
||||||
@ -161,7 +170,15 @@ public: //Texture
|
|||||||
Texture2D *CreateAttachmentTextureDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
Texture2D *CreateAttachmentTextureDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||||
{
|
{
|
||||||
return CreateAttachmentTexture( video_format,width,height,
|
return CreateAttachmentTexture( video_format,width,height,
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT,//|VK_IMAGE_ASPECT_STENCIL_BIT,
|
VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||||
|
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
||||||
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D *CreateAttachmentTextureDepthStencil(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||||
|
{
|
||||||
|
return CreateAttachmentTexture( video_format,width,height,
|
||||||
|
VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT,
|
||||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||||
}
|
}
|
||||||
@ -266,6 +283,10 @@ public:
|
|||||||
|
|
||||||
RenderTarget *CreateRenderTarget(Framebuffer *);
|
RenderTarget *CreateRenderTarget(Framebuffer *);
|
||||||
|
|
||||||
|
RenderTarget *CreateRenderTarget(const uint,const uint,const List<VkFormat> &);
|
||||||
|
RenderTarget *CreateRenderTarget(const uint,const uint,const VkFormat);
|
||||||
|
RenderTarget *CreateRenderTarget(const uint,const uint,const VkFormat,const VkFormat);
|
||||||
|
|
||||||
Pipeline *CreatePipeline(PipelineData *,const Material *,const RenderTarget *);
|
Pipeline *CreatePipeline(PipelineData *,const Material *,const RenderTarget *);
|
||||||
|
|
||||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||||
|
@ -21,6 +21,24 @@ namespace
|
|||||||
}
|
}
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
|
bool Device::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling)
|
||||||
|
{
|
||||||
|
const VkFormatProperties fp=attr->physical_device->GetFormatProperties(format);
|
||||||
|
|
||||||
|
if(tiling==ImageTiling::Optimal)
|
||||||
|
return(fp.optimalTilingFeatures&bits);
|
||||||
|
else
|
||||||
|
return(fp.linearTilingFeatures&bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D *Device::CreateTexture2D(TextureData *tex_data)
|
||||||
|
{
|
||||||
|
if(!tex_data)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
return(new Texture2D(attr->device,tex_data));
|
||||||
|
}
|
||||||
|
|
||||||
Texture2D *Device::CreateTexture2D(Memory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling)
|
Texture2D *Device::CreateTexture2D(Memory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling)
|
||||||
{
|
{
|
||||||
TextureData *tex_data=new TextureData;
|
TextureData *tex_data=new TextureData;
|
||||||
@ -33,57 +51,89 @@ Texture2D *Device::CreateTexture2D(Memory *mem,VkImage image,ImageView *image_vi
|
|||||||
tex_data->mip_levels = 0;
|
tex_data->mip_levels = 0;
|
||||||
tex_data->tiling = VkImageTiling(tiling);
|
tex_data->tiling = VkImageTiling(tiling);
|
||||||
|
|
||||||
return(new Texture2D(attr->device,tex_data));
|
return CreateTexture2D(tex_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *Device::CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlagBits aspectMask,VkImage image,VkImageLayout image_layout,ImageTiling tiling)
|
void Device::Clear(TextureCreateInfo *tci)
|
||||||
{
|
{
|
||||||
VkExtent3D extent={width,height,1};
|
if(!tci)return;
|
||||||
|
|
||||||
ImageView *iv=CreateImageView(attr->device,VK_IMAGE_VIEW_TYPE_2D,format,extent,aspectMask,image);
|
if(tci->image)DestoryImage(tci->image);
|
||||||
|
if(tci->image_view)delete tci->image_view;
|
||||||
|
if(tci->memory)delete tci->memory;
|
||||||
|
|
||||||
return this->CreateTexture2D(nullptr,image,iv,image_layout,tiling);
|
delete tci;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D *Device::CreateTexture2D(TextureCreateInfo *tci)
|
||||||
|
{
|
||||||
|
if(!tci)return(nullptr);
|
||||||
|
|
||||||
|
if(!tci->image)
|
||||||
|
{
|
||||||
|
Image2DCreateInfo ici(tci->usage,tci->tiling,tci->format,tci->extent.width,tci->extent.height);
|
||||||
|
tci->image=CreateImage(&ici);
|
||||||
|
|
||||||
|
if(!tci->image)
|
||||||
|
{
|
||||||
|
Clear(tci);
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
tci->memory=CreateMemory(tci->image);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!tci->image_view)
|
||||||
|
tci->image_view=CreateImageView2D(attr->device,tci->format,tci->extent,tci->aspect,tci->image);
|
||||||
|
|
||||||
|
Texture2D *tex=CreateTexture2D(tci->memory,tci->image,tci->image_view,tci->image_layout,tci->tiling);
|
||||||
|
|
||||||
|
if(!tex)
|
||||||
|
{
|
||||||
|
Clear(tci);
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete tci;
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D *Device::CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,VkImage image,VkImageLayout image_layout,ImageTiling tiling)
|
||||||
|
{
|
||||||
|
if(!CheckTextureFormatSupport(format,tiling))return(nullptr);
|
||||||
|
|
||||||
|
TextureCreateInfo *tci=new TextureCreateInfo;
|
||||||
|
|
||||||
|
tci->extent.width =width;
|
||||||
|
tci->extent.height =height;
|
||||||
|
tci->extent.depth =1;
|
||||||
|
|
||||||
|
tci->format =format;
|
||||||
|
tci->aspect =aspectMask;
|
||||||
|
tci->image =image;
|
||||||
|
tci->image_layout =image_layout;
|
||||||
|
tci->tiling =tiling;
|
||||||
|
|
||||||
|
return CreateTexture2D(tci);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *Device::CreateTexture2D(const VkFormat format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,ImageTiling tiling)
|
Texture2D *Device::CreateTexture2D(const VkFormat format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,ImageTiling tiling)
|
||||||
{
|
{
|
||||||
const VkFormatProperties fp=attr->physical_device->GetFormatProperties(format);
|
if(!CheckTextureFormatSupport(format,tiling))return(nullptr);
|
||||||
|
|
||||||
|
TextureCreateInfo *tci=new TextureCreateInfo;
|
||||||
|
|
||||||
if(tiling==ImageTiling::Optimal)
|
tci->extent.width =width;
|
||||||
{
|
tci->extent.height =height;
|
||||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
tci->extent.depth =1;
|
||||||
tiling=ImageTiling::Optimal;
|
|
||||||
else
|
|
||||||
tiling=ImageTiling::Linear;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tiling==ImageTiling::Linear)
|
tci->format =format;
|
||||||
{
|
tci->aspect =aspectMask;
|
||||||
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
tci->usage =usage;
|
||||||
tiling=ImageTiling::Linear;
|
tci->image_layout =image_layout;
|
||||||
else
|
tci->tiling =tiling;
|
||||||
return(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Image2DCreateInfo ici(usage,tiling,format,width,height);
|
return CreateTexture2D(tci);
|
||||||
VkImage img=CreateImage(&ici);
|
|
||||||
|
|
||||||
if(!img)return(nullptr);
|
|
||||||
|
|
||||||
Memory *mem=CreateMemory(img);
|
|
||||||
|
|
||||||
if(!mem->BindImage(img))
|
|
||||||
{
|
|
||||||
delete mem;
|
|
||||||
DestoryImage(img);
|
|
||||||
return(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
const VkExtent3D ext={width,height,1};
|
|
||||||
|
|
||||||
ImageView *iv=CreateImageView2D(attr->device,format,ext,aspectMask,img);
|
|
||||||
|
|
||||||
return CreateTexture2D(mem,img,iv,image_layout,tiling);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *Device::CreateTexture2D(const VkFormat format,Buffer *buf,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,const ImageTiling tiling)
|
Texture2D *Device::CreateTexture2D(const VkFormat format,Buffer *buf,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,const ImageTiling tiling)
|
||||||
@ -101,13 +151,21 @@ Texture2D *Device::CreateTexture2D(const VkFormat format,Buffer *buf,uint32_t wi
|
|||||||
|
|
||||||
Texture2D *Device::CreateTexture2D(const VkFormat format,void *data,uint32_t width,uint32_t height,uint32_t size,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,const ImageTiling tiling)
|
Texture2D *Device::CreateTexture2D(const VkFormat format,void *data,uint32_t width,uint32_t height,uint32_t size,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,const ImageTiling tiling)
|
||||||
{
|
{
|
||||||
Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
|
Texture2D *tex=CreateTexture2D(format,width,height,aspectMask,usage,image_layout,tiling);
|
||||||
|
|
||||||
if(!buf)return(nullptr);
|
if(!tex)return(nullptr);
|
||||||
|
|
||||||
Texture2D *tex=CreateTexture2D(format,buf,width,height,aspectMask,image_layout,tiling);
|
if(data)
|
||||||
|
{
|
||||||
|
Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
|
||||||
|
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
ChangeTexture2D(tex,buf,0,0,width,height);
|
||||||
|
delete buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete buf;
|
|
||||||
return(tex);
|
return(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user