@@ -155,11 +155,15 @@ bool BufferBindingsGLES::BindUniformData(const ProcTableGLES& gl,
155155 }
156156 }
157157
158- if (!BindTextures (gl, vertex_bindings, ShaderStage::kVertex )) {
158+ std::optional<size_t > next_unit_index =
159+ BindTextures (gl, vertex_bindings, ShaderStage::kVertex );
160+ if (!next_unit_index.has_value ()) {
159161 return false ;
160162 }
161163
162- if (!BindTextures (gl, fragment_bindings, ShaderStage::kFragment )) {
164+ if (!BindTextures (gl, fragment_bindings, ShaderStage::kFragment ,
165+ *next_unit_index)
166+ .has_value ()) {
163167 return false ;
164168 }
165169
@@ -334,20 +338,22 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
334338 return true ;
335339}
336340
337- bool BufferBindingsGLES::BindTextures (const ProcTableGLES& gl,
338- const Bindings& bindings,
339- ShaderStage stage) {
340- size_t active_index = 0 ;
341+ std::optional<size_t > BufferBindingsGLES::BindTextures (
342+ const ProcTableGLES& gl,
343+ const Bindings& bindings,
344+ ShaderStage stage,
345+ size_t unit_start_index) {
346+ size_t active_index = unit_start_index;
341347 for (const auto & data : bindings.sampled_images ) {
342348 const auto & texture_gles = TextureGLES::Cast (*data.second .texture .resource );
343349 if (data.second .texture .GetMetadata () == nullptr ) {
344350 VALIDATION_LOG << " No metadata found for texture binding." ;
345- return false ;
351+ return std:: nullopt ;
346352 }
347353
348354 auto location = ComputeTextureLocation (data.second .texture .GetMetadata ());
349355 if (location == -1 ) {
350- return false ;
356+ return std:: nullopt ;
351357 }
352358
353359 // --------------------------------------------------------------------------
@@ -356,15 +362,15 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
356362 if (active_index >= gl.GetCapabilities ()->GetMaxTextureUnits (stage)) {
357363 VALIDATION_LOG << " Texture units specified exceed the capabilities for "
358364 " this shader stage." ;
359- return false ;
365+ return std:: nullopt ;
360366 }
361367 gl.ActiveTexture (GL_TEXTURE0 + active_index);
362368
363369 // --------------------------------------------------------------------------
364370 // / Bind the texture.
365371 // /
366372 if (!texture_gles.Bind ()) {
367- return false ;
373+ return std:: nullopt ;
368374 }
369375
370376 // --------------------------------------------------------------------------
@@ -373,7 +379,7 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
373379 // /
374380 const auto & sampler_gles = SamplerGLES::Cast (*data.second .sampler .resource );
375381 if (!sampler_gles.ConfigureBoundTexture (texture_gles, gl)) {
376- return false ;
382+ return std:: nullopt ;
377383 }
378384
379385 // --------------------------------------------------------------------------
@@ -386,7 +392,7 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
386392 // /
387393 active_index++;
388394 }
389- return true ;
395+ return active_index ;
390396}
391397
392398} // namespace impeller
0 commit comments