Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


What is more efficient?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 DarkRonin   Members   -  Reputation: 613

Like
0Likes
Like

Posted 20 February 2014 - 01:11 AM

Hi Guys,

 

I am making massive progress with a game engine I am writing, but am now wondering what would be more efficient. Rendering sprites using the DX9 sprite interface or just using textured quads?

 

I am calling sprite Begin, End, and Flush only once - even if I am rendering 1000 sprites, so I think I am going as efficient as I can in that regard. But, am wondering if I could squeeze out more potential if I used quads instead.

 

What do you guys recommend?

 

Thanks in advance :)



Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7801

Like
1Likes
Like

Posted 20 February 2014 - 01:52 AM

Best to encapsulate your sprite interface and use either a DX9 Spirte or quad implementation. This way you can test out different approaches without the necessarity to rewrite most of your code.

 

PS:

There might be although some trapdoors when using quads, e.g. filtering, I believe, that sprites are more memory copy operations, while quads will be more like rendering. When rendering you have some advantages (use shaders for some pretty effects) and disadvantages (filtering which could result in bluring your sprites when not really careful).


Edited by Ashaman73, 20 February 2014 - 02:00 AM.


#3 DarkRonin   Members   -  Reputation: 613

Like
1Likes
Like

Posted 20 February 2014 - 02:00 AM

Thanks Ashaman73, I was hoping there was an easy answer. But you are right, the only way to really tell is to try it out and see.

 

My code is pretty clean as the sprite calls are allready neatly wrapped up. So, I just need to make some quads and test things out.



#4 Hodgman   Moderators   -  Reputation: 31013

Like
4Likes
Like

Posted 20 February 2014 - 02:10 AM

All the D3DX stuff are just helpful wrappers around common D3D tasks. 

 

If you implement the exact same D3D operations yourself, it would have exactly the same performance as the D3DX version. Unfortunately I don't think the code for the D3DX sprite interface is available so that you can see what it's doing...

 

Generally the D3DX code can be improved upon, which is why it's just there as a helper library, rather than an actual part of D3D itself. It's likely just a wrapper around a dynamic vertex/index buffer, which it copies your rects into, and then constructs indexed-draw calls based on the textures used.

 

You can very likely build a better version yourself based around the specific needs of your game. There's some good info on buffer management here if you want to try:

https://developer.nvidia.com/sites/default/files/akamai/gamedev/files/gdc12/Efficient_Buffer_Management_McDonald.pdf



#5 DarkRonin   Members   -  Reputation: 613

Like
0Likes
Like

Posted 20 February 2014 - 03:08 AM

Cool, thanks for the advice and the link - just downloaded now and I'll have a read.



#6 Eck   Crossbones+   -  Reputation: 3095

Like
1Likes
Like

Posted 20 February 2014 - 08:05 AM

Actually, I was just reading an XNA book that was talking about the guts of SpriteBatch. It turns out that Spritebatch uses textured quads because the GPU hardware is so specialized it turns out to be faster. I suspect if you roll your own textured quad drawing implementation, it might be marginally faster than SpriteBatch. But the ONLY true test of which one is faster is to code them and profile them both.

 

A couple of related links:

http://www.gamedev.net/topic/536693-xna-textured-quad-vs-sprite-batch/

http://gamedev.stackexchange.com/questions/21220/how-exactly-does-xnas-spritebatch-work



#7 DarkRonin   Members   -  Reputation: 613

Like
0Likes
Like

Posted 20 February 2014 - 10:48 PM

Nice one. I am about to have a read of your links.

#8 Tom KQT   Members   -  Reputation: 1611

Like
0Likes
Like

Posted 21 February 2014 - 02:00 AM

There might be although some trapdoors when using quads, e.g. filtering, I believe, that sprites are more memory copy operations, while quads will be more like rendering. When rendering you have some advantages (use shaders for some pretty effects) and disadvantages (filtering which could result in bluring your sprites when not really careful).

D3DX sprites are rendered using textured quads, so it's the same thing.

 

In my opinion the D3DX helper interfaces for sprites and fonts (and meshes etc.) are excellent when you are starting and actually may be perfectly fine for you for a long time. But sooner or later you'll want to implement it yourself. Especially ID3DXFont is very slow. The problem is that they are quite generalised and you can make a more efficient code by making it directly as you want and need.


Edited by Tom KQT, 21 February 2014 - 03:01 AM.


#9 mhagain   Crossbones+   -  Reputation: 8137

Like
0Likes
Like

Posted 21 February 2014 - 02:02 AM

Generally the D3DX code can be improved upon, which is why it's just there as a helper library, rather than an actual part of D3D itself. It's likely just a wrapper around a dynamic vertex/index buffer, which it copies your rects into, and then constructs indexed-draw calls based on the textures used.

 

This is exactly how it's implemented, yes.  You can use PIX to view the actual D3D calls that the sprite interface makes and determine that it's nothing more than a wrapper.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS