Jump to content
  • Advertisement
Sign in to follow this  
sickbattery

[SlimDX] Texture.FromStream Invalid Data

This topic is 3349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!