Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

How to create Direct2D Device from Direct3D device? #286

Closed
PavelBrokhman opened this issue Feb 20, 2014 · 2 comments
Closed

How to create Direct2D Device from Direct3D device? #286

PavelBrokhman opened this issue Feb 20, 2014 · 2 comments

Comments

@PavelBrokhman
Copy link

I am trying to transfer code from C++ Sample to C# using SharpDX. Here the code I am using:

// Create the Direct3D 11 API device object and a corresponding context.
// Returns the Direct3D device created.
var d3dDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, creationFlags, featureLevels);
// Returns feature level of device created.
m_d3dFeatureLevel = d3dDevice.FeatureLevel;
m_d3dDevice = new SharpDX.Direct3D11.Device1(d3dDevice.NativePointer);
m_d3dContext = new SharpDX.Direct3D11.DeviceContext1(d3dDevice.ImmediateContext.NativePointer);
var dxgiDevice = new SharpDX.DXGI.Device(m_d3dDevice.NativePointer);
// Create the Direct2D device object and a corresponding context.
m_d2dDevice = new SharpDX.Direct2D1.Device(m_d2dFactory, dxgiDevice);

m_d2dContext = new SharpDX.Direct2D1.DeviceContext(m_d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

It fails when I try to create m_d2dDevice. In C++ this code is working. Actually they use "As" function to get objects. I have tried to use SharpDX's "As" and it didn't work at all, too.

@xoofx
Copy link
Member

xoofx commented Feb 20, 2014

You should not use NativePointer at all as you are messing completely COM pointers. This is usually reserved for internal use. There is at least a sample in SharpDX that shows how to initialize Direct2D from Direct3D device, See for example DeviceManager.CreateDeviceResources

@xoofx xoofx closed this as completed Feb 20, 2014
@PavelBrokhman
Copy link
Author

:) This is the very similar sample, that I have tried to transfer to the SharpDX. The one that is created by Template in VS2012 for C++.

From: xoofx [mailto:notifications@github.com]
Sent: February 19, 2014 9:00 PM
To: sharpdx/SharpDX
Cc: PavelBrokhman
Subject: Re: [SharpDX] How to create Direct2D Device from Direct3D device? (#286)

You should not use NativePointer at all as you are messing completely COM pointers. This is usually reserved for internal use. There is at least a sample in SharpDX that shows how to initialize Direct2D from Direct3D device, See for example DeviceManager.CreateDeviceResources https://github.com/sharpdx/SharpDX/blob/master/Samples/Win8/CommonDX/DeviceManager.cs#L151


Reply to this email directly or view it on GitHub #286 (comment) . https://github.com/notifications/beacon/5633942__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcwODM5NDQwOSwiZGF0YSI6eyJpZCI6MjYwNDkwMjd9fQ==--de408e4dac9bdcaee63b5edc0cab169855cafd32.gif

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants