Mon, 10 Mar 2014 14:12:28 +0200
- refactor
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
1 | #define GL_GLEXT_PROTOTYPES |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
2 | #include <GL/glu.h> |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
3 | #include <GL/glext.h> |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | #include "GLCompiler.h" |
675
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
5 | #include "LDObject.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
6 | #include "Colors.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
7 | #include "Document.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
8 | #include "Misc.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
9 | #include "GLRenderer.h" |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
10 | #include "Dialogs.h" |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
11 | |
695
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
12 | cfg (String, gl_selectcolor, "#0080FF") |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
13 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
14 | struct GLErrorInfo |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
15 | { |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
16 | GLenum value; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
17 | QString text; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
18 | }; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
19 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
20 | static const GLErrorInfo g_GLErrors[] = |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
21 | { |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
22 | { GL_NO_ERROR, "No error" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
23 | { GL_INVALID_ENUM, "Unacceptable enumerator passed" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
24 | { GL_INVALID_VALUE, "Numeric argument out of range" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
25 | { GL_INVALID_OPERATION, "The operation is not allowed to be done in this state" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
26 | { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"}, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
27 | { GL_OUT_OF_MEMORY, "Out of memory" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
28 | { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
29 | { GL_STACK_OVERFLOW, "The operation would have caused an overflow" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
30 | }; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
32 | #include <QTime> |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
33 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
34 | #define CLOCK_INIT QTime t0; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
35 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
36 | #define CLOCK_START \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
37 | { \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
38 | t0 = QTime::currentTime(); \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
39 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
40 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
41 | #define CLOCK_TIME(A) \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
42 | { \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
43 | fprint (stderr, A ": %1ms\n", t0.msecsTo (QTime::currentTime())); \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
44 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
45 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
46 | #define DEBUG_PRINT(...) fprint (stdout, __VA_ARGS__) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | extern_cfg (Bool, gl_blackedges); |
698 | 49 | static QList<short> g_warnedColors; |
50 | static const QColor g_BFCFrontColor (40, 192, 40); | |
51 | static const QColor g_BFCBackColor (224, 40, 40); | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
54 | // |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
55 | void checkGLError_private (const char* file, int line) |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
56 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
57 | QString errmsg; |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
58 | GLenum errnum = glGetError(); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
59 | |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
60 | if (errnum == GL_NO_ERROR) |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
61 | return; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
62 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
63 | for (const GLErrorInfo& err : g_GLErrors) |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
64 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
65 | if (err.value == errnum) |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
66 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
67 | errmsg = err.text; |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
68 | break; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
69 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
70 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
71 | |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
72 | print ("OpenGL ERROR: at %1:%2: %3", basename (QString (file)), line, errmsg); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
73 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
74 | |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
75 | // ============================================================================= |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
76 | // |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
77 | GLCompiler::GLCompiler() |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | { |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
79 | needMerge(); |
698 | 80 | memset (m_VBOSizes, 0, sizeof m_VBOSizes); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
81 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
82 | |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
83 | // ============================================================================= |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
84 | // |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
85 | void GLCompiler::initialize() |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
86 | { |
698 | 87 | glGenBuffers (g_numVBOs, &mVBOs[0]); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
88 | checkGLError(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
91 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
92 | // |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
93 | GLCompiler::~GLCompiler() |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | { |
698 | 95 | glDeleteBuffers (g_numVBOs, &mVBOs[0]); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
96 | checkGLError(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
100 | // |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | uint32 GLCompiler::getColorRGB (const QColor& color) |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | return |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | (color.red() & 0xFF) << 0x00 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | (color.green() & 0xFF) << 0x08 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | (color.blue() & 0xFF) << 0x10 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | (color.alpha() & 0xFF) << 0x18; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
111 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
112 | QColor GLCompiler::getIndexColor (int id) const |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
113 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
114 | // Calculate a color based from this index. This method caters for |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
115 | // 16777216 objects. I don't think that will be exceeded anytime soon. :) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
116 | int r = (id / 0x10000) % 0x100, |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
117 | g = (id / 0x100) % 0x100, |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
118 | b = id % 0x100; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
119 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
120 | return QColor (r, g, b); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
121 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
122 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
123 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
124 | // |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
125 | QColor GLCompiler::getPolygonColor (LDPolygon& poly, LDObject* topobj) const |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | QColor qcol; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
129 | if (poly.color == maincolor) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
130 | qcol = GLRenderer::getMainColor(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | else |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
133 | LDColor* col = getColor (poly.color); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
134 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
135 | if (col) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
136 | qcol = col->faceColor; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
137 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
138 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
139 | if (poly.color == edgecolor) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
140 | { |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
141 | qcol = QColor (32, 32, 32); // luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
142 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
143 | /* |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
144 | if (!gl_blackedges && poly.obj->getParent() && (col = getColor (poly.obj->getParent()->getColor()))) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
145 | qcol = col->edgeColor; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
146 | */ |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
147 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
148 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
149 | if (qcol.isValid() == false) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
150 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
151 | // The color was unknown. Use main color to make the poly.object at least |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
152 | // not appear pitch-black. |
698 | 153 | if (poly.num != 2 && poly.num != 5) |
674 | 154 | qcol = GLRenderer::getMainColor(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | else |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
156 | qcol = Qt::black; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
158 | // Warn about the unknown color, but only once. |
698 | 159 | if (g_warnedColors.contains (poly.color) == false) |
160 | { | |
161 | print ("Unknown color %1!\n", poly.color); | |
162 | g_warnedColors << poly.color; | |
163 | } | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
165 | return qcol; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
168 | if (topobj->isSelected()) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | { |
695
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
170 | // Brighten it up for the select list. |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
171 | QColor selcolor (gl_selectcolor); |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
172 | qcol.setRed ((qcol.red() + selcolor.red()) / 2); |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
173 | qcol.setGreen ((qcol.green() + selcolor.green()) / 2); |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
174 | qcol.setBlue ((qcol.blue() + selcolor.blue()) / 2); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | return qcol; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
181 | // |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | void GLCompiler::needMerge() |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | { |
698 | 184 | for (int i = 0; i < countof (m_vboChanged); ++i) |
185 | m_vboChanged[i] = true; | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
189 | // |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | void GLCompiler::stageForCompilation (LDObject* obj) |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
192 | mStaged << obj; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
193 | removeDuplicates (mStaged); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
196 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
197 | // |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
198 | void GLCompiler::compileDocument (LDDocument* doc) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
199 | { |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
200 | if (doc == null) |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
201 | return; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
202 | |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
203 | for (LDObject* obj : doc->objects()) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
204 | compileObject (obj); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
205 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
206 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
207 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
208 | // |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
209 | void GLCompiler::compileStaged() |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
210 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
211 | for (LDObject* obj : mStaged) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
212 | compileObject (obj); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
213 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
214 | mStaged.clear(); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
215 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
216 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
217 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
218 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
219 | void GLCompiler::prepareVBO (int vbonum) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
220 | { |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
221 | // Compile anything that still awaits it |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
222 | compileStaged(); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
223 | |
698 | 224 | if (m_vboChanged[vbonum] == false) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
225 | return; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
226 | |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
227 | QVector<GLfloat> vbodata; |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
228 | |
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
229 | for (auto it = mObjectInfo.begin(); it != mObjectInfo.end(); ++it) |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
230 | { |
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
231 | if (it.key()->document() == getCurrentDocument()) |
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
232 | vbodata += it->data[vbonum]; |
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
233 | } |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
234 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
235 | glBindBuffer (GL_ARRAY_BUFFER, mVBOs[vbonum]); |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
236 | glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_DYNAMIC_DRAW); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
237 | glBindBuffer (GL_ARRAY_BUFFER, 0); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
238 | checkGLError(); |
698 | 239 | m_vboChanged[vbonum] = false; |
240 | m_VBOSizes[vbonum] = vbodata.size(); | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
241 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
242 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
243 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
244 | // |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
245 | void GLCompiler::dropObject (LDObject* obj) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
246 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
247 | auto it = mObjectInfo.find (obj); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
248 | |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
249 | if (it != mObjectInfo.end()) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
250 | { |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
251 | mObjectInfo.erase (it); |
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
252 | needMerge(); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
253 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
254 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
255 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
256 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
257 | // |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
258 | void GLCompiler::compileObject (LDObject* obj) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
259 | { |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
260 | print ("compiling #%1\n", obj->id()); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
261 | ObjectVBOInfo info; |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
262 | dropObject (obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
263 | compileSubObject (obj, obj, &info); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
264 | mObjectInfo[obj] = info; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
265 | needMerge(); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
266 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
267 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
268 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
269 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
270 | void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
271 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
272 | EVBOSurface surface; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
273 | int numverts; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
274 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
275 | switch (poly.num) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
276 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
277 | case 3: surface = vboTriangles; numverts = 3; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
278 | case 4: surface = vboQuads; numverts = 4; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
279 | case 2: surface = vboLines; numverts = 2; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
280 | case 5: surface = vboCondLines; numverts = 2; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
281 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
282 | default: |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
283 | print ("OMGWTFBBQ weird polygon with number %1 (topobj: #%2, %3), origin: %4", |
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
284 | (int) poly.num, topobj->id(), topobj->typeName(), poly.origin); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
285 | assert (false); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
286 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
287 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
288 | for (int complement = 0; complement < vboNumComplements; ++complement) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
289 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
290 | const int vbonum = getVBONumber (surface, (EVBOComplement) complement); |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
291 | QVector<GLfloat>& vbodata = objinfo->data[vbonum]; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
292 | const QColor normalColor = getPolygonColor (poly, topobj); |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
293 | const QColor pickColor = getIndexColor (topobj->id()); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
294 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
295 | for (int vert = 0; vert < numverts; ++vert) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
296 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
297 | switch ((EVBOComplement) complement) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
298 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
299 | case vboSurfaces: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
300 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
301 | // Write coordinates. Apparently Z must be flipped too? |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
302 | vbodata << poly.vertices[vert].x() |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
303 | << -poly.vertices[vert].y() |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
304 | << -poly.vertices[vert].z(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
305 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
306 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
307 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
308 | case vboNormalColors: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
309 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
310 | writeColor (vbodata, normalColor); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
311 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
312 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
313 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
314 | case vboPickColors: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
315 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
316 | writeColor (vbodata, pickColor); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
317 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
318 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
319 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
320 | case vboBFCFrontColors: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
321 | { |
698 | 322 | writeColor (vbodata, g_BFCFrontColor); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
323 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
324 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
325 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
326 | case vboBFCBackColors: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
327 | { |
698 | 328 | writeColor (vbodata, g_BFCBackColor); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
329 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
330 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
331 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
332 | case vboNumComplements: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
333 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
334 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
335 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
336 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
337 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
338 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
339 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
340 | // |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
341 | void GLCompiler::compileSubObject (LDObject* obj, LDObject* topobj, ObjectVBOInfo* objinfo) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
342 | { |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
343 | switch (obj->type()) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
344 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
345 | // Note: We cannot split quads into triangles here, it would mess up the |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
346 | // wireframe view. Quads must go into separate vbos. |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
347 | case LDObject::ETriangle: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
348 | case LDObject::EQuad: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
349 | case LDObject::ELine: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
350 | case LDObject::ECondLine: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
351 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
352 | LDPolygon* poly = obj->getPolygon(); |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
353 | poly->id = topobj->id(); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
354 | compilePolygon (*poly, topobj, objinfo); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
355 | delete poly; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
356 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
357 | } |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
358 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
359 | case LDObject::ESubfile: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
360 | { |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
361 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
362 | auto data = ref->inlinePolygons(); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
363 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
364 | for (LDPolygon& poly : data) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
365 | { |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
366 | poly.id = topobj->id(); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
367 | compilePolygon (poly, topobj, objinfo); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
368 | } |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
369 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
370 | } |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
371 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
372 | default: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
373 | break; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
374 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
375 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
376 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
377 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
378 | // |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
379 | void GLCompiler::writeColor (QVector<GLfloat>& array, const QColor& color) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
380 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
381 | array << ((float) color.red()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
382 | << ((float) color.green()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
383 | << ((float) color.blue()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
384 | << ((float) color.alpha()) / 255.0f; |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
385 | } |