-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshader.h
45 lines (39 loc) · 2.03 KB
/
shader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*******************************************************************
** Taken and adapted from learnopengl.com (part of a Breakout game)
******************************************************************/
#ifndef SHADER_H
#define SHADER_H
#include <string>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
// General purpsoe shader object. Compiles from file, generates
// compile/link-time error messages and hosts several utility
// functions for easy management.
class Shader
{
public:
// State
GLuint ID;
// Constructor
Shader() { }
// Sets the current shader as active
Shader &Use();
// Compiles the shader from given source code
void Compile(const GLchar *vertexSource, const GLchar *fragmentSource, const GLchar *geometrySource = nullptr); // Note: geometry source code is optional
// Utility functions
void SetFloat (const GLchar *name, GLfloat value, GLboolean useShader = false);
void SetInteger (const GLchar *name, GLint value, GLboolean useShader = false);
void SetVector2uint (const GLchar *name, GLuint x, GLuint y, GLboolean useShader = false);
void SetVector2f (const GLchar *name, GLfloat x, GLfloat y, GLboolean useShader = false);
void SetVector2f (const GLchar *name, const glm::vec2 &value, GLboolean useShader = false);
void SetVector3f (const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLboolean useShader = false);
void SetVector3f (const GLchar *name, const glm::vec3 &value, GLboolean useShader = false);
void SetVector4f (const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLboolean useShader = false);
void SetVector4f (const GLchar *name, const glm::vec4 &value, GLboolean useShader = false);
void SetMatrix4 (const GLchar *name, const glm::mat4 &matrix, GLboolean useShader = false);
private:
// Checks if compilation or linking failed and if so, print the error logs
void checkCompileErrors(GLuint object, std::string type);
};
#endif