0030799: Draw Harness, ViewerTest - setup uniforms via vshader command
[occt.git] / src / ViewerTest / ViewerTest_OpenGlCommands.cxx
index 3a614a3..dc5feb2 100644 (file)
 #include <Graphic3d_Group.hxx>
 #include <Graphic3d_ShaderObject.hxx>
 #include <Graphic3d_ShaderProgram.hxx>
-#include <OpenGl_AspectFace.hxx>
-#include <OpenGl_AspectLine.hxx>
-#include <OpenGl_AspectMarker.hxx>
-#include <OpenGl_AspectText.hxx>
+#include <OpenGl_Aspects.hxx>
 #include <OpenGl_Context.hxx>
 #include <OpenGl_Element.hxx>
 #include <OpenGl_GlCore20.hxx>
@@ -158,11 +155,9 @@ void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
   const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
 
   // To test linking against OpenGl_Workspace and all aspect classes
-  const OpenGl_AspectMarker* aMA = theWorkspace->AspectMarker();
-  aMA->Aspect()->Type();
-  const OpenGl_AspectText* aTA = theWorkspace->AspectText();
-  aTA->Aspect()->Font();
-  OpenGl_Vec4 aColor = theWorkspace->LineColor();
+  const OpenGl_Aspects* aMA = theWorkspace->Aspects();
+  aMA->Aspect()->MarkerType();
+  OpenGl_Vec4 aColor = theWorkspace->InteriorColor();
 
   aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), Aspect_TOL_SOLID,
                                           Graphic3d_TOSM_UNLIT, Graphic3d_AlphaMode_Opaque, false,
@@ -585,7 +580,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)
 {
@@ -612,9 +607,66 @@ static Standard_Integer VShaderProg (Draw_Interpretor& /*theDI*/,
     anArg.LowerCase();
     Graphic3d_TypeOfShaderObject aShaderTypeArg = Graphic3d_TypeOfShaderObject(-1);
     if (!aProgram.IsNull()
-     &&  aProgram->ShaderObjects().IsEmpty()
-     && (anArg == "-off"
-      || anArg ==  "off"))
+      && anArg == "-uniform"
+      && anArgIter + 2 < theArgNb)
+    {
+      TCollection_AsciiString aName = theArgVec[++anArgIter];
+      aProgram->PushVariableFloat (aName, float (Draw::Atof (theArgVec[++anArgIter])));
+    }
+    else 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 +902,12 @@ 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:   [-uniform Name FloatValue]"
+                  "\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);
 }