87 lines
1.8 KiB
C++
Raw Normal View History

2024-11-01 16:55:46 +08:00
#include "RenderAPI.h"
#include "PlatformBase.h"
// Direct3D 11 implementation of RenderAPI.
#if SUPPORT_D3D11
#include <assert.h>
#include <d3d11.h>
#include "Unity/IUnityGraphicsD3D11.h"
class RenderAPI_D3D11 : public RenderAPI
{
public:
RenderAPI_D3D11();
virtual ~RenderAPI_D3D11() { }
2024-12-11 17:42:08 +08:00
virtual void processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces);
2024-11-01 16:55:46 +08:00
2024-12-11 17:42:08 +08:00
virtual bool getUsesReverseZ() { return (int)m_Device->GetFeatureLevel() >= (int)D3D_FEATURE_LEVEL_10_0; }
virtual void initSupportFeature() override;
2024-11-01 16:55:46 +08:00
private:
ID3D11Device* m_Device;
};
RenderAPI* CreateRenderAPI_D3D11()
{
return new RenderAPI_D3D11();
}
// Simple compiled shader bytecode.
//
// Shader source that was used:
#if 0
cbuffer MyCB : register(b0)
{
float4x4 worldMatrix;
}
void VS(float3 pos : POSITION, float4 color : COLOR, out float4 ocolor : COLOR, out float4 opos : SV_Position)
{
opos = mul(worldMatrix, float4(pos, 1));
ocolor = color;
}
float4 PS(float4 color : COLOR) : SV_TARGET
{
return color;
}
#endif // #if 0
//
// Which then was compiled with:
// fxc /Tvs_4_0_level_9_3 /EVS source.hlsl /Fh outVS.h /Qstrip_reflect /Qstrip_debug /Qstrip_priv
// fxc /Tps_4_0_level_9_3 /EPS source.hlsl /Fh outPS.h /Qstrip_reflect /Qstrip_debug /Qstrip_priv
// and results pasted & formatted to take less lines here
RenderAPI_D3D11::RenderAPI_D3D11()
: m_Device(NULL)
{
}
2024-12-11 17:42:08 +08:00
void RenderAPI_D3D11::processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces)
2024-11-01 16:55:46 +08:00
{
switch (type)
{
case kUnityGfxDeviceEventInitialize:
{
IUnityGraphicsD3D11* d3d = interfaces->Get<IUnityGraphicsD3D11>();
m_Device = d3d->GetDevice();
break;
}
case kUnityGfxDeviceEventShutdown:
break;
}
}
2024-12-11 17:42:08 +08:00
void RenderAPI_D3D11::initSupportFeature()
2024-11-01 16:55:46 +08:00
{
}
#endif // #if SUPPORT_D3D11