3030namespace vkb
3131{
3232class RenderTarget ;
33- class ShaderSource ;
3433
3534namespace core
3635{
@@ -83,12 +82,12 @@ class Subpass
8382 using ResolveModeFlagBitsType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::ResolveModeFlagBits, VkResolveModeFlagBits>::type;
8483 using SampleCountflagBitsType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::SampleCountFlagBits, VkSampleCountFlagBits>::type;
8584
86- using DepthStencilStateType =
87- typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::rendering::HPPDepthStencilState , vkb::DepthStencilState >::type;
88- using RenderTargetType = typename std::conditional<bindingType == vkb:: BindingType::Cpp, vkb::rendering::HPPRenderTarget , vkb::RenderTarget >::type;
85+ using DepthStencilStateType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::rendering::HPPDepthStencilState, vkb::DepthStencilState>::type;
86+ using RenderTargetType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::rendering::HPPRenderTarget , vkb::RenderTarget >::type;
87+ using ShaderSourceType = typename std::conditional<bindingType == BindingType::Cpp, vkb::core::HPPShaderSource , vkb::ShaderSource >::type;
8988
9089 public:
91- Subpass (vkb::rendering::RenderContext<bindingType> &render_context, ShaderSource &&vertex_shader, ShaderSource &&fragment_shader);
90+ Subpass (vkb::rendering::RenderContext<bindingType> &render_context, ShaderSourceType &&vertex_shader, ShaderSourceType &&fragment_shader);
9291
9392 Subpass (const Subpass &) = delete ;
9493 Subpass (Subpass &&) = default ;
@@ -124,14 +123,14 @@ class Subpass
124123 ResolveModeFlagBitsType get_depth_stencil_resolve_mode () const ;
125124 DepthStencilStateType &get_depth_stencil_state ();
126125 const bool &get_disable_depth_stencil_attachment () const ;
127- const ShaderSource &get_fragment_shader () const ;
126+ const ShaderSourceType &get_fragment_shader () const ;
128127 const std::vector<uint32_t > &get_input_attachments () const ;
129128 LightingState<bindingType> &get_lighting_state ();
130129 const std::vector<uint32_t > &get_output_attachments () const ;
131130 RenderContext<bindingType> &get_render_context ();
132131 std::unordered_map<std::string, ShaderResourceMode> const &get_resource_mode_map () const ;
133132 SampleCountflagBitsType get_sample_count () const ;
134- const ShaderSource &get_vertex_shader () const ;
133+ const ShaderSourceType &get_vertex_shader () const ;
135134 void set_color_resolve_attachments (std::vector<uint32_t > const &color_resolve);
136135 void set_debug_name (const std::string &name);
137136 void set_disable_depth_stencil_attachment (bool disable_depth_stencil);
@@ -148,6 +147,14 @@ class Subpass
148147 */
149148 void update_render_target_attachments (RenderTargetType &render_target);
150149
150+ protected:
151+ vkb::rendering::HPPDepthStencilState get_depth_stencil_state_impl () const ;
152+ vkb::core::HPPShaderSource const &get_fragment_shader_impl () const ;
153+ LightingStateCpp &get_lighting_state_impl ();
154+ vk::SampleCountFlagBits get_sample_count_impl () const ;
155+ vkb::rendering::RenderContextCpp &get_render_context_impl ();
156+ vkb::core::HPPShaderSource const &get_vertex_shader_impl () const ;
157+
151158 private:
152159 // / Default to no color resolve attachments
153160 std::vector<uint32_t > color_resolve_attachments = {};
@@ -175,7 +182,7 @@ class Subpass
175182 // / The structure containing all the requested render-ready lights for the scene
176183 LightingStateCpp lighting_state{};
177184
178- ShaderSource fragment_shader;
185+ vkb::core::HPPShaderSource fragment_shader;
179186
180187 // / Default to no input attachments
181188 std::vector<uint32_t > input_attachments = {};
@@ -188,8 +195,8 @@ class Subpass
188195 // A map of shader resource names and the mode of constant data
189196 std::unordered_map<std::string, ShaderResourceMode> resource_mode_map;
190197
191- vk::SampleCountFlagBits sample_count{vk::SampleCountFlagBits::e1 };
192- ShaderSource vertex_shader;
198+ vk::SampleCountFlagBits sample_count{vk::SampleCountFlagBits::e1 };
199+ vkb::core::HPPShaderSource vertex_shader;
193200};
194201
195202using SubpassC = Subpass<vkb::BindingType::C>;
@@ -206,12 +213,20 @@ inline glm::mat4 vulkan_style_projection(const glm::mat4 &proj)
206213
207214template <vkb::BindingType bindingType>
208215inline Subpass<bindingType>::Subpass(vkb::rendering::RenderContext<bindingType> &render_context,
209- ShaderSource &&vertex_source,
210- ShaderSource &&fragment_source) :
211- render_context{reinterpret_cast <vkb::rendering::RenderContextCpp &>(render_context)},
212- vertex_shader{std::move (vertex_source)},
213- fragment_shader{std::move (fragment_source)}
216+ ShaderSourceType &&vertex_source,
217+ ShaderSourceType &&fragment_source) :
218+ render_context{reinterpret_cast <vkb::rendering::RenderContextCpp &>(render_context)}
214219{
220+ if constexpr (bindingType == vkb::BindingType::Cpp)
221+ {
222+ vertex_shader = std::move (vertex_source);
223+ fragment_shader = std::move (fragment_source);
224+ }
225+ else
226+ {
227+ vertex_shader = std::move (reinterpret_cast <vkb::core::HPPShaderSource &&>(vertex_source));
228+ fragment_shader = std::move (reinterpret_cast <vkb::core::HPPShaderSource &&>(fragment_source));
229+ }
215230}
216231
217232template <vkb::BindingType bindingType>
@@ -263,18 +278,25 @@ inline typename Subpass<bindingType>::SampleCountflagBitsType Subpass<bindingTyp
263278{
264279 if constexpr (bindingType == vkb::BindingType::Cpp)
265280 {
266- return sample_count ;
281+ return get_sample_count_impl () ;
267282 }
268283 else
269284 {
270- return static_cast <VkSampleCountFlagBits>(sample_count );
285+ return static_cast <VkSampleCountFlagBits>(get_sample_count_impl () );
271286 }
272287}
273288
274289template <vkb::BindingType bindingType>
275- inline const ShaderSource &Subpass<bindingType>::get_vertex_shader() const
290+ inline const typename Subpass<bindingType>::ShaderSourceType &Subpass<bindingType>::get_vertex_shader() const
276291{
277- return vertex_shader;
292+ if constexpr (bindingType == vkb::BindingType::Cpp)
293+ {
294+ return get_vertex_shader_impl ();
295+ }
296+ else
297+ {
298+ return reinterpret_cast <vkb::ShaderSource const &>(get_vertex_shader_impl ());
299+ }
278300}
279301
280302template <vkb::BindingType bindingType>
@@ -402,9 +424,16 @@ inline const bool &Subpass<bindingType>::get_disable_depth_stencil_attachment()
402424}
403425
404426template <vkb::BindingType bindingType>
405- inline const ShaderSource &Subpass<bindingType>::get_fragment_shader() const
427+ inline const typename Subpass<bindingType>::ShaderSourceType &Subpass<bindingType>::get_fragment_shader() const
406428{
407- return fragment_shader;
429+ if constexpr (bindingType == vkb::BindingType::Cpp)
430+ {
431+ return get_fragment_shader_impl ();
432+ }
433+ else
434+ {
435+ return reinterpret_cast <vkb::ShaderSource const &>(get_fragment_shader_impl ());
436+ }
408437}
409438
410439template <vkb::BindingType bindingType>
@@ -475,5 +504,42 @@ inline void Subpass<bindingType>::update_render_target_attachments(RenderTargetT
475504 render_target.set_input_attachments (input_attachments);
476505 render_target.set_output_attachments (output_attachments);
477506}
507+
508+ template <vkb::BindingType bindingType>
509+ inline vkb::core::HPPShaderSource const &Subpass<bindingType>::get_fragment_shader_impl() const
510+ {
511+ return fragment_shader;
512+ }
513+
514+ template <vkb::BindingType bindingType>
515+ inline vk::SampleCountFlagBits Subpass<bindingType>::get_sample_count_impl() const
516+ {
517+ return sample_count;
518+ }
519+
520+ template <vkb::BindingType bindingType>
521+ inline vkb::rendering::HPPDepthStencilState Subpass<bindingType>::get_depth_stencil_state_impl() const
522+ {
523+ return depth_stencil_state;
524+ }
525+
526+ template <vkb::BindingType bindingType>
527+ inline LightingStateCpp &Subpass<bindingType>::get_lighting_state_impl()
528+ {
529+ return lighting_state;
530+ }
531+
532+ template <vkb::BindingType bindingType>
533+ inline vkb::rendering::RenderContextCpp &Subpass<bindingType>::get_render_context_impl()
534+ {
535+ return render_context;
536+ }
537+
538+ template <vkb::BindingType bindingType>
539+ inline vkb::core::HPPShaderSource const &Subpass<bindingType>::get_vertex_shader_impl() const
540+ {
541+ return vertex_shader;
542+ }
543+
478544} // namespace rendering
479545} // namespace vkb
0 commit comments