PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/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
20#ifndef _EFFECT_H_
21#define _EFFECT_H_
22
23struct IDirect3DTexture9;
24
25class EffectBase
26{
27public:
28	static void RegisterScriptInterface( class asIScriptEngine* );
29	EffectBase()
30	{
31		m_iRefCount = 1;
32	}
33
34	virtual ~EffectBase() {};
35
36	void AddRef()
37	{
38		m_iRefCount++;
39	}
40
41	void Release()
42	{
43		if ( --m_iRefCount == 0 )
44			delete this;
45	}
46
47	virtual  IDirect3DTexture9* GetTexture() { return 0; }
48	virtual  IDirect3DTexture9* GetRenderTarget() { return 0; }
49
50protected:
51	int m_iRefCount;
52};
53
54template<class A, class B>
55B* refCast(A* a)
56{
57	// If the handle already is a null handle, then just return the null handle
58	if( !a ) return 0;
59
60	// Now try to dynamically cast the pointer to the wanted type
61	B* b = dynamic_cast<B*>(a);
62	if( b != 0 )
63	{
64		// Since the cast was made, we need to increase the ref counter for the returned handle
65		b->AddRef();
66	}
67	return b;
68}
69
70#endif