Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture
Direct3D9 Texture Direct3D9 Texture
Direct3D9 Texture
Go Back  Xtreme Visual Basic Talk > > > > Direct3D9 Texture


Reply
 
Thread Tools Display Modes
  #1  
Old 10-22-2007, 03:21 PM
er32 er32 is offline
Regular
 
Join Date: Oct 2003
Location: Turkey
Posts: 68
Unhappy Direct3D9 Texture


vb.net 2005 dx9
i need to render a system.drawing.bitmap onto a direct3d.texture with faster way,

Texture.FromFile is extremely slow, i heard a faster way exist with pointers, but i don't know how to use, please help
Reply With Quote
  #2  
Old 11-11-2007, 11:25 AM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

why don't you create the texture from a System.IO.Stream.

load the bitmap from the stream and also load the texture from the same stream, that should work and also be alot faster thatwhat you are doing now.

Haven't done it myself so i don't know if it will work, but i don't really see why it shouldn't if you make the stream shareable.

just realised i'm doing everything in C#, so the methods might be different. Give it a try anyway.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!

Last edited by Leade; 11-11-2007 at 11:32 AM.
Reply With Quote
  #3  
Old 11-12-2007, 09:25 AM
er32 er32 is offline
Regular
 
Join Date: Oct 2003
Location: Turkey
Posts: 68
Default

i'm also tried System.IO.Stream but speed is still slow
may i see your C# code if you loading it faster way, i will try to convert it to vb.net, or if you can convert too, i will be grateful
Reply With Quote
  #4  
Old 11-12-2007, 11:06 AM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

it wasn't that slow when i did it. then again we all have how own definitions on how fast something must be. the code won't be that different to vb.net, just the format will be different. When i get my internet fixed at home. i'll put an example up.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #5  
Old 11-12-2007, 11:12 AM
er32 er32 is offline
Regular
 
Join Date: Oct 2003
Location: Turkey
Posts: 68
Default

how much fast?
actually i need instantly loading textures.
i'm trying to play series of pictures taken from a video, but its 5-6 fps because loading is slow, and picture files are too many for loading into memory so i can't load all to memory.
DirectDraw9 is fast enough to play them, but Direct3D9 is not enough, i think there is a faster way exist and i don't know that. Maybe mix D3D and DD together, but i never success it
Reply With Quote
  #6  
Old 11-12-2007, 11:19 AM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

theres a way of getting the image straight from the video, i.e video textures, theres a tutorial in vb.net dx9 that does it with fast results.

i think the class is called Microsoft.DirectX.VideoTexture or something like that.

The reason yours is slow is because your probably loading it at every call, all you have to do is change the pointer to another part of the file.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #7  
Old 11-12-2007, 01:15 PM
cugone cugone is offline
Centurion
 
Join Date: Nov 2007
Posts: 160
Default

I would highly recommend "Microsoft Visual Basic Game Programming for Teens, 2nd Edition" by Jonathan S. Harbour. Published by Thomson Course Technology. ISBN-13: 978-1-59863-390-0, ISBN-10: 1-59863-390-2

Amazon Link

Unlike the first edition, this one is written entirely in VB.NET 2005. (one warning though. There's an undeclared typo in the book. Any time the code calls for device flags to be created it uses "+" and it should be "or"):

Book (Incorrect Usage):
Dim flags as CreateFlags
flags = CreateFlags.HardwareVertexProcessing
flags += CreateFlags.PureDevice


Proper Use:
Dim flags as CreateFlags
flags = CreateFlags.HardwareVertexProcessing or CreateFlags.PureDevice
Reply With Quote
  #8  
Old 11-14-2007, 02:48 AM
er32 er32 is offline
Regular
 
Join Date: Oct 2003
Location: Turkey
Posts: 68
Default

how to change pointer to another part of memory or file?
Reply With Quote
  #9  
Old 11-14-2007, 04:40 AM
er32 er32 is offline
Regular
 
Join Date: Oct 2003
Location: Turkey
Posts: 68
Default

this one is what i used, that is slow, not enough for play image sequence

Code:
Dim ILockRect As New Rectangle(0, 0, 704, 576)
Dim IPA(0) As Integer
IPA(0) = 704 * 576 * 2
Dim IBMP As System.Drawing.Bitmap
Dim IBD As System.Drawing.Imaging.BitmapData
Dim ID3DT As Microsoft.DirectX.Direct3D.Texture = New Microsoft.DirectX.Direct3D.Texture(D3DDevice, ILockRect.Width, ILockRect.Height, 1, Microsoft.DirectX.Direct3D.Usage.Dynamic, Microsoft.DirectX.Direct3D.Format.R5G6B5, Microsoft.DirectX.Direct3D.Pool.Default)
Dim ID3DBytes() As Byte

'...looping stuff...

IBMP = New System.Drawing.Bitmap("file0001.jpg")
IBD = IBMP.LockBits(ILockRect, System.Drawing.Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format16bppRgb565)
ID3DBytes = ID3DT.LockRectangle(GetType(Byte), 0, ILockRect, Microsoft.DirectX.Direct3D.LockFlags.None, IPA)
System.Runtime.InteropServices.Marshal.Copy(IBD.Scan0, ID3DBytes, 0, UBound(ID3DBytes) + 1)
ID3DT.UnlockRectangle(0)
IBMP.UnlockBits(IBD)

'...render stuff...

...

i think locking can done with this also but i'm not sure how to use it
Code:
Dim IDXGS As Microsoft.DirectX.GraphicsStream

IDXGS = ID3DT.LockRectangle(0, ILockRect, Microsoft.DirectX.Direct3D.LockFlags.None)
and i can't found about VideoTexture , if you have used it , let me know how to do it
Reply With Quote
  #10  
Old 11-15-2007, 11:16 AM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

Here are some small things that i have noticed...

Does this have to be so big. Locking is a slow process with very large images.
Code:
Dim ILockRect As New Rectangle(0, 0, 704, 576) 
Dim IPA(0) As Integer
IPA(0) = 704 * 576 * 2

If this is looping stuff, how many times are these called, cos they need only be called once before the loop. check it isn't being made nullable somewhere in your code

Code:
IBMP = New System.Drawing.Bitmap("file0001.jpg")
Imaging.PixelFormat.Format16bppRgb565)
Give me some time and i'll write you an example in C#.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #11  
Old 11-16-2007, 01:42 AM
er32 er32 is offline
Regular
 
Join Date: Oct 2003
Location: Turkey
Posts: 68
Default

its actually

Code:
IBMP = New System.Drawing.Bitmap("file"+CStr(I)+".jpg")
this code is working but slow

yes it have to be large size file, but directdraw can load it fastly, why direct3d can't, that is main problem.

if i can copy image without locking, it is also ok
if i can just change texture's pointer to bitmap's data, it is also ok
but i dunno how to do,
time is not important for now, so you have much free time to write example
Reply With Quote
  #12  
Old 11-17-2007, 01:40 PM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default And here it is.....

Well it took me a good 15 mins to write this so i hope it helps....
It's writen in C#, but thats very similar to Vb.net anyway

Code:
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX.DirectSound;
using Microsoft.DirectX.AudioVideoPlayback;

            public class GM2D_Video
            {
                private Microsoft.DirectX.AudioVideoPlayback.Video AV_Dev;
                private Microsoft.DirectX.Direct3D.Texture AV_Texture;

                //Creation
                public void Create(string File)
                {
                    AV_Dev = new Microsoft.DirectX.AudioVideoPlayback.Video(File);
                    //AV_Dev = Video.FromFile(path);
                }

                //Play & Loop
                public void Play()
                {
                    AV_Dev.Play();
                }
                
                //Direct3D Texture 9
                public void RenderToTexture(Microsoft.DirectX.Direct3D.Device Device3D9)
                {
                    AV_Dev.TextureReadyToRender += new Microsoft.DirectX.AudioVideoPlayback.TextureRenderEventHandler(this.RenderIt);
                    AV_Dev.RenderToTexture(Device3D9);
                }
                void RenderIt(object sender, Microsoft.DirectX.AudioVideoPlayback.TextureRenderEventArgs e)
                {
                    lock (this)
                    {
                        // Set our texture so we can render it
                        AV_Texture = e.Texture;
                    }
                }
                public Microsoft.DirectX.Direct3D.Texture Get_Texture()
                {
                    return AV_Texture;
                }
            }
To use this just call the rendertotexture command once and give a Device as an attribute.

Then when you need the texture use the gettexture property to get the new updated texture, the rest is done through events..
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #13  
Old 11-18-2007, 11:05 AM
er32 er32 is offline
Regular
 
Join Date: Oct 2003
Location: Turkey
Posts: 68
Default

thanks, but i have already tried this way, have bugs, texture not rendered correctly, and program crashes and consume big system memory
Reply With Quote
  #14  
Old 11-18-2007, 11:16 AM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

Really, it's fine for me and i'm doing in on a Dell 1.4ghz laptop. Highest resolution for image copying is 800x600 16bit, Which i realise is bigger than the resolution your using.

Lower the resolution of the recieving bitmap/texture or you will always get speed issues.

It can be done you have to look at your code and optimize the hell out of it, make sure unused variables are removed and objects are properly deleted.

Give me a little longer and i'll figure out a faster way.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture Direct3D9 Texture
Direct3D9 Texture
Direct3D9 Texture
 
Direct3D9 Texture
Direct3D9 Texture
 
-->