Bubba-3D  0.9.0
Awesome game engine!
ShaderProgram.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 #pragma once
18 
19 #include <map>
20 #include <string>
21 #include <linmath/float2.h>
22 #include "glutil/glutil.h"
23 #include "linmath/float3.h"
24 #include "IShader.h"
25 
40 public:
41  ShaderProgram();
42 
46  void loadShader(IShader *vertexShader, IShader *fragmentShader);
47 
51  void use();
52 
64 
65  void setUniform1i(std::string name, int value);
66  void setUniform1f(std::string name, float value);
67  void setUniform2f(std::string name, chag::float2 value);
68  void setUniform3f(std::string name, chag::float3 value);
69  void setUniform4f(std::string name, chag::float4 value);
70  void setUniformMatrix4fv(std::string name, chag::float4x4 matrix);
71 
72  void setUniformBufferObjectBinding(std::string bufferName, int index);
73  void initUniformBufferObject(std::string bufferName, int size, int index);
74  void setUniformBufferSubData(std::string bufferName, int offset, int size, const GLvoid *data);
75 
76 private:
77 
78  void linkProgram();
79  void checkLinkageErrors();
80  void logLinkageError();
81 
82  void createProgram(GLuint vertexShader, GLuint fragmentShader);
83 
84  GLint getUniformLocation(std::string name);
85 
86  IShader* vertexShader;
87  IShader* fragmentShader;
88 
89  GLuint shaderID;
90  std::map<std::string, GLint> uniformLocations;
91  GLint previousShaderProgram;
92 
93 };
void restorePreviousShaderProgram()
Class for maintaining OpenGL shader programs.
Definition: ShaderProgram.h:39
void loadShader(IShader *vertexShader, IShader *fragmentShader)
void backupCurrentShaderProgram()