src/gl/gridprogram.cpp

changeset 167
c1ff4f107569
parent 156
65b75beed7e0
child 216
c7241f504117
equal deleted inserted replaced
166:8857351912d0 167:c1ff4f107569
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include "gridprogram.h" 19 #include "gridprogram.h"
20 20
21 // Based on https://stackoverflow.com/q/30842755
22 const char vertexShaderSource[] = R"( 21 const char vertexShaderSource[] = R"(
23 #version 330 core 22 #version 330 core
24 23
25 layout (location = 0) in vec2 in_position; 24 layout (location = 0) in vec2 in_position;
26 uniform mat4 view; 25 uniform mat4 view;
54 )"; 53 )";
55 54
56 GridProgram::GridProgram(QObject *parent) : 55 GridProgram::GridProgram(QObject *parent) :
57 AbstractBasicShaderProgram{parent} 56 AbstractBasicShaderProgram{parent}
58 { 57 {
59 this->gridData.reserve(8004); 58 constexpr int extent = 50;
60 for (int i = -1000; i < 1000; i += 1) 59 this->gridData.reserve(8 * extent + 4);
60 for (int i = -extent; i <= extent; i += 1)
61 { 61 {
62 this->gridData.push_back({i, -1000}); 62 this->gridData.push_back({i, -extent});
63 this->gridData.push_back({i, 1000}); 63 this->gridData.push_back({i, extent});
64 } 64 }
65 for (int i = -1000; i < 1000; i += 1) 65 for (int i = -extent; i <= extent; i += 1)
66 { 66 {
67 this->gridData.push_back({-1000, i}); 67 this->gridData.push_back({-extent, i});
68 this->gridData.push_back({1000, i}); 68 this->gridData.push_back({extent, i});
69 } 69 }
70 } 70 }
71 71
72 void GridProgram::setGridMatrix(const glm::mat4& newGridMatrix) 72 void GridProgram::setGridMatrix(const glm::mat4& newGridMatrix)
73 { 73 {

mercurial