-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvault.h
148 lines (122 loc) · 3.68 KB
/
vault.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* The Vault is for loading and storing resources that you only need one
* copy of, but that you use in many places in your model:
*
* * textures
*
* * vertex shaders
*
* * fragment shaders
*
* For this project, you'll extend Vault to create a vault for your own model.
*/
#pragma once
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <exception>
#include "GL/glew.h"
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
#include "imageio.h"
#include "rijndael.h"
/**
* Tracks the shader key.
*/
extern const char* SHADER_KEY;
/** Shader filenames and data */
extern const char* SHADER_FILENAMES[];
extern const char* SHADER_DATA[];
extern int SHADER_COUNT;
/**
* HACK: When this pointer is not NULL, shader source code
* from loaded shaders is stored inside it. This pointer is not NULL
* whenever you generate shaders.cpp.
*/
extern std::map<std::string, std::string>* shaderSourceCode;
void CharStr2HexStr(unsigned char const* pucCharStr, char* pszHexStr, int iSize);
void HexStr2CharStr(char const* pszHexStr, unsigned char* pucCharStr, int iSize);
const char* encrypt(const char* unhexed, const char* key);
const char* decrypt(const char* hexed, const char* key);
/**
* Stores a shader's OpenGL ID and its source code filename.
*/
class ShaderItem {
public:
GLuint id;
const char* source_code;
GLuint type;
ShaderItem(const char* _source_code, GLuint _type);
void load(GLuint program);
void unload(GLuint program);
};
/** Stores a list of shaders. */
typedef std::vector<ShaderItem> ShaderList;
/**
* A shader program, which includes vertex and fragment shaders.
*/
class ShaderProgram {
protected:
/** List of OpenGL shader ID's and their filenames. */
ShaderList shaders;
/** OpenGL ID for the shader program. */
GLuint program;
public:
/**
* Creates a shader program, which loads and compiles shaders from the
* given source code.
*
* @param vertexShader Filename of your vertex shader, or NULL if you
* have no vertex shader.
*
* @param fragmentShader Filename of your fragment shader, or NULL if you
* have no fragment shader.
*
* @param geometryShader Filename of your geometry shader, or NULL if you
* don't have one. This parameter is OPTIONAL.
*
* @throw an exception if the shader can't be created.
* This exception will be handled by Modeler when it tries to create
* your shader, and will report things like compiler errors and file
* reading errors.
*/
ShaderProgram(const char* vertexShader,
const char* fragmentShader,
const char* geometryShader = NULL);
/** Makes sure unload() gets called. */
~ShaderProgram();
/** Returns the shader program's ID. */
const GLuint getID() const;
/** Tells OpenGL to use this texture. */
void use() const;
/** Load the shader */
void load();
/** Detaches and deletes the shader program and its shaders. */
void unload();
};
/**
* Texture loader
*/
class Texture2D {
protected:
GLuint texture, envMode;
const char* image;
public:
Texture2D(const char* _image,
const GLuint _envMode = GL_REPLACE);
/** Returns the texture ID. */
const GLuint getID() const;
/** Tells OpenGL to use this texture. */
void use() const;
/** Makes sure unload() gets called. */
~Texture2D();
/** Load the texture */
void load();
/** Unload the texture, freeing its OpenGL resources. */
void unload();
};
/**
* Reads a file into a string (useful for reading shader code into memory).
*/
const char* readFile(const char* const file);