FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
shader_manager.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_SHADER_MANAGER_HPP_INCLUDED
18#define _FGE_SHADER_MANAGER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21
22#include "FastEngine/manager/C_baseManager.hpp"
23#include "FastEngine/vulkan/C_shader.hpp"
24
25#define FGE_SHADER_BAD FGE_MANAGER_BAD
26#define FGE_SHADER_DEFAULT_VERTEX "FGE:VERTEX"
27#define FGE_SHADER_DEFAULT_NOTEXTURE_FRAGMENT "FGE:NT_FRAG"
28#define FGE_SHADER_DEFAULT_FRAGMENT "FGE:FRAG"
29
30namespace fge::shader
31{
32
33struct DataBlock : manager::BaseDataBlock<vulkan::Shader>
34{};
35
36enum class ShaderInputTypes
37{
38 SHADER_HLSL,
39 SHADER_GLSL,
40 SHADER_SPIRV
41};
42
50class FGE_API ShaderManager : public manager::BaseManager<vulkan::Shader, DataBlock>
51{
52public:
53 using BaseManager::BaseManager;
54
68 bool initialize() override;
69 [[nodiscard]] bool isInitialized() override;
70 void uninitialize() override;
71
86 bool loadFromMemory(std::string_view name,
87 void const* data,
88 int size,
89 fge::vulkan::Shader::Type type,
90 ShaderInputTypes input,
91 bool debugBuild = false);
102 bool loadFromFile(std::string_view name,
103 std::filesystem::path path,
104 fge::vulkan::Shader::Type type,
105 ShaderInputTypes input,
106 bool debugBuild = false);
107};
108
113FGE_API extern ShaderManager gManager;
114
133FGE_API bool CompileAndLinkShader(fge::vulkan::Shader::Type type,
134 char const* shaderIn,
135 int shaderInSize,
136 std::vector<uint32_t>& shaderOut,
137 char const* shaderName,
138 char const* entryPointName,
139 bool debugBuild,
140 bool isHlsl);
141
142FGE_API bool SaveSpirVToBinaryFile(std::vector<uint32_t> const& spirv, std::filesystem::path const& path);
143
148} // namespace fge::shader
149
150#endif // _FGE_SHADER_MANAGER_HPP_INCLUDED
Base class for all managers.
Definition C_baseManager.hpp:63
Manage shaders.
Definition shader_manager.hpp:51
bool initialize() override
Initialize the shader manager.
bool loadFromFile(std::string_view name, std::filesystem::path path, fge::vulkan::Shader::Type type, ShaderInputTypes input, bool debugBuild=false)
Load a shader from a file.
bool loadFromMemory(std::string_view name, void const *data, int size, fge::vulkan::Shader::Type type, ShaderInputTypes input, bool debugBuild=false)
Load a shader from the memory.
FGE_API bool CompileAndLinkShader(fge::vulkan::Shader::Type type, char const *shaderIn, int shaderInSize, std::vector< uint32_t > &shaderOut, char const *shaderName, char const *entryPointName, bool debugBuild, bool isHlsl)
Public API access to glslang.
FGE_API ShaderManager gManager
The global shader manager.
Definition C_baseManager.hpp:42
Definition shader_manager.hpp:34