Jump to content

  • Log In with Google      Sign In   
  • Create Account


SRGB in Direct2D?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Telanor   Members   -  Reputation: 1320

Like
1Likes
Like

Posted 24 October 2012 - 06:19 PM

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

D2D:
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

Sponsor:

#2 Telanor   Members   -  Reputation: 1320

Like
3Likes
Like

Posted 24 October 2012 - 11:13 PM

Problem solved. I created a render target view of the d3d backbuffer without the SRGB format so direct2d can just write to that.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS