2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/render/renderers/render-renderer.h>
22 #include <dali/graphics-api/graphics-types.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/internal/common/image-sampler.h>
25 #include <dali/internal/render/common/render-instruction.h>
26 #include <dali/internal/render/data-providers/node-data-provider.h>
27 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
28 #include <dali/internal/render/renderers/pipeline-cache.h>
29 #include <dali/internal/render/renderers/render-sampler.h>
30 #include <dali/internal/render/renderers/render-texture.h>
31 #include <dali/internal/render/renderers/render-vertex-buffer.h>
32 #include <dali/internal/render/renderers/shader-cache.h>
33 #include <dali/internal/render/renderers/uniform-buffer-view-pool.h>
34 #include <dali/internal/render/renderers/uniform-buffer-view.h>
35 #include <dali/internal/render/shaders/program.h>
36 #include <dali/internal/render/shaders/render-shader.h>
37 #include <dali/internal/update/common/uniform-map.h>
38 #include <dali/public-api/signals/render-callback.h>
40 namespace Dali::Internal
44 // Helper to get the property value getter by type
45 typedef const float& (PropertyInputImpl::*FuncGetter)(BufferIndex) const;
46 constexpr FuncGetter GetPropertyValueGetter(Property::Type type)
50 case Property::BOOLEAN:
52 return FuncGetter(&PropertyInputImpl::GetBoolean);
54 case Property::INTEGER:
56 return FuncGetter(&PropertyInputImpl::GetInteger);
60 return FuncGetter(&PropertyInputImpl::GetFloat);
62 case Property::VECTOR2:
64 return FuncGetter(&PropertyInputImpl::GetVector2);
66 case Property::VECTOR3:
68 return FuncGetter(&PropertyInputImpl::GetVector3);
70 case Property::VECTOR4:
72 return FuncGetter(&PropertyInputImpl::GetVector4);
74 case Property::MATRIX3:
76 return FuncGetter(&PropertyInputImpl::GetMatrix3);
78 case Property::MATRIX:
80 return FuncGetter(&PropertyInputImpl::GetMatrix);
90 * Helper function that returns size of uniform datatypes based
93 constexpr int GetPropertyValueSizeForUniform(Property::Type type)
97 case Property::Type::BOOLEAN:
101 case Property::Type::FLOAT:
103 return sizeof(float);
105 case Property::Type::INTEGER:
109 case Property::Type::VECTOR2:
111 return sizeof(Vector2);
113 case Property::Type::VECTOR3:
115 return sizeof(Vector3);
117 case Property::Type::VECTOR4:
119 return sizeof(Vector4);
121 case Property::Type::MATRIX3:
123 return sizeof(Matrix3);
125 case Property::Type::MATRIX:
127 return sizeof(Matrix);
137 * Helper function to calculate the correct alignment of data for uniform buffers
138 * @param dataSize size of uniform buffer
139 * @return aligned offset of data
141 inline uint32_t GetUniformBufferDataAlignment(uint32_t dataSize)
143 return ((dataSize / 256u) + ((dataSize % 256u) ? 1u : 0u)) * 256u;
150 Renderer* Renderer::New(SceneGraph::RenderDataProvider* dataProvider,
151 Render::Geometry* geometry,
152 uint32_t blendingBitmask,
153 const Vector4& blendColor,
154 FaceCullingMode::Type faceCullingMode,
155 bool preMultipliedAlphaEnabled,
156 DepthWriteMode::Type depthWriteMode,
157 DepthTestMode::Type depthTestMode,
158 DepthFunction::Type depthFunction,
159 StencilParameters& stencilParameters)
161 return new Renderer(dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction, stencilParameters);
164 Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider,
165 Render::Geometry* geometry,
166 uint32_t blendingBitmask,
167 const Vector4& blendColor,
168 FaceCullingMode::Type faceCullingMode,
169 bool preMultipliedAlphaEnabled,
170 DepthWriteMode::Type depthWriteMode,
171 DepthTestMode::Type depthTestMode,
172 DepthFunction::Type depthFunction,
173 StencilParameters& stencilParameters)
174 : mGraphicsController(nullptr),
175 mRenderDataProvider(dataProvider),
177 mProgramCache(nullptr),
180 mStencilParameters(stencilParameters),
182 mIndexedDrawFirstElement(0),
183 mIndexedDrawElementsCount(0),
184 mDepthFunction(depthFunction),
185 mFaceCullingMode(faceCullingMode),
186 mDepthWriteMode(depthWriteMode),
187 mDepthTestMode(depthTestMode),
188 mPremultipliedAlphaEnabled(preMultipliedAlphaEnabled),
189 mShaderChanged(false),
192 if(blendingBitmask != 0u)
194 mBlendingOptions.SetBitmask(blendingBitmask);
197 mBlendingOptions.SetBlendColor(blendColor);
200 void Renderer::Initialize(Graphics::Controller& graphicsController, ProgramCache& programCache, Render::ShaderCache& shaderCache, Render::UniformBufferManager& uniformBufferManager, Render::PipelineCache& pipelineCache)
202 mGraphicsController = &graphicsController;
203 mProgramCache = &programCache;
204 mShaderCache = &shaderCache;
205 mUniformBufferManager = &uniformBufferManager;
206 mPipelineCache = &pipelineCache;
209 Renderer::~Renderer() = default;
211 void Renderer::SetGeometry(Render::Geometry* geometry)
213 mGeometry = geometry;
216 void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size)
218 mDrawCommands.clear();
219 mDrawCommands.insert(mDrawCommands.end(), pDrawCommands, pDrawCommands + size);
222 void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graphics::Texture*>& boundTextures)
224 uint32_t textureUnit = 0;
226 const Dali::Vector<Render::Texture*>* textures(mRenderDataProvider->GetTextures());
227 const Dali::Vector<Render::Sampler*>* samplers(mRenderDataProvider->GetSamplers());
229 std::vector<Graphics::TextureBinding> textureBindings;
231 if(textures != nullptr)
233 const std::uint32_t texturesCount(static_cast<std::uint32_t>(textures->Count()));
234 textureBindings.reserve(texturesCount);
236 for(uint32_t i = 0; i < texturesCount; ++i) // not expecting more than uint32_t of textures
238 if((*textures)[i] && (*textures)[i]->GetGraphicsObject())
240 Graphics::Texture* graphicsTexture = (*textures)[i]->GetGraphicsObject();
241 // if the sampler exists,
242 // if it's default, delete the graphics object
243 // otherwise re-initialize it if dirty
245 const Graphics::Sampler* graphicsSampler = samplers ? ((*samplers)[i] ? (*samplers)[i]->GetGraphicsObject()
249 boundTextures.PushBack(graphicsTexture);
250 const Graphics::TextureBinding textureBinding{graphicsTexture, graphicsSampler, textureUnit};
251 textureBindings.push_back(textureBinding);
258 if(!textureBindings.empty())
260 commandBuffer.BindTextures(textureBindings);
264 void Renderer::SetFaceCullingMode(FaceCullingMode::Type mode)
266 mFaceCullingMode = mode;
270 void Renderer::SetBlendingBitMask(uint32_t bitmask)
272 mBlendingOptions.SetBitmask(bitmask);
276 void Renderer::SetBlendColor(const Vector4& color)
278 mBlendingOptions.SetBlendColor(color);
282 void Renderer::SetIndexedDrawFirstElement(uint32_t firstElement)
284 mIndexedDrawFirstElement = firstElement;
288 void Renderer::SetIndexedDrawElementsCount(uint32_t elementsCount)
290 mIndexedDrawElementsCount = elementsCount;
294 void Renderer::EnablePreMultipliedAlpha(bool enable)
296 mPremultipliedAlphaEnabled = enable;
300 void Renderer::SetDepthWriteMode(DepthWriteMode::Type depthWriteMode)
302 mDepthWriteMode = depthWriteMode;
306 void Renderer::SetDepthTestMode(DepthTestMode::Type depthTestMode)
308 mDepthTestMode = depthTestMode;
312 DepthWriteMode::Type Renderer::GetDepthWriteMode() const
314 return mDepthWriteMode;
317 DepthTestMode::Type Renderer::GetDepthTestMode() const
319 return mDepthTestMode;
322 void Renderer::SetDepthFunction(DepthFunction::Type depthFunction)
324 mDepthFunction = depthFunction;
328 DepthFunction::Type Renderer::GetDepthFunction() const
330 return mDepthFunction;
333 void Renderer::SetRenderMode(RenderMode::Type renderMode)
335 mStencilParameters.renderMode = renderMode;
339 RenderMode::Type Renderer::GetRenderMode() const
341 return mStencilParameters.renderMode;
344 void Renderer::SetStencilFunction(StencilFunction::Type stencilFunction)
346 mStencilParameters.stencilFunction = stencilFunction;
350 StencilFunction::Type Renderer::GetStencilFunction() const
352 return mStencilParameters.stencilFunction;
355 void Renderer::SetStencilFunctionMask(int stencilFunctionMask)
357 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
361 int Renderer::GetStencilFunctionMask() const
363 return mStencilParameters.stencilFunctionMask;
366 void Renderer::SetStencilFunctionReference(int stencilFunctionReference)
368 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
372 int Renderer::GetStencilFunctionReference() const
374 return mStencilParameters.stencilFunctionReference;
377 void Renderer::SetStencilMask(int stencilMask)
379 mStencilParameters.stencilMask = stencilMask;
383 int Renderer::GetStencilMask() const
385 return mStencilParameters.stencilMask;
388 void Renderer::SetStencilOperationOnFail(StencilOperation::Type stencilOperationOnFail)
390 mStencilParameters.stencilOperationOnFail = stencilOperationOnFail;
394 StencilOperation::Type Renderer::GetStencilOperationOnFail() const
396 return mStencilParameters.stencilOperationOnFail;
399 void Renderer::SetStencilOperationOnZFail(StencilOperation::Type stencilOperationOnZFail)
401 mStencilParameters.stencilOperationOnZFail = stencilOperationOnZFail;
405 StencilOperation::Type Renderer::GetStencilOperationOnZFail() const
407 return mStencilParameters.stencilOperationOnZFail;
410 void Renderer::SetStencilOperationOnZPass(StencilOperation::Type stencilOperationOnZPass)
412 mStencilParameters.stencilOperationOnZPass = stencilOperationOnZPass;
416 StencilOperation::Type Renderer::GetStencilOperationOnZPass() const
418 return mStencilParameters.stencilOperationOnZPass;
421 void Renderer::Upload()
423 mGeometry->Upload(*mGraphicsController);
426 bool Renderer::Render(Graphics::CommandBuffer& commandBuffer,
427 BufferIndex bufferIndex,
428 const SceneGraph::NodeDataProvider& node,
429 const Matrix& modelMatrix,
430 const Matrix& modelViewMatrix,
431 const Matrix& viewMatrix,
432 const Matrix& projectionMatrix,
435 Vector<Graphics::Texture*>& boundTextures,
436 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
439 // Before doing anything test if the call happens in the right queue
440 if(mDrawCommands.empty() && queueIndex > 0)
445 // Check if there is render callback
448 Graphics::DrawNativeInfo info{};
449 info.api = Graphics::DrawNativeAPI::GLES;
450 info.callback = &static_cast<Dali::CallbackBase&>(*mRenderCallback);
451 info.userData = &mRenderCallbackInput;
452 info.reserved = nullptr;
454 // pass render callback input
455 mRenderCallbackInput.size = size;
456 mRenderCallbackInput.projection = projectionMatrix;
457 Matrix::Multiply(mRenderCallbackInput.mvp, modelViewMatrix, projectionMatrix);
460 commandBuffer.DrawNative(&info);
465 std::vector<DevelRenderer::DrawCommand*> commands;
466 for(auto& cmd : mDrawCommands)
468 if(cmd.queue == queueIndex)
470 commands.emplace_back(&cmd);
474 // Have commands but nothing to be drawn - abort
475 if(!mDrawCommands.empty() && commands.empty())
481 if(!mDrawCommands.empty())
483 blend = (commands[0]->queue != DevelRenderer::RENDER_QUEUE_OPAQUE) && blend;
487 ShaderDataPtr shaderData = mRenderDataProvider->GetShader().GetShaderData();
489 Program* program = Program::New(*mProgramCache,
491 *mGraphicsController);
494 DALI_LOG_ERROR("Failed to get program for shader at address %p.\n", reinterpret_cast<const void*>(&mRenderDataProvider->GetShader()));
498 // If program doesn't have Gfx program object assigned yet, prepare it.
499 if(!program->GetGraphicsProgramPtr())
501 const std::vector<char>& vertShader = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::VERTEX_SHADER);
502 const std::vector<char>& fragShader = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER);
503 Dali::Graphics::Shader& vertexShader = mShaderCache->GetShader(
505 Graphics::PipelineStage::VERTEX_SHADER,
506 shaderData->GetSourceMode());
508 Dali::Graphics::Shader& fragmentShader = mShaderCache->GetShader(
510 Graphics::PipelineStage::FRAGMENT_SHADER,
511 shaderData->GetSourceMode());
513 std::vector<Graphics::ShaderState> shaderStates{
514 Graphics::ShaderState()
515 .SetShader(vertexShader)
516 .SetPipelineStage(Graphics::PipelineStage::VERTEX_SHADER),
517 Graphics::ShaderState()
518 .SetShader(fragmentShader)
519 .SetPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER)};
521 auto createInfo = Graphics::ProgramCreateInfo();
522 createInfo.SetShaderState(shaderStates);
523 auto graphicsProgram = mGraphicsController->CreateProgram(createInfo, nullptr);
524 program->SetGraphicsProgram(std::move(graphicsProgram));
527 // Prepare the graphics pipeline. This may either re-use an existing pipeline or create a new one.
528 auto& pipeline = PrepareGraphicsPipeline(*program, instruction, node, blend);
530 commandBuffer.BindPipeline(pipeline);
532 BindTextures(commandBuffer, boundTextures);
534 BuildUniformIndexMap(bufferIndex, node, size, *program);
536 WriteUniformBuffer(bufferIndex, commandBuffer, program, instruction, node, modelMatrix, modelViewMatrix, viewMatrix, projectionMatrix, size);
538 bool drawn = false; // Draw can fail if there are no vertex buffers or they haven't been uploaded yet
539 // @todo We should detect this case much earlier to prevent unnecessary work
541 if(mDrawCommands.empty())
543 drawn = mGeometry->Draw(*mGraphicsController, commandBuffer, mIndexedDrawFirstElement, mIndexedDrawElementsCount);
547 for(auto& cmd : commands)
549 mGeometry->Draw(*mGraphicsController, commandBuffer, cmd->firstIndex, cmd->elementCount);
557 void Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program)
559 // Check if the map has changed
560 DALI_ASSERT_DEBUG(mRenderDataProvider && "No Uniform map data provider available");
562 const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMapDataProvider();
564 if(uniformMapDataProvider.GetUniformMapChanged(bufferIndex) ||
565 node.GetUniformMapChanged(bufferIndex) ||
566 mUniformIndexMap.Count() == 0 ||
569 // Reset shader pointer
570 mShaderChanged = false;
572 const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap(bufferIndex);
573 const SceneGraph::CollectedUniformMap& uniformMapNode = node.GetUniformMap(bufferIndex);
575 const uint32_t mapCount = uniformMap.Count();
576 const uint32_t mapNodeCount = uniformMapNode.Count();
578 mUniformIndexMap.Clear(); // Clear contents, but keep memory if we don't change size
579 mUniformIndexMap.Resize(mapCount + mapNodeCount);
581 // Copy uniform map into mUniformIndexMap
582 uint32_t mapIndex = 0;
583 for(; mapIndex < mapCount; ++mapIndex)
585 mUniformIndexMap[mapIndex].propertyValue = uniformMap[mapIndex].propertyPtr;
586 mUniformIndexMap[mapIndex].uniformName = uniformMap[mapIndex].uniformName;
587 mUniformIndexMap[mapIndex].uniformNameHash = uniformMap[mapIndex].uniformNameHash;
588 mUniformIndexMap[mapIndex].uniformNameHashNoArray = uniformMap[mapIndex].uniformNameHashNoArray;
589 mUniformIndexMap[mapIndex].arrayIndex = uniformMap[mapIndex].arrayIndex;
592 for(uint32_t nodeMapIndex = 0; nodeMapIndex < mapNodeCount; ++nodeMapIndex)
594 auto hash = uniformMapNode[nodeMapIndex].uniformNameHash;
595 auto& name = uniformMapNode[nodeMapIndex].uniformName;
597 for(uint32_t i = 0; i < mapCount; ++i)
599 if(mUniformIndexMap[i].uniformNameHash == hash &&
600 mUniformIndexMap[i].uniformName == name)
602 mUniformIndexMap[i].propertyValue = uniformMapNode[nodeMapIndex].propertyPtr;
610 mUniformIndexMap[mapIndex].propertyValue = uniformMapNode[nodeMapIndex].propertyPtr;
611 mUniformIndexMap[mapIndex].uniformName = uniformMapNode[nodeMapIndex].uniformName;
612 mUniformIndexMap[mapIndex].uniformNameHash = uniformMapNode[nodeMapIndex].uniformNameHash;
613 mUniformIndexMap[mapIndex].uniformNameHashNoArray = uniformMapNode[nodeMapIndex].uniformNameHashNoArray;
614 mUniformIndexMap[mapIndex].arrayIndex = uniformMapNode[nodeMapIndex].arrayIndex;
619 mUniformIndexMap.Resize(mapIndex);
623 void Renderer::WriteUniformBuffer(
624 BufferIndex bufferIndex,
625 Graphics::CommandBuffer& commandBuffer,
627 const SceneGraph::RenderInstruction& instruction,
628 const SceneGraph::NodeDataProvider& node,
629 const Matrix& modelMatrix,
630 const Matrix& modelViewMatrix,
631 const Matrix& viewMatrix,
632 const Matrix& projectionMatrix,
636 uint32_t uboOffset{0u};
638 auto& reflection = mGraphicsController->GetProgramReflection(program->GetGraphicsProgram());
640 uint32_t uniformBlockAllocationBytes = program->GetUniformBlocksMemoryRequirements().totalSizeRequired;
642 // Create uniform buffer view from uniform buffer
643 Graphics::UniquePtr<Render::UniformBufferView> uboView{nullptr};
644 if(uniformBlockAllocationBytes)
646 auto uboPoolView = mUniformBufferManager->GetUniformBufferViewPool(bufferIndex);
647 uboView = uboPoolView->CreateUniformBufferView(uniformBlockAllocationBytes);
650 // update the uniform buffer
651 // pass shared UBO and offset, return new offset for next item to be used
652 // don't process bindings if there are no uniform buffers allocated
655 auto uboCount = reflection.GetUniformBlockCount();
656 mUniformBufferBindings.resize(uboCount);
658 std::vector<Graphics::UniformBufferBinding>* bindings{&mUniformBufferBindings};
660 mUniformBufferBindings[0].buffer = uboView->GetBuffer(&mUniformBufferBindings[0].offset);
662 // Write default uniforms
663 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MODEL_MATRIX), *uboView, modelMatrix);
664 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::VIEW_MATRIX), *uboView, viewMatrix);
665 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::PROJECTION_MATRIX), *uboView, projectionMatrix);
666 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MODEL_VIEW_MATRIX), *uboView, modelViewMatrix);
668 auto mvpUniformInfo = program->GetDefaultUniform(Program::DefaultUniformIndex::MVP_MATRIX);
669 if(mvpUniformInfo && !mvpUniformInfo->name.empty())
671 Matrix modelViewProjectionMatrix(false);
672 Matrix::Multiply(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix);
673 WriteDefaultUniform(mvpUniformInfo, *uboView, modelViewProjectionMatrix);
676 auto normalUniformInfo = program->GetDefaultUniform(Program::DefaultUniformIndex::NORMAL_MATRIX);
677 if(normalUniformInfo && !normalUniformInfo->name.empty())
679 Matrix3 normalMatrix(modelViewMatrix);
680 normalMatrix.Invert();
681 normalMatrix.Transpose();
682 WriteDefaultUniform(normalUniformInfo, *uboView, normalMatrix);
685 Vector4 finalColor; ///< Applied renderer's opacity color
686 const Vector4& color = node.GetRenderColor(bufferIndex); ///< Actor's original color
687 if(mPremultipliedAlphaEnabled)
689 const float& alpha = color.a * mRenderDataProvider->GetOpacity(bufferIndex);
690 finalColor = Vector4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);
694 finalColor = Vector4(color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity(bufferIndex));
696 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::COLOR), *uboView, finalColor);
697 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::ACTOR_COLOR), *uboView, color);
699 // Write uniforms from the uniform map
700 FillUniformBuffer(*program, instruction, *uboView, bindings, uboOffset, bufferIndex);
702 // Write uSize in the end, as it shouldn't be overridable by dynamic properties.
703 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::SIZE), *uboView, size);
705 commandBuffer.BindUniformBuffers(*bindings);
710 bool Renderer::WriteDefaultUniform(const Graphics::UniformInfo* uniformInfo, Render::UniformBufferView& ubo, const T& data)
712 if(uniformInfo && !uniformInfo->name.empty())
714 WriteUniform(ubo, *uniformInfo, data);
721 void Renderer::WriteUniform(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const T& data)
723 WriteUniform(ubo, uniformInfo, &data, sizeof(T));
726 void Renderer::WriteUniform(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const void* data, uint32_t size)
728 ubo.Write(data, size, ubo.GetOffset() + uniformInfo.offset);
731 void Renderer::FillUniformBuffer(Program& program,
732 const SceneGraph::RenderInstruction& instruction,
733 Render::UniformBufferView& ubo,
734 std::vector<Graphics::UniformBufferBinding>*& outBindings,
736 BufferIndex updateBufferIndex)
738 auto& reflection = mGraphicsController->GetProgramReflection(program.GetGraphicsProgram());
739 auto uboCount = reflection.GetUniformBlockCount();
742 uint32_t dataOffset = offset;
743 for(auto i = 0u; i < uboCount; ++i)
745 mUniformBufferBindings[i].dataSize = reflection.GetUniformBlockSize(i);
746 mUniformBufferBindings[i].binding = reflection.GetUniformBlockBinding(i);
748 dataOffset += GetUniformBufferDataAlignment(mUniformBufferBindings[i].dataSize);
749 mUniformBufferBindings[i].buffer = ubo.GetBuffer(&mUniformBufferBindings[i].offset);
751 for(UniformIndexMappings::Iterator iter = mUniformIndexMap.Begin(),
752 end = mUniformIndexMap.End();
756 auto& uniform = *iter;
757 int arrayIndex = uniform.arrayIndex;
759 if(!uniform.uniformFunc)
761 auto uniformInfo = Graphics::UniformInfo{};
762 auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(),
763 uniform.uniformNameHash,
764 uniform.uniformNameHashNoArray,
767 uniform.uniformOffset = uniformInfo.offset;
768 uniform.uniformLocation = uniformInfo.location;
772 auto dst = ubo.GetOffset() + uniformInfo.offset;
773 const auto typeSize = GetPropertyValueSizeForUniform((*iter).propertyValue->GetType());
774 const auto dest = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
775 const auto func = GetPropertyValueGetter((*iter).propertyValue->GetType());
777 ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
781 uniform.uniformSize = typeSize;
782 uniform.uniformFunc = func;
787 auto dst = ubo.GetOffset() + uniform.uniformOffset;
788 const auto typeSize = uniform.uniformSize;
789 const auto dest = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
790 const auto func = uniform.uniformFunc;
792 ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
798 // write output bindings
799 outBindings = &mUniformBufferBindings;
805 void Renderer::SetSortAttributes(SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const
807 sortAttributes.shader = &(mRenderDataProvider->GetShader());
808 sortAttributes.geometry = mGeometry;
811 void Renderer::SetShaderChanged(bool value)
813 mShaderChanged = value;
816 bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider* node)
824 if(mRenderCallback || mShaderChanged || mGeometry->AttributesChanged())
829 auto* textures = mRenderDataProvider->GetTextures();
832 for(auto iter = textures->Begin(), end = textures->End(); iter < end; ++iter)
834 auto texture = *iter;
835 if(texture && texture->IsNativeImage())
842 uint64_t hash = 0xc70f6907UL;
843 const SceneGraph::CollectedUniformMap& uniformMapNode = node->GetUniformMap(bufferIndex);
844 for(const auto& uniformProperty : uniformMapNode)
846 hash = uniformProperty.propertyPtr->Hash(bufferIndex, hash);
849 const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMapDataProvider();
850 const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap(bufferIndex);
851 for(const auto& uniformProperty : uniformMap)
853 hash = uniformProperty.propertyPtr->Hash(bufferIndex, hash);
856 if(mUniformsHash != hash)
858 mUniformsHash = hash;
865 Graphics::Pipeline& Renderer::PrepareGraphicsPipeline(
867 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
868 const SceneGraph::NodeDataProvider& node,
871 if(mGeometry->AttributesChanged())
876 // Prepare query info
877 PipelineCacheQueryInfo queryInfo{};
878 queryInfo.program = &program;
879 queryInfo.renderer = this;
880 queryInfo.geometry = mGeometry;
881 queryInfo.blendingEnabled = blend;
882 queryInfo.blendingOptions = &mBlendingOptions;
883 queryInfo.alphaPremultiplied = mPremultipliedAlphaEnabled;
884 queryInfo.cameraUsingReflection = instruction.GetCamera()->GetReflectionUsed();
886 auto pipelineResult = mPipelineCache->GetPipeline(queryInfo, true);
888 // should be never null?
889 return *pipelineResult.pipeline;
892 void Renderer::SetRenderCallback(RenderCallback* callback)
894 mRenderCallback = callback;
897 } // namespace Render
899 } // namespace Dali::Internal