• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "shader_util.h"
17 
18 #include <scene/ext/intf_ecs_context.h>
19 #include <scene/ext/intf_render_resource.h>
20 #include <scene/ext/util.h>
21 
22 #include <3d/render/default_material_constants.h>
23 #include <render/device/intf_shader_manager.h>
24 
SCENE_BEGIN_NAMESPACE()25 SCENE_BEGIN_NAMESPACE()
26 
27 bool ShaderUtil::Build(const META_NS::IMetadata::Ptr& d)
28 {
29     IInternalScene::Ptr p;
30     if (Super::Build(d)) {
31         p = GetInterfaceBuildArg<IInternalScene>(d, "Scene");
32         scene_ = p;
33     }
34     return p != nullptr;
35 }
36 
CreateDefaultShader() const37 Future<IShader::Ptr> ShaderUtil::CreateDefaultShader() const
38 {
39     if (auto scene = scene_.lock()) {
40         return scene->AddTask([=] {
41             auto& shaderMgr = scene->GetRenderContext().GetDevice().GetShaderManager();
42             auto renderSlotId =
43                 shaderMgr.GetRenderSlotId(CORE3D_NS::DefaultMaterialShaderConstants::RENDER_SLOT_FORWARD_OPAQUE);
44             auto rsd = shaderMgr.GetRenderSlotData(renderSlotId);
45 
46             auto shader = META_NS::GetObjectRegistry().Create<IShader>(ClassId::Shader);
47             if (auto i = interface_cast<IRenderResource>(shader)) {
48                 i->SetRenderHandle(scene, rsd.shader);
49             }
50             return shader;
51         });
52     }
53     return {};
54 }
55 
56 SCENE_END_NAMESPACE()