Lagrange
ShaderLoader.h
1/*
2 * Copyright 2021 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/Entity.h>
15#include <lagrange/ui/api.h>
16#include <lagrange/ui/types/Shader.h>
17
18namespace lagrange {
19namespace ui {
20
21struct LA_UI_API ShaderLoader
22{
23 enum class PathType { REAL, VIRTUAL };
24
25 using result_type = std::shared_ptr<Shader>;
26
27 result_type operator()(
28 const std::string& generic_path,
29 PathType pathtype,
30 const ShaderDefines& defines = {}) const;
31};
32using ShaderCache = entt::resource_cache<Shader, ShaderLoader>;
33using ShaderResource = entt::resource<Shader>;
34
35// using ShaderDef = std::tuple<std::string, std::string, ShaderLoader::PathType, ShaderDefines>;
37{
38 std::string path;
39 ShaderLoader::PathType path_type = ShaderLoader::PathType::REAL;
40 std::string display_name;
41 ShaderDefines defines;
42};
43using RegisteredShaders = std::unordered_map<entt::id_type, ShaderDefinition>;
44
45
46//Register shader with given id that can be used to load/reload and access the shader
47LA_UI_API entt::id_type
48register_shader_as(Registry& r, entt::id_type id, const ShaderDefinition& def);
49
50//Register shader, returns and ID that can be used to load/reload and access the shader
51LA_UI_API entt::id_type register_shader(Registry& r, const ShaderDefinition& def);
52LA_UI_API entt::id_type
53register_shader(Registry& r, const std::string& path, const std::string& display_name);
54
55LA_UI_API entt::id_type
56register_shader_variant(Registry& r, entt::id_type id, const ShaderDefines& shader_defines);
57
58LA_UI_API ShaderResource get_shader(Registry& r, entt::id_type id);
59
60
61LA_UI_API RegisteredShaders& get_registered_shaders(Registry& r);
62LA_UI_API ShaderCache& get_shader_cache(Registry& r);
63
70 const std::string& virtual_path,
71 const std::string& contents,
72 bool overwrite = false);
73
74} // namespace ui
75} // namespace lagrange
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
LA_UI_API bool add_file_to_shader_virtual_fs(const std::string &virtual_path, const std::string &contents, bool overwrite=false)
Creates a file using virtual_path with contents in the shader virtual file system.
Definition: ShaderLoader.cpp:145
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: ShaderLoader.h:37
Definition: ShaderLoader.h:22