all codes use new method, it's TextureCreateInfo
This commit is contained in:
2
CMCore
2
CMCore
Submodule CMCore updated: 5a8e5f7884...180228d46a
@@ -131,70 +131,6 @@ public: //Texture
|
||||
|
||||
void Clear(TextureCreateInfo *);
|
||||
|
||||
Texture2D *CreateTexture2D(GPUMemory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling);
|
||||
Texture2D *CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,VkImage image,VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
||||
|
||||
Texture2D *CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
||||
|
||||
Texture2D *CreateTexture2DColor(VkFormat video_format,uint32_t width,uint32_t height,ImageTiling tiling=ImageTiling::Optimal)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
(tiling==ImageTiling::Optimal?VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:VK_IMAGE_LAYOUT_GENERAL),
|
||||
tiling);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2DDepth(VkFormat video_format,uint32_t width,uint32_t height,ImageTiling tiling=ImageTiling::Optimal)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
(tiling==ImageTiling::Optimal?VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:VK_IMAGE_LAYOUT_GENERAL),
|
||||
tiling);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTexture(VkFormat video_format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,aspectMask,usage|VK_IMAGE_USAGE_SAMPLED_BIT,image_layout);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTextureColor(VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateAttachmentTexture( video_format,width,height,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTextureDepth(VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateAttachmentTexture( video_format,width,height,
|
||||
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(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_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2D( VkFormat video_format,GPUBuffer *buf,uint32_t width,uint32_t height,
|
||||
VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
ImageTiling tiling =ImageTiling::Optimal);
|
||||
|
||||
Texture2D *CreateTexture2D( VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,
|
||||
VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
ImageTiling tiling =ImageTiling::Optimal);
|
||||
|
||||
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,const VkBufferImageCopy *,const int count);
|
||||
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,const List<ImageRegion> &);
|
||||
|
||||
|
@@ -18,56 +18,256 @@ struct TextureCreateInfo
|
||||
VkExtent3D extent;
|
||||
VkFormat format;
|
||||
uint32_t usage;
|
||||
uint32_t mipmap; ///<如果值>0表示提供的数据已有mipmaps,如果为0表示自动生成mipmaps
|
||||
uint32_t mipmap; ///<如果值>0表示提供的数据已有mipmaps,如果为0表示自动生成mipmaps
|
||||
VkImageAspectFlags aspect;
|
||||
ImageTiling tiling;
|
||||
|
||||
void * pixels;
|
||||
GPUBuffer * buffer;
|
||||
|
||||
VkImage image;
|
||||
GPUMemory * memory;
|
||||
ImageView * image_view;
|
||||
VkImageLayout image_layout;
|
||||
|
||||
VkImage image; //如果没有IMAGE,则创建。(交换链等会直接提供image,所以存在外部传入现像)
|
||||
GPUMemory * memory; //同时需分配内存并绑定
|
||||
|
||||
ImageView * image_view; //如果没有imageview,则创建
|
||||
|
||||
void * pixels; //如果没有buffer但有pixels,则根据pixels和以上条件创建buffer
|
||||
VkDeviceSize pixel_bytes;
|
||||
GPUBuffer * buffer; //如果pixels也没有,则代表不会立即写入图像数据
|
||||
|
||||
public:
|
||||
|
||||
TextureCreateInfo()
|
||||
{
|
||||
hgl_zero(*this);
|
||||
mipmap=1;
|
||||
}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit):TextureCreateInfo()
|
||||
{
|
||||
usage=VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
void SetAutoMipmaps(){mipmap=0;}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit,const VkExtent2D &ext,const VkFormat &fmt,VkImage img):TextureCreateInfo()
|
||||
{
|
||||
aspect=aspect_bit;
|
||||
tiling=ImageTiling::Optimal;
|
||||
image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
|
||||
extent.width=ext.width;
|
||||
extent.height=ext.height;
|
||||
extent.depth=1;
|
||||
|
||||
format=fmt;
|
||||
image=img;
|
||||
}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit,const uint32_t u,const ImageTiling it,const VkImageLayout il):TextureCreateInfo()
|
||||
{
|
||||
aspect=aspect_bit;
|
||||
|
||||
usage=u;
|
||||
tiling=it;
|
||||
image_layout=il;
|
||||
}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit,const VkFormat &fmt,const uint32_t u,const ImageTiling it,const VkImageLayout il):TextureCreateInfo()
|
||||
{
|
||||
aspect=aspect_bit;
|
||||
|
||||
format=fmt;
|
||||
usage=u;
|
||||
tiling=it;
|
||||
image_layout=il;
|
||||
}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit,const uint32_t u,const ImageTiling it)
|
||||
:TextureCreateInfo(aspect_bit,u,it,
|
||||
(tiling==ImageTiling::Optimal?
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
|
||||
VK_IMAGE_LAYOUT_GENERAL)){}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit,const VkExtent2D &ext,const uint32_t u,const ImageTiling it)
|
||||
:TextureCreateInfo(aspect_bit,u,it)
|
||||
{
|
||||
extent.width=ext.width;
|
||||
extent.height=ext.height;
|
||||
extent.depth=1;
|
||||
}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit,const VkFormat &fmt,const VkExtent2D &ext,const uint32_t u,const ImageTiling it,const VkImageLayout il)
|
||||
:TextureCreateInfo(aspect_bit,u,it,il)
|
||||
{
|
||||
format=fmt;
|
||||
extent.width=ext.width;
|
||||
extent.height=ext.height;
|
||||
extent.depth=1;
|
||||
}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit,const uint32_t u)
|
||||
:TextureCreateInfo(aspect_bit,u,ImageTiling::Optimal,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL){}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bit)
|
||||
:TextureCreateInfo( aspect_bit,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
ImageTiling::Optimal,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL){}
|
||||
|
||||
TextureCreateInfo(const VkFormat fmt):TextureCreateInfo()
|
||||
{
|
||||
if(IsDepthStencilFormat(fmt))
|
||||
aspect=VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
else
|
||||
if(IsDepthFormat(fmt))
|
||||
aspect=VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
else
|
||||
if(CheckVulkanFormat(fmt))
|
||||
{
|
||||
aspect=VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
aspect=0;
|
||||
}
|
||||
|
||||
format=fmt;
|
||||
usage=VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
}
|
||||
|
||||
TextureCreateInfo(const uint32_t aspect_bits,const VkFormat fmt,const VkExtent2D &ext):TextureCreateInfo(fmt)
|
||||
{
|
||||
aspect=aspect;
|
||||
|
||||
extent.width=ext.width;
|
||||
extent.height=ext.height;
|
||||
extent.depth=1;
|
||||
}
|
||||
|
||||
bool SetFormat(const VkFormat fmt)
|
||||
{
|
||||
if(!CheckVulkanFormat(fmt))return(false);
|
||||
|
||||
if(aspect&VK_IMAGE_ASPECT_DEPTH_BIT)
|
||||
{
|
||||
if(aspect&VK_IMAGE_ASPECT_STENCIL_BIT)
|
||||
{
|
||||
if(!IsDepthStencilFormat(fmt))return(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!IsDepthFormat(fmt))return(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(aspect&VK_IMAGE_ASPECT_STENCIL_BIT)
|
||||
if(!IsStencilFormat(fmt))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool SetData(GPUBuffer *buf,const uint32_t w,const uint32_t h)
|
||||
{
|
||||
if(!buf||w<=0||h<=0)return(false);
|
||||
|
||||
buffer=buf;
|
||||
|
||||
extent.width=w;
|
||||
extent.height=h;
|
||||
extent.depth=1;
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//struct TextureCreateInfo
|
||||
|
||||
class AttachmentTextureCreateInfo:public TextureCreateInfo
|
||||
struct ColorTextureCreateInfo:public TextureCreateInfo
|
||||
{
|
||||
public:
|
||||
ColorTextureCreateInfo():TextureCreateInfo(VK_IMAGE_ASPECT_COLOR_BIT){}
|
||||
ColorTextureCreateInfo(const VkFormat format,const VkExtent2D &ext):TextureCreateInfo(VK_IMAGE_ASPECT_COLOR_BIT,format,ext){}
|
||||
};//struct ColorTextureCreateInfo:public TextureCreateInfo
|
||||
|
||||
AttachmentTextureCreateInfo(const uint32_t aspect_bit):TextureCreateInfo()
|
||||
struct DepthTextureCreateInfo:public TextureCreateInfo
|
||||
{
|
||||
DepthTextureCreateInfo():TextureCreateInfo(VK_IMAGE_ASPECT_DEPTH_BIT){}
|
||||
DepthTextureCreateInfo(const VkFormat format,const VkExtent2D &ext):TextureCreateInfo(VK_IMAGE_ASPECT_COLOR_BIT,format,ext){}
|
||||
};//struct DepthTextureCreateInfo:public TextureCreateInfo
|
||||
|
||||
struct DepthStencilTextureCreateInfo:public TextureCreateInfo
|
||||
{
|
||||
DepthStencilTextureCreateInfo():TextureCreateInfo(VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT){}
|
||||
};//struct DepthStencilTextureCreateInfo:public TextureCreateInfo
|
||||
|
||||
struct AttachmentTextureCreateInfo:public TextureCreateInfo
|
||||
{
|
||||
AttachmentTextureCreateInfo(const uint32_t aspect_bit,const uint32_t u,const VkImageLayout il):TextureCreateInfo(aspect_bit,u,ImageTiling::Optimal,il){}
|
||||
};//struct AttachmentTextureCreateInfo:public TextureCreateInfo
|
||||
|
||||
struct ColorAttachmentTextureCreateInfo:public AttachmentTextureCreateInfo
|
||||
{
|
||||
ColorAttachmentTextureCreateInfo()
|
||||
:AttachmentTextureCreateInfo( VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
||||
|VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
||||
|VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
||||
|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL){}
|
||||
|
||||
ColorAttachmentTextureCreateInfo(const VkFormat fmt,const VkExtent3D &ext):ColorAttachmentTextureCreateInfo()
|
||||
{
|
||||
aspect=aspect_bit;
|
||||
tiling=ImageTiling::Optimal;
|
||||
|
||||
if(aspect_bit&VK_IMAGE_ASPECT_COLOR_BIT)
|
||||
{
|
||||
usage=VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
image_layout=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
else
|
||||
if(aspect_bit&VK_IMAGE_ASPECT_DEPTH_BIT)
|
||||
{
|
||||
usage=VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
image_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
format=fmt;
|
||||
extent=ext;
|
||||
}
|
||||
};
|
||||
|
||||
struct DepthAttachmentTextureCreateInfo:public AttachmentTextureCreateInfo
|
||||
{
|
||||
DepthAttachmentTextureCreateInfo()
|
||||
:AttachmentTextureCreateInfo( 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_USAGE_SAMPLED_BIT,
|
||||
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL){}
|
||||
|
||||
DepthAttachmentTextureCreateInfo(const VkFormat fmt,const VkExtent3D &ext):DepthAttachmentTextureCreateInfo()
|
||||
{
|
||||
format=fmt;
|
||||
extent=ext;
|
||||
}
|
||||
};
|
||||
|
||||
struct DepthStencilAttachmentTextureCreateInfo:public AttachmentTextureCreateInfo
|
||||
{
|
||||
DepthStencilAttachmentTextureCreateInfo()
|
||||
:AttachmentTextureCreateInfo( 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_SAMPLED_BIT,
|
||||
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL){}
|
||||
|
||||
DepthStencilAttachmentTextureCreateInfo(const VkFormat fmt,const VkExtent3D &ext):DepthStencilAttachmentTextureCreateInfo()
|
||||
{
|
||||
format=fmt;
|
||||
extent=ext;
|
||||
}
|
||||
};
|
||||
|
||||
struct SwapchainColorTextureCreateInfo:public TextureCreateInfo
|
||||
{
|
||||
SwapchainColorTextureCreateInfo(const VkFormat fmt,const VkExtent2D &ext,VkImage img)
|
||||
:TextureCreateInfo(VK_IMAGE_ASPECT_COLOR_BIT,ext,fmt,img){}
|
||||
};//struct SwapchainColorTextureCreateInfo:public TextureCreateInfo
|
||||
|
||||
struct SwapchainDepthTextureCreateInfo:public TextureCreateInfo
|
||||
{
|
||||
SwapchainDepthTextureCreateInfo(const VkFormat fmt,const VkExtent2D &ext)
|
||||
:TextureCreateInfo( VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||
fmt,
|
||||
ext,
|
||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
||||
ImageTiling::Optimal,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED){}
|
||||
};//struct SwapchainColorTextureCreateInfo:public TextureCreateInfo
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_TEXTURE_CREATE_INFO_INCLUDE
|
@@ -23,15 +23,17 @@ RenderTarget *GPUDevice::CreateRenderTarget(const uint w,const uint h,
|
||||
|
||||
const uint32_t color_count=color_format_list.GetCount();
|
||||
|
||||
const VkExtent3D extent={w,h,1};
|
||||
|
||||
AutoDeleteObjectArray<Texture2D> color_texture_list(color_count);
|
||||
AutoDeleteArray<ImageView *> color_iv_list=new ImageView *[color_count]; //iv只是从Texture2D中取出来的,无需一个个delete
|
||||
AutoDeleteArray<ImageView *> color_iv_list(color_count); //iv只是从Texture2D中取出来的,无需一个个delete
|
||||
|
||||
Texture2D **tp=color_texture_list;
|
||||
ImageView **iv=color_iv_list;
|
||||
|
||||
for(const VkFormat &fmt:color_format_list)
|
||||
{
|
||||
Texture2D *color_texture=CreateAttachmentTextureColor(fmt,w,h);
|
||||
Texture2D *color_texture=CreateTexture2D(new ColorAttachmentTextureCreateInfo(fmt,extent));
|
||||
|
||||
if(!color_texture)
|
||||
{
|
||||
@@ -43,7 +45,7 @@ RenderTarget *GPUDevice::CreateRenderTarget(const uint w,const uint h,
|
||||
*iv++=color_texture->GetImageView();
|
||||
}
|
||||
|
||||
Texture2D *depth_texture=(depth_format!=FMT_UNDEFINED)?CreateAttachmentTextureDepth(depth_format,w,h):nullptr;
|
||||
Texture2D *depth_texture=(depth_format!=FMT_UNDEFINED)?CreateTexture2D(new DepthAttachmentTextureCreateInfo(depth_format,extent)):nullptr;
|
||||
|
||||
Framebuffer *fb=CreateFramebuffer(rp,color_iv_list,color_count,depth_texture?depth_texture->GetImageView():nullptr);
|
||||
|
||||
|
@@ -78,39 +78,15 @@ bool GPUDevice::CreateSwapchainColorTexture()
|
||||
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->swap_chain_count),sc_images)!=VK_SUCCESS)
|
||||
return(false);
|
||||
|
||||
VkImage *ip=sc_images;
|
||||
Texture2D *tex;
|
||||
|
||||
for(uint32_t i=0; i<swapchain->swap_chain_count; i++)
|
||||
{
|
||||
tex=CreateTexture2D(attr->format,
|
||||
swapchain->extent.width,
|
||||
swapchain->extent.height,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
*ip,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED);
|
||||
|
||||
swapchain->sc_color.Add(tex);
|
||||
|
||||
++ip;
|
||||
}
|
||||
for(VkImage ip:sc_images)
|
||||
swapchain->sc_color.Add(CreateTexture2D(new SwapchainColorTextureCreateInfo(attr->format,swapchain->extent,ip)));
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool GPUDevice::CreateSwapchainDepthTexture()
|
||||
{
|
||||
const VkFormat depth_format=attr->physical_device->GetDepthFormat();
|
||||
|
||||
const VkFormatProperties props=attr->physical_device->GetFormatProperties(depth_format);
|
||||
|
||||
swapchain->sc_depth=CreateTexture2D(depth_format,
|
||||
swapchain->extent.width,
|
||||
swapchain->extent.height,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
(props.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)?ImageTiling::Optimal:ImageTiling::Linear);
|
||||
swapchain->sc_depth=CreateTexture2D(new SwapchainDepthTextureCreateInfo(attr->physical_device->GetDepthFormat(),swapchain->extent));
|
||||
|
||||
return swapchain->sc_depth;
|
||||
}
|
||||
|
@@ -34,21 +34,6 @@ Texture2D *GPUDevice::CreateTexture2D(TextureData *tex_data)
|
||||
return(new Texture2D(attr->device,tex_data));
|
||||
}
|
||||
|
||||
Texture2D *GPUDevice::CreateTexture2D(GPUMemory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling)
|
||||
{
|
||||
TextureData *tex_data=new TextureData;
|
||||
|
||||
tex_data->memory = mem;
|
||||
tex_data->image_layout = image_layout;
|
||||
tex_data->image = image;
|
||||
tex_data->image_view = image_view;
|
||||
|
||||
tex_data->mip_levels = 0;
|
||||
tex_data->tiling = VkImageTiling(tiling);
|
||||
|
||||
return CreateTexture2D(tex_data);
|
||||
}
|
||||
|
||||
void GPUDevice::Clear(TextureCreateInfo *tci)
|
||||
{
|
||||
if(!tci)return;
|
||||
@@ -64,6 +49,8 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
|
||||
{
|
||||
if(!tci)return(nullptr);
|
||||
|
||||
if(tci->extent.width*tci->extent.height*tci->extent.depth<=0)return(nullptr);
|
||||
|
||||
if(!tci->image)
|
||||
{
|
||||
Image2DCreateInfo ici(tci->usage,tci->tiling,tci->format,tci->extent.width,tci->extent.height,tci->mipmap);
|
||||
@@ -81,7 +68,17 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
|
||||
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);
|
||||
TextureData *tex_data=new TextureData;
|
||||
|
||||
tex_data->memory = tci->memory;
|
||||
tex_data->image_layout = tci->image_layout;
|
||||
tex_data->image = tci->image;
|
||||
tex_data->image_view = tci->image_view;
|
||||
|
||||
tex_data->mip_levels = tci->mipmap;
|
||||
tex_data->tiling = VkImageTiling(tci->tiling);
|
||||
|
||||
Texture2D *tex=CreateTexture2D(tex_data);
|
||||
|
||||
if(!tex)
|
||||
{
|
||||
@@ -89,79 +86,17 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
delete tci;
|
||||
return tex;
|
||||
}
|
||||
if((!tci->buffer)&&tci->pixels&&tci->pixel_bytes>0)
|
||||
tci->buffer=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tci->pixel_bytes,tci->pixels);
|
||||
|
||||
Texture2D *GPUDevice::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 *GPUDevice::CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,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->usage =usage;
|
||||
tci->image_layout =image_layout;
|
||||
tci->tiling =tiling;
|
||||
|
||||
return CreateTexture2D(tci);
|
||||
}
|
||||
|
||||
Texture2D *GPUDevice::CreateTexture2D(VkFormat format,GPUBuffer *buf,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout,const ImageTiling tiling)
|
||||
{
|
||||
if(!buf)return(nullptr);
|
||||
|
||||
Texture2D *tex=CreateTexture2D(format,width,height,aspectMask,usage,image_layout,tiling);
|
||||
|
||||
if(!tex)return(nullptr);
|
||||
|
||||
ChangeTexture2D(tex,buf,0,0,width,height);
|
||||
|
||||
return(tex);
|
||||
}
|
||||
|
||||
Texture2D *GPUDevice::CreateTexture2D(VkFormat format,void *data,uint32_t width,uint32_t height,uint32_t size,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout,ImageTiling tiling)
|
||||
{
|
||||
Texture2D *tex=CreateTexture2D(format,width,height,aspectMask,usage,image_layout,tiling);
|
||||
|
||||
if(!tex)return(nullptr);
|
||||
|
||||
if(data)
|
||||
if(tci->buffer)
|
||||
{
|
||||
GPUBuffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
|
||||
|
||||
if(buf)
|
||||
{
|
||||
ChangeTexture2D(tex,buf,0,0,width,height);
|
||||
delete buf;
|
||||
}
|
||||
ChangeTexture2D(tex,tci->buffer,0,0,tci->extent.width,tci->extent.height);
|
||||
delete tci->buffer;
|
||||
}
|
||||
|
||||
return(tex);
|
||||
delete tci;
|
||||
return tex;
|
||||
}
|
||||
|
||||
bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,const VkBufferImageCopy *buffer_image_copy,const int count)
|
||||
|
@@ -157,7 +157,14 @@ namespace
|
||||
{
|
||||
buf->Unmap();
|
||||
|
||||
tex=device->CreateTexture2D(format,buf,file_header.width,file_header.height);
|
||||
TextureCreateInfo *tci=new TextureCreateInfo(format);
|
||||
|
||||
tci->SetData(buf,file_header.width,file_header.height);
|
||||
|
||||
tex=device->CreateTexture2D(tci);
|
||||
|
||||
if(tex)
|
||||
buf=nullptr;
|
||||
}
|
||||
|
||||
Texture2D *GetTexture()
|
||||
|
@@ -80,17 +80,18 @@ TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const
|
||||
if(!vf)return(nullptr);
|
||||
|
||||
Texture2D *tex=nullptr;
|
||||
VkExtent2D extent={tex_width,tex_height};
|
||||
|
||||
if(vf->color>VulkanDataType::NONE
|
||||
&&vf->color<VulkanDataType::END)
|
||||
{
|
||||
tex=CreateTexture2DColor(format,tex_width,tex_height);
|
||||
tex=CreateTexture2D(new ColorTextureCreateInfo(format,extent));
|
||||
}
|
||||
else
|
||||
if(vf->depth>VulkanDataType::NONE
|
||||
&&vf->depth<VulkanDataType::END)
|
||||
{
|
||||
tex=CreateTexture2DDepth(format,tex_width,tex_height);
|
||||
tex=CreateTexture2D(new DepthTextureCreateInfo(format,extent));
|
||||
}
|
||||
else
|
||||
return(nullptr);
|
||||
|
Reference in New Issue
Block a user