Sign in to follow this  
Michael Tanczos

slimdx/directshow.net - Custom allocator porting problem

Recommended Posts

Hey all, I'm trying to port the directshow.net custom allocator example to us vb.net and slimdx.. but I'm not entirely sure how to port one line of code. Notes: - the unmanagedSurfaces array is an array of Int32's - 85C31227-3DE5-4f00-9B3A-F11AC38C18B5 is the GUID for IDirect3DTexture9 - the line confusing me is Dim text As Texture = DirectCast(surf.GetContainer((New Guid("85C31227-3DE5-4f00-9B3A-F11AC38C18B5")), Texture)
surfaces = New Hashtable(unmanagedSurfaces.Length)
textures = New Hashtable(unmanagedSurfaces.Length)

For i As Integer = 0 To lpNumBuffers - 1
   Dim surf As Surface = Surface.FromPointer(unmanagedSurfaces(i))

   ' How do I convert this line to work with slimDX?
   Dim text As Texture = DirectCast(surf.GetContainer((New Guid("85C31227-3DE5-4f00-9B3A-F11AC38C18B5")), Texture)

   surfaces.Add(unmanagedSurfaces(i), surf)
   textures.Add(unmanagedSurfaces(i), text)
Next


This line of code seems to be attempting to obtain the reference for a texture associated with the original surface based on the surface itself. It is backwards from creating a texture and referencing one of the texture surfaces. The slimDX version would require "Public Function GetContainer(Of TContainer As ComObject) As TContainer" (member function of the Surface class) but IDirect3DTexture seems to be undefined. Any ideas on how to get this texture? Thanks so much. - Michael Tanczos

Share this post


Link to post
Share on other sites
I don't know VB, but in C# you could just do Texture texture = surface.GetContainer<Texture>() and be done with it. All ComObjects know their native interface and GUID so you don't have to worry about it.

Share this post


Link to post
Share on other sites
Just do:
text = surf.GetContainer(Of Texture)()
Assuming I've got the VB syntax right. SlimDX knows to do the rest on its own.

[EDIT] Beaten [sad] But you don't need the DirectCast, either! Pretty slick, huh?

P.S. GetContainer is not a fast function. Keep that in mind.

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