【发布时间】:2022-09-24 10:13:56
【问题描述】:
我正在 Unreal 中开发一个编辑器插件,我需要在其中访问材料的指令计数。我发现通常在引擎代码中为编辑器完成此操作。
\\Engine\\Source\\Editor\\MaterialEditor\\Public\\ 中的 MaterialStatsCommon.h 具有包含此内容的 FMaterialStatsUtils 类。
/** class used for various stats utilities */
class FMaterialStatsUtils
{
public:
MATERIALEDITOR_API static void ExtractMatertialStatsInfo(struct FShaderStatsInfo& OutInfo, const FMaterialResource* Target);
};
这里的所有内容都是公开的,但是 FShaderStatsInfo 是在 MaterialStats.h 中声明的,它在同一个模块中但在一个私有文件夹中。
在我的插件中包含该模块后,使用此功能很容易。也就是说,只要我转发声明 FShaderStatsInfo。但是,当我实际尝试从我的插件中访问任何 FShaderStatsInfo 时,我不能,因为它说类型不完整并且我实际上无法包含 MaterialStats.h。
无论如何,有没有围绕这个或不同的方式来访问材料上的相同内容?
我被卡住的地方:
#include \"MaterialStatsCommon.h\"
struct FShaderStatsInfo;
void MyEditorBPLibraryName::GetMaterialStatsInfo(UMaterial* Material, int32 BasePassShaderInstructionCount, int32 VertexShaderInstructionCount, int32 TextureSampleCount)
{
if (Material == nullptr)
{
return;
}
FShaderStatsInfo* OutInfo = nullptr;
FMaterialStatsUtils::ExtractMatertialStatsInfo(*OutInfo, Material->GetMaterialResource(ERHIFeatureLevel::SM5, EMaterialQualityLevel::Num));
//OutInfo-> I needed ShaderInstructionCount from this struct, but can\'t access anything in it
return;
}
以及我需要在 MaterialStats.h 中使用的结构:
#include \"MaterialStatsCommon.h\"
#include \"UObject/GCObject.h\"
/** structure used to store various statistics extracted from compiled shaders */
struct FShaderStatsInfo
{
struct FContent
{
FString StrDescription;
FString StrDescriptionLong;
};
TMap<ERepresentativeShader, FContent> ShaderInstructionCount;
FContent SamplersCount;
FContent InterpolatorsCount;
FContent TextureSampleCount;
FContent VirtualTextureLookupCount;
FString StrShaderErrors;
void Reset()
{
ShaderInstructionCount.Empty();
SamplersCount.StrDescription = TEXT(\"Compiling...\");
SamplersCount.StrDescriptionLong = TEXT(\"Compiling...\");
InterpolatorsCount.StrDescription = TEXT(\"Compiling...\");
InterpolatorsCount.StrDescriptionLong = TEXT(\"Compiling...\");
TextureSampleCount.StrDescription = TEXT(\"Compiling...\");
TextureSampleCount.StrDescriptionLong = TEXT(\"Compiling...\");
VirtualTextureLookupCount.StrDescription = TEXT(\"Compiling...\");
VirtualTextureLookupCount.StrDescriptionLong = TEXT(\"Compiling...\");
StrShaderErrors.Empty();
}
void Empty()
{
ShaderInstructionCount.Empty();
SamplersCount.StrDescription.Empty();
SamplersCount.StrDescriptionLong.Empty();
InterpolatorsCount.StrDescription.Empty();
InterpolatorsCount.StrDescriptionLong.Empty();
TextureSampleCount.StrDescription.Empty();
TextureSampleCount.StrDescriptionLong.Empty();
VirtualTextureLookupCount.StrDescription.Empty();
VirtualTextureLookupCount.StrDescriptionLong.Empty();
StrShaderErrors.Empty();
}
bool HasErrors()
{
return !StrShaderErrors.IsEmpty();
}
};
标签: c++ game-development unreal-engine4