title: Is it safe/acceptable to call SDL_SetTextureColorMod every frame multiple times?
body: <p>As a simple way to render multiple textures that are the same other than color I load a plain white circle in to an <code>SDL_Texture</code> then just call <code>SDL_SetTextureColorMod()</code> giving it the color I want to make the circle. </p>
  
  <p>This all works fine if the textures are individual (Example 1) but if I am sharing the <code>SDL_Texture</code> so that mutiple objects all reference it, it means that <code>SDL_SetTextureColorMod()</code> must be called every render frame before the object renders the texture since the color it gave last time may have been changed by another object (Example 2).</p>
  
  <p>Is calling <code>SDL_SetTextureColorMod()</code> every render frame, for potentially quite a lot of objects sharing a texture, going to cause major performance issues?</p>
  
  <p>The reason it is required is the system is designed using a shared texture functionality with basic reference counting (I understand that there are probably better ways to do this using smart pointers but that is not the topic for discussion here). Is it going to be better to just let each object have it's own copy of the <code>SDL_Texture</code> so it only has to set the color once (or whenever it needs to change) rather than every render frame?</p>
  
  <p>Example 1:</p>
  
  <pre><code>SDL_Texture* tex1;
  SDL_Texture* tex2;
  SDL_Texture* tex3;
  ...
  // All 3 instances have their own SDL_Texture
  MyObject A(tex1);
  MyObject B(tex2);
  MyObject C(tex3);
  ...
  // A call to set the color of the texture is only required once for each class
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>SDL_Texture* tex;
  ...
  // All 3 instances share the SDL_Texture
  MyObject A(tex);
  MyObject B(tex);
  MyObject C(tex);
  ...
  // A call to set the color of the texture must be made before rendering 
  // each object to ensure that any other object has not set a different color.
  // E.g if the draw order was A, B, C and the color was set to be different
  // for each object then before rendering B, each frame it would need to set 
  // the color again otherwise it would have the color of A and the same 
  // for the others    
  </code></pre>
  
  <p>Edit: This would also extend to <code>SDL_SetTextureAlphaMod()</code> and <code>SDL_SetTextureBlendMode()</code> or other similar functions</p>
  
  <p>For reference I'm using SDL2.</p>
  
  <p>Update: Originally it was thought that the call to the function is only updating a color blending flag. I have done some more investigation and this is partially correct which can be seen in the function in - <a href="http://pastebin.com/pMjgVkmM" rel="nofollow">http://pastebin.com/pMjgVkmM</a></p>
  
  <p>However, if the renderer has a function assigned for <code>SetTextureColorMod()</code> which appears to be the case in most parts, then it mapped to a function 'SW_SetTextureColorMod()' - <a href="http://pastebin.com/qYtxD0TH" rel="nofollow">http://pastebin.com/qYtxD0TH</a> </p>
  
  <p>This in turn calls <code>SDL_SetSurfaceColorMod()</code> - <a href="http://pastebin.com/GrsVibAz" rel="nofollow">http://pastebin.com/GrsVibAz</a></p>
  
  <p>My concern here is at this point there is a potential call of <code>SDL_InvalidateMap</code> which I think can cause deallocation although I am not sure - <a href="http://pastebin.com/r0HGJYHT" rel="nofollow">http://pastebin.com/r0HGJYHT</a></p>