Write default uniforms in UBO before the properties in the uniform map 04/254804/1
authorRichard Huang <r.huang@samsung.com>
Tue, 9 Mar 2021 10:37:18 +0000 (10:37 +0000)
committerRichard Huang <r.huang@samsung.com>
Tue, 9 Mar 2021 10:37:18 +0000 (10:37 +0000)
Change-Id: I331991bd521ade1f8daad4c690e98a20cc56e18b

dali/internal/render/renderers/render-renderer.cpp

index 182425670669a605ffa70c6aa064721572c79267..2915ad5fcc2babc3da04290bf5141932e6f4235f 100644 (file)
@@ -889,22 +889,13 @@ void Renderer::Render(Context&                                             conte
     auto ubo = mUniformBuffer[bufferIndex].get();
     if(ubo)
     {
-      std::vector<Graphics::UniformBufferBinding>* bindings{nullptr};
-      FillUniformBuffers(*program, instruction, *ubo, bindings, uboOffset, bufferIndex);
+      auto& reflection = mGraphicsController->GetProgramReflection(program->GetGraphicsProgram());
+      auto  uboCount   = reflection.GetUniformBlockCount();
+      mUniformBufferBindings.resize(uboCount);
 
-      Vector4        finalColor;
-      const Vector4& color = node.GetRenderColor(bufferIndex);
-      if(mPremultipledAlphaEnabled)
-      {
-        float alpha = color.a * mRenderDataProvider->GetOpacity(bufferIndex);
-        finalColor  = Vector4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);
-      }
-      else
-      {
-        finalColor = Vector4(color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity(bufferIndex));
-      }
+      std::vector<Graphics::UniformBufferBinding>* bindings{&mUniformBufferBindings};
 
-      // We know bindings for this renderer, so we can use 'offset' and write additional uniforms
+      // Write default uniforms
       Matrix modelViewProjectionMatrix(false);
       Matrix::Multiply(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix);
 
@@ -913,8 +904,6 @@ void Renderer::Render(Context&                                             conte
       WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::PROJECTION_MATRIX), *ubo, *bindings, projectionMatrix);
       WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MVP_MATRIX), *ubo, *bindings, modelViewProjectionMatrix);
       WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MODEL_VIEW_MATRIX), *ubo, *bindings, modelViewMatrix);
-      WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::SIZE), *ubo, *bindings, size);
-      WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::COLOR), *ubo, *bindings, finalColor);
 
       // Update normal matrix only when used in the shader
       Matrix3 normalMatrix(modelViewMatrix);
@@ -922,6 +911,25 @@ void Renderer::Render(Context&                                             conte
       normalMatrix.Transpose();
       WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::NORMAL_MATRIX), *ubo, *bindings, normalMatrix);
 
+      Vector4        finalColor;
+      const Vector4& color = node.GetRenderColor(bufferIndex);
+      if(mPremultipledAlphaEnabled)
+      {
+        float alpha = color.a * mRenderDataProvider->GetOpacity(bufferIndex);
+        finalColor  = Vector4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);
+      }
+      else
+      {
+        finalColor = Vector4(color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity(bufferIndex));
+      }
+      WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::COLOR), *ubo, *bindings, finalColor);
+
+      // Write uniforms from the uniform map
+      FillUniformBuffers(*program, instruction, *ubo, bindings, uboOffset, bufferIndex);
+
+      // Write uSize in the end, as it shouldn't be overridable by dynamic properties.
+      WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::SIZE), *ubo, *bindings, size);
+
       commandBuffer->BindUniformBuffers(*bindings);
     }
 
@@ -990,8 +998,6 @@ void Renderer::FillUniformBuffers(Program&
   auto& reflection = mGraphicsController->GetProgramReflection(program.GetGraphicsProgram());
   auto  uboCount   = reflection.GetUniformBlockCount();
 
-  mUniformBufferBindings.resize(uboCount);
-
   // Setup bindings
   uint32_t dataOffset = offset;
   for(auto i = 0u; i < uboCount; ++i)