Thu, 06 Feb 2014 22:11:28 +0200
- work on improved rendering performance
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 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
12 | struct GLErrorInfo |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
13 | { |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
14 | GLenum value; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
15 | QString text; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
16 | }; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
17 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
18 | static const GLErrorInfo g_GLErrors[] = |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
19 | { |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
20 | { GL_NO_ERROR, "No error" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
21 | { GL_INVALID_ENUM, "Unacceptable enumerator passed" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
22 | { GL_INVALID_VALUE, "Numeric argument out of range" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
23 | { 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
|
24 | { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"}, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
25 | { GL_OUT_OF_MEMORY, "Out of memory" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
26 | { 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
|
27 | { 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
|
28 | }; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
30 | #include <QTime> |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
31 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
32 | #define CLOCK_INIT QTime t0; |
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_START \ |
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 | t0 = QTime::currentTime(); \ |
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 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
39 | #define CLOCK_TIME(A) \ |
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 | fprint (stderr, A ": %1ms\n", t0.msecsTo (QTime::currentTime())); \ |
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 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
44 | #define DEBUG_PRINT(...) fprint (stdout, __VA_ARGS__) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | extern_cfg (Bool, gl_blackedges); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
47 | static QList<short> gWarnedColors; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
48 | static const QColor gBFCFrontColor (40, 192, 40); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
49 | static const QColor gBFCBackColor (224, 40, 40); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
52 | // |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
53 | void checkGLError_private (const char* file, int line) |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
54 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
55 | QString errmsg; |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
56 | GLenum errnum = glGetError(); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
57 | |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
58 | if (errnum == GL_NO_ERROR) |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
59 | return; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
60 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
61 | for (const GLErrorInfo& err : g_GLErrors) |
679
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 | if (err.value == errnum) |
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 | errmsg = err.text; |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
66 | break; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
67 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
68 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
69 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
70 | log ("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
|
71 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
72 | |
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 | // |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
75 | GLCompiler::GLCompiler() : |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
76 | m_Document (null) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | { |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
78 | needMerge(); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
79 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
80 | |
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 | void GLCompiler::initialize() |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
84 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
85 | glGenBuffers (gNumVBOs, &mVBOs[0]); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
86 | checkGLError(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
89 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
90 | // |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
91 | GLCompiler::~GLCompiler() |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
93 | glDeleteBuffers (gNumVBOs, &mVBOs[0]); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
94 | checkGLError(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
98 | // |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | uint32 GLCompiler::getColorRGB (const QColor& color) |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | return |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | (color.red() & 0xFF) << 0x00 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | (color.green() & 0xFF) << 0x08 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | (color.blue() & 0xFF) << 0x10 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | (color.alpha() & 0xFF) << 0x18; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
109 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
110 | QColor GLCompiler::getIndexColor (int id) const |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
111 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
112 | // 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
|
113 | // 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
|
114 | int r = (id / 0x10000) % 0x100, |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
115 | g = (id / 0x100) % 0x100, |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
116 | b = id % 0x100; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
117 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
118 | return QColor (r, g, b); |
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 | |
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 | QColor GLCompiler::getPolygonColor (LDPolygon& poly, LDObject* topobj) const |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | QColor qcol; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
127 | if (poly.color == maincolor) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
128 | qcol = GLRenderer::getMainColor(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | else |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
131 | LDColor* col = getColor (poly.color); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
132 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
133 | if (col) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
134 | qcol = col->faceColor; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
135 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
136 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
137 | if (poly.color == edgecolor) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
138 | { |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
139 | 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
|
140 | LDColor* col; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
141 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
142 | /* |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
143 | 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
|
144 | qcol = col->edgeColor; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
145 | */ |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
146 | } |
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 | if (qcol.isValid() == false) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
149 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
150 | // 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
|
151 | // not appear pitch-black. |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
152 | if (poly.color != edgecolor) |
674 | 153 | qcol = GLRenderer::getMainColor(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | else |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
155 | qcol = Qt::black; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
157 | // Warn about the unknown color, but only once. |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
158 | for (short i : gWarnedColors) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
159 | if (poly.color == i) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
160 | return qcol; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
162 | log ("%1: Unknown color %2!\n", __func__, poly.color); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
163 | gWarnedColors << poly.color; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
164 | return qcol; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
167 | if (topobj->isSelected()) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | // Brighten it up if selected. |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | const int add = 51; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | qcol.setRed (min (qcol.red() + add, 255)); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | qcol.setGreen (min (qcol.green() + add, 255)); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | qcol.setBlue (min (qcol.blue() + add, 255)); |
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 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
184 | // Set all of mChanged to true |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
185 | // memset (mChanged, 0xFF, sizeof mChanged); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
186 | for (int i = 0; i < ((int) (sizeof mChanged / sizeof *mChanged)); ++i) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
187 | mChanged[i] = true; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
191 | // |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | void GLCompiler::stageForCompilation (LDObject* obj) |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
194 | mStaged << obj; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
195 | removeDuplicates (mStaged); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
198 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
199 | // |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
200 | void GLCompiler::compileDocument() |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
201 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
202 | if (getDocument() == null) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
203 | return; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
204 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
205 | for (LDObject* obj : getDocument()->getObjects()) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
206 | compileObject (obj); |
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 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
210 | // |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
211 | void GLCompiler::compileStaged() |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
212 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
213 | for (LDObject* obj : mStaged) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
214 | compileObject (obj); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
215 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
216 | mStaged.clear(); |
676
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 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
219 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
220 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
221 | void GLCompiler::prepareVBO (int vbonum) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
222 | { |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
223 | // Compile anything that still awaits it |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
224 | compileStaged(); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
225 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
226 | if (mChanged[vbonum] == false) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
227 | return; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
228 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
229 | glBindBuffer (GL_ARRAY_BUFFER, mVBOs[vbonum]); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
230 | checkGLError(); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
231 | glBufferData (GL_ARRAY_BUFFER, mVBOData[vbonum].size() * sizeof(float), |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
232 | mVBOData[vbonum].constData(), GL_DYNAMIC_DRAW); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
233 | checkGLError(); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
234 | glBindBuffer (GL_ARRAY_BUFFER, 0); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
235 | checkGLError(); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
236 | mChanged[vbonum] = false; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
237 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
238 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
239 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
240 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
241 | void GLCompiler::uncompileObject (LDObject* obj) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
242 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
243 | auto it = mObjectInfo.find (obj); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
244 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
245 | if (it == mObjectInfo.end()) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
246 | return; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
247 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
248 | ObjectVBOInfo* info = &(*it); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
249 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
250 | for (int i = 0; i < gNumVBOs; ++i) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
251 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
252 | if (info->size[i] == 0) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
253 | continue; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
254 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
255 | mVBOData[i].remove (info->offset[i], info->size[i]); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
256 | mChanged[i] = true; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
257 | } |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
258 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
259 | mObjectInfo.erase (it); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
260 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
261 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
262 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
263 | // |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
264 | void GLCompiler::compileObject (LDObject* obj) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
265 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
266 | ObjectVBOInfo info; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
267 | uncompileObject (obj); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
268 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
269 | for (int i = 0; i < gNumVBOs; ++i) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
270 | info.offset[i] = mVBOData[i].size(); |
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 | memset (info.size, 0, sizeof info.size); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
273 | compileSubObject (obj, obj, &info); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
274 | mObjectInfo[obj] = info; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
275 | needMerge(); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
276 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
277 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
278 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
279 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
280 | void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
281 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
282 | EVBOSurface surface; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
283 | int numverts; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
284 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
285 | switch (poly.num) |
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 | case 3: surface = vboTriangles; numverts = 3; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
288 | case 4: surface = vboQuads; numverts = 4; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
289 | case 2: surface = vboLines; numverts = 2; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
290 | case 5: surface = vboCondLines; numverts = 2; break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
291 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
292 | default: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
293 | log ("OMGWTFBBQ weird polygon with number %1 (topobj: #%2, %3), origin: %4", |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
294 | (int) poly.num, topobj->getID(), topobj->getTypeName(), poly.origin); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
295 | assert (false); |
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 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
298 | for (int complement = 0; complement < vboNumComplements; ++complement) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
299 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
300 | const int vbonum = getVBONumber (surface, (EVBOComplement) complement); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
301 | QVector<GLfloat>& vbodata = mVBOData[vbonum]; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
302 | const QColor normalColor = getPolygonColor (poly, topobj); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
303 | const QColor pickColor = getIndexColor (topobj->getID()); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
304 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
305 | for (int vert = 0; vert < numverts; ++vert) |
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 | objinfo->size[vbonum] += (complement == vboSurfaces) ? 3 : 4; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
308 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
309 | switch ((EVBOComplement) complement) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
310 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
311 | case vboSurfaces: |
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 | // Write coordinates. Apparently Z must be flipped too? |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
314 | vbodata << poly.vertices[vert].x() |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
315 | << -poly.vertices[vert].y() |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
316 | << -poly.vertices[vert].z(); |
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 vboNormalColors: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
321 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
322 | writeColor (vbodata, normalColor); |
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 vboPickColors: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
327 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
328 | writeColor (vbodata, pickColor); |
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 vboBFCFrontColors: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
333 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
334 | writeColor (vbodata, gBFCFrontColor); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
335 | break; |
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 | case vboBFCBackColors: |
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 | writeColor (vbodata, gBFCBackColor); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
341 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
342 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
343 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
344 | case vboNumComplements: |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
345 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
346 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
347 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
348 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
349 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
350 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
351 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
352 | // |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
353 | void GLCompiler::compileSubObject (LDObject* obj, LDObject* topobj, ObjectVBOInfo* objinfo) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
354 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
355 | CLOCK_INIT |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
356 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
357 | switch (obj->getType()) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
358 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
359 | // 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
|
360 | // wireframe view. Quads must go into separate vbos. |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
361 | case LDObject::ETriangle: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
362 | case LDObject::EQuad: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
363 | case LDObject::ELine: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
364 | case LDObject::ECondLine: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
365 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
366 | LDPolygon* poly = obj->getPolygon(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
367 | poly->id = topobj->getID(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
368 | compilePolygon (*poly, topobj, objinfo); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
369 | delete poly; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
370 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
371 | } |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
372 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
373 | case LDObject::ESubfile: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
374 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
375 | CLOCK_INIT |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
376 | CLOCK_START |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
377 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
378 | auto data = ref->inlinePolygons(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
379 | CLOCK_TIME ("Inline") |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
380 | CLOCK_START |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
381 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
382 | for (LDPolygon& poly : data) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
383 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
384 | poly.id = topobj->getID(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
385 | compilePolygon (poly, topobj, objinfo); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
386 | } |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
387 | CLOCK_TIME ("Compile") |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
388 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
389 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
390 | } |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
391 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
392 | default: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
393 | break; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
394 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
395 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
396 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
397 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
398 | // |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
399 | void GLCompiler::writeColor (QVector<GLfloat>& array, const QColor& color) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
400 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
401 | array << ((float) color.red()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
402 | << ((float) color.green()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
403 | << ((float) color.blue()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
404 | << ((float) color.alpha()) / 255.0f; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
405 | } |