Sun, 02 Feb 2020 00:49:32 +0200
made configurationoptions.txt visible in Qt Creator
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" | |
30 | 23 | #include <glm/gtc/type_ptr.hpp> |
19 | 24 | #include <QMap> |
25 | #include <QSet> | |
26 | 26 | #include <QOpenGLVertexArrayObject> |
27 | #include <QOpenGLBuffer> | |
28 | #include <QOpenGLShaderProgram> | |
19 | 29 | |
21 | 30 | class Model; |
31 | class DocumentManager; | |
32 | ||
19 | 33 | namespace gl |
34 | { | |
35 | class Compiler; | |
34
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
36 | |
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
37 | struct Vertex |
21 | 38 | { |
34
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
39 | glm::vec3 position; |
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
40 | glm::vec4 color; |
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
41 | glm::vec3 normal; |
21 | 42 | }; |
19 | 43 | } |
44 | ||
45 | class gl::Compiler : public QObject, protected QOpenGLFunctions | |
46 | { | |
47 | Q_OBJECT | |
48 | public: | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
49 | Compiler(const ldraw::ColorTable& colorTable, QObject* parent); |
19 | 50 | ~Compiler(); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
51 | void build(Model* model, DocumentManager* context, const RenderPreferences& preferences); |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
52 | void buildPolygon(Polygon polygon, std::vector<Vertex>* vboData, const gl::RenderPreferences& preferences); |
34
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
53 | std::size_t vertexCount(gl::ArrayClass arrayClass) const; |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
54 | QColor getColorForPolygon(const gl::Polygon& polygon, const RenderPreferences& preferences); |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
55 | glm::vec3 modelCenter() const; |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
56 | double modelDistance() const; |
26 | 57 | void initialize(); |
58 | void bindVertexArray(gl::ArrayClass arrayClass); | |
59 | void releaseVertexArray(gl::ArrayClass arrayClass); | |
60 | void buildShaders(int arrayId); | |
30 | 61 | |
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
|
62 | template<typename T> |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
63 | void setUniform(const char* uniformName, T&& value) |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
64 | { |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
65 | Q_ASSERT(this->initialized); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
66 | for (auto& object : this->glObjects) |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
67 | { |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
68 | 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
|
69 | const int location = glGetUniformLocation(object.program->programId(), uniformName); |
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 | Q_ASSERT(location != -1); |
c57fb7a5ffa3
commit work done on plugging vao to the gl renderer, renders nonsense for now
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
71 | object.program->setUniformValue(location, std::forward<T>(value)); |
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 | 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
|
73 | } |
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 | } |
30 | 75 | |
76 | template<typename Float, glm::qualifier Prec> | |
77 | void setUniformMatrix(const char* uniformName, const glm::mat<4, 4, Float, Prec>& value) | |
78 | { | |
79 | const float (*array)[4][4] = reinterpret_cast<const float(*)[4][4]>(glm::value_ptr(value)); | |
80 | this->setUniform(uniformName, *array); | |
81 | } | |
19 | 82 | private: |
34
1de2b8d64e9f
added some sort of lighting
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
83 | std::size_t storedVertexCounts[gl::NUM_ARRAY_CLASSES] = {0_z}; |
21 | 84 | bool initialized = false; |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
85 | BoundingBox boundingBox; |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
86 | const ldraw::ColorTable& colorTable; |
26 | 87 | struct |
88 | { | |
89 | QOpenGLShaderProgram* program = nullptr; | |
90 | QOpenGLBuffer buffer{QOpenGLBuffer::VertexBuffer}; | |
91 | QOpenGLVertexArrayObject vertexArray; | |
92 | } glObjects[gl::NUM_ARRAY_CLASSES]; | |
19 | 93 | }; |
94 | ||
95 | #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); } | |
96 | void checkGLError (QString file, int line); |