Rendering from a tile map quickly
So say I have a tile map, you know the drill:
{ 0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,
0,0,0,1,1,1,1,0,0,0,0,0,0,0,0 };
or something like that and I wanna render it onto a square grid with 0''s being one texture and 1''s being another. Whats the best way to do this? Right now I just have a nested loop to go though each coordinate and I draw the appropriate texture at the appropriate space on the screen, but i''m told this isn''t the way to go speedwise.
Fastest way would be to put both textures into one larger texture.
Set texture coordinate transform for tile 0, draw all tile 0s.
Set texture coordinate transform for tile 1, draw all tile 1s.
you could keep both textures seperate and
Load texture 0, draw all tile 0.
Load texture 1, draw all tile 1.
Also, drawing each tile individually will hurt. You could create a (or a series of) static vertex buffer(s) for a group of tiles. OR create a dynamic vertex buffer, build a list of vertices needed this frame in system mem, do a memcpy of it all at once (AGP is optmized for large transfers) to the buffer.
Actually, thinking of it, I''d put the textures in a single texture, and while building a dynamic buffer set the UVs to the appropriate values for that tile, and forget the texture transforms altogether.
Set texture coordinate transform for tile 0, draw all tile 0s.
Set texture coordinate transform for tile 1, draw all tile 1s.
you could keep both textures seperate and
Load texture 0, draw all tile 0.
Load texture 1, draw all tile 1.
Also, drawing each tile individually will hurt. You could create a (or a series of) static vertex buffer(s) for a group of tiles. OR create a dynamic vertex buffer, build a list of vertices needed this frame in system mem, do a memcpy of it all at once (AGP is optmized for large transfers) to the buffer.
Actually, thinking of it, I''d put the textures in a single texture, and while building a dynamic buffer set the UVs to the appropriate values for that tile, and forget the texture transforms altogether.
The way I do it is with separate textures. I build up my vertex buffer with a screenful of tiles. Then each render, I go through the current tiles (IE, position read from the texture identifying map) and build an index list. Then I set texture 1, render indices for texture 1, set texture 2, render, etc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement