Advertisement
xoofx

Ripple.h

Apr 17th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. //// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. //// PARTICULAR PURPOSE.
  5. ////
  6. //// Copyright (c) Microsoft Corporation. All rights reserved
  7.  
  8. #include <WRL.h>
  9. #include <math.h>
  10. #include <InitGuid.h>
  11. #include <d2d1_1.h>
  12. #include <d2d1effectauthor.h>
  13. #include <d2d1effecthelpers.h>
  14. #include <d2d1effects.h>
  15.  
  16. #include "BasicReaderWriter.h"
  17.  
  18. DEFINE_GUID(GUID_RipplePixelShader, 0x6716FB29, 0x06A0, 0x460F, 0xAA, 0x9C, 0x8B, 0x8F, 0xF0, 0x33, 0x5E, 0xA6);
  19. DEFINE_GUID(CLSID_CustomRippleEffect, 0xB7B36C92, 0x3498, 0x4A94, 0x9E, 0x95, 0x9F, 0x24, 0x6F, 0x92, 0x45, 0xBF);
  20.  
  21. typedef enum RIPPLE_PROP
  22. {
  23.     RIPPLE_PROP_FREQUENCY = 0,
  24.     RIPPLE_PROP_PHASE = 1,
  25.     RIPPLE_PROP_AMPLITUDE = 2,
  26.     RIPPLE_PROP_SPREAD = 3,
  27.     RIPPLE_PROP_CENTER = 4
  28. };
  29.  
  30. // Our effect contains one transform, which is simply a wrapper around a pixel shader. As such,
  31. // we can simply make the effect itself act as the transform.
  32. class Ripple : public ID2D1EffectImpl, public ID2D1DrawTransform
  33. {
  34. public:
  35.     // Declare effect registration methods.
  36.     static HRESULT Register(_In_ ID2D1Factory1* pFactory);
  37.  
  38.     static HRESULT __stdcall CreateRippleImpl(_Outptr_ IUnknown** effectImpl);
  39.  
  40.     // Declare property getter/setter methods.
  41.     HRESULT SetCenter(D2D1_POINT_2F center);
  42.     D2D1_POINT_2F GetCenter() const;
  43.  
  44.     HRESULT SetFrequency(float frequency);
  45.     float GetFrequency() const;
  46.  
  47.     HRESULT SetPhase(float phase);
  48.     float GetPhase() const;
  49.  
  50.     HRESULT SetAmplitude(float amplitude);
  51.     float GetAmplitude() const;
  52.  
  53.     HRESULT SetSpread(float spread);
  54.     float GetSpread() const;
  55.  
  56.     // Declare ID2D1EffectImpl implementation methods.
  57.     HRESULT __stdcall Initialize(
  58.         _In_ ID2D1EffectContext* contextInternal,
  59.         _In_ ID2D1TransformGraph* transformGraph
  60.         );
  61.  
  62.     HRESULT __stdcall PrepareForRender(D2D1_CHANGE_TYPE changeType);
  63.  
  64.     HRESULT __stdcall SetGraph(_In_ ID2D1TransformGraph* graph);
  65.  
  66.     // Declare ID2D1DrawTransform implementation methods.
  67.     HRESULT __stdcall SetDrawInfo(_In_ ID2D1DrawInfo* renderInfo);
  68.  
  69.     // Declare ID2D1Transform implementation methods.
  70.     HRESULT __stdcall SetInputRects(
  71.         _In_reads_(inputRectsCount) const D2D1_RECT_L* inputRects,
  72.         UINT inputRectsCount
  73.         );
  74.  
  75.     HRESULT __stdcall MapOutputRectToInputRects(
  76.         _In_ const D2D1_RECT_L *outputRect,
  77.         _Out_writes_(cTransformInputs) D2D1_RECT_L* inputRects,
  78.         UINT32 transformInputs
  79.         ) const;
  80.  
  81.     HRESULT __stdcall MapInputRectsToOutputRect(
  82.         _In_reads_(inputRectsCount) const D2D1_RECT_L* inputRects,
  83.         UINT inputRectsCount,
  84.         _Out_ D2D1_RECT_L* outputRect
  85.         ) const;
  86.  
  87.     // Declare ID2D1TransformNode implementation methods.
  88.     UINT32 __stdcall GetInputCount() const;
  89.  
  90.     // Declare IUnknown implementation methods.
  91.     ULONG __stdcall AddRef();
  92.     ULONG __stdcall Release();
  93.     HRESULT __stdcall QueryInterface(_In_ REFIID riid, _Outptr_ void** output);
  94.  
  95. private:
  96.     Ripple();
  97.     void UpdateConstants();
  98.  
  99.     inline static float Clamp(float v, float low, float high)
  100.     {
  101.         return (v < low) ? low : (v > high) ? high : v;
  102.     }
  103.  
  104.     inline static float Round(float v)
  105.     {
  106.         return floor(v + 0.5f);
  107.     }
  108.  
  109.     // This struct defines the constant buffer of our pixel shader.
  110.     struct
  111.     {
  112.         float frequency;
  113.         float phase;
  114.         float amplitude;
  115.         float spread;
  116.         D2D1_POINT_2F center;
  117.     } m_constants;
  118.  
  119.     Microsoft::WRL::ComPtr<ID2D1DrawInfo> m_drawInfo;
  120.  
  121.     LONG m_refCount;
  122. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement