11523215d3407ca6d70b5923b7c176089deecdd9
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-instruction.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/math/matrix.h>
23 #include <dali/public-api/math/viewport.h>
24 #include <dali/internal/update/render-tasks/scene-graph-camera.h>
25 #include <dali/internal/render/common/render-list.h>
26 #include <dali/internal/render/renderers/render-frame-buffer.h>
27 #include <dali/internal/render/gl-resources/context.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Render
36 {
37 class RenderTracker;
38 }
39
40 namespace SceneGraph
41 {
42
43 /**
44  * A set of rendering instructions consisting of:
45  * - The list(s) of renderers sorted in the correct rendering order.
46  * - The camera related matrices to use when rendering.
47  * - An optional off-screen render target.
48  * There is one RenderInstruction per RenderTarget, all renderers of all layers
49  * get collated onto the single list of lists (mRenderLists)
50  */
51 class RenderInstruction
52 {
53 public:
54
55   /**
56    * Default constructor so this can be stored in STL containers
57    */
58   RenderInstruction();
59
60   /**
61    * Destructor
62    */
63   ~RenderInstruction();
64
65   /**
66    * Get the next free Renderlist
67    * @param capacityRequired in this list
68    * @return the renderlist
69    */
70   RenderList& GetNextFreeRenderList( size_t capacityRequired );
71
72   /**
73    * Inform the RenderInstruction that processing for this frame is complete
74    * This method should only be called from Update thread
75    */
76   void UpdateCompleted();
77
78   /**
79    * @return the count of active Renderlists
80    */
81   RenderListContainer::SizeType RenderListCount() const;
82
83   /**
84    * Return the renderlist at given index
85    * @pre index is inside the valid range of initialized lists
86    * @param index of list to return
87    * @return pointer to the renderlist, or null if the index is out of bounds.
88    */
89   const RenderList* GetRenderList( RenderListContainer::SizeType index ) const;
90
91   /**
92    * Reset render-instruction
93    * render-lists are cleared but not released, while matrices and other settings reset in
94    * preparation for building a set of instructions for the renderer.
95    *
96    * @param[in] camera to use to get view and projection matrices.
97    * @param[in] offscreenId A resource Id of an off-screen render target, or 0
98    * @param[in] viewport A pointer to a viewport, of NULL.
99    * @param[in] clearColor A pointer to a color to clear with, or NULL if no clear is required.
100    */
101   void Reset( Camera* camera,
102               Render::FrameBuffer* frameBuffer,
103               const Viewport* viewport,
104               const Vector4* clearColor );
105
106   /**
107    * Get the view matrix for rendering
108    * @param index of the rendering side
109    * @return the view matrix
110    */
111   const Matrix* GetViewMatrix( BufferIndex index ) const
112   {
113     // inlined as this is called once per frame per render instruction
114     return &mCamera->GetViewMatrix( index );
115   }
116
117   /**
118    * Get the projection matrix for rendering
119    * @param index of the rendering side
120    * @return the projection matrix
121    */
122   const Matrix* GetProjectionMatrix( BufferIndex index ) const
123   {
124     // inlined as this is called once per frame per render instruction
125     return &mCamera->GetProjectionMatrix( index );
126   }
127   // for reflection effect
128   const Camera* GetCamera() const
129   {
130     return mCamera;
131   }
132
133 private:
134
135   // Undefined
136   RenderInstruction(const RenderInstruction&);
137   // Undefined
138   RenderInstruction& operator=(const RenderInstruction& rhs);
139
140 public: // Data
141
142   Render::RenderTracker* mRenderTracker;        ///< Pointer to an optional tracker object (not owned)
143
144   Viewport mViewport;                   ///< Optional viewport
145   Vector4  mClearColor;                 ///< Optional color to clear with
146   bool     mIsViewportSet:1;            ///< Flag to determine whether the viewport is set
147   bool     mIsClearColorSet:1;          ///< Flag to determine whether the clearColor is set
148   bool     mIgnoreRenderToFbo:1;        ///< Whether to ignore the render to FBO option (used to measure the performance above 60 fps)
149
150   Render::FrameBuffer* mFrameBuffer;
151
152   Context* mContext;                    ///< The context holding the GL state of rendering
153
154 private: // Data
155
156   Camera* mCamera;  ///< camera that is used
157   RenderListContainer mRenderLists;     ///< container of all render lists
158   RenderListContainer::SizeType mNextFreeRenderList;     ///< index for the next free render list
159
160 };
161
162 } // namespace SceneGraph
163
164 } // namespace Internal
165
166 } // namespace Dali
167
168 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_H