VKDevice增加新的CreateTexture2D函数
This commit is contained in:
parent
837d76f8f1
commit
d3bdaa3c15
@ -107,7 +107,42 @@ public: //material相关
|
||||
|
||||
Texture2D *CreateRefTexture2D(uint32_t width,uint32_t height,VkFormat format,VkImageAspectFlagBits flag,VkImage image,VkImageLayout image_layout,VkImageView image_view);
|
||||
|
||||
Texture2D *CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,bool force_linear=false);
|
||||
Texture2D *CreateTexture2D(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout);
|
||||
|
||||
Texture2D *CreateTexture2DColor(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2DDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTextureColor(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTextureDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT,
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,bool force_linear=false,const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
|
||||
bool ChangeTexture2D(Texture2D *,void *data,uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size);
|
||||
Sampler *CreateSampler(VkSamplerCreateInfo *);
|
||||
|
||||
|
@ -249,8 +249,10 @@ namespace
|
||||
{
|
||||
VkDescriptorPoolSize pool_size[]=
|
||||
{
|
||||
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024},
|
||||
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1024},
|
||||
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024}
|
||||
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1024},
|
||||
{VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 48}
|
||||
};
|
||||
|
||||
VkDescriptorPoolCreateInfo dp_create_info={};
|
||||
|
@ -19,9 +19,61 @@ namespace
|
||||
}
|
||||
}//namespace
|
||||
|
||||
Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,bool force_linear)
|
||||
Texture2D *Device::CreateTexture2D(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout)
|
||||
{
|
||||
if(!data||width<=1||height<=1)return(nullptr);
|
||||
if(video_format<VK_FORMAT_BEGIN_RANGE||video_format>VK_FORMAT_END_RANGE)return(nullptr);
|
||||
if(width<1||height<1)return(nullptr);
|
||||
|
||||
const VkFormatProperties fp=attr->physical_device->GetFormatProperties(video_format);
|
||||
|
||||
if(!(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
&&!(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
|
||||
return(nullptr);
|
||||
|
||||
VkImageCreateInfo imageCreateInfo;
|
||||
|
||||
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageCreateInfo.pNext = nullptr;
|
||||
imageCreateInfo.flags = 0;
|
||||
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
imageCreateInfo.format = video_format;
|
||||
imageCreateInfo.mipLevels = 1;
|
||||
imageCreateInfo.arrayLayers = 1;
|
||||
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
// Set initial layout of the image to undefined
|
||||
imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
imageCreateInfo.extent.width = width;
|
||||
imageCreateInfo.extent.height = height;
|
||||
imageCreateInfo.extent.depth = 1;
|
||||
imageCreateInfo.usage = usage;
|
||||
|
||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
else
|
||||
imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
|
||||
|
||||
VkImage image;
|
||||
|
||||
if(vkCreateImage(attr->device, &imageCreateInfo, nullptr, &image)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
TextureData *tex_data=new TextureData;
|
||||
|
||||
tex_data->ref = false;
|
||||
tex_data->mip_levels = 1;
|
||||
tex_data->image_layout = image_layout;
|
||||
tex_data->image = image;
|
||||
|
||||
tex_data->image_view=CreateImageView2D(attr->device,video_format,aspectMask,image);
|
||||
|
||||
return(new Texture2D(width,height,attr->device,tex_data));
|
||||
}
|
||||
|
||||
Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,bool force_linear,const VkImageLayout image_layout)
|
||||
{
|
||||
if(video_format<VK_FORMAT_BEGIN_RANGE||video_format>VK_FORMAT_END_RANGE)return(nullptr);
|
||||
if(!data||width<1||height<1)return(nullptr);
|
||||
|
||||
const VkFormatProperties fp=attr->physical_device->GetFormatProperties(video_format);
|
||||
|
||||
@ -47,8 +99,9 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32
|
||||
|
||||
TextureData *tex_data=new TextureData;
|
||||
|
||||
tex_data->ref =false;
|
||||
tex_data->mip_levels=1;
|
||||
tex_data->ref = false;
|
||||
tex_data->mip_levels = 1;
|
||||
tex_data->image_layout = image_layout;
|
||||
|
||||
if(force_linear)
|
||||
{
|
||||
@ -71,8 +124,6 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32
|
||||
buffer_image_copy.imageExtent.depth = 1;
|
||||
buffer_image_copy.bufferOffset = 0;
|
||||
|
||||
tex_data->image_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
|
||||
VkImageCreateInfo imageCreateInfo{};
|
||||
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
|
Loading…
x
Reference in New Issue
Block a user