7060fb67fab05af2312b6aadd9c1996eff97bcb3
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-api-shader-details.h
1 #ifndef DALI_GRAPHICS_API_SHADER_DETAILS_H
2 #define DALI_GRAPHICS_API_SHADER_DETAILS_H
3
4 /*
5  * Copyright (c) 2017 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 #include <string>
22 #include <vector>
23
24 namespace Dali
25 {
26 namespace Graphics
27 {
28 namespace API
29 {
30 namespace ShaderDetails
31 {
32
33 constexpr uint32_t ERROR_VERTEX_INPUT_ATTRIBUTE_NOT_FOUND( -1u );
34
35 enum class ShaderSourceType
36 {
37   STRING,
38   BINARY
39 };
40
41 struct ShaderSource
42 {
43   /**
44    * Creates shader source object from source string
45    * @param sourceString
46    */
47   explicit ShaderSource( const std::string& sourceString )
48   {
49     source = sourceString;
50     type = ShaderSourceType::STRING;
51   }
52
53   /**
54    * Creates shader source object from vector
55    * @param sourceBinary
56    */
57   template<class T>
58   explicit ShaderSource( const std::vector<T>& sourceBinary )
59   {
60     code.resize( sourceBinary.size() * sizeof(T) );
61     auto begin = reinterpret_cast<const char*>(&*sourceBinary.begin());
62     auto end = reinterpret_cast<const char*>(&*sourceBinary.end());
63     std::copy( begin, end, code.begin() );
64     type = ShaderSourceType::BINARY;
65   }
66
67   template<char>
68   explicit ShaderSource( const std::vector<char>& sourceBinary )
69   {
70     code = sourceBinary;
71     type = ShaderSourceType::BINARY;
72   }
73
74   /**
75    * Creates shader source object from C-Style binary data
76    * @param pBinary
77    * @param size
78    */
79   explicit ShaderSource( const void* pBinary, uint32_t size )
80   {
81     code.resize( size );
82     auto begin = reinterpret_cast<const char*>(pBinary);
83     auto end = begin + size;
84     std::copy( begin, end, code.begin() );
85     type = ShaderSourceType::BINARY;
86   }
87
88   ShaderSource( const ShaderSource& shaderSource ) = default;
89
90   /**
91    * Tests whether the shader module has been set
92    * @return
93    */
94   bool IsSet() const
95   {
96     if( (type == ShaderSourceType::BINARY && code.empty()) ||
97         (type == ShaderSourceType::STRING && source.empty()) )
98     {
99       return false;
100     }
101     return true;
102   }
103
104   bool operator==(const ShaderSource& rhs ) const
105   {
106     if( type == ShaderSourceType::BINARY )
107     {
108       return code == rhs.code;
109     }
110     else
111     {
112       return source == rhs.source;
113     }
114     return false;
115   }
116
117   std::string       source;
118   std::vector<char> code;
119   ShaderSourceType type;
120 };
121
122 enum class Language {
123   GLSL_1,
124   GLSL_3_1,
125   GLSL_3_2,
126   SPIRV_1_0,
127   SPIRV_1_1,
128 };
129
130 enum class PipelineStage {
131   VERTEX,
132   GEOMETRY,
133   FRAGMENT,
134   COMPUTE,
135   TESSELATION_CONTROL,
136   TESSELATION_EVALUATION,
137 };
138
139 enum class VertexInputAttributeFormat
140 {
141   UNDEFINED,
142   FLOAT,
143   INTEGER,
144   VEC2,
145   VEC3,
146   VEC4
147 };
148
149 enum class UniformClass
150 {
151   SAMPLER,
152   IMAGE,
153   COMBINED_IMAGE_SAMPLER,
154   UNIFORM_BUFFER,
155   UNDEFINED
156 };
157
158 struct UniformInfo
159 {
160   std::string   name{""};
161   UniformClass  uniformClass{ UniformClass::UNDEFINED };
162   uint32_t      binding { 0u };
163   uint32_t      bufferIndex { 0u };
164   uint32_t      offset { 0u };
165   uint32_t      location { 0u };
166 };
167
168 struct UniformBlockInfo
169 {
170   std::string name {""};
171   uint32_t    descriptorSet {0u};
172   uint32_t    binding {0u};
173   uint32_t    size {0u};
174   std::vector<UniformInfo> members {};
175 };
176
177 } // namespace TextureDetails
178 } // namespace API
179 } // namespace Graphics
180 } // namespace Dali
181
182 #endif // DALI_GRAPHICS_API_SHADER_DETAILS_H