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>
39 namespace Dali::Internal
43 // Helper to get the property value getter by type
44 typedef const float& (PropertyInputImpl::*FuncGetter)(BufferIndex) const;
45 constexpr FuncGetter GetPropertyValueGetter(Property::Type type)
49 case Property::BOOLEAN:
51 return FuncGetter(&PropertyInputImpl::GetBoolean);
53 case Property::INTEGER:
55 return FuncGetter(&PropertyInputImpl::GetInteger);
59 return FuncGetter(&PropertyInputImpl::GetFloat);
61 case Property::VECTOR2:
63 return FuncGetter(&PropertyInputImpl::GetVector2);
65 case Property::VECTOR3:
67 return FuncGetter(&PropertyInputImpl::GetVector3);
69 case Property::VECTOR4:
71 return FuncGetter(&PropertyInputImpl::GetVector4);
73 case Property::MATRIX3:
75 return FuncGetter(&PropertyInputImpl::GetMatrix3);
77 case Property::MATRIX:
79 return FuncGetter(&PropertyInputImpl::GetMatrix);
89 * Helper function that returns size of uniform datatypes based
92 constexpr int GetPropertyValueSizeForUniform(Property::Type type)
96 case Property::Type::BOOLEAN:
100 case Property::Type::FLOAT:
102 return sizeof(float);
104 case Property::Type::INTEGER:
108 case Property::Type::VECTOR2:
110 return sizeof(Vector2);
112 case Property::Type::VECTOR3:
114 return sizeof(Vector3);
116 case Property::Type::VECTOR4:
118 return sizeof(Vector4);
120 case Property::Type::MATRIX3:
122 return sizeof(Matrix3);
124 case Property::Type::MATRIX:
126 return sizeof(Matrix);
136 * Helper function to calculate the correct alignment of data for uniform buffers
137 * @param dataSize size of uniform buffer
138 * @return aligned offset of data
140 inline uint32_t GetUniformBufferDataAlignment(uint32_t dataSize)
142 return ((dataSize / 256u) + ((dataSize % 256u) ? 1u : 0u)) * 256u;
149 Renderer* Renderer::New(SceneGraph::RenderDataProvider* dataProvider,
150 Render::Geometry* geometry,
151 uint32_t blendingBitmask,
152 const Vector4& blendColor,
153 FaceCullingMode::Type faceCullingMode,
154 bool preMultipliedAlphaEnabled,
155 DepthWriteMode::Type depthWriteMode,
156 DepthTestMode::Type depthTestMode,
157 DepthFunction::Type depthFunction,
158 StencilParameters& stencilParameters)
160 return new Renderer(dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction, stencilParameters);
163 Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider,
164 Render::Geometry* geometry,
165 uint32_t blendingBitmask,
166 const Vector4& blendColor,
167 FaceCullingMode::Type faceCullingMode,
168 bool preMultipliedAlphaEnabled,
169 DepthWriteMode::Type depthWriteMode,
170 DepthTestMode::Type depthTestMode,
171 DepthFunction::Type depthFunction,
172 StencilParameters& stencilParameters)
173 : mGraphicsController(nullptr),
174 mRenderDataProvider(dataProvider),
176 mProgramCache(nullptr),
179 mStencilParameters(stencilParameters),
181 mIndexedDrawFirstElement(0),
182 mIndexedDrawElementsCount(0),
183 mDepthFunction(depthFunction),
184 mFaceCullingMode(faceCullingMode),
185 mDepthWriteMode(depthWriteMode),
186 mDepthTestMode(depthTestMode),
187 mPremultipliedAlphaEnabled(preMultipliedAlphaEnabled),
188 mShaderChanged(false),
191 if(blendingBitmask != 0u)
193 mBlendingOptions.SetBitmask(blendingBitmask);
196 mBlendingOptions.SetBlendColor(blendColor);
199 void Renderer::Initialize(Graphics::Controller& graphicsController, ProgramCache& programCache, Render::ShaderCache& shaderCache, Render::UniformBufferManager& uniformBufferManager, Render::PipelineCache& pipelineCache)
201 mGraphicsController = &graphicsController;
202 mProgramCache = &programCache;
203 mShaderCache = &shaderCache;
204 mUniformBufferManager = &uniformBufferManager;
205 mPipelineCache = &pipelineCache;
208 Renderer::~Renderer() = default;
210 void Renderer::SetGeometry(Render::Geometry* geometry)
212 mGeometry = geometry;
215 void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size)
217 mDrawCommands.clear();
218 mDrawCommands.insert(mDrawCommands.end(), pDrawCommands, pDrawCommands + size);
221 void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graphics::Texture*>& boundTextures)
223 uint32_t textureUnit = 0;
225 const Dali::Vector<Render::Texture*>* textures(mRenderDataProvider->GetTextures());
226 const Dali::Vector<Render::Sampler*>* samplers(mRenderDataProvider->GetSamplers());
228 std::vector<Graphics::TextureBinding> textureBindings;
230 if(textures != nullptr)
232 const std::uint32_t texturesCount(static_cast<std::uint32_t>(textures->Count()));
233 textureBindings.reserve(texturesCount);
235 for(uint32_t i = 0; i < texturesCount; ++i) // not expecting more than uint32_t of textures
237 if((*textures)[i] && (*textures)[i]->GetGraphicsObject())
239 Graphics::Texture* graphicsTexture = (*textures)[i]->GetGraphicsObject();
240 // if the sampler exists,
241 // if it's default, delete the graphics object
242 // otherwise re-initialize it if dirty
244 const Graphics::Sampler* graphicsSampler = samplers ? ((*samplers)[i] ? (*samplers)[i]->GetGraphicsObject()
248 boundTextures.PushBack(graphicsTexture);
249 const Graphics::TextureBinding textureBinding{graphicsTexture, graphicsSampler, textureUnit};
250 textureBindings.push_back(textureBinding);
257 if(!textureBindings.empty())
259 commandBuffer.BindTextures(textureBindings);
263 void Renderer::SetFaceCullingMode(FaceCullingMode::Type mode)
265 mFaceCullingMode = mode;
269 void Renderer::SetBlendingBitMask(uint32_t bitmask)
271 mBlendingOptions.SetBitmask(bitmask);
275 void Renderer::SetBlendColor(const Vector4& color)
277 mBlendingOptions.SetBlendColor(color);
281 void Renderer::SetIndexedDrawFirstElement(uint32_t firstElement)
283 mIndexedDrawFirstElement = firstElement;
287 void Renderer::SetIndexedDrawElementsCount(uint32_t elementsCount)
289 mIndexedDrawElementsCount = elementsCount;
293 void Renderer::EnablePreMultipliedAlpha(bool enable)
295 mPremultipliedAlphaEnabled = enable;
299 void Renderer::SetDepthWriteMode(DepthWriteMode::Type depthWriteMode)
301 mDepthWriteMode = depthWriteMode;
305 void Renderer::SetDepthTestMode(DepthTestMode::Type depthTestMode)
307 mDepthTestMode = depthTestMode;
311 DepthWriteMode::Type Renderer::GetDepthWriteMode() const
313 return mDepthWriteMode;
316 DepthTestMode::Type Renderer::GetDepthTestMode() const
318 return mDepthTestMode;
321 void Renderer::SetDepthFunction(DepthFunction::Type depthFunction)
323 mDepthFunction = depthFunction;
327 DepthFunction::Type Renderer::GetDepthFunction() const
329 return mDepthFunction;
332 void Renderer::SetRenderMode(RenderMode::Type renderMode)
334 mStencilParameters.renderMode = renderMode;
338 RenderMode::Type Renderer::GetRenderMode() const
340 return mStencilParameters.renderMode;
343 void Renderer::SetStencilFunction(StencilFunction::Type stencilFunction)
345 mStencilParameters.stencilFunction = stencilFunction;
349 StencilFunction::Type Renderer::GetStencilFunction() const
351 return mStencilParameters.stencilFunction;
354 void Renderer::SetStencilFunctionMask(int stencilFunctionMask)
356 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
360 int Renderer::GetStencilFunctionMask() const
362 return mStencilParameters.stencilFunctionMask;
365 void Renderer::SetStencilFunctionReference(int stencilFunctionReference)
367 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
371 int Renderer::GetStencilFunctionReference() const
373 return mStencilParameters.stencilFunctionReference;
376 void Renderer::SetStencilMask(int stencilMask)
378 mStencilParameters.stencilMask = stencilMask;
382 int Renderer::GetStencilMask() const
384 return mStencilParameters.stencilMask;
387 void Renderer::SetStencilOperationOnFail(StencilOperation::Type stencilOperationOnFail)
389 mStencilParameters.stencilOperationOnFail = stencilOperationOnFail;
393 StencilOperation::Type Renderer::GetStencilOperationOnFail() const
395 return mStencilParameters.stencilOperationOnFail;
398 void Renderer::SetStencilOperationOnZFail(StencilOperation::Type stencilOperationOnZFail)
400 mStencilParameters.stencilOperationOnZFail = stencilOperationOnZFail;
404 StencilOperation::Type Renderer::GetStencilOperationOnZFail() const
406 return mStencilParameters.stencilOperationOnZFail;
409 void Renderer::SetStencilOperationOnZPass(StencilOperation::Type stencilOperationOnZPass)
411 mStencilParameters.stencilOperationOnZPass = stencilOperationOnZPass;
415 StencilOperation::Type Renderer::GetStencilOperationOnZPass() const
417 return mStencilParameters.stencilOperationOnZPass;
420 void Renderer::Upload()
422 mGeometry->Upload(*mGraphicsController);
425 bool Renderer::Render(Graphics::CommandBuffer& commandBuffer,
426 BufferIndex bufferIndex,
427 const SceneGraph::NodeDataProvider& node,
428 const Matrix& modelMatrix,
429 const Matrix& modelViewMatrix,
430 const Matrix& viewMatrix,
431 const Matrix& projectionMatrix,
434 Vector<Graphics::Texture*>& boundTextures,
435 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
438 // Before doing anything test if the call happens in the right queue
439 if(mDrawCommands.empty() && queueIndex > 0)
445 std::vector<DevelRenderer::DrawCommand*> commands;
446 for(auto& cmd : mDrawCommands)
448 if(cmd.queue == queueIndex)
450 commands.emplace_back(&cmd);
454 // Have commands but nothing to be drawn - abort
455 if(!mDrawCommands.empty() && commands.empty())
461 if(!mDrawCommands.empty())
463 blend = (commands[0]->queue != DevelRenderer::RENDER_QUEUE_OPAQUE) && blend;
467 ShaderDataPtr shaderData = mRenderDataProvider->GetShader().GetShaderData();
469 Program* program = Program::New(*mProgramCache,
471 *mGraphicsController);
474 DALI_LOG_ERROR("Failed to get program for shader at address %p.\n", reinterpret_cast<const void*>(&mRenderDataProvider->GetShader()));
478 // If program doesn't have Gfx program object assigned yet, prepare it.
479 if(!program->GetGraphicsProgramPtr())
481 const std::vector<char>& vertShader = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::VERTEX_SHADER);
482 const std::vector<char>& fragShader = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER);
483 Dali::Graphics::Shader& vertexShader = mShaderCache->GetShader(
485 Graphics::PipelineStage::VERTEX_SHADER,
486 shaderData->GetSourceMode());
488 Dali::Graphics::Shader& fragmentShader = mShaderCache->GetShader(
490 Graphics::PipelineStage::FRAGMENT_SHADER,
491 shaderData->GetSourceMode());
493 std::vector<Graphics::ShaderState> shaderStates{
494 Graphics::ShaderState()
495 .SetShader(vertexShader)
496 .SetPipelineStage(Graphics::PipelineStage::VERTEX_SHADER),
497 Graphics::ShaderState()
498 .SetShader(fragmentShader)
499 .SetPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER)};
501 auto createInfo = Graphics::ProgramCreateInfo();
502 createInfo.SetShaderState(shaderStates);
503 auto graphicsProgram = mGraphicsController->CreateProgram(createInfo, nullptr);
504 program->SetGraphicsProgram(std::move(graphicsProgram));
507 // Prepare the graphics pipeline. This may either re-use an existing pipeline or create a new one.
508 auto& pipeline = PrepareGraphicsPipeline(*program, instruction, node, blend);
510 commandBuffer.BindPipeline(pipeline);
512 BindTextures(commandBuffer, boundTextures);
514 BuildUniformIndexMap(bufferIndex, node, size, *program);
516 WriteUniformBuffer(bufferIndex, commandBuffer, program, instruction, node, modelMatrix, modelViewMatrix, viewMatrix, projectionMatrix, size);
518 bool drawn = false; // Draw can fail if there are no vertex buffers or they haven't been uploaded yet
519 // @todo We should detect this case much earlier to prevent unnecessary work
521 if(mDrawCommands.empty())
523 drawn = mGeometry->Draw(*mGraphicsController, commandBuffer, mIndexedDrawFirstElement, mIndexedDrawElementsCount);
527 for(auto& cmd : commands)
529 mGeometry->Draw(*mGraphicsController, commandBuffer, cmd->firstIndex, cmd->elementCount);
537 void Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program)
539 // Check if the map has changed
540 DALI_ASSERT_DEBUG(mRenderDataProvider && "No Uniform map data provider available");
542 const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMapDataProvider();
544 if(uniformMapDataProvider.GetUniformMapChanged(bufferIndex) ||
545 node.GetUniformMapChanged(bufferIndex) ||
546 mUniformIndexMap.Count() == 0 ||
549 // Reset shader pointer
550 mShaderChanged = false;
552 const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap(bufferIndex);
553 const SceneGraph::CollectedUniformMap& uniformMapNode = node.GetUniformMap(bufferIndex);
555 auto maxMaps = static_cast<uint32_t>(uniformMap.Count() + uniformMapNode.Count()); // 4,294,967,295 maps should be enough
556 mUniformIndexMap.Clear(); // Clear contents, but keep memory if we don't change size
557 mUniformIndexMap.Resize(maxMaps);
559 // Copy uniform map into mUniformIndexMap
560 uint32_t mapIndex = 0;
561 for(; mapIndex < uniformMap.Count(); ++mapIndex)
563 mUniformIndexMap[mapIndex].propertyValue = uniformMap[mapIndex].propertyPtr;
564 mUniformIndexMap[mapIndex].uniformName = uniformMap[mapIndex].uniformName;
565 mUniformIndexMap[mapIndex].uniformNameHash = uniformMap[mapIndex].uniformNameHash;
566 mUniformIndexMap[mapIndex].uniformNameHashNoArray = uniformMap[mapIndex].uniformNameHashNoArray;
567 mUniformIndexMap[mapIndex].arrayIndex = uniformMap[mapIndex].arrayIndex;
570 for(uint32_t nodeMapIndex = 0; nodeMapIndex < uniformMapNode.Count(); ++nodeMapIndex)
572 auto hash = uniformMapNode[nodeMapIndex].uniformNameHash;
573 auto& name = uniformMapNode[nodeMapIndex].uniformName;
575 for(uint32_t i = 0; i < uniformMap.Count(); ++i)
577 if(mUniformIndexMap[i].uniformNameHash == hash &&
578 mUniformIndexMap[i].uniformName == name)
580 mUniformIndexMap[i].propertyValue = uniformMapNode[nodeMapIndex].propertyPtr;
588 mUniformIndexMap[mapIndex].propertyValue = uniformMapNode[nodeMapIndex].propertyPtr;
589 mUniformIndexMap[mapIndex].uniformName = uniformMapNode[nodeMapIndex].uniformName;
590 mUniformIndexMap[mapIndex].uniformNameHash = uniformMapNode[nodeMapIndex].uniformNameHash;
591 mUniformIndexMap[mapIndex].uniformNameHashNoArray = uniformMapNode[nodeMapIndex].uniformNameHashNoArray;
592 mUniformIndexMap[mapIndex].arrayIndex = uniformMapNode[nodeMapIndex].arrayIndex;
597 mUniformIndexMap.Resize(mapIndex);
601 void Renderer::WriteUniformBuffer(
602 BufferIndex bufferIndex,
603 Graphics::CommandBuffer& commandBuffer,
605 const SceneGraph::RenderInstruction& instruction,
606 const SceneGraph::NodeDataProvider& node,
607 const Matrix& modelMatrix,
608 const Matrix& modelViewMatrix,
609 const Matrix& viewMatrix,
610 const Matrix& projectionMatrix,
614 uint32_t uboOffset{0u};
616 auto& reflection = mGraphicsController->GetProgramReflection(program->GetGraphicsProgram());
618 uint32_t uniformBlockAllocationBytes = program->GetUniformBlocksMemoryRequirements().totalSizeRequired;
620 // Create uniform buffer view from uniform buffer
621 Graphics::UniquePtr<Render::UniformBufferView> uboView{nullptr};
622 if(uniformBlockAllocationBytes)
624 auto uboPoolView = mUniformBufferManager->GetUniformBufferViewPool(bufferIndex);
626 uboView = uboPoolView->CreateUniformBufferView(uniformBlockAllocationBytes);
629 // update the uniform buffer
630 // pass shared UBO and offset, return new offset for next item to be used
631 // don't process bindings if there are no uniform buffers allocated
634 auto uboCount = reflection.GetUniformBlockCount();
635 mUniformBufferBindings.resize(uboCount);
637 std::vector<Graphics::UniformBufferBinding>* bindings{&mUniformBufferBindings};
639 mUniformBufferBindings[0].buffer = uboView->GetBuffer(&mUniformBufferBindings[0].offset);
641 // Write default uniforms
642 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MODEL_MATRIX), *uboView, modelMatrix);
643 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::VIEW_MATRIX), *uboView, viewMatrix);
644 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::PROJECTION_MATRIX), *uboView, projectionMatrix);
645 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MODEL_VIEW_MATRIX), *uboView, modelViewMatrix);
647 auto mvpUniformInfo = program->GetDefaultUniform(Program::DefaultUniformIndex::MVP_MATRIX);
648 if(mvpUniformInfo && !mvpUniformInfo->name.empty())
650 Matrix modelViewProjectionMatrix(false);
651 Matrix::Multiply(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix);
652 WriteDefaultUniform(mvpUniformInfo, *uboView, modelViewProjectionMatrix);
655 auto normalUniformInfo = program->GetDefaultUniform(Program::DefaultUniformIndex::NORMAL_MATRIX);
656 if(normalUniformInfo && !normalUniformInfo->name.empty())
658 Matrix3 normalMatrix(modelViewMatrix);
659 normalMatrix.Invert();
660 normalMatrix.Transpose();
661 WriteDefaultUniform(normalUniformInfo, *uboView, normalMatrix);
664 Vector4 finalColor; ///< Applied renderer's opacity color
665 const Vector4& color = node.GetRenderColor(bufferIndex); ///< Actor's original color
666 if(mPremultipliedAlphaEnabled)
668 const float& alpha = color.a * mRenderDataProvider->GetOpacity(bufferIndex);
669 finalColor = Vector4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);
673 finalColor = Vector4(color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity(bufferIndex));
675 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::COLOR), *uboView, finalColor);
676 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::ACTOR_COLOR), *uboView, color);
678 // Write uniforms from the uniform map
679 FillUniformBuffer(*program, instruction, *uboView, bindings, uboOffset, bufferIndex);
681 // Write uSize in the end, as it shouldn't be overridable by dynamic properties.
682 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::SIZE), *uboView, size);
684 commandBuffer.BindUniformBuffers(*bindings);
689 bool Renderer::WriteDefaultUniform(const Graphics::UniformInfo* uniformInfo, Render::UniformBufferView& ubo, const T& data)
691 if(uniformInfo && !uniformInfo->name.empty())
693 WriteUniform(ubo, *uniformInfo, data);
700 void Renderer::WriteUniform(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const T& data)
702 WriteUniform(ubo, uniformInfo, &data, sizeof(T));
705 void Renderer::WriteUniform(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const void* data, uint32_t size)
707 ubo.Write(data, size, ubo.GetOffset() + uniformInfo.offset);
710 void Renderer::FillUniformBuffer(Program& program,
711 const SceneGraph::RenderInstruction& instruction,
712 Render::UniformBufferView& ubo,
713 std::vector<Graphics::UniformBufferBinding>*& outBindings,
715 BufferIndex updateBufferIndex)
717 auto& reflection = mGraphicsController->GetProgramReflection(program.GetGraphicsProgram());
718 auto uboCount = reflection.GetUniformBlockCount();
721 uint32_t dataOffset = offset;
722 for(auto i = 0u; i < uboCount; ++i)
724 mUniformBufferBindings[i].dataSize = reflection.GetUniformBlockSize(i);
725 mUniformBufferBindings[i].binding = reflection.GetUniformBlockBinding(i);
727 dataOffset += GetUniformBufferDataAlignment(mUniformBufferBindings[i].dataSize);
728 mUniformBufferBindings[i].buffer = ubo.GetBuffer(&mUniformBufferBindings[i].offset);
730 for(UniformIndexMappings::Iterator iter = mUniformIndexMap.Begin(),
731 end = mUniformIndexMap.End();
735 auto& uniform = *iter;
736 int arrayIndex = uniform.arrayIndex;
738 if(!uniform.uniformFunc)
740 auto uniformInfo = Graphics::UniformInfo{};
741 auto uniformFound = program.GetUniform(uniform.uniformName.GetCString(),
742 uniform.uniformNameHashNoArray ? uniform.uniformNameHashNoArray
743 : uniform.uniformNameHash,
746 uniform.uniformOffset = uniformInfo.offset;
747 uniform.uniformLocation = uniformInfo.location;
751 auto dst = ubo.GetOffset() + uniformInfo.offset;
752 const auto typeSize = GetPropertyValueSizeForUniform((*iter).propertyValue->GetType());
753 const auto dest = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
754 const auto func = GetPropertyValueGetter((*iter).propertyValue->GetType());
756 ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
760 uniform.uniformSize = typeSize;
761 uniform.uniformFunc = func;
766 auto dst = ubo.GetOffset() + uniform.uniformOffset;
767 const auto typeSize = uniform.uniformSize;
768 const auto dest = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
769 const auto func = uniform.uniformFunc;
771 ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
777 // write output bindings
778 outBindings = &mUniformBufferBindings;
784 void Renderer::SetSortAttributes(SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const
786 sortAttributes.shader = &(mRenderDataProvider->GetShader());
787 sortAttributes.geometry = mGeometry;
790 void Renderer::SetShaderChanged(bool value)
792 mShaderChanged = value;
795 bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider* node)
803 if(mShaderChanged || mGeometry->AttributesChanged())
808 auto* textures = mRenderDataProvider->GetTextures();
811 for(auto iter = textures->Begin(), end = textures->End(); iter < end; ++iter)
813 auto texture = *iter;
814 if(texture && texture->IsNativeImage())
821 uint64_t hash = 0xc70f6907UL;
822 const SceneGraph::CollectedUniformMap& uniformMapNode = node->GetUniformMap(bufferIndex);
823 for(const auto& uniformProperty : uniformMapNode)
825 hash = uniformProperty.propertyPtr->Hash(bufferIndex, hash);
828 const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMapDataProvider();
829 const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap(bufferIndex);
830 for(const auto& uniformProperty : uniformMap)
832 hash = uniformProperty.propertyPtr->Hash(bufferIndex, hash);
835 if(mUniformsHash != hash)
837 mUniformsHash = hash;
844 Graphics::Pipeline& Renderer::PrepareGraphicsPipeline(
846 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
847 const SceneGraph::NodeDataProvider& node,
850 if(mGeometry->AttributesChanged())
855 // Prepare query info
856 PipelineCacheQueryInfo queryInfo{};
857 queryInfo.program = &program;
858 queryInfo.renderer = this;
859 queryInfo.geometry = mGeometry;
860 queryInfo.blendingEnabled = blend;
861 queryInfo.blendingOptions = &mBlendingOptions;
862 queryInfo.alphaPremultiplied = mPremultipliedAlphaEnabled;
863 queryInfo.cameraUsingReflection = instruction.GetCamera()->GetReflectionUsed();
865 auto pipelineResult = mPipelineCache->GetPipeline(queryInfo, true);
867 // should be never null?
868 return *pipelineResult.pipeline;
871 } // namespace Render
873 } // namespace Dali::Internal