Wed, 22 Jan 2020 00:23:29 +0200
at least VAOs work now
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 | #pragma once | |
20 | #include "main.h" | |
21 | #include "gl/common.h" | |
22 | #include "types/boundingbox.h" | |
23 | #include <QMap> | |
24 | #include <QSet> | |
26 | 25 | #include <QOpenGLVertexArrayObject> |
26 | #include <QOpenGLBuffer> | |
27 | #include <QOpenGLShaderProgram> | |
19 | 28 | |
21 | 29 | class Model; |
30 | class DocumentManager; | |
31 | ||
19 | 32 | namespace gl |
33 | { | |
34 | class Compiler; | |
35 | class Renderer; | |
21 | 36 | struct VboAddress |
37 | { | |
26 | 38 | ArrayClass vboClass; |
21 | 39 | VboSubclass vboSubclass; |
40 | }; | |
41 | int vboIndex(const VboAddress vboAddress); | |
19 | 42 | } |
43 | ||
44 | class gl::Compiler : public QObject, protected QOpenGLFunctions | |
45 | { | |
46 | Q_OBJECT | |
47 | public: | |
26 | 48 | Compiler(const ColorTable& colorTable, QObject* parent); |
19 | 49 | ~Compiler(); |
21 | 50 | void build(Model* model, DocumentManager* context); |
51 | void buildPolygon(Polygon polygon, std::vector<GLfloat>* vboData); | |
52 | void upload(const int vboIndex, const std::vector<GLfloat>& data); | |
53 | GLuint vbo(const VboAddress vboAddress) const; | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
54 | std::size_t vboSize(const VboAddress vboAddress) const; |
26 | 55 | QColor getColorForPolygon(const gl::Polygon& polygon); |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
56 | Point3D modelCenter() const; |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
57 | double modelDistance() const; |
26 | 58 | void initialize(); |
59 | void bindVertexArray(gl::ArrayClass arrayClass); | |
60 | void releaseVertexArray(gl::ArrayClass arrayClass); | |
61 | void buildShaders(int arrayId); | |
19 | 62 | private: |
26 | 63 | QOpenGLVertexArrayObject vertexArrays[gl::NUM_ARRAY_CLASSES]; |
64 | //GLuint storedVbo[gl::numVbos]; | |
19 | 65 | bool m_vboChanged[gl::numVbos] = {true}; |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
66 | std::size_t storedVboSizes[gl::numVbos] = {0_z}; |
21 | 67 | bool initialized = false; |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
68 | BoundingBox boundingBox; |
26 | 69 | const ColorTable& colorTable; |
70 | struct | |
71 | { | |
72 | QOpenGLShaderProgram* program = nullptr; | |
73 | QOpenGLBuffer buffer{QOpenGLBuffer::VertexBuffer}; | |
74 | QOpenGLVertexArrayObject vertexArray; | |
75 | } glObjects[gl::NUM_ARRAY_CLASSES]; | |
19 | 76 | }; |
77 | ||
78 | #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); } | |
79 | void checkGLError (QString file, int line); |