2 * Copyright (c) 2018 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/update/graphics/graphics-algorithms.h>
23 #include <dali/graphics-api/graphics-api-controller.h>
24 #include <dali/graphics-api/graphics-api-frame.h>
25 #include <dali/graphics-api/graphics-api-render-command.h>
28 #include <dali/internal/common/buffer-index.h>
29 #include <dali/internal/render/common/render-instruction-container.h>
30 #include <dali/internal/render/common/render-instruction.h>
40 void SubmitRenderItemList( Graphics::API::Controller& graphics,
41 Graphics::API::Frame& frame,
42 BufferIndex bufferIndex,
43 Graphics::API::RenderCommandBuilder& commandBuilder,
44 Matrix viewProjection,
45 const RenderList& renderItemList )
47 // TODO: @todo Set shaders and other properties
48 //commandBuilder.Set( );
50 // TODO: @todo Clipping...
52 auto numberOfRenderItems = renderItemList.Count();
59 } __attribute__((aligned(16)));
61 auto uniformBuffer = graphics.CreateBuffer<DataT>( numberOfRenderItems );
62 auto data = uniformBuffer->GetData();
63 for( auto i = 0u; i < numberOfRenderItems; ++i )
65 auto& item = renderItemList.GetItem( i );
66 Matrix::Multiply( data[i].world, item.mModelMatrix, viewProjection );
67 data[i].color = item.mNode->GetWorldColor( bufferIndex );
68 data[i].size = item.mSize;
70 commandBuilder.Set( Graphics::API::PrimitiveCount{numberOfRenderItems} );
72 auto buffers = std::vector<Graphics::API::BufferInfo>{};
73 buffers.emplace_back(std::move(uniformBuffer));
75 commandBuilder.Set( Graphics::API::BufferList{std::move(buffers)} );
76 auto cmd = commandBuilder.Build();
77 graphics.SubmitCommand( std::move(cmd) );
80 void SubmitInstruction( Graphics::API::Controller& graphics,
81 Graphics::API::Frame& frame,
82 BufferIndex bufferIndex,
83 RenderInstruction& instruction )
85 using namespace Graphics::API;
87 // Create constant buffer with static uniforms: view matrix, progrjection matrix
89 // TODO: @todo: buffer for constant uniforms
91 auto contantUniforms = BuildBuffer<ProjectionMatrix, ViewMatrix>();
92 constantUniforms["uProjection"] = projectionMatrix;
93 constantUniforms["uViewMatrix"] = viewMatrix;
96 const Matrix* viewMatrix = instruction.GetViewMatrix( bufferIndex );
97 const Matrix* projectionMatrix = instruction.GetProjectionMatrix( bufferIndex );
98 Matrix viewProjection;
99 Matrix::Multiply( viewProjection, *viewMatrix, *projectionMatrix );
101 auto commandBuilder = RenderCommandBuilder{};
103 auto numberOfRenderLists = instruction.RenderListCount();
104 for( auto i = 0u; i < numberOfRenderLists; ++i )
106 SubmitRenderItemList(
107 graphics, frame, bufferIndex, commandBuilder, viewProjection, *instruction.GetRenderList( i ) );
112 void SubmitRenderInstructions( Graphics::API::Controller& graphics,
113 RenderInstructionContainer& renderInstructions,
114 BufferIndex bufferIndex )
116 auto frame = Graphics::API::Frame{};
117 graphics.BeginFrame();
119 auto numberOfInstructions = renderInstructions.Count( bufferIndex );
120 for( size_t i = 0; i < numberOfInstructions; ++i )
122 RenderInstruction& instruction = renderInstructions.At( bufferIndex, i );
124 SubmitInstruction( graphics, frame, bufferIndex, instruction );
127 graphics.EndFrame( );
130 } // namespace SceneGraph
131 } // namespace Internal