Elaztek Developer Hub
Blamite Game Engine - Tool (Library)
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 #include <Strings/components/utils/list/list.h>
7 
8 #include "../ToolCommand.hpp"
9 #include "../console.h"
10 
11 #ifdef TOOL_LIB_EXPORTS
12 #define TOOL_LIB_API __declspec(dllexport)
13 #else
14 #define TOOL_LIB_API __declspec(dllimport)
15 #endif
16 
26 {
27 private:
28  int successful_compiles = 0;
29  int warning_compiles = 0;
30  int failed_compiles = 0;
31 
32  void attempt_shader_compile(std::string file_path, std::string output_file_path, bool vertex_shader);
33  void compile_shaders(std::string base_directory);
34 
35  std::string profile = "";
36 
37 public:
38 
40  {
41  command = "compile-shaders";
42  syntax = "compile-shaders <directory> <profile> [-bulk]";
43  description = "compiles a collection of shaders from a directory. if -bulk is specified, scans through a given directory and compiles all shaders found within subdirectories.";
44  }
45 
46  int execute(std::vector<std::string> args)
47  {
48  if (args.size() == 0)
49  {
50  BlamStrings::Logger::LogEvent("no directory path was provided, cannot compile shaders", BlamLogLevel::Warning);
51  return -1;
52  }
53 
54  if (args.size() == 1)
55  {
56  BlamStrings::Logger::LogEvent("no shader profile was provided, cannot compile shaders", BlamLogLevel::Warning);
57  return -1;
58  }
59 
60  if (!BlamStrings::Utils::IO::FileExists(args[0]))
61  {
62  BlamStrings::Logger::LogEvent("directory '" + args[0] + "' does not exist, cannot compile shaders", BlamLogLevel::Warning);
63  return -1;
64  }
65 
66  if (!BlamStrings::Utils::IO::IsDirectory(args[0]))
67  {
68  BlamStrings::Logger::LogEvent("the path '" + args[0] + "' refers to a file, not a directory, cannot compile shaders", BlamLogLevel::Warning);
69  return -1;
70  }
71 
72  profile = args[1];
73 
74  bool bulk_compile = false;
75 
76  if (args.size() > 2)
77  {
78  for (int i = 2; i < args.size(); i++)
79  {
80  if (args.at(i) == "-bulk")
81  {
82  bulk_compile = true;
83  }
84  }
85  }
86 
87  if (bulk_compile)
88  {
89  std::vector<std::string> directory_list = BlamStrings::Utils::IO::GetDirectoryList(args[0]);
90 
91  for (int i = 0; i < directory_list.size(); i++)
92  {
93  compile_shaders(directory_list.at(i));
94  }
95  }
96  else
97  {
98  compile_shaders(args[0]);
99  }
100 
101  BlamStrings::Logger::LogEvent("shader compilation finished", TerminalColor::Cyan);
102  BlamStrings::Logger::LogEvent("results:");
103  BlamStrings::Logger::LogEvent("succeeded : " + std::to_string(successful_compiles), TerminalColor::BrightGreen);
104  BlamStrings::Logger::LogEvent("warnings : " + std::to_string(warning_compiles), TerminalColor::Yellow);
105  BlamStrings::Logger::LogEvent("failures : " + std::to_string(failed_compiles), TerminalColor::BrightRed);
106  return 0;
107  }
108 };
CompileShadersCommand.hpp
CompileShadersCommand
Class for the Compile Shaders command.
Definition: CompileShadersCommand.hpp:25
ToolCommand::syntax
std::string syntax
The syntax of the command. This should include the command name, as well as any arguments.
Definition: ToolCommand.hpp:19
CompileShadersCommand::execute
int execute(std::vector< std::string > args)
Executes the command.
Definition: CompileShadersCommand.hpp:46
CompileShadersCommand::CompileShadersCommand
CompileShadersCommand()
Definition: CompileShadersCommand.hpp:39
ToolCommand::command
std::string command
The name of the command.
Definition: ToolCommand.hpp:18
ToolCommand
Base class representing a Tool command.
Definition: ToolCommand.hpp:15
ToolCommand::description
std::string description
A description of the command.
Definition: ToolCommand.hpp:20