|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
#include <fstream> |
|
|
|
|
#include <spdlog/spdlog.h> |
|
|
|
|
#include <unordered_map> |
|
|
|
|
#include <utility> |
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
@ -27,6 +28,12 @@ bool shader_handle::handle_error(const std::string &filename) {
@@ -27,6 +28,12 @@ bool shader_handle::handle_error(const std::string &filename) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shader_handle::add_shader(GLuint type, const std::string &filename) { |
|
|
|
|
add_shader(type, filename, {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shader_handle::add_shader( |
|
|
|
|
GLuint type, const std::string &filename, |
|
|
|
|
std::unordered_map<std::string, std::string> templates) { |
|
|
|
|
shader = glCreateShader(type); |
|
|
|
|
|
|
|
|
|
// read source
|
|
|
|
@ -40,6 +47,16 @@ void shader_handle::add_shader(GLuint type, const std::string &filename) {
@@ -40,6 +47,16 @@ void shader_handle::add_shader(GLuint type, const std::string &filename) {
|
|
|
|
|
throw std::runtime_error("Could not open filepath " + filename); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// apply templates
|
|
|
|
|
for (const auto &item : templates) { |
|
|
|
|
auto position = std::string::npos; |
|
|
|
|
while ((position = source.rfind(item.first, position)) != |
|
|
|
|
std::string::npos) { |
|
|
|
|
source.replace(position, item.first.size(), item.second); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
spdlog::info("New shader: {}\n{}", filename, source); |
|
|
|
|
|
|
|
|
|
const char *cstr = source.c_str(); |
|
|
|
|
glShaderSource(shader, 1, &cstr, NULL); |
|
|
|
|
|
|
|
|
@ -62,6 +79,16 @@ shader_handle::shader_handle(std::string filename)
@@ -62,6 +79,16 @@ shader_handle::shader_handle(std::string filename)
|
|
|
|
|
add_shader(GL_VERTEX_SHADER, std::move(filename)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
shader_handle::shader_handle( |
|
|
|
|
std::string filename, std::string filename2, |
|
|
|
|
std::unordered_map<std::string, std::string> templates) |
|
|
|
|
: program(glCreateProgram()) { |
|
|
|
|
|
|
|
|
|
add_shader(GL_VERTEX_SHADER, std::move(filename), templates); |
|
|
|
|
add_shader(GL_FRAGMENT_SHADER, std::move(filename2), templates); |
|
|
|
|
link(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
shader_handle::shader_handle(std::string filename, std::string filename2) |
|
|
|
|
: program(glCreateProgram()) { |
|
|
|
|
add_shader(GL_VERTEX_SHADER, std::move(filename)); |
|
|
|
|