1/****************************************************************************
2**
3** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include <Qt3DRender/private/stringtoint_p.h>
41#include "gllights_p.h"
42
43#define LIGHT_POSITION_NAME QLatin1String(".position")
44#define LIGHT_TYPE_NAME QLatin1String(".type")
45#define LIGHT_COLOR_NAME QLatin1String(".color")
46#define LIGHT_INTENSITY_NAME QLatin1String(".intensity")
47#define LIGHT_DIRECTION_NAME QLatin1String(".direction")
48#define LIGHT_LINEAR_ATTENUATION_NAME QLatin1String(".linearAttenuation")
49#define LIGHT_QUADRATIC_ATTENUATION_NAME QLatin1String(".quadraticAttenuation")
50#define LIGHT_CONSTANT_ATTENUATION_NAME QLatin1String(".constantAttenuation")
51#define LIGHT_CUT_OFF_ANGLE_NAME QLatin1String(".cutOffAngle")
52
53#define DECLARE_LIGHT_STRUCT_NAME(idx)\
54 QLatin1String("lights[") + QLatin1Char(char('0' + idx)) + QLatin1Char(']')
55
56#define DECLARE_LIGHT_POSITION_NAME(idx)\
57 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_POSITION_NAME)
58
59#define DECLARE_LIGHT_TYPE_NAME(idx)\
60 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_TYPE_NAME)
61
62#define DECLARE_LIGHT_COLOR_NAME(idx)\
63 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_COLOR_NAME)
64
65#define DECLARE_LIGHT_INTENSITY_NAME(idx)\
66 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_INTENSITY_NAME)
67
68#define DECLARE_LIGHT_DIRECTION_NAME(idx)\
69 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_DIRECTION_NAME)
70
71#define DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(idx)\
72 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_LINEAR_ATTENUATION_NAME)
73
74#define DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(idx)\
75 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_QUADRATIC_ATTENUATION_NAME)
76
77#define DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(idx)\
78 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_CONSTANT_ATTENUATION_NAME)
79
80#define DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(idx)\
81 StringToInt::lookupId(LIGHT_STRUCT_NAMES[idx] + LIGHT_CUT_OFF_ANGLE_NAME)
82
83#define DECLARE_LIGHT_STRUCT_UNROLL_NAME(idx)\
84 QLatin1String("light_") + QLatin1Char(char('0' + idx))
85
86#define DECLARE_LIGHT_POSITION_UNROLL_NAME(idx)\
87 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_POSITION_NAME)
88
89#define DECLARE_LIGHT_TYPE_UNROLL_NAME(idx)\
90 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_TYPE_NAME)
91
92#define DECLARE_LIGHT_COLOR_UNROLL_NAME(idx)\
93 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_COLOR_NAME)
94
95#define DECLARE_LIGHT_INTENSITY_UNROLL_NAME(idx)\
96 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_INTENSITY_NAME)
97
98#define DECLARE_LIGHT_DIRECTION_UNROLL_NAME(idx)\
99 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_DIRECTION_NAME)
100
101#define DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(idx)\
102 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_LINEAR_ATTENUATION_NAME)
103
104#define DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(idx)\
105 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_QUADRATIC_ATTENUATION_NAME)
106
107#define DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(idx)\
108 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_CONSTANT_ATTENUATION_NAME)
109
110#define DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(idx)\
111 StringToInt::lookupId(LIGHT_STRUCT_UNROLL_NAMES[idx] + LIGHT_CUT_OFF_ANGLE_NAME)
112
113QT_BEGIN_NAMESPACE
114
115namespace Qt3DRender {
116namespace Render {
117namespace OpenGL {
118
119int GLLights::LIGHT_COUNT_NAME_ID = StringToInt::lookupId(str: QLatin1String("lightCount"));
120
121QString GLLights::LIGHT_STRUCT_NAMES[MAX_LIGHTS] = {
122 DECLARE_LIGHT_STRUCT_NAME(0),
123 DECLARE_LIGHT_STRUCT_NAME(1),
124 DECLARE_LIGHT_STRUCT_NAME(2),
125 DECLARE_LIGHT_STRUCT_NAME(3),
126 DECLARE_LIGHT_STRUCT_NAME(4),
127 DECLARE_LIGHT_STRUCT_NAME(5),
128 DECLARE_LIGHT_STRUCT_NAME(6),
129 DECLARE_LIGHT_STRUCT_NAME(7)
130};
131
132int GLLights::LIGHT_POSITION_NAMES[MAX_LIGHTS] = {
133 DECLARE_LIGHT_POSITION_NAME(0),
134 DECLARE_LIGHT_POSITION_NAME(1),
135 DECLARE_LIGHT_POSITION_NAME(2),
136 DECLARE_LIGHT_POSITION_NAME(3),
137 DECLARE_LIGHT_POSITION_NAME(4),
138 DECLARE_LIGHT_POSITION_NAME(5),
139 DECLARE_LIGHT_POSITION_NAME(6),
140 DECLARE_LIGHT_POSITION_NAME(7)
141};
142
143int GLLights::LIGHT_TYPE_NAMES[MAX_LIGHTS] = {
144 DECLARE_LIGHT_TYPE_NAME(0),
145 DECLARE_LIGHT_TYPE_NAME(1),
146 DECLARE_LIGHT_TYPE_NAME(2),
147 DECLARE_LIGHT_TYPE_NAME(3),
148 DECLARE_LIGHT_TYPE_NAME(4),
149 DECLARE_LIGHT_TYPE_NAME(5),
150 DECLARE_LIGHT_TYPE_NAME(6),
151 DECLARE_LIGHT_TYPE_NAME(7)
152};
153
154int GLLights::LIGHT_COLOR_NAMES[MAX_LIGHTS] = {
155 DECLARE_LIGHT_COLOR_NAME(0),
156 DECLARE_LIGHT_COLOR_NAME(1),
157 DECLARE_LIGHT_COLOR_NAME(2),
158 DECLARE_LIGHT_COLOR_NAME(3),
159 DECLARE_LIGHT_COLOR_NAME(4),
160 DECLARE_LIGHT_COLOR_NAME(5),
161 DECLARE_LIGHT_COLOR_NAME(6),
162 DECLARE_LIGHT_COLOR_NAME(7)
163};
164
165int GLLights::LIGHT_INTENSITY_NAMES[MAX_LIGHTS] = {
166 DECLARE_LIGHT_INTENSITY_NAME(0),
167 DECLARE_LIGHT_INTENSITY_NAME(1),
168 DECLARE_LIGHT_INTENSITY_NAME(2),
169 DECLARE_LIGHT_INTENSITY_NAME(3),
170 DECLARE_LIGHT_INTENSITY_NAME(4),
171 DECLARE_LIGHT_INTENSITY_NAME(5),
172 DECLARE_LIGHT_INTENSITY_NAME(6),
173 DECLARE_LIGHT_INTENSITY_NAME(7)
174};
175
176int GLLights::LIGHT_DIRECTION_NAMES[MAX_LIGHTS] = {
177 DECLARE_LIGHT_DIRECTION_NAME(0),
178 DECLARE_LIGHT_DIRECTION_NAME(1),
179 DECLARE_LIGHT_DIRECTION_NAME(2),
180 DECLARE_LIGHT_DIRECTION_NAME(3),
181 DECLARE_LIGHT_DIRECTION_NAME(4),
182 DECLARE_LIGHT_DIRECTION_NAME(5),
183 DECLARE_LIGHT_DIRECTION_NAME(6),
184 DECLARE_LIGHT_DIRECTION_NAME(7)
185};
186
187int GLLights::LIGHT_LINEAR_ATTENUATION_NAMES[MAX_LIGHTS] = {
188 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(0),
189 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(1),
190 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(2),
191 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(3),
192 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(4),
193 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(5),
194 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(6),
195 DECLARE_LIGHT_LINEAR_ATTENUATION_NAME(7)
196};
197
198int GLLights::LIGHT_QUADRATIC_ATTENUATION_NAMES[MAX_LIGHTS] = {
199 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(0),
200 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(1),
201 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(2),
202 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(3),
203 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(4),
204 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(5),
205 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(6),
206 DECLARE_LIGHT_QUADRATIC_ATTENUATION_NAME(7)
207};
208
209int GLLights::LIGHT_CONSTANT_ATTENUATION_NAMES[MAX_LIGHTS] = {
210 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(0),
211 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(1),
212 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(2),
213 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(3),
214 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(4),
215 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(5),
216 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(6),
217 DECLARE_LIGHT_CONSTANT_ATTENUATION_NAME(7)
218};
219
220int GLLights::LIGHT_CUT_OFF_ANGLE_NAMES[MAX_LIGHTS] = {
221 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(0),
222 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(1),
223 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(2),
224 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(3),
225 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(4),
226 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(5),
227 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(6),
228 DECLARE_LIGHT_CUT_OFF_ANGLE_NAME(7)
229};
230
231QString GLLights::LIGHT_STRUCT_UNROLL_NAMES[MAX_LIGHTS] = {
232 DECLARE_LIGHT_STRUCT_UNROLL_NAME(0),
233 DECLARE_LIGHT_STRUCT_UNROLL_NAME(1),
234 DECLARE_LIGHT_STRUCT_UNROLL_NAME(2),
235 DECLARE_LIGHT_STRUCT_UNROLL_NAME(3),
236 DECLARE_LIGHT_STRUCT_UNROLL_NAME(4),
237 DECLARE_LIGHT_STRUCT_UNROLL_NAME(5),
238 DECLARE_LIGHT_STRUCT_UNROLL_NAME(6),
239 DECLARE_LIGHT_STRUCT_UNROLL_NAME(7)
240};
241
242int GLLights::LIGHT_POSITION_UNROLL_NAMES[MAX_LIGHTS] = {
243 DECLARE_LIGHT_POSITION_UNROLL_NAME(0),
244 DECLARE_LIGHT_POSITION_UNROLL_NAME(1),
245 DECLARE_LIGHT_POSITION_UNROLL_NAME(2),
246 DECLARE_LIGHT_POSITION_UNROLL_NAME(3),
247 DECLARE_LIGHT_POSITION_UNROLL_NAME(4),
248 DECLARE_LIGHT_POSITION_UNROLL_NAME(5),
249 DECLARE_LIGHT_POSITION_UNROLL_NAME(6),
250 DECLARE_LIGHT_POSITION_UNROLL_NAME(7)
251};
252
253int GLLights::LIGHT_TYPE_UNROLL_NAMES[MAX_LIGHTS] = {
254 DECLARE_LIGHT_TYPE_UNROLL_NAME(0),
255 DECLARE_LIGHT_TYPE_UNROLL_NAME(1),
256 DECLARE_LIGHT_TYPE_UNROLL_NAME(2),
257 DECLARE_LIGHT_TYPE_UNROLL_NAME(3),
258 DECLARE_LIGHT_TYPE_UNROLL_NAME(4),
259 DECLARE_LIGHT_TYPE_UNROLL_NAME(5),
260 DECLARE_LIGHT_TYPE_UNROLL_NAME(6),
261 DECLARE_LIGHT_TYPE_UNROLL_NAME(7)
262};
263
264int GLLights::LIGHT_COLOR_UNROLL_NAMES[MAX_LIGHTS] = {
265 DECLARE_LIGHT_COLOR_UNROLL_NAME(0),
266 DECLARE_LIGHT_COLOR_UNROLL_NAME(1),
267 DECLARE_LIGHT_COLOR_UNROLL_NAME(2),
268 DECLARE_LIGHT_COLOR_UNROLL_NAME(3),
269 DECLARE_LIGHT_COLOR_UNROLL_NAME(4),
270 DECLARE_LIGHT_COLOR_UNROLL_NAME(5),
271 DECLARE_LIGHT_COLOR_UNROLL_NAME(6),
272 DECLARE_LIGHT_COLOR_UNROLL_NAME(7)
273};
274
275int GLLights::LIGHT_INTENSITY_UNROLL_NAMES[MAX_LIGHTS] = {
276 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(0),
277 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(1),
278 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(2),
279 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(3),
280 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(4),
281 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(5),
282 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(6),
283 DECLARE_LIGHT_INTENSITY_UNROLL_NAME(7)
284};
285
286int GLLights::LIGHT_DIRECTION_UNROLL_NAMES[MAX_LIGHTS] = {
287 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(0),
288 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(1),
289 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(2),
290 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(3),
291 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(4),
292 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(5),
293 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(6),
294 DECLARE_LIGHT_DIRECTION_UNROLL_NAME(7)
295};
296
297int GLLights::LIGHT_LINEAR_ATTENUATION_UNROLL_NAMES[MAX_LIGHTS] = {
298 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(0),
299 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(1),
300 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(2),
301 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(3),
302 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(4),
303 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(5),
304 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(6),
305 DECLARE_LIGHT_LINEAR_ATTENUATION_UNROLL_NAME(7)
306};
307
308int GLLights::LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAMES[MAX_LIGHTS] = {
309 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(0),
310 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(1),
311 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(2),
312 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(3),
313 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(4),
314 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(5),
315 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(6),
316 DECLARE_LIGHT_QUADRATIC_ATTENUATION_UNROLL_NAME(7)
317};
318
319int GLLights::LIGHT_CONSTANT_ATTENUATION_UNROLL_NAMES[MAX_LIGHTS] = {
320 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(0),
321 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(1),
322 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(2),
323 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(3),
324 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(4),
325 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(5),
326 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(6),
327 DECLARE_LIGHT_CONSTANT_ATTENUATION_UNROLL_NAME(7)
328};
329
330int GLLights::LIGHT_CUT_OFF_ANGLE_UNROLL_NAMES[MAX_LIGHTS] = {
331 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(0),
332 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(1),
333 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(2),
334 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(3),
335 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(4),
336 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(5),
337 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(6),
338 DECLARE_LIGHT_CUT_OFF_ANGLE_UNROLL_NAME(7)
339};
340
341} // namespace OpenGL
342} // namespace Render
343} // namespace Qt3DRender
344
345QT_END_NAMESPACE
346

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