8 #include "VectorMath.h"
18 namespace BatchedIconShaderCode
20 const std::string PositionName =
"Position";
21 const std::string UVName =
"UV";
22 const std::string ModelViewProjectionMatrixName =
"ModelViewProjectionMatrix";
23 const std::string ParamsName =
"Color";
24 const std::string IconColorName =
"IconColor";
26 const std::string _vertexDecls =
27 "attribute highp vec3 "+PositionName+
";\n"
28 "attribute mediump vec2 "+UVName+
";\n"
29 "attribute lowp vec4 "+ParamsName+
";\n"
31 "varying mediump vec2 DestinationUV;\n"
32 "varying lowp vec4 DestinationColor;\n"
33 "uniform lowp vec4 "+IconColorName+
";\n"
34 "uniform highp mat4 "+ModelViewProjectionMatrixName+
";\n";
36 const std::string DiffuseName =
"Diffuse";
38 const std::string _fragmentDecls =
39 "varying mediump vec2 DestinationUV;\n"
40 "varying lowp vec4 DestinationColor;\n"
41 "uniform sampler2D "+DiffuseName+
";\n";
43 const std::string _vertexCode =
"void main(void) { \n"
44 "DestinationUV = UV;\n"
45 "DestinationColor = "+IconColorName+
";\n"
46 "DestinationColor.a *= "+ParamsName+
".x;\n"
47 "gl_Position = ModelViewProjectionMatrix * vec4(Position.xyz, 1.0);\n"
50 const std::string _fragmentCode =
"void main(void) { \n"
51 "gl_FragColor = DestinationColor * texture2D("+DiffuseName+
", DestinationUV.xy);\n"
65 BatchedIconShaderCode::_vertexDecls + BatchedIconShaderCode::_vertexCode,
66 BatchedIconShaderCode::_fragmentDecls + BatchedIconShaderCode::_fragmentCode);
69 const GLuint GetDiffuseSamplerId()
const {
return 0; }
71 void SetMVP(
const m44& mvp)
const
73 bool transpose =
false;
74 SetUniformM44(mvp, m_mvpUniformLocation, transpose);
77 void SetColor(
const v4& color)
const
79 SetUniformV4(color, m_colorUniformLocation);
85 SetUniformTextureSampler(glState, GetDiffuseSamplerId(), m_diffuseTextureSamplerUniformLocation);
89 BatchedIconShader(
const TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) :
Shader(shaderId)
91 CompileProgram(vertexShaderCode, fragmentShaderCode);
93 m_mvpUniformLocation = GetUniformLocation(BatchedIconShaderCode::ModelViewProjectionMatrixName);
94 m_colorUniformLocation = GetUniformLocation(BatchedIconShaderCode::IconColorName);
95 m_diffuseTextureSamplerUniformLocation = GetUniformLocation(BatchedIconShaderCode::DiffuseName);
99 GLuint m_mvpUniformLocation ;
100 GLuint m_colorUniformLocation;
101 GLuint m_diffuseTextureSamplerUniformLocation;