diff --git a/inc/hgl/graph/vulkan/VK.h b/inc/hgl/graph/vulkan/VK.h index b2f08098..2c8888fa 100644 --- a/inc/hgl/graph/vulkan/VK.h +++ b/inc/hgl/graph/vulkan/VK.h @@ -63,20 +63,6 @@ enum class ShaderType Compute =VK_SHADER_STAGE_COMPUTE_BIT };// -struct PushConstant256 -{ - Matrix4f projection; - Matrix4f modelview; - Matrix4f mvp; - Matrix3f normal; -};// - -struct PushConstant128 -{ - Matrix4f projection; - Matrix4f modelview; -};// - #ifdef _DEBUG bool CheckStrideBytesByFormat(); ///<检验所有数据类型长度数组是否符合规则 #endif//_DEBUG diff --git a/inc/hgl/graph/vulkan/VKCommandBuffer.h b/inc/hgl/graph/vulkan/VKCommandBuffer.h index 25a84301..7071e9ef 100644 --- a/inc/hgl/graph/vulkan/VKCommandBuffer.h +++ b/inc/hgl/graph/vulkan/VKCommandBuffer.h @@ -5,6 +5,23 @@ #include #include VK_NAMESPACE_BEGIN +//push constant 一般只有128/256字节,仅能存在矩阵。 +//所以我们将每个对象的独立变换矩阵存在push constant中 + +struct PushConstant256 +{ + Matrix4f projection; + Matrix4f modelview; + Matrix4f mvp; + Matrix3f normal; +};// + +struct PushConstant128 +{ + Matrix4f projection; + Matrix4f modelview; +};// + class CommandBuffer { VkDevice device; @@ -95,6 +112,9 @@ public: vkCmdPushConstants(cmd_buf,pipeline_layout,(VkShaderStageFlagBits)shader_type,offset,size,pValues); } + void PushConstants(const PushConstant256 *pc){vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0,sizeof(PushConstant256),pc);} + void PushConstants(const PushConstant128 *pc){vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0,sizeof(PushConstant128),pc);} + bool Bind(Renderable *); void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}