Original Post
Hello, I want to create a small 2D engine, which should be based on Direct3D. Sprites should be rendered as textured squads. Now I am thinking about a way to optimize the rendering pipeline (for example, by sorting the sprites by texture) I had 4 methods in mind and would like to hear your opinions about them. 1) Very simple: Batch all sprites in a dynamic vertex buffer. (just one lock+unlock) Then render each sprite separately (many DrawPrimitive calls, a lot of overhead) 2) Similar to 1), but: Instead of drawing each sprite separately, try to group sprites, which use the same texture and which normally would be rendered one after another. Example: The user passes the following sprites to the engine: Sprite0(Tex0), Sprite1(Tex1), Sprite2(Tex1), Sprite3(Tex0), Sprite4(Tex1) Sprite1 and Sprite2 would be rendered with one call. Sprite4 cannot be included, as Sprite3 may lie under Sprite4. 3) Use a layering system. The user creates layers (each layer has its own z-Value) and puts sprites on them. Each layer is rendered separately with textures being sorted. (It is assumed that on one layer there are no overlying sprites) 4) Try to reduce all sprites to one layer: If a sprites lies above another, the sprite which lies on top will be subtracted from the lower sprite (using boolean operations). This will also avoid overdraw. Then you are able to render all sprites (sorted by texture) without paying attention to their z-Value. (Problem here: I have not thought about textures with alpha channels. Rendering transparent sprites would increase the complexity of this algorithm) I would be glad if you could give me some advice. Maybe some solutions (especially the last one) would even negatively influence the performance. I have not thought about using the z-Buffer either, as I consider it to be not accurate enough. By the way: Does anybody know which method is used by the implementation of the ID3DXSprite interface?