1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029810: Visualization - Tool for debugging shaders

A new tool for debugging shaders has been introduced.
The new method OpenGl_ShaderProgram::UpdateDebugDump() allows dynamically
dumping/restoring certain shader program (vertex and fragment shaders) to/from external file.

The file name is generated from the program's name with suffix ".vs" or ".fs" for shader type.
The environment variable CSF_ShadersDirectoryDump specifies the folder for dumps.

If the file does not exist (first frame), then it is automatically saved.
When the file date/time is changed in comparison with recent cached date,
then the file will be automatically loaded from external file,
thus this file can be modified in any editor.

OpenGl_ShaderManager now generates a human-readable resource ids for standard GLSL programs.

Draw Harness command vshader has been extended with arguments -list,-dump and -reload
for debugging shaders within OpenGl_Context.
This commit is contained in:
asl
2019-02-26 13:56:03 +03:00
committed by apn
parent 1e756cb979
commit d95f5ce102
14 changed files with 347 additions and 108 deletions

View File

@@ -585,7 +585,7 @@ static bool parseShaderTypeArg (Graphic3d_TypeOfShaderObject& theType,
//function : VShaderProg
//purpose : Sets the pair of vertex and fragment shaders for the object
//==============================================================================
static Standard_Integer VShaderProg (Draw_Interpretor& /*theDI*/,
static Standard_Integer VShaderProg (Draw_Interpretor& theDI,
Standard_Integer theArgNb,
const char** theArgVec)
{
@@ -611,10 +611,60 @@ static Standard_Integer VShaderProg (Draw_Interpretor& /*theDI*/,
TCollection_AsciiString anArg (theArgVec[anArgIter]);
anArg.LowerCase();
Graphic3d_TypeOfShaderObject aShaderTypeArg = Graphic3d_TypeOfShaderObject(-1);
if (!aProgram.IsNull()
&& aProgram->ShaderObjects().IsEmpty()
&& (anArg == "-off"
|| anArg == "off"))
if (anArg == "-list"
|| ((anArg == "-update"
|| anArg == "-dump"
|| anArg == "-debug"
|| anArg == "-reload"
|| anArg == "-load")
&& anArgIter + 1 < theArgNb))
{
Handle(OpenGl_Context) aGlCtx;
if (Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aCtx->CurrentViewer()->Driver()))
{
aGlCtx = aDriver->GetSharedContext();
}
if (aGlCtx.IsNull())
{
std::cout << "Error: no OpenGl_Context\n";
return 1;
}
if (anArg == "-list")
{
for (OpenGl_Context::OpenGl_ResourcesMap::Iterator aResIter (aGlCtx->SharedResources()); aResIter.More(); aResIter.Next())
{
if (Handle(OpenGl_ShaderProgram) aResProg = Handle(OpenGl_ShaderProgram)::DownCast (aResIter.Value()))
{
theDI << aResProg->ResourceId() << " ";
}
}
}
else
{
TCollection_AsciiString aShaderName = theArgVec[++anArgIter];
Handle(OpenGl_ShaderProgram) aResProg;
if (!aGlCtx->GetResource (aShaderName, aResProg))
{
std::cout << "Syntax error: shader resource '" << aShaderName << "' is not found\n";
return 1;
}
if (aResProg->UpdateDebugDump (aGlCtx, "", false, anArg == "-dump"))
{
aCtx->UpdateCurrentViewer();
}
}
if (anArgIter + 1 < theArgNb)
{
std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
return 0;
}
else if (!aProgram.IsNull()
&& aProgram->ShaderObjects().IsEmpty()
&& (anArg == "-off"
|| anArg == "off"))
{
aProgram.Nullify();
}
@@ -850,7 +900,11 @@ void ViewerTest::OpenGlCommands(Draw_Interpretor& theCommands)
"\n\t\t: [-off] [-phong] [-aspect {shading|line|point|text}=shading]"
"\n\t\t: [-header VersionHeader]"
"\n\t\t: [-tessControl TessControlShader -tesseval TessEvaluationShader]"
"\n\t\t: Assign custom GLSL program to presentation aspects.",
"\n\t\t: Assign custom GLSL program to presentation aspects."
"\nvshader [-list] [-dump] [-reload] ShaderId"
"\n\t\t: -list prints the list of registered GLSL programs"
"\n\t\t: -dump dumps specified GLSL program (for debugging)"
"\n\t\t: -reload restores dump of specified GLSL program",
__FILE__, VShaderProg, aGroup);
theCommands.Add("vshaderprog", "Alias for vshader", __FILE__, VShaderProg, aGroup);
}