diff --git a/inc/hgl/graph/vulkan/VK.h b/inc/hgl/graph/vulkan/VK.h index 566d566d..8833750b 100644 --- a/inc/hgl/graph/vulkan/VK.h +++ b/inc/hgl/graph/vulkan/VK.h @@ -27,6 +27,8 @@ class Texture3D; class TextureCubemap; class TextureCubemapArray; +class Sampler; + class Buffer; class VertexBuffer; class IndexBuffer; diff --git a/inc/hgl/graph/vulkan/VKDevice.h b/inc/hgl/graph/vulkan/VKDevice.h index 9d0352da..5ee01b0c 100644 --- a/inc/hgl/graph/vulkan/VKDevice.h +++ b/inc/hgl/graph/vulkan/VKDevice.h @@ -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(); diff --git a/inc/hgl/graph/vulkan/VKSampler.h b/inc/hgl/graph/vulkan/VKSampler.h new file mode 100644 index 00000000..d29dfb06 --- /dev/null +++ b/inc/hgl/graph/vulkan/VKSampler.h @@ -0,0 +1,31 @@ +#ifndef HGL_GRAPH_VULKAN_SAMPLER_INCLUDE +#define HGL_GRAPH_VULKAN_SAMPLER_INCLUDE + +#include +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 diff --git a/inc/hgl/graph/vulkan/VKTexture.h b/inc/hgl/graph/vulkan/VKTexture.h index 5442d31b..3e9847db 100644 --- a/inc/hgl/graph/vulkan/VKTexture.h +++ b/inc/hgl/graph/vulkan/VKTexture.h @@ -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 diff --git a/src/RenderDevice/Vulkan/CMakeLists.txt b/src/RenderDevice/Vulkan/CMakeLists.txt index 69e43763..8befc53f 100644 --- a/src/RenderDevice/Vulkan/CMakeLists.txt +++ b/src/RenderDevice/Vulkan/CMakeLists.txt @@ -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) diff --git a/src/RenderDevice/Vulkan/VKDeviceTexture.cpp b/src/RenderDevice/Vulkan/VKDeviceTexture.cpp index b09cfdef..6733fb6f 100644 --- a/src/RenderDevice/Vulkan/VKDeviceTexture.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceTexture.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -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 diff --git a/src/RenderDevice/Vulkan/VKSampler.cpp b/src/RenderDevice/Vulkan/VKSampler.cpp new file mode 100644 index 00000000..513e118c --- /dev/null +++ b/src/RenderDevice/Vulkan/VKSampler.cpp @@ -0,0 +1,7 @@ +#include +VK_NAMESPACE_BEGIN +Sampler::~Sampler() +{ + vkDestroySampler(device,sampler,nullptr); +} +VK_NAMESPACE_END