Jump to content
  • Advertisement
Sign in to follow this  
bolshas

Atlas editor performance question

This topic is 4001 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 developing an atlas editor and have this code for updating the certain areas:
        public void SetTerrainTexture(int x, int y, Bitmap image)
        {
            Graphics g = Graphics.FromImage(MainImage);
            g.DrawImage(image, new Point(x * 256, y * 256));
            g.Dispose();        
        }
        public void UpdateTerrainTexture()
        {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            MainImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Position = 0;
            MainTexture = TextureLoader.FromStream(device, stream);
        }
Each update takes about 1 sec. The question what would be the way to optimise this? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Loading and saving a PNG even to memory will be the slow bit. Either save an uncompressed format like TGA or BMP, or find another way to do it.

If it wasn't managed code I'd suggest a combination of GetDIBits() and D3DXLoadSurfaceFromMemory(), but I'm not sure what the managed equivalents are.

Share this post


Link to post
Share on other sites
Consider threading - it should be nice and simple with .NET as well [grin]

Your code will probably choke on two main parts - the encoding as PNG and the actual writing to disk. Both could be offloaded into a seperate thread and allow your main app to continue processing with little impact.

Then again, accessing D3DX across multiple threads isn't always a good idea (but ISTR MDX is thread-safe by default) but try it and see.

hth
Jack

Share this post


Link to post
Share on other sites
Yes, threading helped a bit. That's how i did it:


public void SetTerrainTexture(int x, int y, Bitmap image)
{
StreamWrite = new System.Threading.Thread(new System.Threading.ThreadStart(delegate { SetTerrainTextureThread(x, y, image); }));
StreamWrite.IsBackground = true;
StreamWrite.Start();
}



Anyways now it still takes time to lead the image on the texture but the app doesn't hang. Cool for now.

Another problem now:

I have heard that textures from stream should be ^2 in size. So here are my details:

map size: 16x16
single quad size in texture map: 256x256
texture map size: 4096x4096

The problem: the quads seem to overloop by about a half on top of each other.

All suggestions are welcome!

Share this post


Link to post
Share on other sites
Quote:
Original post by bolshas
The problem: the quads seem to overloop by about a half on top of each other.
I don't really follow your description here - any chance of a screenshot or diagram to demonstrate?

As for the 2N texture sizes - it's best to keep these dimensions if you can, but it's not set in stone. There are legitimate cases when it's better not to use 2N...

hth
Jack

Share this post


Link to post
Share on other sites
Ok, here's the function for creating the texture:


MainImage = new Bitmap(2048, 2048);

public void SetTerrainTexture(int x, int y, Bitmap image)
{
StreamWrite = new System.Threading.Thread(new System.Threading.ThreadStart(delegate { SetTerrainTextureThread(x, y, image); }));
StreamWrite.IsBackground = true;
StreamWrite.Start();
}

private void SetTerrainTextureThread(int x, int y, Bitmap image)
{
Graphics g = Graphics.FromImage(MainImage);
g.DrawImage(image, x * 256, y * 256);
g.Dispose();
Debug.WriteLine(image.Height);
Debug.WriteLine(MainImage.Height);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
MainImage.Save(stream, ImageFormat.Bmp);
stream.Position = 0;
MainTexture = TextureLoader.FromStream(device, stream);
}


I'm not sure how to upload my image here so I'll try to explain: I got a terrain of 9x9 vertices (8x8 quads) with a displayed grid among vertices.

I call SetTerrainTexture with x and y 0 and 0 respectively and image is 256x256.

So I should see the image covering exactly one quad since MainImage is 2048x2048 and 2048/256 = 8.

But I see the image overlapping the grid by about 10%.

I don't get it - all my sizes are ^2 even the terrain.

Any ideas are welcome :)

Share this post


Link to post
Share on other sites
Just solved it - it was a problem with my Tu and Tv.

Another question - what is the best way of texturing large terrains?

For example if my single quad is 256x256 and my card supports 4096x4096 then it means that i can afford 16x16 texture. Should I create multiple subsets or meshes or is there another way?

[Edited by - bolshas on November 3, 2007 10:34:40 AM]

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!