QmlMaterial 0.1.0
Loading...
Searching...
No Matches
blur_mask_material.h
1#pragma once
2
3#include <array>
4#include <QSGMaterial>
5#include <QVector2D>
6#include <QVector4D>
7#include "qml_material/scenegraph/texture_cache.h"
8
9namespace qml_material::sg
10{
11
12enum class BlurStyle : int
13{
14 Normal = 0,
15 Solid = 1,
16 Outer = 2,
17 Inner = 3,
18};
19
27class BlurMaskMaterial : public QSGMaterial {
28public:
30 ~BlurMaskMaterial() = default;
31
32 QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override;
33 QSGMaterialType* type() const override;
34 int compare(const QSGMaterial* other) const override;
35
37 void init_profile_texture(QQuickWindow* win);
38 auto profile_texture() -> QSGTexture*;
39
40 void init_corner_textures(QQuickWindow* win);
41 const CornerCutoutTexture& corner_texture(int index) const;
42
43 // Uniform state (populated by the owning node each frame).
44 float sigma { 0.0f };
45 QVector2D rect_size { 0.0f, 0.0f };
46 QVector4D radius { 0.0f, 0.0f, 0.0f, 0.0f }; // TL, TR, BL, BR
47 BlurStyle style { BlurStyle::Normal };
48
50 [[nodiscard]] float effective_radius() const;
51
52private:
53 // Not owned; textures come from the per-window cache.
54 QSGTexture* m_profile_texture { nullptr };
55 std::array<CornerCutoutTexture, 4> m_corner_textures {};
56};
57
58class BlurMaskShader : public QSGMaterialShader {
59public:
60 BlurMaskShader();
61
62 bool updateUniformData(QSGMaterialShader::RenderState& state, QSGMaterial* newMaterial,
63 QSGMaterial* oldMaterial) override;
64
65 void updateSampledImage(RenderState&, int binding, QSGTexture** texture,
66 QSGMaterial* newMaterial, QSGMaterial*) override;
67};
68
69} // namespace qml_material::sg
Definition blur_mask_material.h:27
float effective_radius() const
Effective uniform radius used by the shader (= max of the 4 radii).
Definition blur_mask_material.cpp:26
void init_profile_texture(QQuickWindow *win)
Bind the per-window shared 1D unit-CDF profile texture. Cheap.
Definition blur_mask_material.cpp:68