Source code: Implementing Direct3D for fun and profit

Almost a year and a half ago I blogged about several useful things that you can do with custom IDirect3DDevice9 implementations. I don’t know why I did not post the code back then, but anyway – here it is:

dummydevice.h – this is just an example of a dummy device implementation; it implements all device methods with stubs that can’t be called without a debugging break. This is useful for other partial implementations.

deferreddevice.h – this is the implementation of the device that buffers various rendering calls and then allows to execute them on some other device. Note that it lives in a fixed size memory buffer, which can be easily changed, and that it implements only a subset of rendering-related functions (i.e. no FFP).

texturedevice.h – this is the implementation of the device that works with D3DXCreateTextureFromFile for 2D textures and cubemaps (3D texture support is missing but can be added in the same way).

DL_BREAK is the replacement for __debugbreak, DL_ASSERT is a custom assertion macro (with neat (void)sizeof(!(expr)) trick that I hope everybody knows about by now), everything else should be obvious.

Advertisements
This entry was posted in Direct3D. Bookmark the permalink.

3 Responses to Source code: Implementing Direct3D for fun and profit

  1. moorx says:

    Thanks for the article and sharing the code!

    In the initial article you mentioned calling the kick method on PS3. Does that mean you’re using a custom implementation of the interface as a portability layer that calls libgcm or psgl when processing the command queue? If so – how do you deal with all the custom Direct3D data types and interfaces? Do you have custom implementations for them too?

  2. zeuxcg says:

    This is a low-level implementation that’s used for Direct3D layer.

    There is a cross-platform interface layer with wrappers for things like textures, render targets, shaders, vertex buffers and command buffer (context). The PS3 implementation uses libgcm directly, the D3D9 implementation uses the code posted above. The native D3D interfaces are not exposed unless necessary (i.e. you can always get access to them, but you don’t need them to write code).

  3. Delimitry says:

    Thank you, the code is awesome.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s