FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
shader_manager.hpp
1/*
2 * Copyright 2025 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 final : 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 final : public manager::BaseManager<vulkan::Shader, DataBlock>
51{
52public:
53 using BaseManager::BaseManager;
54
68 bool initialize() override;
69
84 bool loadFromMemory(std::string_view name,
85 void const* data,
86 int size,
87 fge::vulkan::Shader::Type type,
88 ShaderInputTypes input,
89 bool debugBuild = false);
100 bool loadFromFile(std::string_view name,
101 std::filesystem::path path,
102 fge::vulkan::Shader::Type type,
103 ShaderInputTypes input,
104 bool debugBuild = false);
105};
106
111FGE_API extern ShaderManager gManager;
112
117
131FGE_API bool CompileAndLinkShader(fge::vulkan::Shader::Type type,
132 char const* shaderIn,
133 int shaderInSize,
134 std::vector<uint32_t>& shaderOut,
135 char const* shaderName,
136 char const* entryPointName,
137 bool debugBuild,
138 bool isHlsl);
139
140FGE_API bool SaveSpirVToBinaryFile(std::vector<uint32_t> const& spirv, std::filesystem::path const& path);
141
145
146} // namespace fge::shader
147
148#endif // _FGE_SHADER_MANAGER_HPP_INCLUDED
Base class for all managers.
Definition C_baseManager.hpp:78
std::size_t size() const
Definition C_baseManager.inl:40
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