Support Directx 9 and Directx 11 (both)

Started by
16 comments, last by Hodgman 11 years, 7 months ago
They are using #ifdef. One build compiles to a DirectX 9.0 .DLL, another to a DirectX 11 .DLL. The .EXE has no idea what DirectX is and is not linking to either of them.
The .DLL simply provides an agnostic interface for rendering and the .EXE loads one or the other at run-time based on parameters passed to it.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement

They are using #ifdef. One build compiles to a DirectX 9.0 .DLL, another to a DirectX 11 .DLL. The .EXE has no idea what DirectX is and is not linking to either of them.
The .DLL simply provides an agnostic interface for rendering and the .EXE loads one or the other at run-time based on parameters passed to it.


L. Spiro


Yes, I'm not saying they didn't use #ifdef to create the dlls, what I say is that the .exe does something similar to the code I posted (the .exe doesn't use #ifdef).
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/
Actually the .EXE will only have branches for which DLL to load.
Both DLL’s probably expose the same classes, so the EXE is more likely to just do a check on the input flags and branch for just the DLL, followed by something like:

Render * prRenderer = new Renderer();


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


Actually the .EXE will only have branches for which DLL to load.
Both DLL’s probably expose the same classes, so the EXE is more likely to just do a check on the input flags and branch for just the DLL, followed by something like:

Render * prRenderer = new Renderer();


L. Spiro


what would be the code for that flag-based branching?
I can't figure it out without using LoadLibrary, and I don't like LoadLibrary because then you have to get pointers to every function you use (In addition there's overhead when calling through a function pointer).
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/
You'd only have to get a function pointer for creating the Renderer; after that you use the returned pointer as normal.

The cost is going to be no worse than a non-inlined function call at that point.

1. Decide which DLL to load
2. Load DLL
3. Get pointer to creation function
4. Use creation function to create renderer
5. Use returned object pointer as normal

No mess, no fuss.

You'd only have to get a function pointer for creating the Renderer; after that you use the returned pointer as normal.

The cost is going to be no worse than a non-inlined function call at that point.

1. Decide which DLL to load
2. Load DLL
3. Get pointer to creation function
4. Use creation function to create renderer
5. Use returned object pointer as normal

No mess, no fuss.


I got it.
Thank you very much!
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/

[quote name='angelmu88' timestamp='1346507798' post='4975431']but I don't want to rewrite the whole code
Any of your code that interacts with the Direct3D API will need to be re-written.

Have you written your own D3D wrapper so that only some of your code interacts with D3D directly (and the rest interacts with your wrapper), or does your whole engine use parts of D3D?
[/quote]

wait what about feature levels? http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876(v=vs.85).aspx

[quote name='Hodgman' timestamp='1346510528' post='4975436']
[quote name='angelmu88' timestamp='1346507798' post='4975431']but I don't want to rewrite the whole code
Any of your code that interacts with the Direct3D9 API will need to be re-written [for the Direct3D11 API].
[/quote]wait what about feature levels? http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876(v=vs.85).aspx
[/quote]Features levels are a part of the D3D11 API that allows you to use that API on older hardware (e.g. DX9 compatible hardware).
If you wanted to use the "9 on 11" feature level, you'd still have to port your renderer over to the D3D11 API first.

Also, for some stupid reason, there's no DX11 feature-level that corresponds to SM3.0, so if you want to support SM3 (360/PS3 level hardware) then you've still got to maintain the DX9 version of your renderer :/

This topic is closed to new replies.

Advertisement