2 * Copyright (c) 2021 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/render-sampler.h>
29 #include <dali/internal/render/renderers/render-texture.h>
30 #include <dali/internal/render/renderers/render-vertex-buffer.h>
31 #include <dali/internal/render/renderers/shader-cache.h>
32 #include <dali/internal/render/renderers/uniform-buffer-view-pool.h>
33 #include <dali/internal/render/renderers/uniform-buffer-view.h>
34 #include <dali/internal/render/shaders/program.h>
35 #include <dali/internal/render/shaders/render-shader.h>
36 #include <dali/internal/update/common/uniform-map.h>
37 #include <dali/internal/render/renderers/pipeline-cache.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:{ return sizeof(bool);}
97 case Property::Type::FLOAT:{ return sizeof(float);}
98 case Property::Type::INTEGER:{ return sizeof(int);}
99 case Property::Type::VECTOR2:{ return sizeof(Vector2);}
100 case Property::Type::VECTOR3:{ return sizeof(Vector3);}
101 case Property::Type::VECTOR4:{ return sizeof(Vector4);}
102 case Property::Type::MATRIX3:{ return sizeof(Matrix3);}
103 case Property::Type::MATRIX:{ return sizeof(Matrix);}
112 * Helper function to calculate the correct alignment of data for uniform buffers
113 * @param dataSize size of uniform buffer
114 * @return aligned offset of data
116 inline uint32_t GetUniformBufferDataAlignment(uint32_t dataSize)
118 return ((dataSize / 256u) + ((dataSize % 256u) ? 1u : 0u)) * 256u;
125 Renderer* Renderer::New(SceneGraph::RenderDataProvider* dataProvider,
126 Render::Geometry* geometry,
127 uint32_t blendingBitmask,
128 const Vector4& blendColor,
129 FaceCullingMode::Type faceCullingMode,
130 bool preMultipliedAlphaEnabled,
131 DepthWriteMode::Type depthWriteMode,
132 DepthTestMode::Type depthTestMode,
133 DepthFunction::Type depthFunction,
134 StencilParameters& stencilParameters)
136 return new Renderer(dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction, stencilParameters);
139 Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider,
140 Render::Geometry* geometry,
141 uint32_t blendingBitmask,
142 const Vector4& blendColor,
143 FaceCullingMode::Type faceCullingMode,
144 bool preMultipliedAlphaEnabled,
145 DepthWriteMode::Type depthWriteMode,
146 DepthTestMode::Type depthTestMode,
147 DepthFunction::Type depthFunction,
148 StencilParameters& stencilParameters)
149 : mGraphicsController(nullptr),
150 mRenderDataProvider(dataProvider),
152 mProgramCache(nullptr),
155 mStencilParameters(stencilParameters),
157 mIndexedDrawFirstElement(0),
158 mIndexedDrawElementsCount(0),
159 mDepthFunction(depthFunction),
160 mFaceCullingMode(faceCullingMode),
161 mDepthWriteMode(depthWriteMode),
162 mDepthTestMode(depthTestMode),
163 mPremultipliedAlphaEnabled(preMultipliedAlphaEnabled),
164 mShaderChanged(false),
167 if(blendingBitmask != 0u)
169 mBlendingOptions.SetBitmask(blendingBitmask);
172 mBlendingOptions.SetBlendColor(blendColor);
175 void Renderer::Initialize(Graphics::Controller& graphicsController, ProgramCache& programCache, Render::ShaderCache& shaderCache, Render::UniformBufferManager& uniformBufferManager, Render::PipelineCache& pipelineCache)
177 mGraphicsController = &graphicsController;
178 mProgramCache = &programCache;
179 mShaderCache = &shaderCache;
180 mUniformBufferManager = &uniformBufferManager;
181 mPipelineCache = &pipelineCache;
184 Renderer::~Renderer() = default;
186 void Renderer::SetGeometry(Render::Geometry* geometry)
188 mGeometry = geometry;
191 void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size)
193 mDrawCommands.clear();
194 mDrawCommands.insert(mDrawCommands.end(), pDrawCommands, pDrawCommands + size);
197 void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graphics::Texture*>& boundTextures)
199 uint32_t textureUnit = 0;
201 std::vector<Render::Sampler*>& samplers(mRenderDataProvider->GetSamplers());
202 std::vector<Render::Texture*>& textures(mRenderDataProvider->GetTextures());
204 std::vector<Graphics::TextureBinding> textureBindings;
205 for(uint32_t i = 0; i < static_cast<uint32_t>(textures.size()); ++i) // not expecting more than uint32_t of textures
207 if(textures[i] && textures[i]->GetGraphicsObject())
209 // if the sampler exists,
210 // if it's default, delete the graphics object
211 // otherwise re-initialize it if dirty
213 const Graphics::Sampler* graphicsSampler = (samplers[i] ? samplers[i]->GetGraphicsObject()
216 boundTextures.PushBack(textures[i]->GetGraphicsObject());
217 const Graphics::TextureBinding textureBinding{textures[i]->GetGraphicsObject(), graphicsSampler, textureUnit};
218 textureBindings.push_back(textureBinding);
224 if(!textureBindings.empty())
226 commandBuffer.BindTextures(textureBindings);
230 void Renderer::SetFaceCullingMode(FaceCullingMode::Type mode)
232 mFaceCullingMode = mode;
236 void Renderer::SetBlendingBitMask(uint32_t bitmask)
238 mBlendingOptions.SetBitmask(bitmask);
242 void Renderer::SetBlendColor(const Vector4& color)
244 mBlendingOptions.SetBlendColor(color);
248 void Renderer::SetIndexedDrawFirstElement(uint32_t firstElement)
250 mIndexedDrawFirstElement = firstElement;
254 void Renderer::SetIndexedDrawElementsCount(uint32_t elementsCount)
256 mIndexedDrawElementsCount = elementsCount;
260 void Renderer::EnablePreMultipliedAlpha(bool enable)
262 mPremultipliedAlphaEnabled = enable;
266 void Renderer::SetDepthWriteMode(DepthWriteMode::Type depthWriteMode)
268 mDepthWriteMode = depthWriteMode;
272 void Renderer::SetDepthTestMode(DepthTestMode::Type depthTestMode)
274 mDepthTestMode = depthTestMode;
278 DepthWriteMode::Type Renderer::GetDepthWriteMode() const
280 return mDepthWriteMode;
283 DepthTestMode::Type Renderer::GetDepthTestMode() const
285 return mDepthTestMode;
288 void Renderer::SetDepthFunction(DepthFunction::Type depthFunction)
290 mDepthFunction = depthFunction;
294 DepthFunction::Type Renderer::GetDepthFunction() const
296 return mDepthFunction;
299 void Renderer::SetRenderMode(RenderMode::Type renderMode)
301 mStencilParameters.renderMode = renderMode;
305 RenderMode::Type Renderer::GetRenderMode() const
307 return mStencilParameters.renderMode;
310 void Renderer::SetStencilFunction(StencilFunction::Type stencilFunction)
312 mStencilParameters.stencilFunction = stencilFunction;
316 StencilFunction::Type Renderer::GetStencilFunction() const
318 return mStencilParameters.stencilFunction;
321 void Renderer::SetStencilFunctionMask(int stencilFunctionMask)
323 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
327 int Renderer::GetStencilFunctionMask() const
329 return mStencilParameters.stencilFunctionMask;
332 void Renderer::SetStencilFunctionReference(int stencilFunctionReference)
334 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
338 int Renderer::GetStencilFunctionReference() const
340 return mStencilParameters.stencilFunctionReference;
343 void Renderer::SetStencilMask(int stencilMask)
345 mStencilParameters.stencilMask = stencilMask;
349 int Renderer::GetStencilMask() const
351 return mStencilParameters.stencilMask;
354 void Renderer::SetStencilOperationOnFail(StencilOperation::Type stencilOperationOnFail)
356 mStencilParameters.stencilOperationOnFail = stencilOperationOnFail;
360 StencilOperation::Type Renderer::GetStencilOperationOnFail() const
362 return mStencilParameters.stencilOperationOnFail;
365 void Renderer::SetStencilOperationOnZFail(StencilOperation::Type stencilOperationOnZFail)
367 mStencilParameters.stencilOperationOnZFail = stencilOperationOnZFail;
371 StencilOperation::Type Renderer::GetStencilOperationOnZFail() const
373 return mStencilParameters.stencilOperationOnZFail;
376 void Renderer::SetStencilOperationOnZPass(StencilOperation::Type stencilOperationOnZPass)
378 mStencilParameters.stencilOperationOnZPass = stencilOperationOnZPass;
382 StencilOperation::Type Renderer::GetStencilOperationOnZPass() const
384 return mStencilParameters.stencilOperationOnZPass;
387 void Renderer::Upload()
389 mGeometry->Upload(*mGraphicsController);
392 bool Renderer::Render(Graphics::CommandBuffer& commandBuffer,
393 BufferIndex bufferIndex,
394 const SceneGraph::NodeDataProvider& node,
395 const Matrix& modelMatrix,
396 const Matrix& modelViewMatrix,
397 const Matrix& viewMatrix,
398 const Matrix& projectionMatrix,
401 Vector<Graphics::Texture*>& boundTextures,
402 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
405 // Before doing anything test if the call happens in the right queue
406 if(mDrawCommands.empty() && queueIndex > 0)
412 std::vector<DevelRenderer::DrawCommand*> commands;
413 for(auto& cmd : mDrawCommands)
415 if(cmd.queue == queueIndex)
417 commands.emplace_back(&cmd);
421 // Have commands but nothing to be drawn - abort
422 if(!mDrawCommands.empty() && commands.empty())
428 if(!mDrawCommands.empty())
430 blend = (commands[0]->queue != DevelRenderer::RENDER_QUEUE_OPAQUE) && blend;
434 ShaderDataPtr shaderData = mRenderDataProvider->GetShader().GetShaderData();
436 Program* program = Program::New(*mProgramCache,
438 *mGraphicsController);
441 DALI_LOG_ERROR("Failed to get program for shader at address %p.\n", reinterpret_cast<void*>(&mRenderDataProvider->GetShader()));
445 // If program doesn't have Gfx program object assigned yet, prepare it.
446 if(!program->GetGraphicsProgramPtr())
448 const std::vector<char> &vertShader = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::VERTEX_SHADER);
449 const std::vector<char> &fragShader = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER);
450 Dali::Graphics::Shader &vertexShader = mShaderCache->GetShader(
452 Graphics::PipelineStage::VERTEX_SHADER,
453 shaderData->GetSourceMode());
455 Dali::Graphics::Shader &fragmentShader = mShaderCache->GetShader(
457 Graphics::PipelineStage::FRAGMENT_SHADER,
458 shaderData->GetSourceMode());
460 std::vector<Graphics::ShaderState> shaderStates{
461 Graphics::ShaderState()
462 .SetShader(vertexShader)
463 .SetPipelineStage(Graphics::PipelineStage::VERTEX_SHADER),
464 Graphics::ShaderState()
465 .SetShader(fragmentShader)
466 .SetPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER)};
468 auto createInfo = Graphics::ProgramCreateInfo();
469 createInfo.SetShaderState(shaderStates);
470 auto graphicsProgram = mGraphicsController->CreateProgram(createInfo, nullptr);
471 program->SetGraphicsProgram(std::move(graphicsProgram));
474 // Prepare the graphics pipeline. This may either re-use an existing pipeline or create a new one.
475 auto& pipeline = PrepareGraphicsPipeline(*program, instruction, node, blend);
477 commandBuffer.BindPipeline(pipeline);
479 BindTextures(commandBuffer, boundTextures);
481 BuildUniformIndexMap(bufferIndex, node, size, *program);
483 WriteUniformBuffer(bufferIndex, commandBuffer, program, instruction, node, modelMatrix, modelViewMatrix, viewMatrix, projectionMatrix, size);
485 bool drawn = false; // Draw can fail if there are no vertex buffers or they haven't been uploaded yet
486 // @todo We should detect this case much earlier to prevent unnecessary work
488 if(mDrawCommands.empty())
490 drawn = mGeometry->Draw(*mGraphicsController, commandBuffer, mIndexedDrawFirstElement, mIndexedDrawElementsCount);
494 for(auto& cmd : commands)
496 mGeometry->Draw(*mGraphicsController, commandBuffer, cmd->firstIndex, cmd->elementCount);
504 void Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program)
506 // Check if the map has changed
507 DALI_ASSERT_DEBUG(mRenderDataProvider && "No Uniform map data provider available");
509 const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
511 if(uniformMapDataProvider.GetUniformMapChanged(bufferIndex) ||
512 node.GetUniformMapChanged(bufferIndex) ||
513 mUniformIndexMap.Count() == 0 ||
516 // Reset shader pointer
517 mShaderChanged = false;
519 const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap(bufferIndex);
520 const SceneGraph::CollectedUniformMap& uniformMapNode = node.GetUniformMap(bufferIndex);
522 auto maxMaps = static_cast<uint32_t>(uniformMap.Count() + uniformMapNode.Count()); // 4,294,967,295 maps should be enough
523 mUniformIndexMap.Clear(); // Clear contents, but keep memory if we don't change size
524 mUniformIndexMap.Resize(maxMaps);
526 // Copy uniform map into mUniformIndexMap
527 uint32_t mapIndex = 0;
528 for(; mapIndex < uniformMap.Count(); ++mapIndex)
530 mUniformIndexMap[mapIndex].propertyValue = uniformMap[mapIndex].propertyPtr;
531 mUniformIndexMap[mapIndex].uniformName = uniformMap[mapIndex].uniformName;
532 mUniformIndexMap[mapIndex].uniformNameHash = uniformMap[mapIndex].uniformNameHash;
533 mUniformIndexMap[mapIndex].uniformNameHashNoArray = uniformMap[mapIndex].uniformNameHashNoArray;
534 mUniformIndexMap[mapIndex].arrayIndex = uniformMap[mapIndex].arrayIndex;
537 for(uint32_t nodeMapIndex = 0; nodeMapIndex < uniformMapNode.Count(); ++nodeMapIndex)
539 auto hash = uniformMapNode[nodeMapIndex].uniformNameHash;
540 auto& name = uniformMapNode[nodeMapIndex].uniformName;
542 for(uint32_t i = 0; i < uniformMap.Count(); ++i)
544 if(mUniformIndexMap[i].uniformNameHash == hash &&
545 mUniformIndexMap[i].uniformName == name)
547 mUniformIndexMap[i].propertyValue = uniformMapNode[nodeMapIndex].propertyPtr;
555 mUniformIndexMap[mapIndex].propertyValue = uniformMapNode[nodeMapIndex].propertyPtr;
556 mUniformIndexMap[mapIndex].uniformName = uniformMapNode[nodeMapIndex].uniformName;
557 mUniformIndexMap[mapIndex].uniformNameHash = uniformMapNode[nodeMapIndex].uniformNameHash;
558 mUniformIndexMap[mapIndex].uniformNameHashNoArray = uniformMapNode[nodeMapIndex].uniformNameHashNoArray;
559 mUniformIndexMap[mapIndex].arrayIndex = uniformMapNode[nodeMapIndex].arrayIndex;
564 mUniformIndexMap.Resize(mapIndex);
568 void Renderer::WriteUniformBuffer(
569 BufferIndex bufferIndex,
570 Graphics::CommandBuffer& commandBuffer,
572 const SceneGraph::RenderInstruction& instruction,
573 const SceneGraph::NodeDataProvider& node,
574 const Matrix& modelMatrix,
575 const Matrix& modelViewMatrix,
576 const Matrix& viewMatrix,
577 const Matrix& projectionMatrix,
581 uint32_t uboOffset{0u};
583 auto &reflection = mGraphicsController->GetProgramReflection(program->GetGraphicsProgram());
585 uint32_t uniformBlockAllocationBytes = program->GetUniformBlocksMemoryRequirements().totalSizeRequired;
587 // Create uniform buffer view from uniform buffer
588 Graphics::UniquePtr<Render::UniformBufferView> uboView{nullptr};
589 if(uniformBlockAllocationBytes)
591 auto uboPoolView = mUniformBufferManager->GetUniformBufferViewPool(bufferIndex);
593 uboView = uboPoolView->CreateUniformBufferView(uniformBlockAllocationBytes);
596 // update the uniform buffer
597 // pass shared UBO and offset, return new offset for next item to be used
598 // don't process bindings if there are no uniform buffers allocated
601 auto uboCount = reflection.GetUniformBlockCount();
602 mUniformBufferBindings.resize(uboCount);
604 std::vector<Graphics::UniformBufferBinding>* bindings{&mUniformBufferBindings};
606 mUniformBufferBindings[0].buffer = uboView->GetBuffer(&mUniformBufferBindings[0].offset);
608 // Write default uniforms
609 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MODEL_MATRIX), *uboView, modelMatrix);
610 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::VIEW_MATRIX), *uboView, viewMatrix);
611 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::PROJECTION_MATRIX), *uboView, projectionMatrix);
612 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::MODEL_VIEW_MATRIX), *uboView, modelViewMatrix);
614 auto mvpUniformInfo = program->GetDefaultUniform(Program::DefaultUniformIndex::MVP_MATRIX);
615 if(mvpUniformInfo && !mvpUniformInfo->name.empty())
617 Matrix modelViewProjectionMatrix(false);
618 Matrix::Multiply(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix);
619 WriteDefaultUniform(mvpUniformInfo, *uboView, modelViewProjectionMatrix);
622 auto normalUniformInfo = program->GetDefaultUniform(Program::DefaultUniformIndex::NORMAL_MATRIX);
623 if(normalUniformInfo && !normalUniformInfo->name.empty())
625 Matrix3 normalMatrix(modelViewMatrix);
626 normalMatrix.Invert();
627 normalMatrix.Transpose();
628 WriteDefaultUniform(normalUniformInfo, *uboView, normalMatrix);
632 const Vector4& color = node.GetRenderColor(bufferIndex);
633 if(mPremultipliedAlphaEnabled)
635 float alpha = color.a * mRenderDataProvider->GetOpacity(bufferIndex);
636 finalColor = Vector4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);
640 finalColor = Vector4(color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity(bufferIndex));
642 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::COLOR), *uboView, finalColor);
644 // Write uniforms from the uniform map
645 FillUniformBuffer(*program, instruction, *uboView, bindings, uboOffset, bufferIndex);
647 // Write uSize in the end, as it shouldn't be overridable by dynamic properties.
648 WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::SIZE), *uboView, size);
650 commandBuffer.BindUniformBuffers(*bindings);
655 bool Renderer::WriteDefaultUniform(const Graphics::UniformInfo* uniformInfo, Render::UniformBufferView& ubo, const T& data)
657 if(uniformInfo && !uniformInfo->name.empty())
659 WriteUniform(ubo, *uniformInfo, data);
666 void Renderer::WriteUniform(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const T& data)
668 WriteUniform(ubo, uniformInfo, &data, sizeof(T));
671 void Renderer::WriteUniform(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const void* data, uint32_t size)
673 ubo.Write(data, size, ubo.GetOffset() + uniformInfo.offset);
676 void Renderer::FillUniformBuffer(Program& program,
677 const SceneGraph::RenderInstruction& instruction,
678 Render::UniformBufferView& ubo,
679 std::vector<Graphics::UniformBufferBinding>*& outBindings,
681 BufferIndex updateBufferIndex)
683 auto& reflection = mGraphicsController->GetProgramReflection(program.GetGraphicsProgram());
684 auto uboCount = reflection.GetUniformBlockCount();
687 uint32_t dataOffset = offset;
688 for(auto i = 0u; i < uboCount; ++i)
690 mUniformBufferBindings[i].dataSize = reflection.GetUniformBlockSize(i);
691 mUniformBufferBindings[i].binding = reflection.GetUniformBlockBinding(i);
693 dataOffset += GetUniformBufferDataAlignment(mUniformBufferBindings[i].dataSize);
694 mUniformBufferBindings[i].buffer = ubo.GetBuffer(&mUniformBufferBindings[i].offset);
696 for(UniformIndexMappings::Iterator iter = mUniformIndexMap.Begin(),
697 end = mUniformIndexMap.End();
701 // @todo This means parsing the uniform string every frame. Instead, store the array index if present.
702 int arrayIndex = (*iter).arrayIndex;
704 auto uniformInfo = Graphics::UniformInfo{};
705 auto uniformFound = program.GetUniform((*iter).uniformName.GetCString(),
706 (*iter).uniformNameHashNoArray ? (*iter).uniformNameHashNoArray
707 : (*iter).uniformNameHash,
712 auto dst = ubo.GetOffset() + uniformInfo.offset;
713 const auto typeSize = GetPropertyValueSizeForUniform( (*iter).propertyValue->GetType() );
714 const auto dest = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
715 const auto func = GetPropertyValueGetter((*iter).propertyValue->GetType());
716 ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
722 // write output bindings
723 outBindings = &mUniformBufferBindings;
729 void Renderer::SetSortAttributes(SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const
731 sortAttributes.shader = &(mRenderDataProvider->GetShader());
732 sortAttributes.geometry = mGeometry;
735 void Renderer::SetShaderChanged(bool value)
737 mShaderChanged = value;
740 bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider* node)
748 if(mShaderChanged || mGeometry->AttributesChanged())
753 for(const auto& texture : mRenderDataProvider->GetTextures())
755 if(texture && texture->IsNativeImage())
761 uint64_t hash = 0xc70f6907UL;
762 const SceneGraph::CollectedUniformMap& uniformMapNode = node->GetUniformMap(bufferIndex);
763 for(const auto& uniformProperty : uniformMapNode)
765 hash = uniformProperty.propertyPtr->Hash(bufferIndex, hash);
768 const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
769 const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap(bufferIndex);
770 for(const auto& uniformProperty : uniformMap)
772 hash = uniformProperty.propertyPtr->Hash(bufferIndex, hash);
775 if(mUniformsHash != hash)
777 mUniformsHash = hash;
784 Graphics::Pipeline& Renderer::PrepareGraphicsPipeline(
786 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
787 const SceneGraph::NodeDataProvider& node,
790 if(mGeometry->AttributesChanged())
795 // Prepare query info
796 PipelineCacheQueryInfo queryInfo{};
797 queryInfo.program = &program;
798 queryInfo.renderer = this;
799 queryInfo.geometry = mGeometry;
800 queryInfo.blendingEnabled = blend;
801 queryInfo.blendingOptions = &mBlendingOptions;
802 queryInfo.alphaPremultiplied = mPremultipliedAlphaEnabled;
803 queryInfo.cameraUsingReflection = instruction.GetCamera()->GetReflectionUsed();
805 auto pipelineResult = mPipelineCache->GetPipeline( queryInfo, true );
807 // should be never null?
808 return *pipelineResult.pipeline;
811 } // namespace Render
813 } // namespace Dali::Internal