Sun, 26 Jan 2020 14:29:30 +0200
replaced matrix and vertex classes with glm
19 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2018 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #define GL_GLEXT_PROTOTYPES | |
20 | #include <GL/glu.h> | |
21 | #include <GL/glext.h> | |
26 | 22 | #include <QMessageBox> |
19 | 23 | #include "gl/compiler.h" |
24 | #include "documentmanager.h" | |
25 | #include "invert.h" | |
26 | #include "ring.h" | |
27 | ||
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
28 | static const char* vertexShaderSource = R"( |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
29 | #version 330 core |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
30 | |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
31 | layout(location=0) in vec3 position; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
32 | layout(location=1) in vec4 color; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
33 | out vec4 vColor; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
34 | uniform mat4 CameraTransformation; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
35 | |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
36 | void main() |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
37 | { |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
38 | vColor = color; |
28 | 39 | gl_Position = CameraTransformation * vec4(position, 1.0); |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
40 | } |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
41 | )"; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
42 | |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
43 | static const char* fragmentShaderSource = R"( |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
44 | #version 330 core |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
45 | |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
46 | in vec4 vColor; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
47 | out vec4 fColor; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
48 | |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
49 | void main() |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
50 | { |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
51 | fColor = vColor; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
52 | } |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
53 | )"; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
54 | |
26 | 55 | gl::Compiler::Compiler(const ColorTable& colorTable, QObject* parent) : |
56 | QObject{parent}, | |
57 | colorTable{colorTable} | |
21 | 58 | { |
59 | } | |
60 | ||
19 | 61 | gl::Compiler::~Compiler() |
62 | { | |
26 | 63 | } |
19 | 64 | |
26 | 65 | void gl::Compiler::initialize() |
66 | { | |
67 | if (not this->initialized) | |
68 | { | |
69 | this->initializeOpenGLFunctions(); | |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
70 | for (int i = 0; i < gl::NUM_ARRAY_CLASSES; i += 1) |
26 | 71 | { |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
72 | auto& object = this->glObjects[i]; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
73 | object.program = new QOpenGLShaderProgram; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
74 | object.program->create(); |
28 | 75 | const bool vertexShaderCompiled = object.program->addShaderFromSourceCode(QOpenGLShader::Vertex, ::vertexShaderSource); |
76 | QString log; | |
77 | if (not vertexShaderCompiled) | |
78 | { | |
79 | log += "\n" + tr("Vertex shader:") + "\n" + object.program->log(); | |
80 | } | |
81 | const bool fragmentShaderCompiled = object.program->addShaderFromSourceCode(QOpenGLShader::Fragment, ::fragmentShaderSource); | |
82 | if (not fragmentShaderCompiled) | |
83 | { | |
84 | log += "\n" + tr("Fragment shader:") + "\n" + object.program->log(); | |
85 | } | |
86 | if (not vertexShaderCompiled or not fragmentShaderCompiled) | |
87 | { | |
88 | QMessageBox::critical(nullptr, tr("Shader compile error"), tr("Could not compile shaders.") + "\n" + log); | |
89 | std::exit(-1); | |
90 | } | |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
91 | object.program->link(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
92 | object.program->bind(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
93 | object.buffer.create(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
94 | object.buffer.bind(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
95 | object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
96 | object.vertexArray.create(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
97 | object.vertexArray.bind(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
98 | object.program->enableAttributeArray(0); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
99 | object.program->enableAttributeArray(1); |
30 | 100 | constexpr int stride = 7 * sizeof(GLfloat); |
101 | object.program->setAttributeBuffer(0, GL_FLOAT, 0 * sizeof(GLfloat), 3, stride); | |
102 | object.program->setAttributeBuffer(1, GL_FLOAT, 3 * sizeof(GLfloat), 4, stride); | |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
103 | object.vertexArray.release(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
104 | object.buffer.release(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
105 | object.program->release(); |
26 | 106 | } |
107 | this->initialized = true; | |
108 | } | |
19 | 109 | } |
21 | 110 | |
111 | void gl::Compiler::build(Model* model, DocumentManager* context) | |
112 | { | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
113 | this->boundingBox = {}; |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
114 | std::vector<GLfloat> vboData[gl::NUM_ARRAY_CLASSES]; |
21 | 115 | const std::vector<gl::Polygon> polygons = model->getPolygons(context); |
116 | for (const gl::Polygon& polygon : polygons) | |
117 | { | |
118 | this->buildPolygon(polygon, vboData); | |
119 | } | |
26 | 120 | for (int arrayId = 0; arrayId < gl::NUM_ARRAY_CLASSES; arrayId += 1) |
21 | 121 | { |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
122 | auto& buffer = this->glObjects[arrayId].buffer; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
123 | auto& vector = vboData[arrayId]; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
124 | this->storedVboSizes[arrayId] = vector.size(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
125 | buffer.bind(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
126 | buffer.allocate(vector.data(), static_cast<int>(vector.size() * sizeof vector[0])); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
127 | buffer.release(); |
21 | 128 | } |
129 | } | |
130 | ||
26 | 131 | gl::ArrayClass classifyPolygon(const gl::Polygon& polygon) |
21 | 132 | { |
133 | switch (polygon.type) | |
134 | { | |
135 | case gl::Polygon::EdgeLine: | |
26 | 136 | return gl::ArrayClass::Lines; |
21 | 137 | case gl::Polygon::Triangle: |
26 | 138 | return gl::ArrayClass::Triangles; |
21 | 139 | case gl::Polygon::Quadrilateral: |
26 | 140 | return gl::ArrayClass::Quads; |
21 | 141 | case gl::Polygon::ConditionalEdge: |
26 | 142 | return gl::ArrayClass::ConditionalLines; |
21 | 143 | } |
26 | 144 | return gl::ArrayClass::Lines; |
21 | 145 | } |
146 | ||
26 | 147 | [[maybe_unused]] |
148 | static QColor colorFromId(linetypes::Id id) | |
21 | 149 | { |
150 | // Calculate a color based from this index. This method caters for | |
151 | // 16777216 objects. I don't think that will be exceeded anytime soon. | |
152 | const int r = (id.value / 0x10000) % 0x100; | |
153 | const int g = (id.value / 0x100) % 0x100; | |
154 | const int b = id.value % 0x100; | |
155 | return {r, g, b}; | |
156 | } | |
157 | ||
158 | void gl::Compiler::buildPolygon(gl::Polygon polygon, std::vector<GLfloat>* vboData) | |
159 | { | |
26 | 160 | const gl::ArrayClass vboClass = classifyPolygon(polygon); |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
161 | //std::vector<GLfloat>& vertexBuffer = vboData[gl::vboIndex({vboClass, gl::VboSubclass::VertexData})]; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
162 | std::vector<GLfloat>& vertexBuffer = vboData[static_cast<int>(vboClass)]; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
163 | /* |
26 | 164 | std::vector<GLfloat>& normalsBuffer = vboData[gl::vboIndex({vboClass, gl::VboSubclass::Normals})]; |
21 | 165 | auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); |
26 | 166 | reserveMore(normalsBuffer, polygon.numPolygonVertices() * 3_z); |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
167 | for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
21 | 168 | { |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
169 | const glm::vec3& v1 = vertexRing[i - 1]; |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
170 | const glm::vec3& v2 = vertexRing[i]; |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
171 | const glm::vec3& v3 = vertexRing[i + 1]; |
21 | 172 | const QVector3D normal = QVector3D::crossProduct(v3 - v2, v1 - v2).normalized(); |
173 | for (const GLfloat coord : {normal.x(), normal.y(), normal.z()}) | |
26 | 174 | normalsBuffer.push_back(coord); |
21 | 175 | } |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
176 | */ |
26 | 177 | reserveMore(vertexBuffer, polygon.numPolygonVertices() * 7); |
178 | const QColor color = this->getColorForPolygon(polygon); | |
21 | 179 | // Transform vertices so that they're suitable for GL rendering |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
180 | for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
21 | 181 | { |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
182 | glm::vec3& point = polygon.vertices[i]; |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
183 | this->boundingBox.consider(polygon.vertices[i]); |
26 | 184 | vertexBuffer.push_back(static_cast<GLfloat>(point.x)); |
185 | vertexBuffer.push_back(static_cast<GLfloat>(point.y)); | |
186 | vertexBuffer.push_back(static_cast<GLfloat>(point.z)); | |
187 | vertexBuffer.push_back(static_cast<GLfloat>(color.redF())); | |
188 | vertexBuffer.push_back(static_cast<GLfloat>(color.greenF())); | |
189 | vertexBuffer.push_back(static_cast<GLfloat>(color.blueF())); | |
190 | vertexBuffer.push_back(static_cast<GLfloat>(color.alphaF())); | |
21 | 191 | } |
192 | } | |
193 | ||
26 | 194 | QColor gl::Compiler::getColorForPolygon(const gl::Polygon& polygon) |
21 | 195 | { |
196 | QColor color; | |
26 | 197 | // For normal colors, use the polygon's color. |
198 | if (polygon.color == colors::main) | |
21 | 199 | { |
26 | 200 | color = {255, 255, 64}; // mainColorRepresentation(); |
21 | 201 | } |
26 | 202 | else if (polygon.color == colors::edge) |
21 | 203 | { |
26 | 204 | // Edge color is black, unless we have a dark background, in which case lines need to be bright. |
205 | color = Qt::black; //luma(config::backgroundColor()) > 40 ? Qt::black : Qt::white; | |
21 | 206 | } |
207 | else | |
208 | { | |
26 | 209 | // Not main or edge color, use the polygon's color as is. |
210 | color = this->colorTable[polygon.color].faceColor; | |
21 | 211 | } |
212 | return color; | |
213 | } | |
214 | ||
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
215 | glm::vec3 gl::Compiler::modelCenter() const |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
216 | { |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
217 | return boxCenter(this->boundingBox); |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
218 | } |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
219 | |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
220 | double gl::Compiler::modelDistance() const |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
221 | { |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
222 | return longestMeasure(this->boundingBox); |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
223 | } |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
224 | |
26 | 225 | void gl::Compiler::bindVertexArray(gl::ArrayClass arrayClass) |
226 | { | |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
227 | auto& object = this->glObjects[static_cast<int>(arrayClass)]; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
228 | object.vertexArray.bind(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
229 | object.program->bind(); |
26 | 230 | } |
231 | ||
232 | void gl::Compiler::releaseVertexArray(gl::ArrayClass arrayClass) | |
233 | { | |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
234 | auto& object = this->glObjects[static_cast<int>(arrayClass)]; |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
235 | object.program->release(); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
236 | object.vertexArray.release(); |
26 | 237 | } |
238 | ||
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
239 | std::size_t gl::Compiler::vboSize(const gl::ArrayClass arrayClass) const |
21 | 240 | { |
27
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
241 | return this->storedVboSizes[static_cast<int>(arrayClass)]; |
21 | 242 | } |
243 | ||
244 | int gl::vboIndex(const VboAddress vboAddress) | |
245 | { | |
246 | return static_cast<std::uint8_t>(vboAddress.vboClass) * gl::numVboSubclasses | |
247 | + static_cast<std::uint8_t>(vboAddress.vboSubclass); | |
248 | } | |
28 | 249 | |
250 | QMatrix4x4 gl::toQMatrix(const glm::mat4& matrix) | |
251 | { | |
252 | return { | |
253 | matrix[0][0], | |
254 | matrix[0][1], | |
255 | matrix[0][2], | |
256 | matrix[0][3], | |
257 | matrix[1][0], | |
258 | matrix[1][1], | |
259 | matrix[1][2], | |
260 | matrix[1][3], | |
261 | matrix[2][0], | |
262 | matrix[2][1], | |
263 | matrix[2][2], | |
264 | matrix[2][3], | |
265 | matrix[3][0], | |
266 | matrix[3][1], | |
267 | matrix[3][2], | |
268 | matrix[3][3], | |
269 | }; | |
270 | } |