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
54struct ShadowVertex : BasicVertex {
55 // shadow
56 float offset_x;
57 float offset_y;
58 float distance_correction;
59
60 void set_offset(QVector2D v) noexcept {
61 offset_x = v.x();
62 offset_y = v.y();
63 }
64};
65auto create_shadow_geometry() -> up<QSGGeometry>;
66
67enum ShadowFlags
68{
69 None_ShadowFlag = 0x00,
72 TransparentOccluder_ShadowFlag = 0x01,
74 GeometricOnly_ShadowFlag = 0x02,
76 DirectionalLight_ShadowFlag = 0x04,
78 ConcaveBlurOnly_ShadowFlag = 0x08,
80 All_ShadowFlag = 0x0F
81};
82struct ShadowParams {
83 QVector3D z_plane_params;
84 QVector3D light_pos;
85 float light_radius { 0 };
86 QRgb ambient_color { 0 };
87 QRgb spot_color { 0 };
88 uint32_t flags { 0 };
89 QVector4D radius;
90};
91void update_shadow_geometry(QSGGeometry* geo, const ShadowParams& params, const QRectF& rect);
92
93} // namespace qml_material::sg