1616#include " impeller/renderer/formats.h"
1717#include " impeller/renderer/pipeline_library.h"
1818#include " impeller/renderer/render_pass.h"
19+ #include " impeller/renderer/sampler_library.h"
1920#include " impeller/renderer/shader_function.h"
2021#include " impeller/renderer/shader_types.h"
2122
@@ -31,6 +32,11 @@ void RuntimeEffectContents::SetUniformData(
3132 uniform_data_ = std::move (uniform_data);
3233}
3334
35+ void RuntimeEffectContents::SetTextureInputs (
36+ std::vector<TextureInput> texture_inputs) {
37+ texture_inputs_ = std::move (texture_inputs);
38+ }
39+
3440bool RuntimeEffectContents::Render (const ContentContext& renderer,
3541 const Entity& entity,
3642 RenderPass& pass) const {
@@ -136,21 +142,59 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
136142 // /
137143
138144 size_t buffer_index = 0 ;
145+ size_t sampler_index = 0 ;
139146 for (auto uniform : runtime_stage_->GetUniforms ()) {
140147 // TODO(113715): Populate this metadata once GLES is able to handle
141148 // non-struct uniform names.
142149 ShaderMetadata metadata;
143150
144- size_t alignment =
145- std::max (uniform.bit_width / 8 , DefaultUniformAlignment ());
146- auto buffer_view = pass.GetTransientsBuffer ().Emplace (
147- uniform_data_->data () + uniform.location * sizeof (float ),
148- uniform.GetSize (), alignment);
149-
150- ShaderUniformSlot slot;
151- slot.name = uniform.name .c_str ();
152- slot.ext_res_0 = buffer_index;
153- cmd.BindResource (ShaderStage::kFragment , slot, metadata, buffer_view);
151+ switch (uniform.type ) {
152+ case kSampledImage : {
153+ FML_DCHECK (sampler_index < texture_inputs_.size ());
154+ auto & input = texture_inputs_[sampler_index];
155+
156+ auto sampler =
157+ context->GetSamplerLibrary ()->GetSampler (input.sampler_descriptor );
158+
159+ SampledImageSlot image_slot;
160+ image_slot.name = uniform.name .c_str ();
161+ image_slot.texture_index = sampler_index;
162+ image_slot.sampler_index = sampler_index;
163+ cmd.BindResource (ShaderStage::kFragment , image_slot, metadata,
164+ input.texture , sampler);
165+
166+ sampler_index++;
167+ break ;
168+ }
169+ case kFloat : {
170+ size_t alignment =
171+ std::max (uniform.bit_width / 8 , DefaultUniformAlignment ());
172+ auto buffer_view = pass.GetTransientsBuffer ().Emplace (
173+ uniform_data_->data () + uniform.location * sizeof (float ),
174+ uniform.GetSize (), alignment);
175+
176+ ShaderUniformSlot uniform_slot;
177+ uniform_slot.name = uniform.name .c_str ();
178+ uniform_slot.ext_res_0 = buffer_index;
179+ cmd.BindResource (ShaderStage::kFragment , uniform_slot, metadata,
180+ buffer_view);
181+ break ;
182+ }
183+ case kBoolean :
184+ case kSignedByte :
185+ case kUnsignedByte :
186+ case kSignedShort :
187+ case kUnsignedShort :
188+ case kSignedInt :
189+ case kUnsignedInt :
190+ case kSignedInt64 :
191+ case kUnsignedInt64 :
192+ case kHalfFloat :
193+ case kDouble :
194+ VALIDATION_LOG << " Unsupported uniform type for " << uniform.name
195+ << " ." ;
196+ return true ;
197+ }
154198
155199 buffer_index++;
156200 }
0 commit comments