1// This file can be included several times.
2#if(!defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H)) || \
3 (defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H_AS_ES))
4
5#if !defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H)
6#define ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H
7#endif
8
9#if defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H_AS_ES)
10#define ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H_AS_ES
11#endif
12
13#include <base/color.h>
14#include <base/vmath.h>
15#include <engine/client/graphics_defines.h>
16
17class CGLSL;
18
19class CGLSLProgram
20{
21public:
22 void CreateProgram();
23 void DeleteProgram();
24
25 bool AddShader(CGLSL *pShader) const;
26
27 void LinkProgram();
28 void UseProgram() const;
29 TWGLuint GetProgramId() const;
30
31 void DetachShader(CGLSL *pShader) const;
32 void DetachShaderById(TWGLuint ShaderId) const;
33 void DetachAllShaders() const;
34
35 //Support various types
36 void SetUniformVec2(int Loc, int Count, const float *pValue);
37 void SetUniformVec4(int Loc, int Count, const float *pValue);
38 void SetUniform(int Loc, int Value);
39 void SetUniform(int Loc, bool Value);
40 void SetUniform(int Loc, float Value);
41 void SetUniform(int Loc, int Count, const float *pValues);
42
43 //for performance reason we do not use SetUniform with using strings... save the Locations of the variables instead
44 int GetUniformLoc(const char *pName) const;
45
46 CGLSLProgram();
47 virtual ~CGLSLProgram();
48
49protected:
50 TWGLuint m_ProgramId;
51 bool m_IsLinked;
52};
53
54class CGLSLTWProgram : public CGLSLProgram
55{
56public:
57 CGLSLTWProgram() :
58 m_LocPos(-1), m_LocTextureSampler(-1), m_LastTextureSampler(-1), m_LastIsTextured(-1)
59 {
60 m_LastScreenTL = m_LastScreenBR = vec2(-1, -1);
61 }
62
63 int m_LocPos;
64 int m_LocTextureSampler;
65
66 int m_LastTextureSampler;
67 int m_LastIsTextured;
68 vec2 m_LastScreenTL;
69 vec2 m_LastScreenBR;
70};
71
72class CGLSLTextProgram : public CGLSLTWProgram
73{
74public:
75 CGLSLTextProgram()
76
77 {
78 m_LastColor[0] = m_LastColor[1] = m_LastColor[2] = m_LastColor[3] = -1.f;
79 m_LastOutlineColor[0] = m_LastOutlineColor[1] = m_LastOutlineColor[2] = m_LastOutlineColor[3] = -1.f;
80 m_LastTextSampler = m_LastTextOutlineSampler = -1;
81 m_LastTextureSize = -1;
82 }
83
84 int m_LocColor;
85 int m_LocOutlineColor;
86 int m_LocTextSampler;
87 int m_LocTextOutlineSampler;
88 int m_LocTextureSize;
89
90 ColorRGBA m_LastColor;
91 ColorRGBA m_LastOutlineColor;
92 int m_LastTextSampler;
93 int m_LastTextOutlineSampler;
94 int m_LastTextureSize;
95};
96
97class CGLSLPrimitiveProgram : public CGLSLTWProgram
98{
99public:
100};
101
102class CGLSLPrimitiveExProgram : public CGLSLTWProgram
103{
104public:
105 CGLSLPrimitiveExProgram()
106
107 {
108 m_LastRotation = 0.f;
109 m_LastCenter = vec2(0, 0);
110 m_LastVerticesColor = ColorRGBA(-1, -1, -1, -1);
111 }
112
113 int m_LocRotation;
114 int m_LocCenter;
115 int m_LocVertciesColor;
116
117 float m_LastRotation;
118 vec2 m_LastCenter;
119 ColorRGBA m_LastVerticesColor;
120};
121
122class CGLSLSpriteMultipleProgram : public CGLSLTWProgram
123{
124public:
125 CGLSLSpriteMultipleProgram()
126
127 {
128 m_LastCenter = vec2(0, 0);
129 m_LastVerticesColor = ColorRGBA(-1, -1, -1, -1);
130 }
131
132 int m_LocRSP;
133 int m_LocCenter;
134 int m_LocVertciesColor;
135
136 vec2 m_LastCenter;
137 ColorRGBA m_LastVerticesColor;
138};
139
140class CGLSLQuadProgram : public CGLSLTWProgram
141{
142public:
143 int m_LocColors;
144 int m_LocOffsets;
145 int m_LocRotations;
146 int m_LocQuadOffset;
147};
148
149class CGLSLTileProgram : public CGLSLTWProgram
150{
151public:
152 CGLSLTileProgram() :
153 m_LocColor(-1), m_LocOffset(-1), m_LocDir(-1), m_LocNum(-1), m_LocJumpIndex(-1) {}
154
155 int m_LocColor;
156 int m_LocOffset;
157 int m_LocDir;
158 int m_LocScale = -1;
159 int m_LocNum;
160 int m_LocJumpIndex;
161};
162
163#endif
164