增加Device::CreateSampler

This commit is contained in:
hyzboy 2019-05-18 16:10:42 +08:00
parent f5d86f6c32
commit 0879f7fad3
7 changed files with 74 additions and 4 deletions

View File

@ -27,6 +27,8 @@ class Texture3D;
class TextureCubemap;
class TextureCubemapArray;
class Sampler;
class Buffer;
class VertexBuffer;
class IndexBuffer;

View File

@ -89,6 +89,7 @@ public: //Buffer相关
public: //material相关
Texture2D *CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,bool force_linear=false);
Sampler *CreateSampler(VkSamplerCreateInfo *);
ShaderModuleManage *CreateShaderModuleManage();

View File

@ -0,0 +1,31 @@
#ifndef HGL_GRAPH_VULKAN_SAMPLER_INCLUDE
#define HGL_GRAPH_VULKAN_SAMPLER_INCLUDE
#include<hgl/graph/vulkan/VK.h>
VK_NAMESPACE_BEGIN
class Device;
class Sampler
{
VkDevice device;
VkSampler sampler;
protected:
friend class Device;
Sampler(VkDevice dev,VkSampler s)
{
device=dev;
sampler=s;
}
public:
~Sampler();
operator VkSampler(){return sampler;}
operator const VkSampler()const{return sampler;}
};//class Sampler
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SAMPLER_INCLUDE

View File

@ -23,7 +23,7 @@ public:
operator VkImage (){return data?data->image:nullptr;}
operator VkImageLayout (){return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;}
operator VkImageView (){return data?*(data->image_view):nullptr;}
operator ImageView * (){return data?data->image_view:nullptr;}
const uint32 GetMipLevels()const{return data?data->mip_levels:0;}
const bool IsLinear ()const{return data?data->linear:false;}
@ -57,6 +57,9 @@ public:
Texture2D(uint32_t w,uint32_t h,VkDevice dev,TextureData *td):width(w),height(h),Texture(dev,td){}
~Texture2D()=default;
const uint32_t GetWidth()const{return width;}
const uint32_t GetHeight()const{return height;}
};//class Texture2D:public Texture
//class Texture2DArray:public Texture

View File

@ -22,7 +22,8 @@
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderModuleManage.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKSurfaceExtensionName.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKVertexAttributeBinding.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKTexture.h)
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKTexture.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKSampler.h)
SET(RENDER_DEVICE_VULKAN_SOURCE VKFormat.cpp
VKInstance.cpp
@ -49,7 +50,8 @@ SET(RENDER_DEVICE_VULKAN_SOURCE VKFormat.cpp
VKFence.cpp
VKMaterial.cpp
VKRenderable.cpp
VKTexture.cpp)
VKTexture.cpp
VKSampler.cpp)
SET(RENDER_DEVICE_VULKAN_POD_SOURCE pod/VKPipelineCreateInfo.POD.cpp)

View File

@ -1,4 +1,5 @@
#include<hgl/graph/vulkan/VKTexture.h>
#include<hgl/graph/vulkan/VKSampler.h>
#include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
#include<hgl/graph/vulkan/VKBuffer.h>
@ -146,6 +147,29 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32
#undef VK_CHECK_RESULT
}
return(new Texture2D(width,height,tex_data));
return(new Texture2D(width,height,attr->device,tex_data));
}
Sampler *Device::CreateSampler(VkSamplerCreateInfo *sci)
{
if(!sci)return(nullptr);
VkSampler sampler;
if(attr->physical_device->features.samplerAnisotropy)
{
sci->maxAnisotropy = attr->physical_device->properties.limits.maxSamplerAnisotropy;
sci->anisotropyEnable = VK_TRUE;
}
else
{
sci->maxAnisotropy = 1.0;
sci->anisotropyEnable = VK_FALSE;
}
if(vkCreateSampler(attr->device,sci,nullptr,&sampler)!=VK_SUCCESS)
return(nullptr);
return(new Sampler(attr->device,sampler));
}
VK_NAMESPACE_END

View File

@ -0,0 +1,7 @@
#include<hgl/graph/vulkan/VKSampler.h>
VK_NAMESPACE_BEGIN
Sampler::~Sampler()
{
vkDestroySampler(device,sampler,nullptr);
}
VK_NAMESPACE_END