40 using namespace std::string_literals;
42 unsigned int shader = glCreateShader(type);
47 std::ifstream file(filePath);
48 std::ostringstream stream;
49 stream << file.rdbuf();
54 const char* cStrSrc = src.c_str();
55 int strLen =
static_cast<int>(src.size());
56 glShaderSource(shader, 1, &cStrSrc, &strLen);
59 glCompileShader(shader);
61 glGetShaderiv(shader, GL_COMPILE_STATUS, &successful);
66 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLen);
67 std::unique_ptr<char*> infoLog = std::make_unique<char*>(
new char[logLen]);
68 glGetShaderInfoLog(shader, logLen,
nullptr, *infoLog.get());
69 std::string strInfoLog(*infoLog.get(), logLen);
70 glDeleteShader(shader);
71 throw std::runtime_error(
"Unable to compile shader ("s + filePath +
") - \n" + strInfoLog);
86 unsigned int vertexShader =
createShader(GL_VERTEX_SHADER, vertShaderFile);
87 unsigned int fragmentShader =
createShader(GL_FRAGMENT_SHADER, fragShaderFile);
91 glAttachShader(
program, vertexShader);
92 glAttachShader(
program, fragmentShader);
97 glGetProgramiv(
program, GL_LINK_STATUS, &success);
102 glGetProgramiv(
program, GL_INFO_LOG_LENGTH, &logLen);
103 std::unique_ptr<char*> infoLog = std::make_unique<char*>(
new char[logLen]);
104 glGetProgramInfoLog(
program, logLen,
nullptr, *infoLog.get());
105 std::string strInfoLog(*infoLog.get(), logLen);
108 glDeleteShader(vertexShader);
109 glDeleteShader(fragmentShader);
110 throw std::runtime_error(
"Unable to link shaders to program - " + strInfoLog);
113 glDeleteShader(vertexShader);
114 glDeleteShader(fragmentShader);