MCPcopy Create free account
hub / github.com/JeanPhilippeKernel/RendererEngine / Compile

Method Compile

ZEngine/src/ShaderCompiler.cpp:28–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 }
27
28 std::tuple<ShaderOperationResult, GLuint> ShaderCompiler::Compile() {
29 bool compile_process_succeeded{true};
30
31 std::vector<ShaderInformation> shader_information;
32
33 auto find_it = s_already_compiled_shaders_collection.find(m_source_file);
34
35 if (find_it != std::end(s_already_compiled_shaders_collection)) {
36 shader_information = find_it->second;
37 std::for_each(std::begin(shader_information), std::end(shader_information), [](ShaderInformation& item) { item.CompiledOnce = true; });
38 } else {
39 ShaderOperationResult read_operation = m_reader->ReadAsync(m_source_file).get();
40 if (read_operation == ShaderOperationResult::FAILURE) {
41 ZENGINE_CORE_CRITICAL("Compilation process stopped");
42 return std::make_tuple(ShaderOperationResult::FAILURE, 0);
43 }
44
45 shader_information = m_reader->GetInformations();
46 if (shader_information.empty()) {
47 ZENGINE_CORE_CRITICAL("Information collected while reading shader file are incorrect or not enough to continue compilation process");
48 ZENGINE_CORE_CRITICAL("Compilation process stopped");
49 return std::make_tuple(ShaderOperationResult::FAILURE, 0);
50 }
51 }
52
53 while (m_running_stages) {
54
55 ICompilerStage* stage = reinterpret_cast<ICompilerStage*>(m_stage.get());
56 stage->Run(shader_information);
57
58 const auto& stage_info = stage->GetInformation();
59 compile_process_succeeded = compile_process_succeeded && stage_info.IsSuccess;
60
61 if (stage_info.IsSuccess && m_stage->HasNext()) {
62 m_stage->Next();
63 } else {
64 m_running_stages = false;
65 }
66 }
67
68 if (!compile_process_succeeded) {
69 ZENGINE_CORE_CRITICAL("Compilation process weren't able to create a valid Shader Program");
70 return std::make_tuple(ShaderOperationResult::FAILURE, 0);
71 }
72
73 // We store it, so next time we won't run the compilation stage if it has been before
74 s_already_compiled_shaders_collection.emplace(m_source_file, shader_information);
75
76 const auto& first = std::begin(shader_information);
77 return std::make_tuple(ShaderOperationResult::SUCCESS, first->ProgramId);
78 }
79} // namespace ZEngine::Rendering::Shaders::Compilers

Callers 1

CreateProgramMethod · 0.80

Calls 4

ReadAsyncMethod · 0.80
HasNextMethod · 0.80
NextMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected