Sign in to follow this  
ICodeSharp

Managed Direct3D9 Wrapper Structuring Using C#

Recommended Posts

Hey, how is it going? I decided to go on a learning experience yesterday and create my own wrapper for Direct3D9 using only C#. So far I have wrapped the IDirect3D9 interface, most of the IDirect3DDevice9 interface, and which ever structures and enumerators I needed, basically copying straight from the header. Here is my problem though, I am wanting to create a framework similar to Microsoft XNA, for ease of use, but my code just looks, well plain ugly, compaired to Microsoft XNA. I was wondering If I should keep going, create the wrapper, and then implement a framework over top, utilizing the functions of Direct3D9, and just create my own methods, structures and enumerators simliar to Microsoft XNA, or should I Build it into my wrapper, for a more clean .NET feel. My only worry is being able to pass my own structures and enumerators into the Direct3D9 functions, without to much grief. I guess its not so much of a problem, since I've got it working and a device running, I was just wondering what are your opinions on this, since every other wrapper I know of is using CPP, not C#. Your ideas are welcome on how I should go about implementing my wrapper. Thanks. So far, the not so pretty and what I'm aiming for, just a look, might not be perfect, all my code is on my other PC.
IDirect3D9 direct3D9 = Direct3D.Direct3DCreate9(Direct3D.DIRECT3D_VERSION);

if(direct3D9 != null)
{
    try
    {
	IDirect3DDevice9 device;

        D3DPRESENT_PARAMETERS pParameters = new D3DPRESENT_PARAMETERS();
	pParameters.Width = window.Width;
	pParameters.Height = window.Height;
	// ............

        direct3D9.CreateDevice(Direct3D.D3DADAPTER_DEFAULT, D3DDEVTYPE.D3DDEVTYPE_HAL, window.Handle,
            D3DCREATE.D3DCREATE_SOFTWARE_VERTEXPROCESSING, ref pParameters, out device);
    }

    catch(COMException cEx)
    {
	// check out the HRESULT and deal with it
    }
}




PresentParameters pParameters = new PresentParameters();
pParameters.Width = window.Width;
pParameters.Height = window.Height;
//.............


Device device = new Device(Adapter.Default, DeviceType.Hardware, window.Handle, pParameters);

For my enumerators, I could just allow the Direct3D9 functions to take the type int, and my structures, well just create a new instance of the D3D struct and copy my information over. Seems like extra overhead to me, but this way, I could create wrappers for OpenGL, Direct3D10, and so on and easily just include them into my framework, instead of integrating the framework into the wrapper. n00b! :D

Share this post


Link to post
Share on other sites
Quote:
Original post by ICodeSharp
plus slimdx uses C++ for its wrapper, not C#.. :P
Yeah, there's a reason for that.

Have you considered using the COM RCW generator that's built into VS to get DX enabled in C#, and then worked from there? It might be a more productive approach. In any case, I subscribe to the approach of renaming everything to make sense in the managed world. (This may not be a big shock.) Otherwise, are you even doing anything that the machine generated COM RCW doesn't already do?

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