src/gl/gridprogram.cpp

changeset 102
9f435f66bd0c
parent 90
e234edb5e613
equal deleted inserted replaced
101:910890292639 102:9f435f66bd0c
61 color = vec4(gridColor.xyz, gridColor.w * d); 61 color = vec4(gridColor.xyz, gridColor.w * d);
62 } 62 }
63 )"; 63 )";
64 64
65 static const glm::vec2 data[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; 65 static const glm::vec2 data[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
66 constexpr std::size_t vertexSize = sizeof data[0];
67
68 GridProgram::GridProgram(QObject* parent) :
69 AbstractShaderProgram{{{GL_QUADS, vertexSize}}, parent}
66 70
67 void GridProgram::setGridMatrix(const glm::mat4& newGridMatrix) 71 void GridProgram::setGridMatrix(const glm::mat4& newGridMatrix)
68 { 72 {
69 this->setMatrix("grid", newGridMatrix); 73 this->setMatrix("grid", newGridMatrix);
70 } 74 }
93 const char* GridProgram::fragmentShaderSource() const 97 const char* GridProgram::fragmentShaderSource() const
94 { 98 {
95 return ::fragmentShaderSource; 99 return ::fragmentShaderSource;
96 } 100 }
97 101
98 const void* GridProgram::vertexData() const
99 {
100 return ::data;
101 }
102
103 int GridProgram::vertexSize() const
104 {
105 return sizeof data[0];
106 }
107
108 int GridProgram::vertexCount() const
109 {
110 return glm::countof(data);
111 }
112
113 void GridProgram::setupVertexArrays() 102 void GridProgram::setupVertexArrays()
114 { 103 {
115 this->program->enableAttributeArray(0); 104 this->program->enableAttributeArray(0);
116 this->program->setAttributeBuffer(0, GL_FLOAT, 0, 2, 0); 105 this->program->setAttributeBuffer(0, GL_FLOAT, 0, 2, 0);
117 this->program->setUniformVector("gridColor", this->gridColor); 106 this->program->setUniformVector("gridColor", this->gridColor);
107 this->upload(&this->arrays[0], ::data, countof(data));
118 } 108 }
119 109
120 GLenum GridProgram::drawMode() const
121 {
122 return GL_QUADS;
123 }

mercurial