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.


Sprite thoery


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
5 replies to this topic

#1 DarkRonin   Members   -  Reputation: 613

Like
0Likes
Like

Posted 16 January 2014 - 04:04 PM

Hi Guys,

 

If you had 10 sprites in your game (varying sizes and textures), would if be more efficent to have an individual sprite interface for each or would it be better to store the position, dimensions, texture, etc.. in a class (or struct) and use a single sprite interface - setting the information from the struct?

 

In my mind the latter would cause less chance of memory leak as you only need to sprite->release() once.

 

I'd love to know your thoughts on this.

 

Thanks in advance :)



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13968

Like
1Likes
Like

Posted 16 January 2014 - 04:51 PM

The bitmap itself and anything related directly to it (such as IDirect3DTexture9) need only be loaded once and maintained by a class.

 

Each instance of that image simply has a pointer to that class along with its own unique position, scale, rotation, etc.  The image data is shared between instances of sprites.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 greenpig83   Members   -  Reputation: 326

Like
1Likes
Like

Posted 16 January 2014 - 04:52 PM

First of all, if its D3d9sprite. You should limit to only 1 LPD3DXSPRITE at a time.

The main problem is that performance. 10 sprite is nothing, but when u have about 1000 sprite onscreen it will be the problem. Use as less sprite->begin(),sprite->end() as possible!

I dont know how LPD3DXSPRITE  work, but with 1 begin/end they are extremely fast (render 1000-1500 sprite in 1ms), with hundreds of different texture. That will be impossible if using primitive (u have to change textures so cant do batching well). However u will lack the ability to use Shader (u still can use but in limit way... I'm still studying it ). Because the speed is unchallanged so it's perfect for 2d game !

 

I dont know what you mean "sprite" in your question. Is that the Texture or the LPD3DXSPRITE. It seem that u worry about Many sprite using the same texture. And when u release the sprite, u release the texture, then it cause memory leak if other sprite still use that texture ? It's just a simple problem of managing resource/pointer. Never load a texture more than 1 time unless special case, it's just unlogical!


Edited by greenpig83, 16 January 2014 - 04:59 PM.


#4 DarkRonin   Members   -  Reputation: 613

Like
0Likes
Like

Posted 16 January 2014 - 04:57 PM

Thanks guys, this clears up my suspicions :)



#5 L. Spiro   Crossbones+   -  Reputation: 13968

Like
0Likes
Like

Posted 16 January 2014 - 05:04 PM

First of all, if its D3d9sprite. You should limit to only 1 LPD3DXSPRITE at a time.
The main problem is that performance. 10 sprite is nothing, but when u have about 1000 sprite onscreen it will be the problem. Use as less sprite->begin(),sprite->end() as possible!
I dont know how LPD3DXSPRITE  work, but with 1 begin/end they are extremely fast (render 1000-1500 sprite in 1ms), with hundreds of different texture. That will be impossible if using primitive (u have to change textures so cant do batching well). However u will lack the ability to use Shader (u still can use but in limit way... I'm still studying it ). Because the speed is unchallanged so it's perfect for 2d game !
 
I dont know what you mean "sprite" in your question. Is that the Texture or the LPD3DXSPRITE.


The performance of ID3DXSprite::Begin() depends largely on passing D3DXSPRITE_DONOTMODIFY_RENDERSTATE and D3DXSPRITE_DONOTSAVESTATE. D3DXSPRITE__SORT_TEXTURE should help if you have multiple textures.
If you do not pass these flags, performance go down the hooooole.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#6 greenpig83   Members   -  Reputation: 326

Like
0Likes
Like

Posted 16 January 2014 - 05:27 PM

 

The performance of ID3DXSprite::Begin() depends largely on passing D3DXSPRITE_DONOTMODIFY_RENDERSTATE and D3DXSPRITE_DONOTSAVESTATE. D3DXSPRITE__SORT_TEXTURE should help if you have multiple textures.

If you do not pass these flags, performance go down the hooooole.


L. Spiro

 

 

In my current project, i use only d3dxsprite_alphablend, and it work very fast (full screen (1600x1200) with sprite of size <32x32 ), so i dont spend time play with  sort_texutre or other things. Maybe because in my case, only about 10-20 different (unit,building...) texture appear at a time.

 

What i'm still not happy about D3DXSPRITE is that i cant apply pallete color (like in old game ) for unit/team color! it only support color Mask, and although color Mask work (& bitwise operator) very fast, it's still cant compare to pallete coloring!


Edited by greenpig83, 16 January 2014 - 05:29 PM.





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