Kiwano Engine v1.3.x
Effect.h
1// Copyright (c) 2023 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/render/DirectX/helper.h>
23#include <d2d1effectauthor.h>
24#include <d2d1effecthelpers.h>
25#include <initguid.h>
26
27DEFINE_GUID(CLSID_CustomPixelEffect, 0x6b0e1068, 0x186e, 0x43f7, 0xbb, 0x5, 0x64, 0x91, 0x9, 0xa5, 0x6a, 0x79);
28
29namespace kiwano
30{
31namespace graphics
32{
33namespace directx
34{
35
37 : public ID2D1EffectImpl
38 , public ID2D1DrawTransform
39{
40public:
41 enum InputIndex : UINT32
42 {
43 Constants = 0,
44 LeftTopExpansion,
45 RightBottomExpansion,
46 };
47
48 static HRESULT Register(_In_ ID2D1Factory1* pFactory);
49 static HRESULT __stdcall CreateEffect(_Outptr_ IUnknown** ppEffectImpl);
50
51 static void RegisterShader(_In_ const CLSID& shaderId, _In_ const BYTE* data, _In_ UINT32 dataSize);
52
53 IFACEMETHODIMP Initialize(_In_ ID2D1EffectContext* pContextInternal, _In_ ID2D1TransformGraph* pTransformGraph);
54
55 IFACEMETHODIMP PrepareForRender(D2D1_CHANGE_TYPE changeType);
56 IFACEMETHODIMP SetGraph(_In_ ID2D1TransformGraph* pGraph);
57
58 // Declare ID2D1DrawTransform implementation methods.
59 IFACEMETHODIMP SetDrawInfo(_In_ ID2D1DrawInfo* pRenderInfo);
60
61 // Declare ID2D1Transform implementation methods.
62 IFACEMETHODIMP MapOutputRectToInputRects(_In_ const D2D1_RECT_L* pOutputRect,
63 _Out_writes_(inputRectCount) D2D1_RECT_L* pInputRects,
64 UINT32 inputRectCount) const;
65
66 IFACEMETHODIMP MapInputRectsToOutputRect(_In_reads_(inputRectCount) CONST D2D1_RECT_L* pInputRects,
67 _In_reads_(inputRectCount) CONST D2D1_RECT_L* pInputOpaqueSubRects,
68 UINT32 inputRectCount, _Out_ D2D1_RECT_L* pOutputRect,
69 _Out_ D2D1_RECT_L* pOutputOpaqueSubRect);
70
71 IFACEMETHODIMP MapInvalidRect(UINT32 inputIndex, D2D1_RECT_L invalidInputRect,
72 _Out_ D2D1_RECT_L* pInvalidOutputRect) const;
73
74 // Declare ID2D1TransformNode implementation methods.
75 IFACEMETHODIMP_(UINT32) GetInputCount() const;
76
77 HRESULT SetConstants(_In_reads_(dataSize) const BYTE* data, UINT32 dataSize);
78 HRESULT GetConstants(_Out_writes_opt_(dataSize) BYTE* data, UINT32 dataSize, _Out_opt_ UINT32* actualSize) const;
79
80 HRESULT SetLeftTopExpansion(D2D1_POINT_2F value);
81 D2D1_POINT_2F GetLeftTopExpansion() const;
82
83 HRESULT SetRightBottomExpansion(D2D1_POINT_2F value);
84 D2D1_POINT_2F GetRightBottomExpansion() const;
85
86 IFACEMETHODIMP_(ULONG) AddRef();
87 IFACEMETHODIMP_(ULONG) Release();
88 IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _Outptr_ void** ppOutput);
89
90private:
92
94
95 LONG m_refCount;
96 ComPtr<ID2D1DrawInfo> m_drawInfo;
97 ComPtr<ID2D1EffectContext> m_effectContext;
98 D2D1_RECT_L m_inputRect;
99 CLSID m_shaderId;
100 const BYTE* m_constants;
101 UINT32 m_constantsSize;
102 D2D1_POINT_2F m_leftTopExpansion;
103 D2D1_POINT_2F m_rightBottomExpansion;
104};
105
106} // namespace directx
107} // namespace graphics
108} // namespace kiwano