Elaztek Developer Hub
Blamite Game Engine - Tool (Library)  00368.02.12.23.1347.blamite
A command-line utility that aids in the creation of Blamite Cache (.map) Files.
CompileShadersCommand.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Strings/components/utils/io/io.h>
4 #include <Strings/components/utils/string/string.h>
5 #include <Strings/components/logger/logger.h>
6 
7 #include "../ToolCommand.hpp"
8 #include "../console.h"
9 
10 #ifdef TOOL_LIB_EXPORTS
11 #define TOOL_LIB_API __declspec(dllexport)
12 #else
13 #define TOOL_LIB_API __declspec(dllimport)
14 #endif
15 
17 {
18 private:
19  int successful_compiles = 0;
20  int warning_compiles = 0;
21  int failed_compiles = 0;
22 
23  void attempt_shader_compile(std::string file_path, std::string output_file_path, bool vertex_shader);
24  void compile_shaders(std::string base_directory);
25 
26 public:
27 
29  {
30  command = "compile-shaders";
31  syntax = "compile-shaders <directory>";
32  description = "[DEPRECATED: bgfx only] scans through a given directory and compiles all vertex and fragment shaders found";
33  }
34 
35  int execute(std::vector<std::string> args)
36  {
37  if (args.size() == 0)
38  {
39  BlamStrings::Logger::LogEvent("no directory path was provided, cannot compile shaders", BlamLogLevel::Warning);
40  return -1;
41  }
42  else
43  {
44  if (BlamStrings::Utils::IO::FileExists(args[0]))
45  {
46  if (BlamStrings::Utils::IO::IsDirectory(args[0]))
47  {
48  std::vector<std::string> directory_list = BlamStrings::Utils::IO::GetDirectoryList(args[0]);
49 
50  for (int i = 0; i < directory_list.size(); i++)
51  {
52  compile_shaders(directory_list.at(i));
53  }
54 
55  BlamStrings::Logger::LogEvent("shader compilation finished", TerminalColor::Cyan);
56  BlamStrings::Logger::LogEvent("results:");
57  BlamStrings::Logger::LogEvent("succeeded : " + std::to_string(successful_compiles), TerminalColor::BrightGreen);
58  BlamStrings::Logger::LogEvent("warnings : " + std::to_string(warning_compiles), TerminalColor::Yellow);
59  BlamStrings::Logger::LogEvent("failures : " + std::to_string(failed_compiles), TerminalColor::BrightRed);
60  }
61  else
62  {
63  BlamStrings::Logger::LogEvent("the path '" + args[0] + "' refers to a file, not a directory, cannot compile shaders", BlamLogLevel::Warning);
64  return -1;
65  }
66  }
67  else
68  {
69  BlamStrings::Logger::LogEvent("directory '" + args[0] + "' does not exist, cannot compile shaders", BlamLogLevel::Warning);
70  return -1;
71  }
72 
73  return 0;
74  }
75 
76  return -1;
77  }
78 };
CompileShadersCommand
Definition: CompileShadersCommand.hpp:16
ToolCommand::syntax
std::string syntax
Definition: ToolCommand.hpp:16
CompileShadersCommand::execute
int execute(std::vector< std::string > args)
Definition: CompileShadersCommand.hpp:35
CompileShadersCommand::CompileShadersCommand
CompileShadersCommand()
Definition: CompileShadersCommand.hpp:28
ToolCommand::command
std::string command
Definition: ToolCommand.hpp:15
ToolCommand
Definition: ToolCommand.hpp:12
ToolCommand::description
std::string description
Definition: ToolCommand.hpp:17