Shader Reflection
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / shader-cache.h
1 #ifndef DALI_INTERNAL_SHADER_CACHE_H
2 #define DALI_INTERNAL_SHADER_CACHE_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 #include <dali/graphics-api/graphics-controller.h>
21 #include <dali/graphics-api/graphics-shader-create-info.h>
22 #include <dali/graphics-api/graphics-shader.h>
23 #include <memory>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Render
30 {
31 /**
32  * Caches graphics shaders as they are created by SceneGraph::Shader.
33  */
34 struct ShaderCache
35 {
36   struct Item
37   {
38     Item()            = default;
39     Item(const Item&) = delete;
40     Item(Item&&)      = default;
41
42     Item(Graphics::UniquePtr<Dali::Graphics::Shader> shader,
43          const std::vector<char>                     shaderCode,
44          Graphics::PipelineStage                     stage,
45          Graphics::ShaderSourceMode                  type)
46     : shader(std::move(shader)),
47       shaderCode(shaderCode),
48       stage(stage),
49       type(type)
50     {
51     }
52
53     ~Item() = default;
54
55     Graphics::UniquePtr<Dali::Graphics::Shader> shader{nullptr};
56     const std::vector<char>                     shaderCode;
57     Graphics::PipelineStage                     stage;
58     Graphics::ShaderSourceMode                  type;
59   };
60
61   /**
62    * Constructor
63    *
64    * @param[in] controller The graphics controller
65    */
66   explicit ShaderCache(Dali::Graphics::Controller& controller);
67
68   /**
69    * Get a shader from it's source code
70    *
71    * @param[in] shaderCode The shader code
72    * @param[in] stage The pipeline stage (e.g. VERTEX_SHADER or FRAGMENT_SHADER etc.)
73    * @param[in] type The type of the shader (i.e. text or binary)
74    * @return the graphics shader
75    */
76   Dali::Graphics::Shader& GetShader(const std::vector<char> shaderCode, Graphics::PipelineStage stage, Graphics::ShaderSourceMode type);
77
78   /**
79    * Destroy any graphics objects owned by this scene graph object
80    */
81   void DestroyGraphicsObjects();
82
83 private:
84   std::vector<Item>           mItems;
85   Dali::Graphics::Controller& mController;
86 };
87
88 } // namespace Render
89 } // namespace Internal
90 } // namespace Dali
91
92 #endif //DALI_INTERNAL_SHADER_CACHE_H