src/gl/compiler.cpp

changeset 259
c27612f0eac0
parent 250
2837b549e616
child 260
48c66a4b1fe5
equal deleted inserted replaced
258:fe094d0687ad 259:c27612f0eac0
14 * 14 *
15 * You should have received a copy of the GNU General Public License 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/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #define GL_GLEXT_PROTOTYPES
20 #include <GL/glu.h>
21 #include <GL/glext.h>
22 #include <QMessageBox> 19 #include <QMessageBox>
23 #include "gl/compiler.h" 20 #include "gl/compiler.h"
24 #include "documentmanager.h" 21 #include "documentmanager.h"
25 #include "invert.h" 22 #include "invert.h"
26 #include "ring.h" 23 #include "ring.h"
211 using Vertex = ModelShaders::Vertex; 208 using Vertex = ModelShaders::Vertex;
212 constexpr int stride = sizeof(Vertex); 209 constexpr int stride = sizeof(Vertex);
213 shader.program->setAttributeBuffer(0, GL_FLOAT, offsetof(Vertex, position), 3, stride); 210 shader.program->setAttributeBuffer(0, GL_FLOAT, offsetof(Vertex, position), 3, stride);
214 shader.program->setAttributeBuffer(1, GL_FLOAT, offsetof(Vertex, color), 4, stride); 211 shader.program->setAttributeBuffer(1, GL_FLOAT, offsetof(Vertex, color), 4, stride);
215 shader.program->setAttributeBuffer(2, GL_FLOAT, offsetof(Vertex, normal), 3, stride); 212 shader.program->setAttributeBuffer(2, GL_FLOAT, offsetof(Vertex, normal), 3, stride);
216 glVertexAttribIPointer(3, 1, GL_INT, stride, reinterpret_cast<void*>(offsetof(Vertex, id))); 213 const void* vertexptr = reinterpret_cast<const void*>(offsetof(Vertex, id));
217 glVertexAttribIPointer(4, 1, GL_INT, stride, reinterpret_cast<void*>(offsetof(Vertex, selected))); 214 glfunc().glVertexAttribPointer(3, 1, GL_INT, GL_FALSE, stride, vertexptr);
215 const void* selectedptr = reinterpret_cast<const void*>(offsetof(Vertex, selected));
216 glfunc().glVertexAttribPointer(4, 1, GL_INT, GL_FALSE, stride, selectedptr);
218 shader.vertexArray.release(); 217 shader.vertexArray.release();
219 shader.buffer.release(); 218 shader.buffer.release();
220 shader.program->release(); 219 shader.program->release();
221 } 220 }
222 modelShaders->initialized = true; 221 modelShaders->initialized = true;
348 { 347 {
349 vertex.selected = (ids.contains({vertex.id})) ? 1 : 0; 348 vertex.selected = (ids.contains({vertex.id})) ? 1 : 0;
350 } 349 }
351 const GLsizeiptr size = static_cast<int>(vector.size() * sizeof vector[0]); 350 const GLsizeiptr size = static_cast<int>(vector.size() * sizeof vector[0]);
352 object.buffer.bind(); 351 object.buffer.bind();
353 glBufferSubData(GL_ARRAY_BUFFER, 0, size, vector.data()); 352 QOpenGLFunctions glfunc;
353 glfunc.glBufferSubData(GL_ARRAY_BUFFER, 0, size, vector.data());
354 object.buffer.release(); 354 object.buffer.release();
355 } 355 }
356 } 356 }
357 357
358 std::size_t gl::vertexCount(const gl::ModelShaders* shaders, const gl::ArrayClass arrayClass) 358 std::size_t gl::vertexCount(const gl::ModelShaders* shaders, const gl::ArrayClass arrayClass)

mercurial