/
shaders.hpp
175 lines (140 loc) · 4.47 KB
/
shaders.hpp
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// 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 3
// 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.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_SHADERS_HPP
#define HEADER_SHADERS_HPP
#include "config/user_config.hpp"
#include "graphics/shader.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_shader.hpp"
#include <IMeshSceneNode.h>
#include <IShaderConstantSetCallBack.h>
#include <EMaterialTypes.h>
using namespace irr;
class ParticleSystemProxy;
namespace MeshShader
{
class ObjectPass1Shader : public TextureShader<ObjectPass1Shader, 1,
core::matrix4, core::matrix4>
{
public:
ObjectPass1Shader();
};
class ObjectPass2Shader : public TextureShader<ObjectPass2Shader, 5, core::matrix4, core::matrix4>
{
public:
ObjectPass2Shader();
};
class TransparentShader : public TextureShader<TransparentShader, 1, core::matrix4, core::matrix4>
{
public:
TransparentShader();
};
class TransparentFogShader : public TextureShader<TransparentFogShader, 1, core::matrix4, core::matrix4, float, float,
float, float, float, video::SColorf>
{
public:
TransparentFogShader();
};
}
#define FOREACH_SHADER(ACT) \
ACT(ES_NORMAL_MAP) \
ACT(ES_NORMAL_MAP_LIGHTMAP) \
ACT(ES_SKYBOX) \
ACT(ES_SPLATTING) \
ACT(ES_WATER) \
ACT(ES_WATER_SURFACE) \
ACT(ES_SPHERE_MAP) \
ACT(ES_GRASS) \
ACT(ES_GRASS_REF) \
ACT(ES_MOTIONBLUR) \
ACT(ES_GAUSSIAN3H) \
ACT(ES_GAUSSIAN3V) \
ACT(ES_MIPVIZ) \
ACT(ES_OBJECT_UNLIT) \
ACT(ES_OBJECTPASS) \
ACT(ES_OBJECTPASS_REF) \
ACT(ES_OBJECTPASS_RIMLIT) \
ACT(ES_DISPLACE) \
#define ENUM(a) a,
#define STR(a) #a,
enum ShaderType
{
FOREACH_SHADER(ENUM)
ES_COUNT
};
#ifdef SHADER_NAMES
static const char *shader_names[] = {
FOREACH_SHADER(STR)
};
#endif
class Shaders
{
private:
static bool m_has_been_initialised;
static int m_shaders[ES_COUNT];
static video::IShaderConstantSetCallBack *m_callbacks[ES_COUNT];
static void check(const int num);
static void loadShaders();
public:
static void init();
static void destroy();
// ------------------------------------------------------------------------
/** Returns the material type of a shader.
* \param num The shader type.
*/
static video::E_MATERIAL_TYPE getShader(const ShaderType num)
{
assert(m_has_been_initialised);
assert(num < ES_COUNT);
return (video::E_MATERIAL_TYPE)m_shaders[num];
} // getShader
// ------------------------------------------------------------------------
/** Returns the callback for the specified shader type.
*/
static video::IShaderConstantSetCallBack* getCallback(const ShaderType num)
{
return m_has_been_initialised ? m_callbacks[num] : NULL;
} // getCallback
// ------------------------------------------------------------------------
void killShaders();
// ========================================================================
/** Shader to draw a colored line.
*/
class ColoredLine : public Shader<ColoredLine, video::SColor>
{
private:
GLuint m_vao, m_vbo;
public:
ColoredLine();
// --------------------------------------------------------------------
/** Bind the vertex array of this shader. */
void bindVertexArray()
{
glBindVertexArray(m_vao);
} // bindVertexArray
// --------------------------------------------------------------------
/** Binds the vbo of this shader. */
void bindBuffer()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
} // bindBuffer
}; // class ColoredLine
}; // class Shaders
#undef ENUM
#undef STR
#undef FOREACH_SHADER
#endif