77 行
2.6 KiB
C#
77 行
2.6 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using TerraFX.Interop.DirectX;
|
|
using TerraFX.Interop.Windows;
|
|
|
|
namespace ComputeSharp.D2D1Interop.Tests.Helpers;
|
|
|
|
/// <summary>
|
|
/// A simple <see cref="ID2D1EffectImpl"/> and <see cref="ID2D1DrawTransform"/> implementation for a given pixel shader.
|
|
/// </summary>
|
|
internal unsafe partial struct PixelShaderEffect
|
|
{
|
|
/// <summary>
|
|
/// The implementation for <see cref="ID2D1EffectImpl"/>.
|
|
/// </summary>
|
|
private static class ID2D1EffectImplMethods
|
|
{
|
|
/// <inheritdoc cref="ID2D1EffectImpl.QueryInterface"/>
|
|
[UnmanagedCallersOnly]
|
|
public static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject)
|
|
{
|
|
return @this->QueryInterface(riid, ppvObject);
|
|
}
|
|
|
|
/// <inheritdoc cref="ID2D1EffectImpl.AddRef"/>
|
|
[UnmanagedCallersOnly]
|
|
public static uint AddRef(PixelShaderEffect* @this)
|
|
{
|
|
return @this->AddRef();
|
|
}
|
|
|
|
/// <inheritdoc cref="ID2D1EffectImpl.Release"/>
|
|
[UnmanagedCallersOnly]
|
|
public static uint Release(PixelShaderEffect* @this)
|
|
{
|
|
return @this->Release();
|
|
}
|
|
|
|
/// <inheritdoc cref="ID2D1EffectImpl.Initialize"/>
|
|
[UnmanagedCallersOnly]
|
|
public static int Initialize(PixelShaderEffect* @this, ID2D1EffectContext* effectContext, ID2D1TransformGraph* transformGraph)
|
|
{
|
|
int hresult = effectContext->LoadPixelShader(
|
|
shaderId: &@this->shaderId,
|
|
shaderBuffer: @this->bytecode,
|
|
shaderBufferCount: (uint)@this->bytecodeSize);
|
|
|
|
if (Windows.SUCCEEDED(hresult))
|
|
{
|
|
hresult = transformGraph->SetSingleTransformNode((ID2D1TransformNode*)&@this->lpVtblForID2D1DrawTransform);
|
|
}
|
|
|
|
return hresult;
|
|
}
|
|
|
|
/// <inheritdoc cref="ID2D1EffectImpl.PrepareForRender"/>
|
|
[UnmanagedCallersOnly]
|
|
public static int PrepareForRender(PixelShaderEffect* @this, D2D1_CHANGE_TYPE changeType)
|
|
{
|
|
if (@this->constantBuffer is not null)
|
|
{
|
|
return @this->d2D1DrawInfo->SetPixelShaderConstantBuffer(
|
|
buffer: @this->constantBuffer,
|
|
bufferCount: (uint)@this->constantBufferSize);
|
|
}
|
|
|
|
return S.S_OK;
|
|
}
|
|
|
|
/// <inheritdoc cref="ID2D1EffectImpl.SetGraph"/>
|
|
[UnmanagedCallersOnly]
|
|
public static int SetGraph(PixelShaderEffect* @this, ID2D1TransformGraph* transformGraph)
|
|
{
|
|
return E.E_NOTIMPL;
|
|
}
|
|
}
|
|
} |