7 #include "VectorMath.h"
17 namespace ColoredVertShaderCode
19 const std::string PositionName =
"Position";
20 const std::string ModelViewProjectionMatrixName =
"ModelViewProjectionMatrix";
21 const std::string ColorName =
"Color";
22 const std::string ColorVaryingName =
"ColorVarying";
24 const std::string _vertexDecls =
25 "attribute highp vec4 "+PositionName+
";\n"
26 "attribute vec4 "+ColorName+
";\n"
27 "varying lowp vec4 "+ColorVaryingName+
";\n"
28 "uniform highp mat4 "+ModelViewProjectionMatrixName+
";\n";
30 const std::string _fragmentDecls =
31 "varying lowp vec4 "+ColorVaryingName+
";\n";
33 const std::string _vertexCode =
34 "void main(void) { \n"
35 ""+ColorVaryingName+
" = "+ColorName+
";\n"
36 "gl_Position = "+ModelViewProjectionMatrixName+
" * vec4(Position.xyz, 1.0);\n"
39 const std::string _fragmentCode =
40 "void main(void) { \n"
41 "gl_FragColor.rgba = "+ColorVaryingName+
".rgba; \n"
53 ColoredVertShaderCode::_vertexDecls + ColoredVertShaderCode::_vertexCode,
54 ColoredVertShaderCode::_fragmentDecls + ColoredVertShaderCode::_fragmentCode
58 void SetMVP(
const m44& mvp)
const
60 bool transpose =
false;
61 SetUniformM44(mvp, m_mvpUniformLocation, transpose);
64 GLuint GetPositionUniform()
const {
return GetVertexAttributes().GetElement(0).GetLocation(); }
65 GLuint GetColorUniform()
const {
return GetVertexAttributes().GetElement(1).GetLocation(); }
73 ColoredVertShader(
const TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) :
Shader(shaderId)
75 CompileProgram(vertexShaderCode, fragmentShaderCode);
76 m_mvpUniformLocation = GetUniformLocation(ColoredVertShaderCode::ModelViewProjectionMatrixName);
82 GLuint m_mvpUniformLocation;