[SlimDX] Texture.FromStream Invalid Data

Started by
7 comments, last by sickbattery 14 years, 8 months ago
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.
Advertisement
Have you tried enabling the debug runtime and seeing what it says?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
I have only VS Express and DebugView doesn't do anything.
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.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Could you tell me a little bit more about a "render target enabled texture" and "GetSurfaceLevel(0)" ?

Quote:Original post by Promit
There's also RenderToSurface.


I'm doing this :) ... but still, I've a Surface and no Texture.
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 ... ?
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.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Now I get it.
Thank you very much :).

This topic is closed to new replies.

Advertisement