Skip to main content
Bumped by Community user
Bumped by Community user

Texture Editing with MulthiMulti-Threading

So I have this giant Texture2D  (4096 * 4096, don't ask why) and all its data stored in an array of Colors. When I hit left MouseButton I create a blue 64 by 64 square at the cursorscursor's position using the following code.

        int dx = Mouse.GetState().X + (int)camera.Pos.X - graphics.PreferredBackBufferWidth / 2;
        int dy = Mouse.GetState().Y + (int)camera.Pos.Y - graphics.PreferredBackBufferHeight / 2;

        for (int x = dx; x < dx + 64; x++)
        {
            for (int y = dy; y < dy + 64; y++)
            {
                textureData[x + y * texture.Width] = Color.Blue;
            }
        }

        texture.SetData<Color>(lvlData);

Sadly this hangs the programmprogram for a split second. So I thought, maybe it's possible to run that picepiece of code in a different thread.

Is it possible to multi-thread that and if so, how would I go about doing that.? Or is it another way to optimize this?

Thanks for any help!

Texture Editing with Multhi-Threading

So I have this giant Texture2D(4096 * 4096, don't ask why) and all its data stored in an array of Colors. When I hit left MouseButton I create a blue 64 by 64 square at the cursors position using the following code.

        int dx = Mouse.GetState().X + (int)camera.Pos.X - graphics.PreferredBackBufferWidth / 2;
        int dy = Mouse.GetState().Y + (int)camera.Pos.Y - graphics.PreferredBackBufferHeight / 2;

        for (int x = dx; x < dx + 64; x++)
        {
            for (int y = dy; y < dy + 64; y++)
            {
                textureData[x + y * texture.Width] = Color.Blue;
            }
        }

        texture.SetData<Color>(lvlData);

Sadly this hangs the programm for a split second. So I thought, maybe it's possible to run that pice of code in a different thread.

Is it possible to multi-thread that and if so, how would I go about doing that. Or is it another way to optimize this?

Thanks for any help!

Texture Editing with Multi-Threading

So I have this giant Texture2D  (4096 * 4096, don't ask why) and all its data stored in an array of Colors. When I hit left MouseButton I create a blue 64 by 64 square at the cursor's position using the following code.

        int dx = Mouse.GetState().X + (int)camera.Pos.X - graphics.PreferredBackBufferWidth / 2;
        int dy = Mouse.GetState().Y + (int)camera.Pos.Y - graphics.PreferredBackBufferHeight / 2;

        for (int x = dx; x < dx + 64; x++)
        {
            for (int y = dy; y < dy + 64; y++)
            {
                textureData[x + y * texture.Width] = Color.Blue;
            }
        }

        texture.SetData<Color>(lvlData);

Sadly this hangs the program for a split second. So I thought, maybe it's possible to run that piece of code in a different thread.

Is it possible to multi-thread that and if so, how would I go about doing that? Or is it another way to optimize this?

Thanks for any help!

Source Link

Texture Editing with Multhi-Threading

So I have this giant Texture2D(4096 * 4096, don't ask why) and all its data stored in an array of Colors. When I hit left MouseButton I create a blue 64 by 64 square at the cursors position using the following code.

        int dx = Mouse.GetState().X + (int)camera.Pos.X - graphics.PreferredBackBufferWidth / 2;
        int dy = Mouse.GetState().Y + (int)camera.Pos.Y - graphics.PreferredBackBufferHeight / 2;

        for (int x = dx; x < dx + 64; x++)
        {
            for (int y = dy; y < dy + 64; y++)
            {
                textureData[x + y * texture.Width] = Color.Blue;
            }
        }

        texture.SetData<Color>(lvlData);

Sadly this hangs the programm for a split second. So I thought, maybe it's possible to run that pice of code in a different thread.

Is it possible to multi-thread that and if so, how would I go about doing that. Or is it another way to optimize this?

Thanks for any help!