Implements a Material Instance viewer to the material editor to see a feature-filtered dump of the generated shaders for a given material.

This commit is contained in:
Areloch 2019-05-17 01:48:45 -05:00
parent 13fb5cd5b9
commit af14de2bb7
19 changed files with 626 additions and 12 deletions

View file

@ -59,7 +59,7 @@ struct GFXStateBlockDesc;
class GFXVertexFormat;
class MatrixSet;
class ProcessedMaterial;
class GuiTreeViewCtrl;
///
class BaseMatInstance
@ -216,6 +216,7 @@ public:
virtual const GFXVertexFormat* getVertexFormat() const = 0;
virtual void dumpShaderInfo() const = 0;
virtual void getShaderInfo(GuiTreeViewCtrl* tree, U32 item) const = 0;
/// Fast test for use of normal maps in this material.
bool hasNormalMap() const { return mHasNormalMaps; }

View file

@ -37,6 +37,8 @@
#include "core/util/safeDelete.h"
#include "ts/tsShape.h"
#include "gui/controls/guiTreeViewCtrl.h"
class MatInstParameters;
class MatInstanceParameterHandle : public MaterialParameterHandle
@ -591,3 +593,35 @@ void MatInstance::dumpShaderInfo() const
mProcessedMaterial->dumpMaterialInfo();
}
void MatInstance::getShaderInfo(GuiTreeViewCtrl* tree, U32 item) const
{
if (mMaterial == NULL)
{
Con::errorf("Trying to get Material information on an invalid MatInstance");
return;
}
if (mProcessedMaterial == NULL)
{
Con::printf(" [no processed material!]");
return;
}
const FeatureSet features = mProcessedMaterial->getFeatures();
String featureDesc = "";
for (U32 i = 0; i < features.getCount(); i++)
{
const FeatureType& ft = features.getAt(i);
featureDesc += ft.getName();
if(i+1 < features.getCount())
featureDesc += ", ";
}
U32 newItem = tree->insertItem(item, featureDesc);
mProcessedMaterial->getMaterialInfo(tree, newItem);
}

View file

@ -44,7 +44,7 @@ class ShaderFeature;
class MatInstanceParameterHandle;
class MatInstParameters;
class ProcessedMaterial;
class GuiTreeViewCtrl;
///
class MatInstance : public BaseMatInstance
@ -86,6 +86,7 @@ public:
virtual const FeatureSet& getFeatures() const;
virtual const FeatureSet& getRequestedFeatures() const { return mFeatureList; }
virtual void dumpShaderInfo() const;
virtual void getShaderInfo(GuiTreeViewCtrl* tree, U32 item) const;
ProcessedMaterial *getProcessedMaterial() const { return mProcessedMaterial; }

View file

@ -36,7 +36,7 @@
#include "sfx/sfxTypes.h"
#include "core/util/safeDelete.h"
#include "T3D/accumulationVolume.h"
#include "gui/controls/guiTreeViewCtrl.h"
IMPLEMENT_CONOBJECT( Material );
@ -647,6 +647,12 @@ DefineEngineMethod( Material, dumpInstances, void, (),,
MATMGR->dumpMaterialInstances( object );
}
DefineEngineMethod(Material, getMaterialInstances, void, (GuiTreeViewCtrl* matTree), (nullAsType< GuiTreeViewCtrl*>()),
"Dumps a formatted list of the currently allocated material instances for this material to the console.")
{
MATMGR->getMaterialInstances(object, matTree);
}
DefineEngineMethod( Material, getAnimFlags, const char*, (U32 id), , "" )
{
char * animFlags = Con::getReturnBuffer(512);
@ -706,6 +712,13 @@ DefineEngineMethod( Material, setAutoGenerated, void, (bool isAutoGenerated), ,
object->setAutoGenerated(isAutoGenerated);
}
DefineEngineMethod(Material, getAutogeneratedFile, const char*, (), , "Get filename of autogenerated shader file")
{
SimObject *material = static_cast<SimObject *>(object);
return material->getFilename();
}
// Accumulation
bool Material::_setAccuEnabled( void *object, const char *index, const char *data )
{

View file

@ -32,6 +32,7 @@
#include "console/consoleTypes.h"
#include "console/engineAPI.h"
#include "gui/controls/guiTreeViewCtrl.h"
MODULE_BEGIN( MaterialManager )
@ -399,6 +400,36 @@ void MaterialManager::dumpMaterialInstances( BaseMaterialDefinition *target ) co
Con::printf( "---------------------- Dump complete ----------------------");
}
void MaterialManager::getMaterialInstances(BaseMaterialDefinition* target, GuiTreeViewCtrl* materailInstanceTree)
{
if (!mMatInstanceList.size())
return;
if (!target)
{
Con::errorf("Can't form a list without a specific MaterialDefinition");
return;
}
if (!materailInstanceTree)
{
Con::errorf("Requires a valid GuiTreeViewCtrl object to populate data into!");
return;
}
U32 matItem = materailInstanceTree->insertItem(0, target->getName());
for (U32 i = 0; i < mMatInstanceList.size(); i++)
{
BaseMatInstance* inst = mMatInstanceList[i];
if (target && inst->getMaterial() != target)
continue;
inst->getShaderInfo(materailInstanceTree, matItem);
}
}
void MaterialManager::_track( MatInstance *matInstance )
{
mMatInstanceList.push_back( matInstance );
@ -488,6 +519,16 @@ DefineEngineFunction( dumpMaterialInstances, void, (), ,
MATMGR->dumpMaterialInstances();
}
DefineEngineFunction(getMaterialInstances, void, (BaseMaterialDefinition* target, GuiTreeViewCtrl* tree), (nullAsType<BaseMaterialDefinition*>(), nullAsType<GuiTreeViewCtrl*>()),
"@brief Dumps a formatted list of currently allocated material instances to the console.\n\n"
"@ingroup Materials")
{
if (target == nullptr || tree == nullptr)
return;
MATMGR->getMaterialInstances(target, tree);
}
DefineEngineFunction( getMapEntry, const char*, (const char * texName), ,
"@hide")
{

View file

@ -37,6 +37,7 @@
class SimSet;
class MatInstance;
class GuiTreeViewCtrl;
class MaterialManager : public ManagedSingleton<MaterialManager>
{
@ -97,6 +98,8 @@ public:
void dumpMaterialInstances( BaseMaterialDefinition *target = NULL ) const;
void getMaterialInstances(BaseMaterialDefinition* target, GuiTreeViewCtrl* tree);
void updateTime();
F32 getTotalTime() const { return mAccumTime; }
F32 getDeltaTime() const { return mDt; }

View file

@ -46,7 +46,7 @@ class SceneRenderState;
class GFXVertexBufferHandleBase;
class GFXPrimitiveBufferHandle;
class MatrixSet;
class GuiTreeViewCtrl;
/// This contains the common data needed to render a pass.
struct RenderPassData
@ -218,6 +218,8 @@ public:
/// Dump shader info, or FF texture info?
virtual void dumpMaterialInfo() { }
virtual void getMaterialInfo(GuiTreeViewCtrl* tree, U32 item) {}
/// Returns the source material.
Material* getMaterial() const { return mMaterial; }

View file

@ -44,7 +44,7 @@
// We need to include customMaterialDefinition for ShaderConstHandles::init
#include "materials/customMaterialDefinition.h"
#include "gui/controls/guiTreeViewCtrl.h"
#include "ts/tsShape.h"
///
@ -1421,3 +1421,26 @@ void ProcessedShaderMaterial::dumpMaterialInfo()
Con::printf( " [%i] %s", i, shader->describeSelf().c_str() );
}
}
void ProcessedShaderMaterial::getMaterialInfo(GuiTreeViewCtrl* tree, U32 item)
{
for (U32 i = 0; i < getNumPasses(); i++)
{
const ShaderRenderPassData* passData = _getRPD(i);
if (passData == NULL)
continue;
char passStr[64];
dSprintf(passStr, 64, "Pass Number: %i", i);
U32 passItem = tree->insertItem(item, passStr);
const GFXShader * shader = passData->shader;
if (shader == NULL)
tree->insertItem(passItem, "[NULL shader]");
else
tree->insertItem(passItem, shader->describeSelf().c_str());
}
}

View file

@ -37,7 +37,6 @@ class ShaderMaterialParameterHandle;
class ShaderFeatureConstHandles;
class CustomMaterial;
class ShaderConstHandles
{
public:
@ -136,6 +135,7 @@ public:
virtual void setBuffers(GFXVertexBufferHandleBase* vertBuffer, GFXPrimitiveBufferHandle* primBuffer);
virtual bool stepInstance();
virtual void dumpMaterialInfo();
virtual void getMaterialInfo(GuiTreeViewCtrl* tree, U32 item);
virtual MaterialParameters* allocMaterialParameters();
virtual MaterialParameters* getDefaultMaterialParameters() { return mDefaultParameters; }
virtual MaterialParameterHandle* getMaterialParameterHandle(const String& name);