summaryrefslogtreecommitdiff
path: root/engine/shader.h
blob: 012165aee355f3413cb83fabd4315f36958bdaf1 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef _SHADER_H_
#define _SHADER_H_

#include <iostream>
#include <string>
#define GL_GLEXT_PROTOTYPES
#ifndef __APPLE__
#include <GL/gl.h>
#include <GL/glu.h>
#else
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#endif

class GLBaseShader {
	friend class GLShaderProgram;

	protected:
		bool shader_source(const char *filename);
		bool shader_source(std::string& filename);
		unsigned int shader;
	public:
		GLBaseShader(GLenum);
};

class GLVertexShader : public GLBaseShader {
	public:
		GLVertexShader() : GLBaseShader(GL_VERTEX_SHADER) {};
		GLVertexShader(const char *s) : GLBaseShader(GL_VERTEX_SHADER) { shader_source(s); };
		GLVertexShader(std::string& s) : GLBaseShader(GL_VERTEX_SHADER) { shader_source(s); };
};

class GLFragmentShader : public GLBaseShader {
	public:
		GLFragmentShader() : GLBaseShader(GL_FRAGMENT_SHADER) {};
		GLFragmentShader(const char *s) : GLBaseShader(GL_FRAGMENT_SHADER) { shader_source(s); };
		GLFragmentShader(std::string& s) : GLBaseShader(GL_FRAGMENT_SHADER) { shader_source(s); };
};

class GLShaderProgram {
	protected:
		unsigned int program;
	public:
		GLShaderProgram();

		bool attach(GLBaseShader&);
		bool detach(GLBaseShader&);
		bool link();
		bool use();
		void remove();
};

void print_ogl_error(GLenum);
bool print_check_ogl_error();

#endif