3

I'm currently in need of a purely managed code DirectX wrapper for .NET. While SlimDX is great, its use of unmanaged code makes it impossible to perform proper dead code analysis on, for the purpose of merging it into your assemblies. With a pure managed wrapper, I'd be able to include just the pieces I use in my assembly, allowing very, very small binaries (my goal is to be able to write 64k demos entirely using .NET).

Does such a thing exist, or am I going to be getting intimate with P/Invoke?

Serafina Brocious
  • 30,433
  • 12
  • 89
  • 114

4 Answers4

1

No such thing, gotta roll your own. And you don't have to worry about the size of your assemblies when you use P/Invoke - if anything, they'll be a lot smaller than if you included their managed counterparts.

Depending on what you're doing (video? audio? 3D?), DirectShow.NET is a fun place to start with this sort of thing, given that it's incomplete and no longer supported.

MusiGenesis
  • 74,184
  • 40
  • 190
  • 334
  • I'm planning on writing full 64k demos (so audio and 3d in a single 64KB binary), but the concern with using something like SlimDX is that I can't strip away the parts I'm not using. However, the more I think through it, the more I wonder why I'm not just using OpenGL with some special hacks. – Serafina Brocious Apr 12 '10 at 01:40
  • If you're this concerned with size, then P/Invoke is *the* way to go in general. Are you trying to make *everything* under 64K (including code and resources etc.)? – MusiGenesis Apr 12 '10 at 01:48
  • Yes, entirely within 64k. The problem with P/Invoke for DX is that the interfaces don't lend themselves well to being P/Invoked. In fact, I'm not certain you /can/ P/Invoke them without having some sort of unmanaged code to handle the VTables. – Serafina Brocious Apr 12 '10 at 01:52
  • I guess my follow-up would be: why 64K? Even if your assembly is under 64K, it isn't *really* that small because it links to a boatload of .Net DLLs and whatnot. – MusiGenesis Apr 12 '10 at 01:54
  • In the demoscene, there are two (standard) classifications for intros: 4K and 64K – Serafina Brocious Apr 12 '10 at 02:08
  • Surely they don't accept .Net demos? I thought with demos *absolutely everything* had to be under the minimum size. A .Net EXE is virtually a Visual Basic "application" (not that there's anything wrong with that). – MusiGenesis Apr 12 '10 at 02:23
  • Most do, yes. For the same reason that they accept demos that use the OpenGL ICD and the kernel. – Serafina Brocious Apr 12 '10 at 02:57
  • I assume the demo scene is kind of like skateboarding, in the sense that there's no way in hell you could ever make a living doing it? – MusiGenesis Apr 12 '10 at 04:05
  • 1
    Directly? No, you can't really do so. However, the skills translate directly to things like game development, and many successful game companies have been started by demosceners (e.g. Remedy Entertainment, creators of Max Payne, Alan Wake, 3DMark, etc). – Serafina Brocious Apr 12 '10 at 07:05
  • The demo scene is one of those things where if you don't get it, no-one can explain it to you. If you need to ask "why 64Kb", you definitely don't get it :) – nathanchere Apr 13 '10 at 00:58
  • 1
    @FerretallicA: I "get" the demo scene - I've written a software synthesizer for smartphones, so I understand the challenge of getting a lot out of a little. I just think writing an app where the EXE happens to be under 64K but only runs at all because a multi-MB framework is already installed on the machine and does all the complicated work for you is a violation of the whole idea of demos. – MusiGenesis Apr 13 '10 at 01:38
  • A couple of months ago my co-worker showed me a game he'd written the night before using XAML. It had 3D tanks in a desert and you drove around and shot at stuff. The XAML for this was something like 120 lines. Does this count as a demo? – MusiGenesis Apr 13 '10 at 01:44
0

You will have to go with P/Invoke and will probably find it too slow (certain data structures P/Invoke very slowly).

Joshua
  • 40,822
  • 8
  • 72
  • 132
  • Yea, that's one of my concerns. I guess there is the option of emitting unmanaged wrappers at runtime. – Serafina Brocious Apr 12 '10 at 01:20
  • There is. That's what mixed mode assemblies are for. – Joshua Apr 12 '10 at 02:26
  • Well no, the problem with mixed mode assemblies is that you can't strip away what you don't want -- that's why SlimDX is no good. I could of course do all of that by hand, but that's considerably more difficult. It's looking like just going OGL is going to save me a lot of time and space. – Serafina Brocious Apr 12 '10 at 03:58
0

There is the managed directx wrapper (MDX) that microsoft shipped with the directx sdk for a while. It's now considered obsolete and not supported but that doesn't mean it doesn't work... To be honest I know little about it or if it will be suitable for your application but it might be worth a look.

jcoder
  • 29,554
  • 19
  • 87
  • 130
0

I just found (while investigating ways of using DirectX from managed code and WPF in particular) about SharpDX. It looks promising and does what you need, see for example Official Release of SharpDX blog entry.

Yet I didn't even downloaded it yet so I'm unable to tell anything more that what is written under the links above.

Adam Badura
  • 5,069
  • 1
  • 35
  • 70