Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements a Material Instance viewer #2357

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions Engine/source/gui/controls/guiTreeViewCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ GuiTreeViewCtrl::GuiTreeViewCtrl()
mTexSelected = NULL;

mRenderTooltipDelegate.bind( this, &GuiTreeViewCtrl::renderTooltip );

mDoFilterChildren = true;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1122,7 +1124,7 @@ void GuiTreeViewCtrl::_expandObjectHierarchy( SimGroup* group )

//------------------------------------------------------------------------------

void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdate )
void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdate, bool skipFlter )
{
if (!item || !mActive || !isVisible() || !mProfile )
return;
Expand All @@ -1145,7 +1147,7 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat

// If we have a filter pattern, sync the item's filtering status to it.

if( !getFilterText().isEmpty() )
if( !getFilterText().isEmpty() && !skipFlter)
{
// Determine the filtering status by looking for the filter
// text in the item's display text.
Expand All @@ -1154,7 +1156,11 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat
item->getDisplayText( sizeof( displayText ), displayText );
if( !dStristr( displayText, mFilterText ) )
{
item->mState.set( Item::Filtered );
//Last check, see if we special-exception this item
if (!mItemFilterExceptionList.contains(item->mId))
item->mState.set(Item::Filtered);
else
item->mState.clear(Item::Filtered);

// If it's not a parent, we're done. Otherwise, there may be children
// that are not filtered so we need to process them first.
Expand All @@ -1163,7 +1169,9 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat
return;
}
else
item->mState.clear( Item::Filtered );
{
item->mState.clear(Item::Filtered);
}
}
else
item->mState.clear( Item::Filtered );
Expand Down Expand Up @@ -1217,7 +1225,10 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat
Item *pChildTemp = child;
child = child->mNext;

_buildItem( pChildTemp, tabLevel + 1, bForceFullUpdate );
if (!mItemFilterExceptionList.contains(item->mId) && !mDoFilterChildren && !item->isFiltered())
_buildItem( pChildTemp, tabLevel + 1, bForceFullUpdate, true );
else
_buildItem(pChildTemp, tabLevel + 1, bForceFullUpdate, false);
}
}
}
Expand Down Expand Up @@ -4775,6 +4786,18 @@ void GuiTreeViewCtrl::setFilterText( const String& text )
mFlags.set( RebuildVisible );
}

void GuiTreeViewCtrl::setItemFilterException(U32 item, bool isExempted)
{
if (isExempted)
{
mItemFilterExceptionList.push_back(item);
}
else
{
mItemFilterExceptionList.remove(item);
}
}

//=============================================================================
// Console Methods.
//=============================================================================
Expand Down Expand Up @@ -5574,6 +5597,20 @@ DefineEngineMethod( GuiTreeViewCtrl, setFilterText, void, ( const char* pattern
object->setFilterText( pattern );
}

DefineEngineMethod(GuiTreeViewCtrl, setFilterChildren, void, (bool doFilterChildren), (true),
"Sets if the filter will also apply to any children of items that manage to pass being filtered.\n\n"
"@param doFilterChildren If true, items that pass the filter do not have their children filtered. If false, all items are filtered.\n\n")
{
object->setFilterChildren(doFilterChildren);
}

DefineEngineMethod(GuiTreeViewCtrl, setItemFilterException, void, (U32 item, bool isExempt), (0, true),
"Set a given item to be excluded from being filtered.\n\n"
"@param item Item ID of the item that is to be exempt from the filter.\n\n"
"@param isExempt If the item is exempt from the filter.\n\n")
{
object->setItemFilterException(item, isExempt);
}
//-----------------------------------------------------------------------------

DefineEngineMethod( GuiTreeViewCtrl, clearFilterText, void, (),,
Expand Down
10 changes: 9 additions & 1 deletion Engine/source/gui/controls/guiTreeViewCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ class GuiTreeViewCtrl : public GuiArrayCtrl
/// Current filter that determines which items in the tree are displayed and which are hidden.
String mFilterText;

/// If true, all items are filtered. If false, then children of items that successfully pass filter are not filtered
bool mDoFilterChildren;

Vector<U32> mItemFilterExceptionList;

/// If true, a trace of actions taken by the control is logged to the console. Can
/// be turned on with the setDebug() script method.
bool mDebug;
Expand Down Expand Up @@ -431,7 +436,7 @@ class GuiTreeViewCtrl : public GuiArrayCtrl

void _deleteItem(Item* item);

void _buildItem(Item* item, U32 tabLevel, bool bForceFullUpdate = false);
void _buildItem(Item* item, U32 tabLevel, bool bForceFullUpdate = false, bool skipFlter = false);

Item* _findItemByAmbiguousId( S32 itemOrObjectId, bool buildVirtual = true );

Expand Down Expand Up @@ -569,6 +574,9 @@ class GuiTreeViewCtrl : public GuiArrayCtrl
/// matches this pattern are displayed.
void setFilterText( const String& text );

void setFilterChildren(bool doFilter) { mDoFilterChildren = doFilter; }
void setItemFilterException(U32 item, bool isExempt);

/// Clear the current item filtering pattern.
void clearFilterText() { setFilterText( String::EmptyString ); }

Expand Down
3 changes: 2 additions & 1 deletion Engine/source/materials/baseMatInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct GFXStateBlockDesc;
class GFXVertexFormat;
class MatrixSet;
class ProcessedMaterial;

class GuiTreeViewCtrl;

///
class BaseMatInstance
Expand Down Expand Up @@ -216,6 +216,7 @@ class BaseMatInstance
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; }
Expand Down
34 changes: 34 additions & 0 deletions Engine/source/materials/matInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "core/util/safeDelete.h"
#include "ts/tsShape.h"

#include "gui/controls/guiTreeViewCtrl.h"

class MatInstParameters;

class MatInstanceParameterHandle : public MaterialParameterHandle
Expand Down Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion Engine/source/materials/matInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ShaderFeature;
class MatInstanceParameterHandle;
class MatInstParameters;
class ProcessedMaterial;

class GuiTreeViewCtrl;

///
class MatInstance : public BaseMatInstance
Expand Down Expand Up @@ -86,6 +86,7 @@ class MatInstance : public BaseMatInstance
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; }
Expand Down
15 changes: 14 additions & 1 deletion Engine/source/materials/materialDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 )
{
Expand Down
41 changes: 41 additions & 0 deletions Engine/source/materials/materialManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "console/consoleTypes.h"
#include "console/engineAPI.h"

#include "gui/controls/guiTreeViewCtrl.h"

MODULE_BEGIN( MaterialManager )

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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")
{
Expand Down
3 changes: 3 additions & 0 deletions Engine/source/materials/materialManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

class SimSet;
class MatInstance;
class GuiTreeViewCtrl;

class MaterialManager : public ManagedSingleton<MaterialManager>
{
Expand Down Expand Up @@ -97,6 +98,8 @@ class MaterialManager : public ManagedSingleton<MaterialManager>

void dumpMaterialInstances( BaseMaterialDefinition *target = NULL ) const;

void getMaterialInstances(BaseMaterialDefinition* target, GuiTreeViewCtrl* tree);

void updateTime();
F32 getTotalTime() const { return mAccumTime; }
F32 getDeltaTime() const { return mDt; }
Expand Down
4 changes: 3 additions & 1 deletion Engine/source/materials/processedMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -218,6 +218,8 @@ class ProcessedMaterial
/// 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; }

Expand Down
25 changes: 24 additions & 1 deletion Engine/source/materials/processedShaderMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

///
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion Engine/source/materials/processedShaderMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ShaderMaterialParameterHandle;
class ShaderFeatureConstHandles;
class CustomMaterial;


class ShaderConstHandles
{
public:
Expand Down Expand Up @@ -136,6 +135,7 @@ class ProcessedShaderMaterial : public ProcessedMaterial
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);
Expand Down
Loading