Bubba-3D  0.9.0
Awesome game engine!
IShader.h
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 //
18 // Created by johan on 2016-03-12.
19 //
20 
21 #ifndef SUPER_BUBBA_AWESOME_SPACE_ISHADER_H
22 #define SUPER_BUBBA_AWESOME_SPACE_ISHADER_H
23 
24 #include <string>
25 #include "Logger.h"
26 #include "glutil/glutil.h"
27 
28 #define MAX_LOG_SIZE 1024
29 
30 class IShader {
31 public:
32  virtual void compile() = 0;
33  virtual void checkErrors() = 0;
34  virtual GLuint getGLId() = 0;
35 
36  GLuint compileShader(GLenum type, const char *source) {
37  GLuint compiledShader = glCreateShader(type);
38  glShaderSource(compiledShader, 1, &source, NULL);
39  glCompileShader(compiledShader);
40  return compiledShader;
41  }
42 
43  void logCompileError(GLuint shader, std::string shaderType) {
44  GLchar compileLog[MAX_LOG_SIZE];
45 
46  glGetShaderInfoLog(shader, MAX_LOG_SIZE, NULL, compileLog);
47  Logger::logError("Failed to compile shader of type " + shaderType + "\n" + compileLog);
48  }
49 
50  void checkCompileErrors(GLuint *shader, std::string shaderType) {
51  GLint successfullyCompiled = false;
52  glGetShaderiv(*shader, GL_COMPILE_STATUS, &successfullyCompiled);
53  if (!successfullyCompiled) {
54  logCompileError(*shader, shaderType);
55  }
56  }
57 
58 
59 };
60 
61 
62 #endif //SUPER_BUBBA_AWESOME_SPACE_ISHADER_H