210
229
void UCShadowNode::setStyle(UCShadow::Style style)
231
DASSERT(style != m_style);
233
style == UCShadow::Outer ? outerVerticesCount : innerVerticesCount,
234
style == UCShadow::Outer ? outerIndicesCount : innerIndicesCount);
235
memcpy(m_geometry.indexData(),
236
style == UCShadow::Outer ? outerIndices() : innerIndices(),
237
(style == UCShadow::Outer ? outerIndicesCount : innerIndicesCount) * sizeof(quint16));
212
238
m_material.setStyle(style);
216
242
// FIXME(loicm) Clean up.
217
243
void UCShadowNode::updateGeometry(
218
const QSizeF& itemSize, float shadow, float radius, QRgb color)
244
const QSizeF& itemSize, float shadow, float radius, float angle, float distance, QRgb color)
220
246
UCShadowNode::Vertex* v = reinterpret_cast<UCShadowNode::Vertex*>(m_geometry.vertexData());
247
const float devicePixelRatio = qGuiApp->devicePixelRatio();
221
248
const float w = static_cast<float>(itemSize.width());
222
249
const float h = static_cast<float>(itemSize.height());
223
250
// Rounded down since renderShape() doesn't support sub-pixel rendering.
224
251
const float maxSize = floorf(qMin(w, h) * 0.5f);
225
252
const float clampedShadow = qMin(shadow, maxSize);
253
const float deviceShadow = clampedShadow * devicePixelRatio;
226
254
// FIXME(loicm) The diagonal at rounded integers pos prevents rasterising pixels on a side.
227
255
const float clampedRadius = qMin(radius, maxSize);
228
const float textureSize = 2.0f * clampedShadow + clampedRadius;
256
const float deviceRadius = clampedRadius * devicePixelRatio;
257
const float textureSize = 2.0f * deviceShadow + deviceRadius;
229
258
const float textureSizeRounded = getStride(static_cast<int>(textureSize), 1, textureStride);
230
259
const float textureOffset = (textureSizeRounded - textureSize) / textureSizeRounded;
231
260
const float textureFactor = (1.0f - textureOffset) / textureSize;
232
261
const quint32 packedColor = packColor(color);
234
263
if (m_style == UCShadow::Outer) {
265
// Get the offsets. Adding 180° to cast the shadow according to the
266
// virtual light position and using the opposite angle to rotate counter
268
sincosf((180.0f - angle) * (M_PI / 180.0f), &s, &c);
269
const float offsetY = s * distance;
270
const float offsetX = c * distance;
271
const float deviceW = w * devicePixelRatio;
272
const float deviceH = h * devicePixelRatio;
273
const float middleS = (deviceW * 0.5f + deviceShadow) * textureFactor + textureOffset;
274
const float middleT = (deviceH * 0.5f + deviceShadow) * textureFactor + textureOffset;
236
v[0].x = -clampedShadow;
237
v[0].y = -clampedShadow;
277
v[0].x = -clampedShadow + offsetX;
278
v[0].y = -clampedShadow + offsetY;
238
279
v[0].s = textureOffset;
239
280
v[0].t = textureOffset;
240
281
v[0].color = packedColor;
242
v[1].y = -clampedShadow;
243
v[1].s = (w * 0.5f + clampedShadow) * textureFactor + textureOffset;
282
v[1].x = w * 0.5f + offsetX;
283
v[1].y = -clampedShadow + offsetY;
244
285
v[1].t = textureOffset;
245
286
v[1].color = packedColor;
246
v[2].x = w + clampedShadow;
247
v[2].y = -clampedShadow;
287
v[2].x = w + clampedShadow + offsetX;
288
v[2].y = -clampedShadow + offsetY;
248
289
v[2].s = textureOffset;
249
290
v[2].t = textureOffset;
250
291
v[2].color = packedColor;
253
v[3].x = clampedRadius;
255
v[3].s = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
256
v[3].t = clampedShadow * textureFactor + textureOffset;
294
v[3].x = -clampedShadow + offsetX;
295
v[3].y = h * 0.5f + offsetY;
296
v[3].s = textureOffset;
257
298
v[3].color = packedColor;
260
v[4].s = (w * 0.5f + clampedShadow) * textureFactor + textureOffset;
261
v[4].t = clampedShadow * textureFactor + textureOffset;
299
v[4].x = w * 0.5f + offsetX;
300
v[4].y = h * 0.5f + offsetY;
262
303
v[4].color = packedColor;
263
v[5].x = w - clampedRadius;
265
v[5].s = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
266
v[5].t = clampedShadow * textureFactor + textureOffset;
304
v[5].x = w + clampedShadow + offsetX;
305
v[5].y = h * 0.5f + offsetY;
306
v[5].s = textureOffset;
267
308
v[5].color = packedColor;
271
v[6].y = clampedRadius;
272
v[6].s = clampedShadow * textureFactor + textureOffset;
273
v[6].t = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
311
v[6].x = -clampedShadow + offsetX;
312
v[6].y = h + clampedShadow + offsetY;
313
v[6].s = textureOffset;
314
v[6].t = textureOffset;
274
315
v[6].color = packedColor;
276
v[7].y = clampedRadius;
277
v[7].s = clampedShadow * textureFactor + textureOffset;
278
v[7].t = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
316
v[7].x = w * 0.5f + offsetX;
317
v[7].y = h + clampedShadow + offsetY;
319
v[7].t = textureOffset;
279
320
v[7].color = packedColor;
282
v[8].x = -clampedShadow;
321
v[8].x = w + clampedShadow + offsetX;
322
v[8].y = h + clampedShadow + offsetY;
284
323
v[8].s = textureOffset;
285
v[8].t = (h * 0.5f + clampedShadow) * textureFactor + textureOffset;
324
v[8].t = textureOffset;
286
325
v[8].color = packedColor;
289
v[9].s = clampedShadow * textureFactor + textureOffset;
290
v[9].t = (h * 0.5f + clampedShadow) * textureFactor + textureOffset;
291
v[9].color = packedColor;
294
v[10].s = clampedShadow * textureFactor + textureOffset;
295
v[10].t = (h * 0.5f + clampedShadow) * textureFactor + textureOffset;
296
v[10].color = packedColor;
297
v[11].x = w + clampedShadow;
299
v[11].s = textureOffset;
300
v[11].t = (h * 0.5f + clampedShadow) * textureFactor + textureOffset;
301
v[11].color = packedColor;
305
v[12].y = h - clampedRadius;
306
v[12].s = clampedShadow * textureFactor + textureOffset;
307
v[12].t = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
308
v[12].color = packedColor;
310
v[13].y = h - clampedRadius;
311
v[13].s = clampedShadow * textureFactor + textureOffset;
312
v[13].t = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
313
v[13].color = packedColor;
316
v[14].x = clampedRadius;
318
v[14].s = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
319
v[14].t = clampedShadow * textureFactor + textureOffset;
320
v[14].color = packedColor;
323
v[15].s = (w * 0.5f + clampedShadow) * textureFactor + textureOffset;
324
v[15].t = clampedShadow * textureFactor + textureOffset;
325
v[15].color = packedColor;
326
v[16].x = w - clampedRadius;
328
v[16].s = (clampedShadow + clampedRadius) * textureFactor + textureOffset;
329
v[16].t = clampedShadow * textureFactor + textureOffset;
330
v[16].color = packedColor;
333
v[17].x = -clampedShadow;
334
v[17].y = h + clampedShadow;
335
v[17].s = textureOffset;
336
v[17].t = textureOffset;
337
v[17].color = packedColor;
339
v[18].y = h + clampedShadow;
340
v[18].s = (w * 0.5f + clampedShadow) * textureFactor + textureOffset;
341
v[18].t = textureOffset;
342
v[18].color = packedColor;
343
v[19].x = w + clampedShadow;
344
v[19].y = h + clampedShadow;
345
v[19].s = textureOffset;
346
v[19].t = textureOffset;
347
v[19].color = packedColor;