소스 검색

Ground work for node editor

Added ability to shader features and shaderGen to create multiple instances of the same feature with the option of calling a static creation function that can take arguments in the form of a struct.

FEATUREMGR now has createFeature to take advantage of this.

The node editor requires this ability as the same node could be used multiple times with different arguments so in its update function we will be calling

```FEATUREMGR->registerFeature(feature_type, (optional default constructor), createFunction);```

then adding it to the feature set with the required arguments to build the shader feature.
```FeatureSet->add(feature_type, index, ParameterStruct);```
marauder2k7 9 달 전
부모
커밋
8c7ddb7cf1

+ 27 - 2
Engine/source/shaderGen/featureMgr.cpp

@@ -96,16 +96,41 @@ ShaderFeature* FeatureMgr::getByType( const FeatureType &type )
    return NULL;
    return NULL;
 }
 }
 
 
+ShaderFeature* FeatureMgr::createFeature(const FeatureType& type, void* argStruct)
+{
+   FeatureInfoVector::iterator iter = mFeatures.begin();
+
+   for (; iter != mFeatures.end(); iter++)
+   {
+      if (*iter->type == type)
+      {
+         if (iter->createFunc != NULL)
+         {
+            return iter->createFunc(argStruct);
+         }
+      }
+   }
+
+   return nullptr;
+}
+
 void FeatureMgr::registerFeature(   const FeatureType &type, 
 void FeatureMgr::registerFeature(   const FeatureType &type, 
-                                    ShaderFeature *feature )
+                                    ShaderFeature *feature,
+                                    CreateShaderFeatureDelegate featureDelegate)
 {
 {
-   // Remove any existing feature first.
+   if (feature == nullptr && featureDelegate == nullptr)
+   {
+      AssertFatal(false, "FeatureMgr::registerFeature - no feature or featureDelegate defined, cannot create this feature.");
+   }
+
+   // Remove any existing feature.
    unregisterFeature( type );
    unregisterFeature( type );
 
 
    // Now add the new feature.
    // Now add the new feature.
    mFeatures.increment();
    mFeatures.increment();
    mFeatures.last().type = &type;
    mFeatures.last().type = &type;
    mFeatures.last().feature = feature;
    mFeatures.last().feature = feature;
+   mFeatures.last().createFunc = featureDelegate;
 
 
    // Make sure we resort the features.
    // Make sure we resort the features.
    mNeedsSort = true;
    mNeedsSort = true;

+ 34 - 6
Engine/source/shaderGen/featureMgr.h

@@ -27,16 +27,28 @@
 #endif 
 #endif 
 #ifndef _TVECTOR_H_
 #ifndef _TVECTOR_H_
 #include "core/util/tVector.h"
 #include "core/util/tVector.h"
-#endif 
+#endif
+
+#ifndef _UTIL_DELEGATE_H_
+#include "core/util/delegate.h"
+#endif
 
 
 class FeatureType;
 class FeatureType;
 class ShaderFeature;
 class ShaderFeature;
 
 
+typedef Delegate<ShaderFeature* (void*)> CreateShaderFeatureDelegate;
+
+/// <summary>
 /// Used by the feature manager.
 /// Used by the feature manager.
+/// </summary>
+/// <param name="type">The shader feature type.</param>
+/// <param name="feature">The shader feature class.</param>
+/// <param name="createFunc">The static create function for this feature.</param>
 struct FeatureInfo
 struct FeatureInfo
 {
 {
    const FeatureType *type;
    const FeatureType *type;
    ShaderFeature *feature;
    ShaderFeature *feature;
+   CreateShaderFeatureDelegate createFunc;
 };
 };
 
 
 
 
@@ -67,10 +79,26 @@ public:
    /// 
    /// 
    ShaderFeature* getByType( const FeatureType &type );
    ShaderFeature* getByType( const FeatureType &type );
 
 
-   // Allows other systems to add features.  index is 
-   // the enum in GFXMaterialFeatureData.
-   void registerFeature(   const FeatureType &type, 
-                           ShaderFeature *feature );
+   /// <summary>
+   /// Creates a shader feature of this type with the arguments provided.
+   /// </summary>
+   /// <param name="type">The shader feature type.</param>
+   /// <param name="argStruct">The arguments for setting up this isntance of the shaderFeature.</param>
+   /// <returns>An instance of the shader feature using its static createFunction taking in the
+   /// argument struct.
+   /// </returns>
+   ShaderFeature* createFeature(const FeatureType& type, void* argStruct);
+
+   /// <summary>
+   /// Allows other systems to add features.  index is 
+   /// the enum in GFXMaterialFeatureData.
+   /// </summary>
+   /// <param name="type">The shader feature type.</param>
+   /// <param name="feature">The shader feature (can be null if featureDelegate defined)</param>
+   /// <param name="featureDelegate">The feature delegate create function.</param>
+   void registerFeature(const FeatureType& type,
+                        ShaderFeature* feature = nullptr,
+                        CreateShaderFeatureDelegate featureDelegate = nullptr);
 
 
    // Unregister a feature.
    // Unregister a feature.
    void unregisterFeature( const FeatureType &type );
    void unregisterFeature( const FeatureType &type );
@@ -86,4 +114,4 @@ public:
 // Helper for accessing the feature manager singleton.
 // Helper for accessing the feature manager singleton.
 #define FEATUREMGR ManagedSingleton<FeatureMgr>::instance()
 #define FEATUREMGR ManagedSingleton<FeatureMgr>::instance()
 
 
-#endif // FEATUREMGR
+#endif // FEATUREMGR

+ 10 - 1
Engine/source/shaderGen/featureSet.cpp

@@ -82,6 +82,14 @@ const FeatureType& FeatureSet::getAt( U32 index, S32 *outIndex ) const
    return *mFeatures[index].type; 
    return *mFeatures[index].type; 
 }
 }
 
 
+void* FeatureSet::getArguments(U32 index) const
+{
+   if (mFeatures[index].argStruct)
+      return mFeatures[index].argStruct;
+
+   return nullptr;
+}
+
 void FeatureSet::clear()
 void FeatureSet::clear()
 {
 {
    mDescription.clear();
    mDescription.clear();
@@ -138,7 +146,7 @@ void FeatureSet::setFeature( const FeatureType &type, bool set, S32 index )
    mDescription.clear();
    mDescription.clear();
 }
 }
 
 
-void FeatureSet::addFeature( const FeatureType &type, S32 index )
+void FeatureSet::addFeature( const FeatureType &type, S32 index, void* argStruct )
 {
 {
    for ( U32 i=0; i < mFeatures.size(); i++ )
    for ( U32 i=0; i < mFeatures.size(); i++ )
    {
    {
@@ -151,6 +159,7 @@ void FeatureSet::addFeature( const FeatureType &type, S32 index )
    FeatureInfo info;
    FeatureInfo info;
    info.type = &type;
    info.type = &type;
    info.index = index;
    info.index = index;
+   info.argStruct = argStruct;
    mFeatures.push_back( info );
    mFeatures.push_back( info );
 
 
    mDescription.clear();
    mDescription.clear();

+ 10 - 2
Engine/source/shaderGen/featureSet.h

@@ -42,6 +42,7 @@ protected:
    {      
    {      
       const FeatureType* type;
       const FeatureType* type;
       S32 index;
       S32 index;
+      void* argStruct;
    };
    };
 
 
    /// The list of featurs.   
    /// The list of featurs.   
@@ -93,14 +94,21 @@ public:
    /// the feature index when it was added.
    /// the feature index when it was added.
    const FeatureType& getAt( U32 index, S32 *outIndex = NULL ) const;
    const FeatureType& getAt( U32 index, S32 *outIndex = NULL ) const;
 
 
+   void* getArguments(U32 index) const;
+
    /// Returns true if this handle has this feature.
    /// Returns true if this handle has this feature.
    bool hasFeature( const FeatureType &type, S32 index = -1 ) const;
    bool hasFeature( const FeatureType &type, S32 index = -1 ) const;
 
 
    /// 
    /// 
    void setFeature( const FeatureType &type, bool set, S32 index = -1 );
    void setFeature( const FeatureType &type, bool set, S32 index = -1 );
 
 
-   /// 
-   void addFeature( const FeatureType &type, S32 index = -1 );
+   /// <summary>
+   /// Adds a feauter to the feature set.
+   /// </summary>
+   /// <param name="type">The shader feature type.</param>
+   /// <param name="index">The inedx the shader feature will be sorted in the set.</param>
+   /// <param name="argStruct">A struct representing arguments for a shader feature.</param>
+   void addFeature( const FeatureType &type, S32 index = -1, void* argStruct = nullptr );
 
 
    /// 
    /// 
    void removeFeature( const FeatureType &type );
    void removeFeature( const FeatureType &type );

+ 19 - 3
Engine/source/shaderGen/shaderGen.cpp

@@ -257,7 +257,13 @@ void ShaderGen::_processVertFeatures( Vector<GFXShaderMacro> &macros, bool macro
    {
    {
       S32 index;
       S32 index;
       const FeatureType &type = features.getAt( i, &index );
       const FeatureType &type = features.getAt( i, &index );
-      ShaderFeature* feature = FEATUREMGR->getByType( type );
+      void* args = features.getArguments(i);
+      ShaderFeature* feature = nullptr;
+      if(args)
+         feature = FEATUREMGR->createFeature(type, args);
+      else
+         feature = FEATUREMGR->getByType( type );
+
       if ( feature )
       if ( feature )
       {
       {
          feature->setProcessIndex( index );
          feature->setProcessIndex( index );
@@ -300,7 +306,12 @@ void ShaderGen::_processPixFeatures( Vector<GFXShaderMacro> &macros, bool macros
    {
    {
       S32 index;
       S32 index;
       const FeatureType &type = features.getAt( i, &index );
       const FeatureType &type = features.getAt( i, &index );
-      ShaderFeature* feature = FEATUREMGR->getByType( type );
+      void* args = features.getArguments(i);
+      ShaderFeature* feature = nullptr;
+      if (args)
+         feature = FEATUREMGR->createFeature(type, args);
+      else
+         feature = FEATUREMGR->getByType(type);
       if ( feature )
       if ( feature )
       {
       {
          feature->setProcessIndex( index );
          feature->setProcessIndex( index );
@@ -342,7 +353,12 @@ void ShaderGen::_printFeatureList(Stream &stream)
    {
    {
       S32 index;
       S32 index;
       const FeatureType &type = features.getAt( i, &index );
       const FeatureType &type = features.getAt( i, &index );
-      ShaderFeature* feature = FEATUREMGR->getByType( type );
+      void* args = features.getArguments(i);
+      ShaderFeature* feature = nullptr;
+      if (args)
+         feature = FEATUREMGR->createFeature(type, args);
+      else
+         feature = FEATUREMGR->getByType(type);
       if ( feature )
       if ( feature )
       {
       {
          String line;
          String line;

+ 1 - 1
Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPreviewWindow.ed.gui

@@ -174,7 +174,7 @@ $guiContent = new GuiControl() {
          canSave = "1";
          canSave = "1";
          Visible = "1";
          Visible = "1";
          Command = "getColorF($thisControl.color, \"MaterialEditorGui.updatePreviewBackground\");"; 
          Command = "getColorF($thisControl.color, \"MaterialEditorGui.updatePreviewBackground\");"; 
-         color = "0 0 0 .7";
+         color = "0.04 0.04 0.04 .7";
          hovertime = "1000";
          hovertime = "1000";
          groupNum = "-1";
          groupNum = "-1";
          buttonType = "PushButton";
          buttonType = "PushButton";