Skip to main content
GameDev.net gamedev.net
🔒 Locked

[SlimDX] Surface.FromPointer

Started by FeverGames Apr 6, 2009 at 11:51 PM 8 replies 3.5k views
Original Post
FeverGames
FeverGames
Hi, I am trying to copy a renderTarget surface to a renderTarget Texture. Can I somehow use

Surface destination = Surface.FromPointer(source.ComPointer);

or is

            bool storedThrow = Configuration.ThrowOnError;
            Configuration.ThrowOnError = false;

            // future: change the first 0 to the ActiveViewTarget id
            Surface destination = texture.GetSurfaceLevel(level);
            if (destination == null || Result.Last.IsFailure)
            {
                Configuration.ThrowOnError = storedThrow;
                throw new InvalidOperationException("Could not obtain resolve target surface.");
            }

            Result result = device.StretchRectangle(source, destination, TextureFilter.Linear);

            if (result.IsFailure)
            {
                result = device.StretchRectangle(source, destination, TextureFilter.None);
                if (result.IsFailure)
                {
                    result = Surface.FromSurface(destination, source, Filter.Default, 0);
                    if (result.IsFailure)
                    {
                        destination.Dispose();
                        source.Dispose();

                        Configuration.ThrowOnError = storedThrow;
                        throw new InvalidOperationException("Could not copy the surfaces.");
                    }
                }
            }

            Configuration.ThrowOnError = storedThrow;
        }

Which one and what would be the fastest? I am trying to implement something like XNA has, RenderTarget.GetTexture();
FeverGames
FeverGames
Or am I totally looking in the wrong direction with this? We are writing a wrapper for both DX9, DX10 and XNA. Because DX10 and DX9 don't use surfaces anymore as in DX9 i was thinking about hiding it. But for some purposes (using a render target as texture) I need the surface to be a texture.
Mike.Popoloski
Mike.Popoloski
Textures and Surfaces are different things. In D3D9, a texture can have many surfaces, which is why you must call GetSurfaceLevel() to get a particular surface for a texture.

If you need to go back the other way, you can use GetContainer() on Surface to get the parent texture.
Mike Popoloski | Journal | SlimDX
Promit
Promit
You might also want to take a look at RenderToSurface and native samples for how to use it as an alternative. It cuts out a lot of the intermediate tedium in setting this stuff up.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
FeverGames
FeverGames
Awsome! Thanks. Never noticed that method!
FeverGames
FeverGames
So does the GetContainer method only works when the surface is part of a created renderTarget texture? Cause i am getting a "The requested COM interface is not available (-2147467262)" on a surface that is created with Surface.CreateRenderTarget();
Mike.Popoloski
Mike.Popoloski
From the DirectX documentation:

Quote:
Provides access to the parent cube texture or texture (mipmap) object, if this surface is a child level of a cube texture or a mipmap. This method can also provide access to the parent swap chain if the surface is a back-buffer child.

If the surface is created using IDirect3DDevice9::CreateRenderTarget or IDirect3DDevice9::CreateOffscreenPlainSurface or IDirect3DDevice9::CreateDepthStencilSurface, the surface is considered stand alone. In this case, IDirect3DSurface9::GetContainer will return the Direct3D device used to create the surface.
Mike Popoloski | Journal | SlimDX
FeverGames
FeverGames
Quote:
Original post by Mike.Popoloski
From the DirectX documentation:

Quote:
Provides access to the parent cube texture or texture (mipmap) object, if this surface is a child level of a cube texture or a mipmap. This method can also provide access to the parent swap chain if the surface is a back-buffer child.

If the surface is created using IDirect3DDevice9::CreateRenderTarget or IDirect3DDevice9::CreateOffscreenPlainSurface or IDirect3DDevice9::CreateDepthStencilSurface, the surface is considered stand alone. In this case, IDirect3DSurface9::GetContainer will return the Direct3D device used to create the surface.


Ok sorry for not finding that on my own. What are my best options then?
FeverGames
FeverGames
All I am trying to do is making the Surface disapear. I made a class that sort of wraps the rendertarget.

But internally if i make the renderTarget a texture i cannot handle a GetRenderTarget(index) very well, but if i make it a renderTarget Surface I cannot use it as a texture unless it slows down (then i use the code from above with the CopyRect).

I really hope someone can give me some advice (and not the, don't try to hide it advice :P)
FeverGames
FeverGames
is there no one that has any idea??

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.