Public Sub renderTiles()
Dim x, y As Integer
For y = 1 To CurMap(1, 1).sizeY
For x = 1 To CurMap(1, 1).sizeX
If lastTile <> CurMap(x, y).MapTile Then FindTexture(CurMap(x, y).MapTile)
If firstRun Then
FindTexture(CurMap(x, y).MapTile)
firstRun = False
End If
lastTile = CurMap(x, y).MapTile
setpoly(x, y)
If ptype = PrimitiveType.TriangleList Then d.SetTexture(0, texture)
d.VertexFormat = CustomVertex.PositionNormalTextured.Format
d.DrawUserPrimitives(ptype, 2, poly)
dirty = False
texture.Dispose()
Next
Next
End Sub
[.net] Speeding up direct3d tiling
I'm currently working on a 3d program that tiles a map to create a scene that looks like a 2D tile based map. Its been coming along great, but I noticed my framerate is horribly slow. This is even without any kind of animations. So i've been working on trying to make it run a bit faster, but can't seem to get anything to work, and can't find anything to suggest a better way to render. I know its not the greatest way to draw primitives to the screen using for...loops, but I can't seem to get anything else to work. I thought about batching using vertex buffers, but can't get that to work. Anyone know of any sources that show how to do vertex buffering in vb.net or another method of doing this. Maybe even a way to only render only the changed areas of the screen instead of the whole screen. Thanks for your time.
Slyprid
- Here is my tile render routine -
Instead of iterating all the tiles and painting them one at a time, with a texture change between each call, you could make batches.
During the iteration, draw nothing but build lists of tiles with the same texture. Then after the iteration, for each list change the texture and draw the whole list with a single call. This should speed things up a lot.
Changing the video driver state (e.g. changing the current texture) is very slow, and should be avoided as much as possible.
During the iteration, draw nothing but build lists of tiles with the same texture. Then after the iteration, for each list change the texture and draw the whole list with a single call. This should speed things up a lot.
Changing the video driver state (e.g. changing the current texture) is very slow, and should be avoided as much as possible.
Quote:Original post by jods
Instead of iterating all the tiles and painting them one at a time, with a texture change between each call, you could make batches.
You should look into using the Sprite object as it will do a lot of the batching/sorting the work for you. Pushing further with what jods said about texture and state changes, a common optimization when using sprites is to pack textures together into one larger texture and only sample a portion of it for each sprite. If you don't use sprite (which will make this easy for you) you can apply a packed texture to multiple quads and specify what part of the texture to use by changing the texture coordinates on the quad.
Yeah, got the batching to work last night, and sped it up from ~6fps to around ~42fps. I'm still debating on making tilesets, but it would probally speed it up more. The only reason not using tilesets atm is i'm using various sized tiles and resizing them in game. This allows the engine to maintain a high quality look while zooming in and such, but I may sacrafice the large textures to go to a tileset if it will speed it up more. I figured i'm going to need all the speed as possible since my next step is to add in animations and animated tiles. Thanks for all the help.
Slyprid
Slyprid
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement