forked from ChasBoyd/DisplayHDRTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SineSweepEffect.h
123 lines (101 loc) · 4.21 KB
/
SineSweepEffect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
DEFINE_GUID(GUID_SineSweepPixelShader, 0xd6ae579b, 0x62a6, 0x47bb, 0x99, 0xc0, 0x64, 0xb6, 0x5c, 0xb1, 0x8c, 0x44);
DEFINE_GUID(CLSID_CustomSineSweepEffect, 0x2bd6d67c, 0x8742, 0x454e, 0x8a, 0x97, 0xb4, 0xca, 0x70, 0x6f, 0x14, 0x6d);
// Our effect contains one transform, which is simply a wrapper around a pixel shader. As such,
// we can simply make the effect itself act as the transform.
class SineSweepEffect : public ID2D1EffectImpl, public ID2D1DrawTransform
{
public:
// Declare effect registration methods.
static HRESULT Register(_In_ ID2D1Factory1* pFactory);
static HRESULT __stdcall CreateSineSweepImpl(_Outptr_ IUnknown** ppEffectImpl);
// Declare ID2D1EffectImpl implementation methods.
IFACEMETHODIMP Initialize(
_In_ ID2D1EffectContext* pContextInternal,
_In_ ID2D1TransformGraph* pTransformGraph
);
IFACEMETHODIMP PrepareForRender(D2D1_CHANGE_TYPE changeType);
IFACEMETHODIMP SetGraph(_In_ ID2D1TransformGraph* pGraph);
// Declare ID2D1DrawTransform implementation methods.
IFACEMETHODIMP SetDrawInfo(_In_ ID2D1DrawInfo* pRenderInfo);
// Declare ID2D1Transform implementation methods.
IFACEMETHODIMP MapOutputRectToInputRects(
_In_ const D2D1_RECT_L* pOutputRect,
_Out_writes_(inputRectCount) D2D1_RECT_L* pInputRects,
UINT32 inputRectCount
) const;
IFACEMETHODIMP MapInputRectsToOutputRect(
_In_reads_(inputRectCount) CONST D2D1_RECT_L* pInputRects,
_In_reads_(inputRectCount) CONST D2D1_RECT_L* pInputOpaqueSubRects,
UINT32 inputRectCount,
_Out_ D2D1_RECT_L* pOutputRect,
_Out_ D2D1_RECT_L* pOutputOpaqueSubRect
);
IFACEMETHODIMP MapInvalidRect(
UINT32 inputIndex,
D2D1_RECT_L invalidInputRect,
_Out_ D2D1_RECT_L* pInvalidOutputRect
) const;
// Declare ID2D1TransformNode implementation methods.
IFACEMETHODIMP_(UINT32) GetInputCount() const;
// Declare IUnknown implementation methods.
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP_(ULONG) Release();
IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _Outptr_ void** ppOutput);
// Declare property getter/setter methods.
HRESULT SetCenter(D2D1_POINT_2F center);
D2D1_POINT_2F GetCenter() const;
HRESULT SetWavelengthHalvingDistance(float frequency);
float GetWavelengthHalvingDistance() const;
HRESULT SetInitialWavelength(float phase);
float GetInitialWavelength() const;
HRESULT SetWhiteLevelMultiplier(float multiplier);
float GetWhiteLevelMultiplier() const;
private:
SineSweepEffect();
HRESULT UpdateConstants();
inline static float Clamp(float v, float low, float high)
{
return (v < low) ? low : (v > high) ? high : v;
}
inline static float Round(float v)
{
return floor(v + 0.5f);
}
// Prevents over/underflows when adding longs.
inline static long SafeAdd(long base, long valueToAdd)
{
if (valueToAdd >= 0)
{
return ((base + valueToAdd) >= base) ? (base + valueToAdd) : LONG_MAX;
}
else
{
return ((base + valueToAdd) <= base) ? (base + valueToAdd) : LONG_MIN;
}
}
// This struct defines the constant buffer of our pixel shader.
// All distances are in pixels, we ignore DPI.
struct
{
float dpi;
D2D1_POINT_2F center;
float initialWavelength;
float wavelengthHalvingDistance;
float whiteLevelMultiplier;
} m_constants;
Microsoft::WRL::ComPtr<ID2D1DrawInfo> m_drawInfo;
Microsoft::WRL::ComPtr<ID2D1EffectContext> m_effectContext;
LONG m_refCount;
D2D1_RECT_L m_inputRect;
float m_dpi;
};