Sign in to follow this  
Telanor

SRGB in Direct2D?

Recommended Posts

Telanor    1486
How does one go about using SRGB in Direct2D? I'm using the usual Direct2D/D3D11 interop and I have my D3D backbuffer set up as SRGB. When I render the D2D surface onto it, the colors are all washed out. If I try to create my shared D3D11 texture with SRGB, I get a D2DERR_UNSUPPORTED_PIXEL_FORMAT error. I haven't had any luck googling how to do this either...

This is a snippet of my code:

D3D:
[code]
var description = new SwapChainDescription
{
BufferCount = 2,
Usage = Usage.RenderTargetOutput,
OutputHandle = Form.Handle,
IsWindowed = true,
ModeDescription = new ModeDescription(1280, 720, new Rational(60, 1), Format.R8G8B8A8_UNorm_SRgb),
SampleDescription = new SampleDescription(1, 0),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard,
};

Device.CreateWithSwapChain(Adapter, DeviceCreationFlags.BgraSupport, description, out device, out swapChain);
[/code]

D2D:
[code]
d3d11Texture = new Texture2D(Engine.Device, new Texture2DDescription
{
Width = (int)Engine.Viewport.Width,
Height = (int)Engine.Viewport.Height,
MipLevels = 1,
ArraySize = 1,
Format = Format.B8G8R8A8_UNorm_SRgb,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.SharedKeyedmutex
});

sharedResource = d3d11Texture.QueryInterface<Resource>();
var d3d10Texture = device10.OpenSharedResource<SharpDX.Direct3D10.Texture2D>(sharedResource.SharedHandle);

d3d10Mutex = d3d10Texture.QueryInterface<KeyedMutex>();
d3d11Mutex = d3d11Texture.QueryInterface<KeyedMutex>();

var d2Factory = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded);
DirectWriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared);

Surface surface = d3d10Texture.AsSurface();
RenderTargetProperties rtp = new RenderTargetProperties
{
MinLevel = SharpDX.Direct2D1.FeatureLevel.Level_10,
Type = RenderTargetType.Hardware,
Usage = RenderTargetUsage.None,
PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
};

dwRenderTarget = new RenderTarget(d2Factory, surface, rtp);
[/code]

That last line is the one that throws the error. If I change Format.Unknown to B8G8R8A8_UNorm_SRgb, I still get the same error. I'm using SharpDX and DirectX 11

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this