Graphics API
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-pipeline-create-info.h
1 #ifndef DALI_GRAPHICS_PIPELINE_CREATE_INFO_H
2 #define DALI_GRAPHICS_PIPELINE_CREATE_INFO_H
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
22 #include <memory>
23
24 // INTERNAL INCLUDES
25 #include "graphics-pipeline.h"
26 #include "graphics-types.h"
27
28 namespace Dali
29 {
30 namespace Graphics
31 {
32 /**
33  * @brief Interface class for generating Pipeline types in the graphics API.
34  *
35  * Pipeline after creation stays immutable unless the dynamic states flag is set.
36  * Dynamic states are set as a bitmask indicating which pipeline states will
37  * be changed dynamically by issuing a command in from the command buffer.
38  *
39  * The dynamic states are listed in Dali::Graphics::PipelineDynamicStateBits.
40  */
41 struct PipelineCreateInfo
42 {
43   /**
44    * @brief Sets pointer to the extension
45    *
46    * The pointer to the extension must be set either to nullptr
47    * or to the valid structure. The structures may create
48    * a chain. The last structure in a chain must point at
49    * nullptr.
50    *
51    * @param[in] value pointer to the valid extension structure
52    * @return reference to this structure
53    */
54   auto& SetNextExtension(ExtensionCreateInfo* value)
55   {
56     nextExtension = value;
57     return *this;
58   }
59
60   /**
61    * @brief Sets the color blend state
62    * param[in] pointer to valid color blend state structure
63    * @return reference to this structure
64    */
65   auto& SetColorBlendState(ColorBlendState* value)
66   {
67     colorBlendState = value;
68     return *this;
69   }
70
71   /**
72    * @brief Sets the shader state for the pipeline
73    *
74    * The function takes an array of shader states in order to compile
75    * the pipeline. Each ShaderState structure determines the pipeline stage
76    * the shader should be executed on. The Shader object may be already created
77    * with a specific stage. Then the ShaderState::inheritPipelineStage must be
78    * set to true.
79    *
80    * Sample:
81    * SetShaderState( { ShaderState().SetShader( vertexShader)
82    *                                .SetPipelineStage( PipelineStage::VERTEX_SHADER ),
83    *                   ShaderState().SetShader( fragmentShader )
84    *                                .SetPipelineStage( PipelineStage::FRAGMENT_SHADER )
85    *                  } );
86    *
87    * In modern graphics API it is possible to attach more than one Shader to a single
88    * stage. For example, one Shader may be just a library of functions:
89    * SetShaderState( { ShaderState().SetShader( vertexShader)
90    *                                .SetPipelineStage( PipelineStage::VERTEX_SHADER ),
91    *                   ShaderState().SetShader( shaderCommons )
92    *                                .SetPipelineStage( PipelineStage::VERTEX_SHADER ),
93    *                   ShaderState().SetShader( fragmentShader )
94    *                                .SetPipelineStage( PipelineStage::FRAGMENT_SHADER )
95    *                  } );
96    *
97    * The Pipeline will compile and link all given shaders.
98    *
99    * param[in] value Valid array of shder states
100    * @return reference to this structure
101    */
102   auto& SetShaderState(const std::vector<ShaderState>& value)
103   {
104     shaderState = &value;
105     return *this;
106   }
107
108   /**
109    * @brief Sets the viewport state
110    * param[in] pointer to valid viewport state structure
111    * @return reference to this structure
112    */
113   auto& SetViewportState(ViewportState* value)
114   {
115     viewportState = value;
116     return *this;
117   }
118
119   /**
120    * @brief Sets the framebuffer state
121    * param[in] pointer to valid framebuffer state structure
122    * @return reference to this structure
123    */
124   auto& SetFramebufferState(FramebufferState* value)
125   {
126     framebufferState = value;
127     return *this;
128   }
129
130   /**
131    * @brief Sets the base pipeline
132    *
133    * Setting base pipeline allows inheriting that pipeline state
134    * and build the new pipeline from it. The base pipeline
135    * must stay valid until derived pipeline needs it.
136    *
137    * param[in] pointer to valid pipeline object
138    * @return reference to this structure
139    */
140   auto& SetBasePipeline(Pipeline* value)
141   {
142     basePipeline = value;
143     return *this;
144   }
145
146   /**
147    * @brief Sets the depth/stencil state
148    * param[in] pointer to valid depth/stencil state structure
149    * @return reference to this structure
150    */
151   auto& SetDepthStencilState(DepthStencilState* value)
152   {
153     depthStencilState = value;
154     return *this;
155   }
156
157   /**
158    * @brief Sets the rasterization state
159    * param[in] pointer to valid rasterization state structure
160    * @return reference to this structure
161    */
162   auto& SetRasterizationState(RasterizationState* value)
163   {
164     rasterizationState = value;
165     return *this;
166   }
167
168   /**
169    * @brief Sets the vertex input state
170    *
171    * Vertex input state describes format of vertices and must
172    * be compatible with attached shaders.
173    *
174    * param[in] pointer to vertex input state structure
175    * @return reference to this structure
176    */
177   auto& SetVertexInputState(VertexInputState* value)
178   {
179     vertexInputState = value;
180     return *this;
181   }
182
183   /**
184    * @brief Sets the input assembly state
185    *
186    * This state describes the topology of the pipeline.
187    *
188    * param[in] pointer to valid input assembly state structure
189    * @return reference to this structure
190    */
191   auto& SetInputAssemblyState(InputAssemblyState* value)
192   {
193     inputAssemblyState = value;
194     return *this;
195   }
196
197   /**
198    * @brief Sets the dynamic state mask
199    *
200    * Certain states can be modified on fly without a need of
201    * creating new pipeline. The commands which modify particular
202    * states may be issued later by executing command buffers.
203    *
204    * param[in] pointer to valid color blend state structure
205    * @return reference to this structure
206    */
207   auto& SetDynamicStateMask(PipelineDynamicStateMask value)
208   {
209     dynamicStateMask = value;
210     return *this;
211   }
212
213   /**
214    * @brief Sets allocation callbacks which will be used when object is created
215    * and destroyed.
216    *
217    * @param[in] value Valid reference to AllocationCallbacksStructure
218    * @return reference to this structure
219    */
220   auto& SetAllocationCallbacks(const AllocationCallbacks& value)
221   {
222     allocationCallbacks = &value;
223     return *this;
224   }
225
226   GraphicsStructureType type{GraphicsStructureType::PIPELINE_CREATE_INFO_STRUCT};
227   ExtensionCreateInfo*  nextExtension{nullptr};
228
229   ColorBlendState*                colorBlendState{nullptr};
230   const std::vector<ShaderState>* shaderState{nullptr};
231   ViewportState*                  viewportState{nullptr};
232   FramebufferState*               framebufferState{nullptr};
233   Pipeline*                       basePipeline{nullptr};
234   DepthStencilState*              depthStencilState{nullptr};
235   RasterizationState*             rasterizationState{nullptr};
236   VertexInputState*               vertexInputState{nullptr};
237   InputAssemblyState*             inputAssemblyState{nullptr};
238   PipelineDynamicStateMask        dynamicStateMask{0u};
239
240   const AllocationCallbacks* allocationCallbacks{nullptr};
241 };
242
243 } // namespace Graphics
244 } // namespace Dali
245
246 #endif // DALI_GRAPHICS_PIPELINE_CREATE_INFO_H