7 #include "VectorMath.h"
17 namespace ColorShaderCode
19 const std::string PositionName =
"Position";
20 const std::string ModelViewProjectionMatrixName =
"ModelViewProjectionMatrix";
21 const std::string ColorName =
"ColorValue";
23 const std::string _vertexDecls =
24 "attribute highp vec4 "+PositionName+
";\n"
25 "uniform highp mat4 "+ModelViewProjectionMatrixName+
";\n";
27 const std::string _fragmentDecls =
28 "uniform lowp vec4 "+ColorName+
";\n";
30 const std::string _vertexCode =
31 "void main(void) { \n"
32 "gl_Position = "+ModelViewProjectionMatrixName+
" * vec4(Position.xyz, 1.0);\n"
35 const std::string _fragmentCode =
36 "void main(void) { \n"
37 "gl_FragColor.rgba = "+ColorName+
".rgba; \n"
45 static ColorShader* Create(
const TShaderId shaderId)
49 ColorShaderCode::_vertexDecls + ColorShaderCode::_vertexCode,
50 ColorShaderCode::_fragmentDecls + ColorShaderCode::_fragmentCode
54 void SetMVP(
const m44& mvp)
const
56 bool transpose =
false;
57 SetUniformM44(mvp, m_mvpUniformLocation, transpose);
60 void SetColor(
const v4& color)
const
62 SetUniformV4(color, m_colorUniformLocation);
71 ColorShader(
const TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) :
Shader(shaderId)
73 CompileProgram(vertexShaderCode, fragmentShaderCode);
74 m_mvpUniformLocation = GetUniformLocation(ColorShaderCode::ModelViewProjectionMatrixName);
75 m_colorUniformLocation = GetUniformLocation(ColorShaderCode::ColorName);
79 GLuint m_mvpUniformLocation;
80 GLuint m_colorUniformLocation;