2019-04-09 02:02:43 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
|
|
|
|
|
2019-05-07 12:46:25 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VK.h>
|
2019-04-09 02:02:43 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-18 22:10:24 +08:00
|
|
|
|
class CommandBuffer
|
|
|
|
|
{
|
|
|
|
|
VkDevice device;
|
|
|
|
|
VkCommandPool pool;
|
|
|
|
|
VkCommandBuffer cmd_buf;
|
2019-04-16 13:21:21 +08:00
|
|
|
|
|
2019-04-18 22:10:24 +08:00
|
|
|
|
VkClearValue clear_values[2];
|
|
|
|
|
VkRect2D render_area;
|
2019-04-20 16:11:39 +08:00
|
|
|
|
VkViewport viewport;
|
2019-04-16 13:21:21 +08:00
|
|
|
|
|
2019-04-18 22:10:24 +08:00
|
|
|
|
public:
|
2019-04-16 13:21:21 +08:00
|
|
|
|
|
2019-04-20 02:28:57 +08:00
|
|
|
|
CommandBuffer(VkDevice dev,const VkExtent2D &extent,VkCommandPool cp,VkCommandBuffer cb);
|
2019-04-18 22:10:24 +08:00
|
|
|
|
~CommandBuffer();
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
2019-04-19 20:23:14 +08:00
|
|
|
|
operator VkCommandBuffer(){return cmd_buf;}
|
2019-05-05 11:54:49 +08:00
|
|
|
|
operator const VkCommandBuffer()const{return cmd_buf;}
|
2019-05-18 15:41:49 +08:00
|
|
|
|
operator const VkCommandBuffer *()const{return &cmd_buf;}
|
2019-04-19 20:23:14 +08:00
|
|
|
|
|
2019-04-18 22:10:24 +08:00
|
|
|
|
void SetRenderArea(const VkRect2D &ra){render_area=ra;}
|
2019-04-19 00:46:49 +08:00
|
|
|
|
void SetClearColor(float r,float g,float b,float a=1.0f)
|
|
|
|
|
{
|
|
|
|
|
clear_values[0].color.float32[0]=r;
|
|
|
|
|
clear_values[0].color.float32[1]=g;
|
|
|
|
|
clear_values[0].color.float32[2]=b;
|
|
|
|
|
clear_values[0].color.float32[3]=a;
|
|
|
|
|
}
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
2019-04-19 00:46:49 +08:00
|
|
|
|
void SetClearDepthStencil(float d=1.0f,float s=0)
|
|
|
|
|
{
|
|
|
|
|
clear_values[1].depthStencil.depth=d;
|
|
|
|
|
clear_values[1].depthStencil.stencil=s;
|
|
|
|
|
}
|
2019-04-25 11:42:00 +08:00
|
|
|
|
|
2019-04-25 11:44:22 +08:00
|
|
|
|
//以上设定在Begin开始后即不可改变
|
|
|
|
|
|
2019-04-29 14:53:56 +08:00
|
|
|
|
bool Begin();
|
2019-05-18 15:41:49 +08:00
|
|
|
|
|
|
|
|
|
void PipelineBarrier(
|
|
|
|
|
VkPipelineStageFlags srcStageMask,
|
|
|
|
|
VkPipelineStageFlags dstStageMask,
|
|
|
|
|
VkDependencyFlags dependencyFlags,
|
|
|
|
|
uint32_t memoryBarrierCount,
|
|
|
|
|
const VkMemoryBarrier* pMemoryBarriers,
|
|
|
|
|
uint32_t bufferMemoryBarrierCount,
|
|
|
|
|
const VkBufferMemoryBarrier* pBufferMemoryBarriers,
|
|
|
|
|
uint32_t imageMemoryBarrierCount,
|
|
|
|
|
const VkImageMemoryBarrier* pImageMemoryBarriers)
|
|
|
|
|
{
|
|
|
|
|
vkCmdPipelineBarrier(cmd_buf,srcStageMask,dstStageMask,dependencyFlags,memoryBarrierCount,pMemoryBarriers,bufferMemoryBarrierCount,pBufferMemoryBarriers,imageMemoryBarrierCount,pImageMemoryBarriers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CopyBufferToImage(
|
|
|
|
|
VkBuffer srcBuffer,
|
|
|
|
|
VkImage dstImage,
|
|
|
|
|
VkImageLayout dstImageLayout,
|
|
|
|
|
uint32_t regionCount,
|
|
|
|
|
const VkBufferImageCopy* pRegions)
|
|
|
|
|
{
|
|
|
|
|
vkCmdCopyBufferToImage(cmd_buf,srcBuffer,dstImage,dstImageLayout,regionCount,pRegions);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 14:53:56 +08:00
|
|
|
|
bool BeginRenderPass(RenderPass *rp,Framebuffer *fb);
|
2019-04-25 11:42:00 +08:00
|
|
|
|
bool Bind(Pipeline *p);
|
2019-05-20 17:52:23 +08:00
|
|
|
|
bool Bind(DescriptorSets *);
|
2019-04-28 17:02:38 +08:00
|
|
|
|
bool Bind(Renderable *);
|
2019-04-29 14:53:56 +08:00
|
|
|
|
void EndRenderPass();
|
2019-04-25 11:42:00 +08:00
|
|
|
|
bool End();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2019-04-25 11:38:57 +08:00
|
|
|
|
void SetDepthBias(float constant_factor,float clamp,float slope_factor);
|
|
|
|
|
void SetDepthBounds(float min_db,float max_db);
|
|
|
|
|
void SetStencilCompareMask(VkStencilFaceFlags faceMask,uint32_t compareMask);
|
|
|
|
|
void SetStencilWriteMask(VkStencilFaceFlags faceMask,uint32_t compareMask);
|
|
|
|
|
void SetStencilReference(VkStencilFaceFlags faceMask,uint32_t compareMask);
|
|
|
|
|
|
|
|
|
|
void SetBlendConstants(const float constants[4]);
|
|
|
|
|
|
|
|
|
|
void SetLineWidth(float);
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-25 11:42:00 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2019-04-19 00:46:49 +08:00
|
|
|
|
void Draw(const uint32_t vertex_count);
|
|
|
|
|
void Draw(const uint32_t vertex_count,const uint32_t instance_count,const uint32_t first_vertex=0,const uint32_t first_instance=0);
|
2019-04-25 14:10:18 +08:00
|
|
|
|
void DrawIndexed(const uint32_t index_count);
|
|
|
|
|
void DrawIndexed(const uint32_t index_count,const uint32_t instance_count,const uint32_t first_index=0,const uint32_t vertex_offset=0,const uint32_t first_instance=0);
|
2019-04-18 22:10:24 +08:00
|
|
|
|
};//class CommandBuffer
|
2019-04-09 02:02:43 +08:00
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|