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