| 7 | #include "../Util/Utils.h" |
| 8 | |
| 9 | BaseShader::BaseShader(const std::string &vertex_file_path, const std::string &fragment_file_path) { |
| 10 | // Create the shaders |
| 11 | VertexShaderID = glCreateShader(GL_VERTEX_SHADER); |
| 12 | FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); |
| 13 | |
| 14 | // Read the Vertex Shader code from the file |
| 15 | std::string VertexShaderCode; |
| 16 | std::ifstream VertexShaderStream(vertex_file_path, std::ios::in); |
| 17 | |
| 18 | ASSERT(VertexShaderStream.is_open(), "Impossible to open! " << vertex_file_path); |
| 19 | std::string Line; |
| 20 | while(getline(VertexShaderStream, Line)) |
| 21 | VertexShaderCode += "\n" + Line; |
| 22 | VertexShaderStream.close(); |
| 23 | |
| 24 | // Read the Fragment Shader code from the file |
| 25 | std::string FragmentShaderCode; |
| 26 | std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in); |
| 27 | if(FragmentShaderStream.is_open()){ |
| 28 | std::string Line; |
| 29 | while(getline(FragmentShaderStream, Line)) |
| 30 | FragmentShaderCode += "\n" + Line; |
| 31 | FragmentShaderStream.close(); |
| 32 | } |
| 33 | |
| 34 | GLint Result = GL_FALSE; |
| 35 | int InfoLogLength; |
| 36 | |
| 37 | // Compile Vertex Shader |
| 38 | LOG(INFO) << "Compiling shader : " << vertex_file_path.c_str(); |
| 39 | char const * VertexSourcePointer = VertexShaderCode.c_str(); |
| 40 | glShaderSource(VertexShaderID, 1, &VertexSourcePointer , nullptr); |
| 41 | glCompileShader(VertexShaderID); |
| 42 | |
| 43 | // Check Vertex Shader |
| 44 | glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); |
| 45 | glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); |
| 46 | if ( InfoLogLength > 0 ){ |
| 47 | std::vector<char> VertexShaderErrorMessage(InfoLogLength+1); |
| 48 | glGetShaderInfoLog(VertexShaderID, InfoLogLength, nullptr, &VertexShaderErrorMessage[0]); |
| 49 | LOG(WARNING) << &VertexShaderErrorMessage[0]; |
| 50 | } |
| 51 | |
| 52 | // Compile Fragment Shader |
| 53 | LOG(INFO) << "Compiling shader : " << fragment_file_path.c_str(); |
| 54 | char const * FragmentSourcePointer = FragmentShaderCode.c_str(); |
| 55 | glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , nullptr); |
| 56 | glCompileShader(FragmentShaderID); |
| 57 | |
| 58 | // Check Fragment Shader |
| 59 | glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); |
| 60 | glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); |
| 61 | if ( InfoLogLength > 0 ){ |
| 62 | std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1); |
| 63 | glGetShaderInfoLog(FragmentShaderID, InfoLogLength, nullptr, &FragmentShaderErrorMessage[0]); |
| 64 | LOG(WARNING) << &FragmentShaderErrorMessage[0]; |
| 65 | } |
| 66 |
nothing calls this directly
no outgoing calls
no test coverage detected