Game Development Community

How can I create a texture is system RAM and then update VRAM?

by John Klimek · in Torque X 2D · 09/01/2007 (10:59 am) · 11 replies

Sorry for the somewhat indescriptive topic (it is too small!), but I'm wondering how I can create a HUGE texture in system RAM (using GDI or whatever), and then upload a part of it to the video card?

Here is an example of the logic I'm looking for:

[During Game Creation]
1. Create a couple of small textures on the video card.
2. Create a huge texture in system RAM.

[During each game loop]
1. Update system RAM texture by modifying alpha values mostly.
2. If needed, grab sections from my system RAM texture and update one or more existing textures on the video card.

How can I do this? I'm not sure how to modify a system RAM texture (GDI graphics object?), change only the alpha values, or upload/update an existing texture on the video card.

Also, TorqueX doesn't support per-pixel collision detection does it?

If anybody could point me in the right direction I would greatly appriciate it.

Thanks!

#1
09/01/2007 (12:25 pm)
This might be a better question for the XNA or DirectX forums, but here goes...

To avoid confusion, don't call bitmaps/images in system RAM textures unless you're talking about a DirectX texture that is created in system memory.

You can create a XNA/DirectX texture from a bitmap. See API docs for .NET framework, XNA and/or DirectX on the Texture and Bitmap classes.

Splitting images is relatively easy with .NET. Again, see API docs or do a search and you should find plenty of info.

Lastly, TorqueX does not have support for per-pixel collisions.
#2
09/01/2007 (8:44 pm)
Thanks for the reply.

I'll check the API documentation. I'm having a hard time finding exactly what I'll need but I'm sure I'll find it.

Thanks!
#3
09/02/2007 (10:31 am)
Check out the Texture2D's SetData method
http://creators.xna.com/search/SearchResults.aspx?q=setdata

But as you can see from those threads, it's not very fast to move stuff between the system memory and GPU's memory. So, you will have to limit how often that happens. Also, if you want to target your game for xbox, it lacks a couple of calls to create textures from image files at runtime.
#4
09/02/2007 (4:10 pm)
Thanks for the information!

I'm looking to create a grid of textures that cover the whole screen plus a little bit more. When the user scrolls the screen then new textures would be uploaded (but only when the user scrolls), so I would think this would be very fast... (hopefully!)
#5
09/04/2007 (3:06 pm)
It's also worth noting that the System.Drawing namespace, which houses most of the imaging functionality (such as the Bitmap class), does not exist in the .net compact framework so you may end up with a solution that doesn't work on XBox if you're not careful.

EDIT: clarity
#6
09/04/2007 (3:52 pm)
I'm not really too worried about X-Box 360 compatibility but thanks for mentioning that!
#7
09/04/2007 (4:12 pm)
Also, in reference to moving things between system and video memory, it can be pretty fast if you update only the regions you need. SetData has an overload that allows you to update a rectangular region of single mip level. I suggest using that if you're trying to update subsections of a texture.
#8
09/04/2007 (5:08 pm)
That sounds perfect!

My only problem now is collision detection.

My huge texture is a Worms/Scorched-Earth terrain and I was hoping to use per-pixel collision detection with TorqueX/XNA but I know thats not possible...
#9
09/04/2007 (5:32 pm)
It's possible, it's just not how Torque X is set up by default. I think Worms and Scorched Earth both used a collision grid. It would require some custom work, but it's definitely doable.
#10
09/04/2007 (5:55 pm)
Do you have any suggestions on how I can do it?

I'm not exactly sure what a collision grid is... (but I thought Worms used per-pixel collisions; although, I'm not sure what the new XBLA Worms uses...)
#11
09/05/2007 (2:58 pm)
I'd just google it. I have no idea how that kind of system should be set up. Anyone have any experience with this?