1// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <Qt3DRender/private/stringtoint_p.h>
5#include "gllights_p.h"
6
7#define LIGHT_POSITION_NAME QLatin1String(".position")
8#define LIGHT_TYPE_NAME QLatin1String(".type")
9#define LIGHT_COLOR_NAME QLatin1String(".color")
10#define LIGHT_INTENSITY_NAME QLatin1String(".intensity")
11#define LIGHT_DIRECTION_NAME QLatin1String(".direction")
12#define LIGHT_LINEAR_ATTENUATION_NAME QLatin1String(".linearAttenuation")
13#define LIGHT_QUADRATIC_ATTENUATION_NAME QLatin1String(".quadraticAttenuation")
14#define LIGHT_CONSTANT_ATTENUATION_NAME QLatin1String(".constantAttenuation")
15#define LIGHT_CUT_OFF_ANGLE_NAME QLatin1String(".cutOffAngle")
16
17#define DECLARE_LIGHT_STRUCT_NAME(idx)\
18 QLatin1String("lights[") + QLatin1Char(char('0' + idx)) + QLatin1Char(']')
19
20#define DECLARE_LIGHT_POSITION_NAME(idx)\
21 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_POSITION_NAME)
22
23#define DECLARE_LIGHT_TYPE_NAME(idx)\
24 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_TYPE_NAME)
25
26#define DECLARE_LIGHT_COLOR_NAME(idx)\
27 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_COLOR_NAME)
28
29#define DECLARE_LIGHT_INTENSITY_NAME(idx)\
30 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_INTENSITY_NAME)
31
32#define DECLARE_LIGHT_DIRECTION_NAME(idx)\
33 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_DIRECTION_NAME)
34
35#define DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(idx)\
36 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_LINEAR_ATTENUATION_NAME)
37
38#define DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(idx)\
39 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_QUADRATIC_ATTENUATION_NAME)
40
41#define DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(idx)\
42 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_CONSTANT_ATTENUATION_NAME)
43
44#define DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(idx)\
45 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_CUT_OFF_ANGLE_NAME)
46
47#define DECLARE_LIGHT_STRUCT_UNROLL_NAME(idx)\
48 QLatin1String("light_") + QLatin1Char(char('0' + idx))
49
50#define DECLARE_LIGHT_POSITION_UNROLL_NAME(idx)\
51 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_POSITION_NAME)
52
53#define DECLARE_LIGHT_TYPE_UNROLL_NAME(idx)\
54 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_TYPE_NAME)
55
56#define DECLARE_LIGHT_COLOR_UNROLL_NAME(idx)\
57 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_COLOR_NAME)
58
59#define DECLARE_LIGHT_INTENSITY_UNROLL_NAME(idx)\
60 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_INTENSITY_NAME)
61
62#define DECLARE_LIGHT_DIRECTION_UNROLL_NAME(idx)\
63 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_DIRECTION_NAME)
64
65#define DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(idx)\
66 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_LINEAR_ATTENUATION_NAME)
67
68#define DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(idx)\
69 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_QUADRATIC_ATTENUATION_NAME)
70
71#define DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(idx)\
72 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_CONSTANT_ATTENUATION_NAME)
73
74#define DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(idx)\
75 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_CUT_OFF_ANGLE_NAME)
76
77QT_BEGIN_NAMESPACE
78
79namespace Qt3DRender {
80namespace Render {
81namespace OpenGL {
82
83int GLLights::LIGHT_COUNT_NAME_ID = StringToInt::lookupId(str: QLatin1String("lightCount"));
84
85QString GLLights::LIGHT_STRUCT_NAMES[MAX_LIGHTS] = {
86 DECLARE_LIGHT_STRUCT_NAME(0),
87 DECLARE_LIGHT_STRUCT_NAME(1),
88 DECLARE_LIGHT_STRUCT_NAME(2),
89 DECLARE_LIGHT_STRUCT_NAME(3),
90 DECLARE_LIGHT_STRUCT_NAME(4),
91 DECLARE_LIGHT_STRUCT_NAME(5),
92 DECLARE_LIGHT_STRUCT_NAME(6),
93 DECLARE_LIGHT_STRUCT_NAME(7)
94};
95
96int GLLights::LIGHT_POSITION_NAMES[MAX_LIGHTS] = {
97 DECLARE_LIGHT_POSITION_NAME(0),
98 DECLARE_LIGHT_POSITION_NAME(1),
99 DECLARE_LIGHT_POSITION_NAME(2),
100 DECLARE_LIGHT_POSITION_NAME(3),
101 DECLARE_LIGHT_POSITION_NAME(4),
102 DECLARE_LIGHT_POSITION_NAME(5),
103 DECLARE_LIGHT_POSITION_NAME(6),
104 DECLARE_LIGHT_POSITION_NAME(7)
105};
106
107int GLLights::LIGHT_TYPE_NAMES[MAX_LIGHTS] = {
108 DECLARE_LIGHT_TYPE_NAME(0),
109 DECLARE_LIGHT_TYPE_NAME(1),
110 DECLARE_LIGHT_TYPE_NAME(2),
111 DECLARE_LIGHT_TYPE_NAME(3),
112 DECLARE_LIGHT_TYPE_NAME(4),
113 DECLARE_LIGHT_TYPE_NAME(5),
114 DECLARE_LIGHT_TYPE_NAME(6),
115 DECLARE_LIGHT_TYPE_NAME(7)
116};
117
118int GLLights::LIGHT_COLOR_NAMES[MAX_LIGHTS] = {
119 DECLARE_LIGHT_COLOR_NAME(0),
120 DECLARE_LIGHT_COLOR_NAME(1),
121 DECLARE_LIGHT_COLOR_NAME(2),
122 DECLARE_LIGHT_COLOR_NAME(3),
123 DECLARE_LIGHT_COLOR_NAME(4),
124 DECLARE_LIGHT_COLOR_NAME(5),
125 DECLARE_LIGHT_COLOR_NAME(6),
126 DECLARE_LIGHT_COLOR_NAME(7)
127};
128
129int GLLights::LIGHT_INTENSITY_NAMES[MAX_LIGHTS] = {
130 DECLARE_LIGHT_INTENSITY_NAME(0),
131 DECLARE_LIGHT_INTENSITY_NAME(1),
132 DECLARE_LIGHT_INTENSITY_NAME(2),
133 DECLARE_LIGHT_INTENSITY_NAME(3),
134 DECLARE_LIGHT_INTENSITY_NAME(4),
135 DECLARE_LIGHT_INTENSITY_NAME(5),
136 DECLARE_LIGHT_INTENSITY_NAME(6),
137 DECLARE_LIGHT_INTENSITY_NAME(7)
138};
139
140int GLLights::LIGHT_DIRECTION_NAMES[MAX_LIGHTS] = {
141 DECLARE_LIGHT_DIRECTION_NAME(0),
142 DECLARE_LIGHT_DIRECTION_NAME(1),
143 DECLARE_LIGHT_DIRECTION_NAME(2),
144 DECLARE_LIGHT_DIRECTION_NAME(3),
145 DECLARE_LIGHT_DIRECTION_NAME(4),
146 DECLARE_LIGHT_DIRECTION_NAME(5),
147 DECLARE_LIGHT_DIRECTION_NAME(6),
148 DECLARE_LIGHT_DIRECTION_NAME(7)
149};
150
151int GLLights::LIGHT_LINEAR_ATTENUATION_NAMES[MAX_LIGHTS] = {
152 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(0),
153 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(1),
154 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(2),
155 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(3),
156 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(4),
157 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(5),
158 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(6),
159 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(7)
160};
161
162int GLLights::LIGHT_QUADRATIC_ATTENUATION_NAMES[MAX_LIGHTS] = {
163 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(0),
164 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(1),
165 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(2),
166 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(3),
167 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(4),
168 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(5),
169 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(6),
170 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(7)
171};
172
173int GLLights::LIGHT_CONSTANT_ATTENUATION_NAMES[MAX_LIGHTS] = {
174 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(0),
175 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(1),
176 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(2),
177 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(3),
178 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(4),
179 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(5),
180 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(6),
181 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(7)
182};
183
184int GLLights::LIGHT_CUT_OFF_ANGLE_NAMES[MAX_LIGHTS] = {
185 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(0),
186 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(1),
187 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(2),
188 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(3),
189 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(4),
190 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(5),
191 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(6),
192 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(7)
193};
194
195QString GLLights::LIGHT_STRUCT_UNROLL_NAMES[MAX_LIGHTS] = {
196 DECLARE_LIGHT_STRUCT_UNROLL_NAME(0),
197 DECLARE_LIGHT_STRUCT_UNROLL_NAME(1),
198 DECLARE_LIGHT_STRUCT_UNROLL_NAME(2),
199 DECLARE_LIGHT_STRUCT_UNROLL_NAME(3),
200 DECLARE_LIGHT_STRUCT_UNROLL_NAME(4),
201 DECLARE_LIGHT_STRUCT_UNROLL_NAME(5),
202 DECLARE_LIGHT_STRUCT_UNROLL_NAME(6),
203 DECLARE_LIGHT_STRUCT_UNROLL_NAME(7)
204};
205
206int GLLights::LIGHT_POSITION_UNROLL_NAMES[MAX_LIGHTS] = {
207 DECLARE_LIGHT_POSITION_UNROLL_NAME(0),
208 DECLARE_LIGHT_POSITION_UNROLL_NAME(1),
209 DECLARE_LIGHT_POSITION_UNROLL_NAME(2),
210 DECLARE_LIGHT_POSITION_UNROLL_NAME(3),
211 DECLARE_LIGHT_POSITION_UNROLL_NAME(4),
212 DECLARE_LIGHT_POSITION_UNROLL_NAME(5),
213 DECLARE_LIGHT_POSITION_UNROLL_NAME(6),
214 DECLARE_LIGHT_POSITION_UNROLL_NAME(7)
215};
216
217int GLLights::LIGHT_TYPE_UNROLL_NAMES[MAX_LIGHTS] = {
218 DECLARE_LIGHT_TYPE_UNROLL_NAME(0),
219 DECLARE_LIGHT_TYPE_UNROLL_NAME(1),
220 DECLARE_LIGHT_TYPE_UNROLL_NAME(2),
221 DECLARE_LIGHT_TYPE_UNROLL_NAME(3),
222 DECLARE_LIGHT_TYPE_UNROLL_NAME(4),
223 DECLARE_LIGHT_TYPE_UNROLL_NAME(5),
224 DECLARE_LIGHT_TYPE_UNROLL_NAME(6),
225 DECLARE_LIGHT_TYPE_UNROLL_NAME(7)
226};
227
228int GLLights::LIGHT_COLOR_UNROLL_NAMES[MAX_LIGHTS] = {
229 DECLARE_LIGHT_COLOR_UNROLL_NAME(0),
230 DECLARE_LIGHT_COLOR_UNROLL_NAME(1),
231 DECLARE_LIGHT_COLOR_UNROLL_NAME(2),
232 DECLARE_LIGHT_COLOR_UNROLL_NAME(3),
233 DECLARE_LIGHT_COLOR_UNROLL_NAME(4),
234 DECLARE_LIGHT_COLOR_UNROLL_NAME(5),
235 DECLARE_LIGHT_COLOR_UNROLL_NAME(6),
236 DECLARE_LIGHT_COLOR_UNROLL_NAME(7)
237};
238
239int GLLights::LIGHT_INTENSITY_UNROLL_NAMES[MAX_LIGHTS] = {
240 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(0),
241 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(1),
242 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(2),
243 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(3),
244 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(4),
245 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(5),
246 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(6),
247 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(7)
248};
249
250int GLLights::LIGHT_DIRECTION_UNROLL_NAMES[MAX_LIGHTS] = {
251 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(0),
252 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(1),
253 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(2),
254 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(3),
255 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(4),
256 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(5),
257 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(6),
258 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(7)
259};
260
261int GLLights::LIGHT_LINEAR_ATTENUATION_UNROLL_NAMES[MAX_LIGHTS] = {
262 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(0),
263 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(1),
264 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(2),
265 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(3),
266 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(4),
267 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(5),
268 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(6),
269 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(7)
270};
271
272int GLLights::LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAMES[MAX_LIGHTS] = {
273 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(0),
274 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(1),
275 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(2),
276 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(3),
277 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(4),
278 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(5),
279 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(6),
280 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(7)
281};
282
283int GLLights::LIGHT_CONSTANT_ATTENUATION_UNROLL_NAMES[MAX_LIGHTS] = {
284 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(0),
285 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(1),
286 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(2),
287 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(3),
288 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(4),
289 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(5),
290 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(6),
291 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(7)
292};
293
294int GLLights::LIGHT_CUT_OFF_ANGLE_UNROLL_NAMES[MAX_LIGHTS] = {
295 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(0),
296 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(1),
297 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(2),
298 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(3),
299 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(4),
300 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(5),
301 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(6),
302 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(7)
303};
304
305} // namespace OpenGL
306} // namespace Render
307} // namespace Qt3DRender
308
309QT_END_NAMESPACE
310

source code of qt3d/src/plugins/renderers/opengl/renderer/gllights.cpp