Jump to content
  • Advertisement
Sign in to follow this  

SRGB in Direct2D?

This topic is 2093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:


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);


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);

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
Problem solved. I created a render target view of the d3d backbuffer without the SRGB format so direct2d can just write to that.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!