8 #include "VectorMath.h"
18 namespace BatchedSpriteShaderCode
20 const std::string PositionName =
"Position";
21 const std::string UVName =
"UV";
22 const std::string ModelViewProjectionMatrixName =
"ModelViewProjectionMatrix";
24 const std::string _vertexDecls =
25 "attribute highp vec3 "+PositionName+
";\n"
26 "attribute mediump vec2 "+UVName+
";\n"
27 "attribute lowp vec4 Color;\n"
29 "varying mediump vec2 DestinationUV;\n"
30 "varying lowp vec4 DestinationColor;\n"
31 "uniform highp mat4 "+ModelViewProjectionMatrixName+
";\n";
33 const std::string DiffuseName =
"Diffuse";
35 const std::string _fragmentDecls =
36 "varying mediump vec2 DestinationUV;\n"
37 "varying lowp vec4 DestinationColor;\n"
38 "uniform sampler2D "+DiffuseName+
";\n";
40 const std::string _vertexCode =
"void main(void) { \n"
41 "DestinationUV = UV;\n"
42 "DestinationColor = Color;\n"
43 "gl_Position = ModelViewProjectionMatrix * vec4(Position.xyz, 1.0);\n"
46 const std::string _fragmentCode =
"void main(void) { \n"
47 "gl_FragColor = DestinationColor * texture2D("+DiffuseName+
", DestinationUV.xy);\n"
61 BatchedSpriteShaderCode::_vertexDecls + BatchedSpriteShaderCode::_vertexCode,
62 BatchedSpriteShaderCode::_fragmentDecls + BatchedSpriteShaderCode::_fragmentCode);
65 const GLuint GetDiffuseSamplerId()
const {
return 0; }
67 void SetMVP(
const m44& mvp)
const
69 bool transpose =
false;
70 SetUniformM44(mvp, m_mvpUniformLocation, transpose);
76 SetUniformTextureSampler(glState, GetDiffuseSamplerId(), m_diffuseTextureSamplerUniformLocation);
80 BatchedSpriteShader(
const TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) :
Shader(shaderId)
82 CompileProgram(vertexShaderCode, fragmentShaderCode);
84 m_mvpUniformLocation = GetUniformLocation(BatchedSpriteShaderCode::ModelViewProjectionMatrixName);
85 m_diffuseTextureSamplerUniformLocation = GetUniformLocation(BatchedSpriteShaderCode::DiffuseName);
89 GLuint m_mvpUniformLocation ;
90 GLuint m_diffuseTextureSamplerUniformLocation;