Skip to main content
gamedev.net
🔒 Locked

TextureLoader problem!!

Started by cvele 6 replies 950+ views
Original Post
cvele
cvele
I code in C#. I am trying to load a texture from a dynamically created 1201x1201 RGB bitmap. I first tried to load texture in most standard way, which takes about 2 minutes to complete(!?):

texture = Texture.FromBitmap(device, bmp, 0, Pool.Managed);
I then tried to do it using memory stream, but it is equaly slow(!?!?):

MemoryStream stream = new MemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
bmp.Dispose();
stream.Position = 0;
texture = Texture.FromStream(device, stream, Usage.Dynamic, Pool.Managed);
And finally, I tried to do it using unsafe code, but it generates the error.

texture = new Texture(dev, bmp.Width, bmp.Height, 1, Usage.Dynamic, Format.R8G8B8, Pool.Default);
Microsoft.DirectX.GraphicsStream a = tekstura.LockRectangle(0, LockFlags.None);
System.Drawing.Imaging.BitmapData bd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
unsafe
{
	uint* to = (uint*)a.InternalDataPointer;
	uint* from = (uint*)bd.Scan0.ToPointer();
	for (int i = 0; i < bd.Height * bd.Width; ++i) to = from;
}
texture.UnlockRectangle(0);
bmp.UnlockBits(bd);
Demirug
Demirug
I don’t know what GPU you use but I have the feeling that it doesn’t support pow of 2 and mipmaps at the same time. This could force the two loader methods to resize your image to 2048*2048.
The reason for the error with your unsafe method could be hardware related too. The R8G8B8 format is not widely supported on today’s GPUs.
cvele
cvele
Thank you for quick reply.
No, graphic card is not the problem. Code behaves exatcly the same on more than 1 computer.
sirob
sirob
Quote:
Original post by cvele
Thank you for quick reply.
No, graphic card is not the problem. Code behaves exatcly the same on more than 1 computer.

That doesn't mean anything, really. It's likely that most computers don't support MIP maps on non-power-of-two textures. What is the actual size of the texture after it is created?
Sirob Yes.» - status: Work-O-Rama.
cvele
cvele
All I want is to make texture from bitmap! Nothing more! I tried that in few different ways and it doesn't work like it is suposed to. Please help!
cvele
cvele
TextureLoader.FromFile works well for me, you know.

Help me please?

PS.
how can I know the texture size?
sirob
sirob
Texture.GetLevelDescription(0)
Sirob Yes.» - status: Work-O-Rama.
cvele
cvele
Thanx!

format is X8R8G8B8 and bitmap's is R8G8B8.
dimensions are 2048x2048 and bitmap's is 1201x1201.
Why is that?
I guess I don't mind that but I just want to make a texture from bitmap as I already mentioned!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.