How do i use PureDevice?

Started by
86 comments, last by ZeroWalker 10 years, 8 months ago
By using Texture.GetSurfaceLevel.

Works for me (tested with SlimDX though so maybe you need to adapt the code a little).


using (var surface = theTexture.GetSurfaceLevel(0))
{
    Surface.FromFileInStream(surface, theStream, SharpDX.Direct3D9.Filter.Point, 0);
}

Oh, I forgot that.


The D3DX functions are quite resourceful, so one can easily miss them wink.png.
Advertisement

Wait, what is the theTexture supposed to be?
Is it my Dynamic Texture:

using (var texture = new Texture(device, 512, 512, 1, Usage.Dynamic, Format.X8R8G8B8, Pool.Default))

and i guess theStream is my MemoryStream with jpeg (is it possible to get it from Memory instead (Byte[], so i don´t need to convert)?
Okay, existed FromMemory, so that was easy enough:)

And, as the surface is disposed of, should i draw the texture/surface while it´s alive, and if so, how do i do that (only used Textures so far).

Many Thanks

The surface is alive as long as the texture is, it belongs to it (all its surfaces, a texture can have several of them). The using clause (and implicit Dispose) is just because of the GetSurfaceLevel. It - like most D3D GetWhatEver calls - will increase the underlying COM object reference counter, so a Dispose is needed (decreasing the counter).

Actually: You wouldn't need to create the texture every time you need to draw. Creating (and disposing) resources every frame is bad. Create it e.g. at application start only (Maybe this has already been mentioned, this thread has grown quite big :p )

Well that´s good to hear:)

Yeah that´s what i want to do, as i currently create/dispose, which just takes power for stuff that could be reused.

But i don´t get how to show the new Texture surface, i have done something like:




    //texture.LockRectangle(0, LockFlags.Discard);
    using (var surface = texture.GetSurfaceLevel(0))
    {
        Surface.FromFileInMemory(surface, TextureData, SharpDX.Direct3D9.Filter.Point, 0);
    }
    //texture.UnlockRectangle(0);
    sprite.Draw(texture, new ColorBGRA(0xffffffff));

And well, it doesn´t do anything except throw errors here and there.


And well, a growing Thread is a good thing, means someone is feeding it;P

Nice i finally got an image;D!
Now it´s starting to go forward:)

The problem now is, the size of the image, as now i can´t set it to -2 which got the size for me, and have to set it to something Valid, which seems to be Power of 2 only.
So not sure how to do that, maybe if it´s possible to choose something higher than the resolution, and just ignore the non-used stuff, and have the image crop to what´s used?

There are overloads for both the loading and the sprite.Draw which take rectangles. Just create a big enough texture. There's also a overload which can spit out the ImageInformation. The latter can be grabbed from a stream directly, if you need to know something in advance.

It's all there, just browse the SharpDX and the MSDN docs.

PS: Congrats, by the way laugh.png

I actually, think i can have solved it.
At least by getting the texture size before.

I simply make a texture before the loop, get the data , get size and everything, set the form and buffer size, and also pass it to the texture.

Though, i can´t use a Dynamic texture for that, though i don´t see a difference?
Will it be faster with Dynamic texture or what?

Cause the only difference for me with it, is that i can´t choose any size, except stuff like 1024x1024, which i guess makes it bound by the power of 2.


Though again, this makes me wonder, do i really even need a texture?
If i can get a surface, can´t i just put the image on the Buffer/device surface or something?

Yeah, never used this myself, but I hear it's sometimes used for video streaming or similar: Device.StretchRectangle

No dynamic ? Only Pow2 ? Hmmm, read both this and this.

Also: search this forum for texture size and format compatibility problems (and learn about Direct3D.CheckDeviceFormat). Or start the DirectX Caps Viewer (a tool from the SDK).

Edit: Sorry, posted without preview tongue.png

Is that a the same kind of surface i am talking about?
I mean just the buffer.
As the only thing i am showing i 1 texture. Meaning, i don´t care what the buffer has, i don´t need depth or anything, just 1 image.
So i could rather just put my image As the buffer or something.

Ah nice, thanks for the links:)

Don´t have the SDK, never got to install it, installed Windows SDK, it said DirectX was with it, and well, it wasn´t;P

Hmm for some reason, the Surface method seems to cause it to stop at some point.
I get no exception or anything, it just jumpt out of the Form for some reason.

Is there anything wrong with this:




                                SharpDX.Windows.RenderLoop.Run(form, () =>
                                {
                                    if (!listening)
                                        form.Dispose();

                                    if (Queue.TryTake(out TextureData, 150))
                                    {
                                        Stoptimer = new Stopwatch();
                                        Stoptimer.Start();

                                        device.BeginScene();
                                        sprite.Begin(SpriteFlags.None);
                                        //form.Text = "Test " + Queue.Count + ": Delayed Frames";
                                        try
                                        {

                                            using (var surface = texture.GetSurfaceLevel(0))
                                            {
                                                Surface.FromFileInMemory(surface, TextureData, SharpDX.Direct3D9.Filter.None, 0);
                                            }

                                            sprite.Draw(texture, new ColorBGRA(0xffffffff));
                                        }

                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message, "Rendering: Texture");
                                        }

                                        sprite.End();
                                        device.EndScene();
                                        device.Present();
                                        Stoptimer.Stop();
                                        Console.WriteLine(Stoptimer.ElapsedTicks);
                                    }
                                });

Listening is True all the time, and the Form does Not exit, it just stop at the last image, very weird.

Worth noting is, i check the Timer, and it goes slower and slower for some reason. It can start at about 60-75k ticks.
Then go slowly up to around 80-95k, and eventually stops (when the loop ends, for some reason i don´t get).

This topic is closed to new replies.

Advertisement