[dali_1.1.34] Merge branch 'devel/master'
[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) 2016 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
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Render
34 {
35 class RenderTracker;
36 }
37
38 namespace SceneGraph
39 {
40
41 /**
42  * A set of rendering instructions consisting of:
43  * - The list(s) of renderers sorted in the correct rendering order.
44  * - The camera related matrices to use when rendering.
45  * - An optional off-screen render target.
46  * There is one RenderInstruction per RenderTarget, all renderers of all layers
47  * get collated onto the single list of lists (mRenderLists)
48  */
49 class RenderInstruction
50 {
51 public:
52
53   /**
54    * Default constructor so this can be stored in STL containers
55    */
56   RenderInstruction();
57
58   /**
59    * Destructor
60    */
61   ~RenderInstruction();
62
63   /**
64    * Get the next free Renderlist
65    * @param capacityRequired in this list
66    * @return the renderlist
67    */
68   RenderList& GetNextFreeRenderList( size_t capacityRequired );
69
70   /**
71    * Inform the RenderInstruction that processing for this frame is complete
72    * This method should only be called from Update thread
73    */
74   void UpdateCompleted();
75
76   /**
77    * @return the count of active Renderlists
78    */
79   RenderListContainer::SizeType RenderListCount() const;
80
81   /**
82    * Return the renderlist at given index
83    * @pre index is inside the valid range of initialized lists
84    * @param index of list to return
85    * @return pointer to the renderlist, or null if the index is out of bounds.
86    */
87   const RenderList* GetRenderList( RenderListContainer::SizeType index ) const;
88
89   /**
90    * Reset render-instruction
91    * render-lists are cleared but not released, while matrices and other settings reset in
92    * preparation for building a set of instructions for the renderer.
93    *
94    * @param[in] camera to use to get view and projection matrices.
95    * @param[in] offscreenId A resource Id of an off-screen render target, or 0
96    * @param[in] viewport A pointer to a viewport, of NULL.
97    * @param[in] clearColor A pointer to a color to clear with, or NULL if no clear is required.
98    */
99   void Reset( Camera* camera,
100               unsigned int offscreenId,
101               const Viewport* viewport,
102               const Vector4* clearColor );
103
104   /**
105    * Get the view matrix for rendering
106    * @param index of the rendering side
107    * @return the view matrix
108    */
109   const Matrix* GetViewMatrix( BufferIndex index ) const
110   {
111     // inlined as this is called once per frame per render instruction
112     return &mCamera->GetViewMatrix( index );
113   }
114
115   /**
116    * Get the projection matrix for rendering
117    * @param index of the rendering side
118    * @return the projection matrix
119    */
120   const Matrix* GetProjectionMatrix( BufferIndex index ) const
121   {
122     // inlined as this is called once per frame per render instruction
123     return &mCamera->GetProjectionMatrix( index );
124   }
125
126 private:
127
128   // Undefined
129   RenderInstruction(const RenderInstruction&);
130   // Undefined
131   RenderInstruction& operator=(const RenderInstruction& rhs);
132
133 public: // Data
134
135   Render::RenderTracker* mRenderTracker;        ///< Pointer to an optional tracker object (not owned)
136
137   Viewport mViewport;                   ///< Optional viewport
138   Vector4  mClearColor;                 ///< Optional color to clear with
139   bool     mIsViewportSet:1;            ///< Flag to determine whether the viewport is set
140   bool     mIsClearColorSet:1;          ///< Flag to determine whether the clearColor is set
141
142   unsigned int mOffscreenTextureId;     ///< Optional offscreen target
143
144 private: // Data
145
146   Camera* mCamera;  ///< camera that is used
147   RenderListContainer mRenderLists;     ///< container of all render lists
148   RenderListContainer::SizeType mNextFreeRenderList;     ///< index for the next free render list
149
150 };
151
152 } // namespace SceneGraph
153
154 } // namespace Internal
155
156 } // namespace Dali
157
158 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_H__