/xbmc/visualizations/Vortex/VortexVis/Core/EffectBase.h

http://github.com/xbmc/xbmc · C Header · 70 lines · 38 code · 11 blank · 21 comment · 5 complexity · c728da9be80c88f5dba744fbeda29fbd MD5 · raw file

  1. /*
  2. * Copyright Š 2010-2013 Team XBMC
  3. * http://xbmc.org
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #ifndef _EFFECT_H_
  20. #define _EFFECT_H_
  21. struct IDirect3DTexture9;
  22. class EffectBase
  23. {
  24. public:
  25. static void RegisterScriptInterface( class asIScriptEngine* );
  26. EffectBase()
  27. {
  28. m_iRefCount = 1;
  29. }
  30. virtual ~EffectBase() {};
  31. void AddRef()
  32. {
  33. m_iRefCount++;
  34. }
  35. void Release()
  36. {
  37. if ( --m_iRefCount == 0 )
  38. delete this;
  39. }
  40. virtual IDirect3DTexture9* GetTexture() { return 0; }
  41. virtual IDirect3DTexture9* GetRenderTarget() { return 0; }
  42. protected:
  43. int m_iRefCount;
  44. };
  45. template<class A, class B>
  46. B* refCast(A* a)
  47. {
  48. // If the handle already is a null handle, then just return the null handle
  49. if( !a ) return 0;
  50. // Now try to dynamically cast the pointer to the wanted type
  51. B* b = dynamic_cast<B*>(a);
  52. if( b != 0 )
  53. {
  54. // Since the cast was made, we need to increase the ref counter for the returned handle
  55. b->AddRef();
  56. }
  57. return b;
  58. }
  59. #endif