FCT
载入中...
搜索中...
未找到
Shaderc_ShaderCompiler.cpp
浏览该文件的文档.
1//
2// Created by Administrator on 2025/4/8.
3//
4#include "../FCTAPI.h"
5namespace FCT {
7 {
8 m_options.SetSourceLanguage(shaderc_source_language_hlsl);
9 m_options.SetTargetSpirv(shaderc_spirv_version_1_5);
10 m_options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_2);
11
12 }
13
14 std::vector<char> Shaderc_ShaderCompiler::compile(const std::string& source, const std::string& entry_point, ShaderKind kind)
15 {
16 fout << "编译着色器" << std::endl;
17 fout << source << std::endl;
18 auto result = m_compiler.CompileGlslToSpv(source.c_str(), source.size(), FCTShaderKindToShaderrcShaderKind(kind), "FCTShader"
19 , entry_point.c_str(), m_options);
20
21 if (result.GetCompilationStatus() != shaderc_compilation_status_success) {
22 ferr << "Shader compilation failed: " << result.GetErrorMessage() << std::endl;
23 return {};
24 }
25
26 const uint32_t* dataStart = result.cbegin();
27 const char* byteStart = reinterpret_cast<const char*>(dataStart);
28 size_t byteSize = (result.cend() - result.cbegin()) * sizeof(uint32_t);
29
30 return std::vector<char>(byteStart, byteStart + byteSize);
31 }
32}
std::vector< char > compile(const std::string &source, const std::string &entry_point, ShaderKind kind) override
std::ostream & ferr
std::ostream & fout
constexpr shaderc_shader_kind FCTShaderKindToShaderrcShaderKind(ShaderKind kind)