QmlMaterial 0.1.0
Loading...
Searching...
No Matches
geometry.h
1#pragma once
2#include <QSGGeometry>
3#include <QColor>
4#include <QVector4D>
5
6#include "qml_material/core.hpp"
7
8namespace qml_material::sg
9{
10
11struct BasicVertex {
12 // position
13 float x;
14 float y;
15
16 // color
17 float r;
18 float g;
19 float b;
20 float a;
21
22 void set_point(float x, float y) noexcept {
23 this->x = x;
24 this->y = y;
25 }
26 void set_point(QVector2D v) noexcept {
27 x = v.x();
28 y = v.y();
29 }
30 void set_color(QRgb c) noexcept {
31 r = qRed(c) / 255.0f;
32 g = qGreen(c) / 255.0f;
33 b = qBlue(c) / 255.0f;
34 a = qAlpha(c) / 255.0f;
35 }
36 void set_color(const QColor& c) noexcept { set_color(c.rgb()); }
37};
38
39struct RectangleVertex : BasicVertex {
40 // circle edge
41 float ce_x; // if in x edge
42 float ce_y; // if in y edge
43 float ce_distance_to_outter; // from inner rect
44 float ce_distance_to_inner; // from inner rect
45
46 operator QVector2D() const { return { x, y }; }
47 operator QColor() const { return QColor::fromRgbF(r, g, b, a); }
48};
49auto create_rectangle_geometry() -> up<QSGGeometry>;
50// tl tr bl br
51void update_rectangle_geometry(RectangleVertex* vertexs, QVector2D size, QRgb color,
52 QVector4D radius);
53
54auto create_blur_mask_geometry() -> up<QSGGeometry>;
55float blur_mask_margin(float sigma) noexcept;
60void update_blur_mask_geometry(BasicVertex* v, QVector2D rect_size, float sigma, QRgb color,
61 QVector4D radius);
62
63struct ShadowVertex : BasicVertex {
64 // shadow
65 float offset_x;
66 float offset_y;
67 float distance_correction;
68 float occluder_x;
69 float occluder_y;
70 float occluder_width;
71 float occluder_height;
72 float occluder_radii[4];
73
74 void set_offset(QVector2D v) noexcept {
75 offset_x = v.x();
76 offset_y = v.y();
77 }
78};
79auto create_shadow_geometry() -> up<QSGGeometry>;
80
81enum ShadowFlags
82{
83 None_ShadowFlag = 0x00,
86 TransparentOccluder_ShadowFlag = 0x01,
88 GeometricOnly_ShadowFlag = 0x02,
90 DirectionalLight_ShadowFlag = 0x04,
92 ConcaveBlurOnly_ShadowFlag = 0x08,
94 All_ShadowFlag = 0x0F
95};
96struct ShadowParams {
97 QVector3D z_plane_params;
98 QVector3D light_pos;
99 float light_radius { 0 };
100 QRgb ambient_color { 0 };
101 QRgb spot_color { 0 };
102 uint32_t flags { 0 };
103 QVector4D radius;
104};
105void update_shadow_geometry(QSGGeometry* geo, const ShadowParams& params, const QRectF& rect);
106QRectF shadow_bounds(const ShadowParams& params, const QRectF& rect);
107
108} // namespace qml_material::sg