Merge branch 'devel/master' into devel/graphics
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / shader-impl.h
1 #ifndef DALI_INTERNAL_SHADER_H
2 #define DALI_INTERNAL_SHADER_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 // INTERNAL INCLUDES
22 #include <dali/internal/common/shader-data.h>            // ShaderPtr
23 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
24 #include <dali/internal/event/common/object-impl.h>      // Dali::Internal::Object
25 #include <dali/public-api/common/dali-common.h>          // DALI_ASSERT_ALWAYS
26 #include <dali/public-api/common/intrusive-ptr.h>        // Dali::IntrusivePtr
27 #include <dali/public-api/rendering/shader.h>            // Dali::Shader
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace SceneGraph
34 {
35 class Shader;
36 }
37
38 class Shader;
39 using ShaderPtr = IntrusivePtr<Shader>;
40
41 /**
42  * Shader is an object that contains an array of structures of values that
43  * can be accessed as properties.
44  */
45 class Shader : public Object
46 {
47 public:
48   /**
49    * @copydoc Dali::Shader::New()
50    */
51   static ShaderPtr New(std::string_view          vertexShader,
52                        std::string_view          fragmentShader,
53                        Dali::Shader::Hint::Value hints);
54
55   /**
56    * Retrieve the scene-graph shader added by this object.
57    * @return A pointer to the shader.
58    */
59   const SceneGraph::Shader& GetShaderSceneObject() const;
60
61 public: // Default property extensions from Object
62   /**
63    * @copydoc Dali::Internal::Object::SetDefaultProperty()
64    */
65   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
66
67   /**
68    * @copydoc Dali::Internal::Object::GetDefaultProperty()
69    */
70   Property::Value GetDefaultProperty(Property::Index index) const override;
71
72   /**
73    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
74    */
75   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
76
77 private: // implementation
78   /**
79    * Constructor
80    *
81    * @param sceneObject the scene object
82    */
83   Shader(const SceneGraph::Shader* sceneObject);
84
85   /**
86    * Second stage initialization
87    */
88   void SetShader(std::string_view vertexShader, std::string_view fragmentShader, Dali::Shader::Hint::Value hints);
89
90 protected:
91   /**
92    * A reference counted object may only be deleted by calling Unreference()
93    */
94   ~Shader() override;
95
96 private: // unimplemented methods
97   Shader()              = delete;
98   Shader(const Shader&) = delete;
99   Shader& operator=(const Shader&) = delete;
100
101 private:
102   Internal::ShaderDataPtr mShaderData;
103
104 public:
105   /**
106    * @copydoc Dali::Shader::GetShaderVersionPrefix()
107    */
108   static std::string GetShaderVersionPrefix();
109
110   /**
111    * @copydoc Dali::Shader::GetVertexShaderPrefix()
112    */
113   static std::string GetVertexShaderPrefix();
114
115   /**
116    * @copydoc Dali::Shader::GetFragmentShaderPrefix()
117    */
118   static std::string GetFragmentShaderPrefix();
119 };
120
121 } // namespace Internal
122
123 // Helpers for public-api forwarding methods
124 inline Internal::Shader& GetImplementation(Dali::Shader& handle)
125 {
126   DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");
127
128   BaseObject& object = handle.GetBaseObject();
129
130   return static_cast<Internal::Shader&>(object);
131 }
132
133 inline const Internal::Shader& GetImplementation(const Dali::Shader& handle)
134 {
135   DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");
136
137   const BaseObject& object = handle.GetBaseObject();
138
139   return static_cast<const Internal::Shader&>(object);
140 }
141
142 } // namespace Dali
143
144 #endif // DALI_INTERNAL_SHADER_H