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 #ifndef SCENE_SRC_RESOURCE_SHADER_H
17 #define SCENE_SRC_RESOURCE_SHADER_H
18
19 #include <scene/ext/intf_ecs_object.h>
20 #include <scene/ext/intf_internal_scene.h>
21 #include <scene/ext/intf_render_resource.h>
22 #include <scene/interface/intf_shader.h>
23 #include <scene/interface/resource/types.h>
24 #include <shared_mutex>
25
26 #include <meta/ext/implementation_macros.h>
27 #include <meta/ext/object.h>
28 #include <meta/interface/resource/intf_dynamic_resource.h>
29
30 #include "render_resource.h"
31
SCENE_BEGIN_NAMESPACE()32 SCENE_BEGIN_NAMESPACE()
33
34 class GraphicsState : public META_NS::IntroduceInterfaces<RenderResource, IGraphicsState> {
35 META_OBJECT_NO_CLASSINFO(GraphicsState, IntroduceInterfaces)
36 public:
37 bool SetGraphicsState(RENDER_NS::RenderHandleReference) override;
38 RENDER_NS::RenderHandleReference GetGraphicsState() const override;
39
40 RENDER_NS::GraphicsState CreateGraphicsState(const IRenderContext::Ptr& context,
41 RENDER_NS::RenderHandleReference state, BASE_NS::string_view defaultRenderSlot);
42 bool UpdateGraphicsState(
43 const IRenderContext::Ptr &context, const RENDER_NS::GraphicsState &gs, BASE_NS::string_view renderSlot);
44 RENDER_NS::GraphicsState CreateNewGraphicsState(const IRenderContext::Ptr& context, bool blend);
45 RENDER_NS::GraphicsState GetGraphicsState(const IRenderContext::Ptr& context) const;
46
47 protected:
48 BASE_NS::string path_;
49 BASE_NS::string variant_;
50 RENDER_NS::RenderHandleReference graphicsState_;
51 };
52
53 class Shader : public META_NS::IntroduceInterfaces<GraphicsState, IShader, IShaderState, META_NS::INamed,
54 META_NS::IPropertyOwner> {
55 META_OBJECT(Shader, ClassId::Shader, IntroduceInterfaces)
56 public:
57 META_BEGIN_STATIC_DATA()
58 META_STATIC_PROPERTY_DATA(META_NS::INamed, BASE_NS::string, Name)
59 META_STATIC_PROPERTY_DATA(IShader, CullModeFlags, CullMode)
60 META_STATIC_PROPERTY_DATA(IShader, bool, Blend)
61 META_END_STATIC_DATA()
62
63 META_IMPLEMENT_PROPERTY(BASE_NS::string, Name)
64 META_IMPLEMENT_PROPERTY(CullModeFlags, CullMode)
65 META_IMPLEMENT_PROPERTY(bool, Blend)
66
67 void OnPropertyChanged(const META_NS::IProperty&) override;
68
69 BASE_NS::string GetName() const override;
GetResourceType()70 CORE_NS::ResourceType GetResourceType() const override
71 {
72 return ClassId::ShaderResource.Id().ToUid();
73 }
74
75 bool SetRenderHandle(RENDER_NS::RenderHandleReference handle) override;
76 bool SetShaderState(RENDER_NS::RenderHandleReference shader, RENDER_NS::RenderHandleReference graphics) override;
77 bool setShaderStateInProgress_ = false;
78 };
79
80 SCENE_END_NAMESPACE()
81
82 #endif