MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ bind_texture() [2/2]

void MayaFlux::Buffers::RenderProcessor::bind_texture ( uint32_t  binding,
const std::shared_ptr< Core::VKImage > &  texture,
vk::Sampler  sampler = nullptr 
)

Bind a texture to a descriptor binding point.

Parameters
bindingBinding index (matches shader layout(binding = N))
textureVKImage texture to bind
samplerOptional sampler (uses default linear if null)

Definition at line 189 of file RenderProcessor.cpp.

193{
194 if (!texture || !texture->is_initialized() || !texture->get_image_view()) {
196 "Cannot bind null texture to binding {}", binding);
197 return;
198 }
199
200 if (!sampler) {
202 sampler = loom.get_default_sampler();
203 }
204
205 m_texture_bindings[binding] = { .texture = texture, .sampler = sampler };
207
209
210 auto& foundry = Portal::Graphics::get_shader_foundry();
211 auto cfg_it = std::ranges::find_if(m_config.bindings,
212 [binding](const auto& pair) {
213 return binding >= pair.second.binding
214 && binding < pair.second.binding + pair.second.count;
215 });
216
217 if (cfg_it != m_config.bindings.end() && !m_descriptor_set_ids.empty()) {
218 const uint32_t cfg_set = cfg_it->second.set;
219 if (cfg_set == 0) {
221 uint32_t array_idx = 0;
222 if (cfg_it->second.count > 1 && binding >= cfg_it->second.binding) {
223 array_idx = binding - cfg_it->second.binding;
224 }
225 foundry.update_descriptor_image(
227 cfg_it->second.binding,
228 texture->get_image_view(),
229 sampler,
230 vk::ImageLayout::eShaderReadOnlyOptimal,
231 array_idx);
232 }
233 } else {
234 auto ds_index = resolve_ds_index(cfg_set);
235 if (ds_index && *ds_index < m_descriptor_set_ids.size()) {
236 foundry.update_descriptor_image(
237 m_descriptor_set_ids[*ds_index],
238 cfg_it->second.binding,
239 texture->get_image_view(),
240 sampler,
241 vk::ImageLayout::eShaderReadOnlyOptimal);
242 }
243 }
244 }
245 }
246
248 "Bound texture to binding {}", binding);
249}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Portal::Graphics::RenderPipelineID m_pipeline_id
std::unordered_map< uint32_t, TextureBinding > m_texture_bindings
Portal::Graphics::DescriptorSetID m_render_transform_descriptor_set_id
std::optional< uint32_t > resolve_ds_index(uint32_t set) const
Resolve logical descriptor set index to actual index.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr RenderPipelineID INVALID_RENDER_PIPELINE
MAYAFLUX_API TextureLoom & get_texture_manager()
Get the global texture manager instance.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr DescriptorSetID INVALID_DESCRIPTOR_SET
std::unordered_map< std::string, ShaderBinding > bindings

References MayaFlux::Buffers::ShaderConfig::bindings, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::get_texture_manager(), MayaFlux::Portal::Graphics::INVALID_DESCRIPTOR_SET, MayaFlux::Portal::Graphics::INVALID_RENDER_PIPELINE, MayaFlux::Buffers::ShaderProcessor::m_config, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, MayaFlux::Buffers::ShaderProcessor::m_needs_descriptor_rebuild, m_pipeline_id, m_render_transform_descriptor_set_id, m_texture_bindings, MF_DEBUG, MF_ERROR, and MayaFlux::Buffers::ShaderProcessor::resolve_ds_index().

Referenced by bind_texture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: