Sign in to follow this  
sickbattery

[SlimDX] Texture.FromStream Invalid Data

Recommended Posts

Hi, I'm trying to create a Texture from a Surface, but I seem to be unable to do so. Could someone take a look at my code and tell me what I'm doing wrong?
_effectSurface = Surface.CreateRenderTarget(_graphigsDevice, pictureBox.Width, pictureBox.Height, Format.A8R8G8B8, MultisampleType.None, 0, true);

DataRectangle data = _effectSurface.LockRectangle(LockFlags.ReadOnly);
_effectTexture = Texture.FromStream(_graphigsDevice,
                                    data.Data,
                                    (int)data.Data.Length,
                                    pictureBox.Width,
                                    pictureBox.Height,
                                    0,
                                    Usage.None,
                                    Format.A8R8G8B8,
                                    Pool.Default,
                                    Filter.None,
                                    Filter.None,
                                    0);

_effectSurface.UnlockRectangle();

I get an "Invalid Data". I also tried FromMemory but it's the same. Regards, sick.

Share this post


Link to post
Share on other sites
Well, if you want to render to texture, the usual way is to create a render target enabled texture, GetSurfaceLevel(0), and then use that as the render target. I'm not sure if what you're doing should actually work -- invalid data means that D3DX doesn't like what it's seeing in the stream. There's also RenderToSurface.

Share this post


Link to post
Share on other sites
Ok, I've found out that this is also possible:


DataStream ds = Surface.ToStream(_effectSurface, ImageFileFormat.Png);

_effectTexture = Texture.FromStream(_graphigsDevice,
ds,
(int)ds.Length,
pictureBox.Width,
pictureBox.Height,
0,
Usage.None,
Format.A8R8G8B8,
Pool.Default,
Filter.None,
Filter.None,
0);



Would you recommend it? I'm rendering only one frame, I don't know if this is a fast way ... ?

Share this post


Link to post
Share on other sites
No, that's probably one of the slowest ways possible.

One of the Usage flags available when you create a texture is RenderTarget. After you do that, you can call GetSurfaceLevel(0) to get a Surface for that texture, and then set it as the active render target. That's usually how you render to texture.

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