featureMgr.h

Engine/source/shaderGen/featureMgr.h

More...

Classes:

class

Used by the feature manager.

Public Defines

define
FEATUREMGR() <>::instance()

Detailed Description

Public Defines

FEATUREMGR() <>::instance()
 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23#ifndef _FEATUREMGR_H_
24#define _FEATUREMGR_H_
25
26#ifndef _TSINGLETON_H_
27#include "core/util/tSingleton.h"
28#endif 
29#ifndef _TVECTOR_H_
30#include "core/util/tVector.h"
31#endif 
32
33class FeatureType;
34class ShaderFeature;
35
36/// Used by the feature manager.
37struct FeatureInfo
38{
39   const FeatureType *type;
40   ShaderFeature *feature;
41};
42
43
44///
45class FeatureMgr
46{
47protected:
48
49   bool mNeedsSort;
50
51   typedef Vector<FeatureInfo> FeatureInfoVector;
52
53   FeatureInfoVector mFeatures;
54
55   static S32 QSORT_CALLBACK _featureInfoCompare( const FeatureInfo *a, const FeatureInfo *b );
56
57public:
58   
59   FeatureMgr();
60   ~FeatureMgr();
61
62   /// Returns the count of registered features.
63   U32 getFeatureCount() const { return mFeatures.size(); }
64
65   /// Returns the feature info at the index.
66   const FeatureInfo& getAt( U32 index );
67
68   /// 
69   ShaderFeature* getByType( const FeatureType &type );
70
71   // Allows other systems to add features.  index is 
72   // the enum in GFXMaterialFeatureData.
73   void registerFeature(   const FeatureType &type, 
74                           ShaderFeature *feature );
75
76   // Unregister a feature.
77   void unregisterFeature( const FeatureType &type );
78
79
80   /// Removes all features.
81   void unregisterAll();
82
83   // For ManagedSingleton.
84   static const char* getSingletonName() { return "FeatureMgr"; }   
85};
86
87// Helper for accessing the feature manager singleton.
88#define FEATUREMGR ManagedSingleton<FeatureMgr>::instance()
89
90#endif // FEATUREMGR
91