-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShader.h
72 lines (57 loc) · 1.73 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Copyright (C) 2006 So Yamaoka
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef _SHADER_H_
#define _SHADER_H_
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include "glee.h"
#endif
/*! Handles GLSL shaders. It can load the code from the file or read straight
* from the char array. */
class Shader
{
public:
//unsigned int pid; // prog id
GLhandleARB pid; // prog id
public:
Shader(const char *vert, const char *frag, bool isFile=true);
~Shader();
/** bind/unbind this shader. */
void bind();
void unbind();
/* Set glUniform values */
void uniform1f(const GLchar *name, float val);
void uniform1i(const GLchar *name, int val);
void uniform2f(const GLchar *name, float val1, float val2);
void uniform3f(const GLchar *name, float val1, float val2, float val3);
// previous and current binder
GLhandleARB previousShader;
static GLhandleARB currentShader;
/** get the program */
//unsigned int getPid()
GLhandleARB getPid()
{
return pid;
}
/** dump log */
void printLog(const char* tag = "");
static void enable();
static void disable();
private:
/** read a shader file
programmer is responsible for deleting returned buffer */
char* read(const char *filename);
/** create shaders from given vert and frag programs. */
void setup(const char *vs, const char *fs);
};
#endif