1 // Created on: 2012-04-09
2 // Created by: Sergey ANIKIN
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <ViewerTest.hxx>
18 #include <AIS_InteractiveContext.hxx>
19 #include <AIS_InteractiveObject.hxx>
21 #include <Draw_Interpretor.hxx>
22 #include <Graphic3d_Group.hxx>
23 #include <Graphic3d_ShaderObject.hxx>
24 #include <Graphic3d_ShaderProgram.hxx>
25 #include <OpenGl_Aspects.hxx>
26 #include <OpenGl_Context.hxx>
27 #include <OpenGl_Element.hxx>
28 #include <OpenGl_GlCore20.hxx>
29 #include <OpenGl_GraphicDriver.hxx>
30 #include <OpenGl_ShaderManager.hxx>
31 #include <OpenGl_Workspace.hxx>
32 #include <OSD_Environment.hxx>
33 #include <OSD_File.hxx>
34 #include <Prs3d_Drawer.hxx>
35 #include <Prs3d_Presentation.hxx>
36 #include <Prs3d_Root.hxx>
37 #include <Prs3d_LineAspect.hxx>
38 #include <Prs3d_ShadingAspect.hxx>
39 #include <Select3D_SensitiveCurve.hxx>
40 #include <SelectMgr_EntityOwner.hxx>
41 #include <SelectMgr_Selection.hxx>
42 #include <TCollection_AsciiString.hxx>
43 #include <V3d_View.hxx>
44 #include <V3d_Viewer.hxx>
45 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
46 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
47 #include <OpenGl_Group.hxx>
49 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
50 const Handle(AIS_InteractiveObject)& theAISObj,
51 Standard_Boolean theReplaceIfExists = Standard_True);
52 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
56 //=======================================================================
57 //function : VUserDraw
58 //purpose : Checks availability and operation of UserDraw feature
59 //=======================================================================
61 class VUserDrawObj : public AIS_InteractiveObject
65 DEFINE_STANDARD_RTTI_INLINE(VUserDrawObj,AIS_InteractiveObject);
78 class Element : public OpenGl_Element
81 Handle(VUserDrawObj) myIObj;
84 Element (const Handle(VUserDrawObj)& theIObj) : myIObj (theIObj) {}
88 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
91 myIObj->Render(theWorkspace);
94 virtual void Release (OpenGl_Context*)
100 DEFINE_STANDARD_ALLOC
104 // Virtual methods implementation
105 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
106 const Handle(Prs3d_Presentation)& thePresentation,
107 const Standard_Integer theMode) Standard_OVERRIDE;
109 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
110 const Standard_Integer theMode) Standard_OVERRIDE;
112 // Called by VUserDrawElement
113 void Render(const Handle(OpenGl_Workspace)& theWorkspace) const;
117 friend class Element;
120 void VUserDrawObj::Compute(const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
121 const Handle(Prs3d_Presentation)& thePrs,
122 const Standard_Integer /*theMode*/)
126 Graphic3d_Vec4 aBndMin (myCoords[0], myCoords[1], myCoords[2], 1.0f);
127 Graphic3d_Vec4 aBndMax (myCoords[3], myCoords[4], myCoords[5], 1.0f);
128 Handle(OpenGl_Group) aGroup = Handle(OpenGl_Group)::DownCast (thePrs->NewGroup());
129 aGroup->SetMinMaxValues (aBndMin.x(), aBndMin.y(), aBndMin.z(),
130 aBndMax.x(), aBndMax.y(), aBndMax.z());
131 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
132 VUserDrawObj::Element* anElem = new VUserDrawObj::Element (this);
133 aGroup->AddElement(anElem);
135 // invalidate bounding box of the scene
136 thePrsMgr->StructureManager()->Update();
139 void VUserDrawObj::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
140 const Standard_Integer /*theMode*/)
142 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
143 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 5);
144 aPnts->SetValue(1, gp_Pnt(myCoords[0], myCoords[1], myCoords[2]));
145 aPnts->SetValue(2, gp_Pnt(myCoords[3], myCoords[4], myCoords[2]));
146 aPnts->SetValue(3, gp_Pnt(myCoords[3], myCoords[4], myCoords[5]));
147 aPnts->SetValue(4, gp_Pnt(myCoords[0], myCoords[1], myCoords[5]));
148 aPnts->SetValue(5, gp_Pnt(myCoords[0], myCoords[1], myCoords[2]));
149 Handle(Select3D_SensitiveCurve) aSensitive = new Select3D_SensitiveCurve(anEntityOwner, aPnts);
150 theSelection->Add(aSensitive);
153 void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
155 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
157 // To test linking against OpenGl_Workspace and all aspect classes
158 const OpenGl_Aspects* aMA = theWorkspace->Aspects();
159 aMA->Aspect()->MarkerType();
160 OpenGl_Vec4 aColor = theWorkspace->InteriorColor();
162 aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), Aspect_TOL_SOLID,
163 Graphic3d_TOSM_UNLIT, Graphic3d_AlphaMode_Opaque, false,
164 Handle(OpenGl_ShaderProgram)());
165 aCtx->SetColor4fv (aColor);
167 const OpenGl_Vec3 aVertArray[4] =
169 OpenGl_Vec3(myCoords[0], myCoords[1], myCoords[2]),
170 OpenGl_Vec3(myCoords[3], myCoords[4], myCoords[2]),
171 OpenGl_Vec3(myCoords[3], myCoords[4], myCoords[5]),
172 OpenGl_Vec3(myCoords[0], myCoords[1], myCoords[5]),
174 Handle(OpenGl_VertexBuffer) aVertBuffer = new OpenGl_VertexBuffer();
175 aVertBuffer->Init (aCtx, 3, 4, aVertArray[0].GetData());
177 // Finally draw something to make sure UserDraw really works
178 aVertBuffer->BindAttribute (aCtx, Graphic3d_TOA_POS);
179 glDrawArrays(GL_LINE_LOOP, 0, aVertBuffer->GetElemsNb());
180 aVertBuffer->UnbindAttribute(aCtx, Graphic3d_TOA_POS);
181 aVertBuffer->Release (aCtx.get());
184 } // end of anonymous namespace
186 static Standard_Integer VUserDraw (Draw_Interpretor& di,
187 Standard_Integer argc,
190 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
191 if (aContext.IsNull())
193 di << argv[0] << "Call 'vinit' before!\n";
197 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
198 if (aDriver.IsNull())
200 std::cerr << "Graphic driver not available.\n";
206 di << argv[0] << "Wrong number of arguments, only the object name expected\n";
210 TCollection_AsciiString aName (argv[1]);
211 VDisplayAISObject(aName, Handle(AIS_InteractiveObject)());
213 Handle(VUserDrawObj) anIObj = new VUserDrawObj();
214 VDisplayAISObject(aName, anIObj);
219 //==============================================================================
220 //function : VFeedback
222 //==============================================================================
224 static int VFeedback (Draw_Interpretor& theDI,
225 Standard_Integer /*theArgNb*/,
226 const char** /*theArgVec*/)
228 #if !defined(GL_ES_VERSION_2_0)
229 // get the active view
230 Handle(V3d_View) aView = ViewerTest::CurrentView();
233 std::cerr << "No active view. Please call vinit.\n";
237 unsigned int aBufferSize = 1024 * 1024;
240 size_t aBytes = (size_t )aBufferSize * sizeof(GLfloat);
241 if (aBytes / sizeof(GLfloat) != (size_t )aBufferSize)
243 // finito la commedia
244 std::cerr << "Can not allocate buffer - requested size ("
245 << (double(aBufferSize / (1024 * 1024)) * double(sizeof(GLfloat)))
246 << " MiB) is out of address space\n";
250 GLfloat* aBuffer = (GLfloat* )Standard::Allocate (aBytes);
253 // finito la commedia
254 std::cerr << "Can not allocate buffer with size ("
255 << (double(aBufferSize / (1024 * 1024)) * double(sizeof(GLfloat)))
260 glFeedbackBuffer ((GLsizei )aBufferSize, GL_2D, aBuffer);
261 glRenderMode (GL_FEEDBACK);
265 GLint aResult = glRenderMode (GL_RENDER);
270 void* aPtr = aBuffer;
271 Standard::Free (aPtr);
276 std::cout << "FeedBack result= " << aResult << "\n";
283 GLint aBitmapsNb = 0;
284 GLint aPassThrNb = 0;
285 GLint aUnknownNb = 0;
286 const GLint NODE_VALUES = 2; // GL_2D
287 for (GLint anIter = 0; anIter < aResult;)
289 const GLfloat aPos = aBuffer[anIter];
290 switch ((GLint )aPos)
296 anIter += 1 + NODE_VALUES;
299 case GL_LINE_RESET_TOKEN:
304 anIter += 1 + 2 * NODE_VALUES;
307 case GL_POLYGON_TOKEN:
309 const GLint aCount = (GLint )aBuffer[++anIter];
311 anIter += aCount * NODE_VALUES + 1;
316 else if (aCount == 4)
326 case GL_BITMAP_TOKEN:
327 case GL_DRAW_PIXEL_TOKEN:
328 case GL_COPY_PIXEL_TOKEN:
331 anIter += 1 + NODE_VALUES;
334 case GL_PASS_THROUGH_TOKEN:
337 anIter += 2; // header + value
348 void* aPtr = aBuffer;
349 Standard::Free (aPtr);
352 theDI << "Total nodes: " << aNodesNb << "\n"
353 << "Points: " << aPntNb << "\n"
354 << "Line segments: " << aLinesNb << "\n"
355 << "Triangles: " << aTriNb << "\n"
356 << "Quads: " << aQuadsNb << "\n"
357 << "Polygons: " << aPolyNb << "\n"
358 << "Bitmap tokens: " << aBitmapsNb << "\n"
359 << "Pass through: " << aPassThrNb << "\n"
360 << "UNKNOWN: " << aUnknownNb << "\n";
362 double aLen2D = double(aNodesNb * 2 + aPntNb + aLinesNb * 2 + (aTriNb + aQuadsNb + aPolyNb) * 2 + aBitmapsNb + aPassThrNb);
363 double aLen3D = double(aNodesNb * 3 + aPntNb + aLinesNb * 2 + (aTriNb + aQuadsNb + aPolyNb) * 2 + aBitmapsNb + aPassThrNb);
364 double aLen3D_rgba = double(aNodesNb * 7 + aPntNb + aLinesNb * 2 + (aTriNb + aQuadsNb + aPolyNb) * 2 + aBitmapsNb + aPassThrNb);
365 theDI << "Buffer size GL_2D: " << aLen2D * double(sizeof(GLfloat)) / double(1024 * 1024) << " MiB\n"
366 << "Buffer size GL_3D: " << aLen3D * double(sizeof(GLfloat)) / double(1024 * 1024) << " MiB\n"
367 << "Buffer size GL_3D_COLOR: " << aLen3D_rgba * double(sizeof(GLfloat)) / double(1024 * 1024) << " MiB\n";
372 std::cout << "Command is unsupported on current platform.\n";
377 //==============================================================================
378 //function : VImmediateFront
380 //==============================================================================
382 static int VImmediateFront (Draw_Interpretor& /*theDI*/,
383 Standard_Integer theArgNb,
384 const char** theArgVec)
387 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
388 if (aContextAIS.IsNull())
390 std::cerr << "No active view. Please call vinit.\n";
394 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
396 if (aDriver.IsNull())
398 std::cerr << "Graphic driver not available.\n";
404 std::cerr << "Wrong number of arguments.\n";
408 ViewerTest::CurrentView()->View()->SetImmediateModeDrawToFront (atoi(theArgVec[1]) != 0);
413 //! Search the info from the key.
414 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
415 const TCollection_AsciiString& theKey)
417 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
419 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
421 return anIter.Value();
424 return TCollection_AsciiString();
427 //==============================================================================
430 //==============================================================================
432 static int VGlInfo (Draw_Interpretor& theDI,
433 Standard_Integer theArgNb,
434 const char** theArgVec)
436 // get the active view
437 Handle(V3d_View) aView = ViewerTest::CurrentView();
440 std::cerr << "No active view. Please call vinit.\n";
444 Standard_Integer anArgIter = 1;
445 Graphic3d_DiagnosticInfo anInfoLevel = Graphic3d_DiagnosticInfo_Basic;
448 TCollection_AsciiString aName (theArgVec[1]);
450 if (aName == "-short")
453 anInfoLevel = Graphic3d_DiagnosticInfo_Short;
455 else if (aName == "-basic")
458 anInfoLevel = Graphic3d_DiagnosticInfo_Basic;
460 else if (aName == "-complete"
464 anInfoLevel = Graphic3d_DiagnosticInfo_Complete;
468 TColStd_IndexedDataMapOfStringString aDict;
469 if (anArgIter >= theArgNb)
471 aView->DiagnosticInformation (aDict, anInfoLevel);
472 TCollection_AsciiString aText;
473 for (TColStd_IndexedDataMapOfStringString::Iterator aValueIter (aDict); aValueIter.More(); aValueIter.Next())
475 if (!aText.IsEmpty())
479 aText += TCollection_AsciiString(" ") + aValueIter.Key() + ": " + aValueIter.Value();
482 theDI << "OpenGL info:\n"
487 const Standard_Boolean isList = theArgNb >= 3;
488 aView->DiagnosticInformation (aDict, Graphic3d_DiagnosticInfo_Complete);
489 for (; anArgIter < theArgNb; ++anArgIter)
491 TCollection_AsciiString aName (theArgVec[anArgIter]);
493 TCollection_AsciiString aValue;
494 if (aName.Search ("VENDOR") != -1)
496 aValue = searchInfo (aDict, "GLvendor");
498 else if (aName.Search ("RENDERER") != -1)
500 aValue = searchInfo (aDict, "GLdevice");
502 else if (aName.Search ("SHADING_LANGUAGE_VERSION") != -1
503 || aName.Search ("GLSL") != -1)
505 aValue = searchInfo (aDict, "GLSLversion");
507 else if (aName.Search ("VERSION") != -1)
509 aValue = searchInfo (aDict, "GLversion");
511 else if (aName.Search ("EXTENSIONS") != -1)
513 aValue = searchInfo (aDict, "GLextensions");
517 std::cerr << "Unknown key '" << aName.ToCString() << "'\n";
523 theDI << "{" << aValue << "} ";
534 //! Parse shader type argument.
535 static bool parseShaderTypeArg (Graphic3d_TypeOfShaderObject& theType,
536 const TCollection_AsciiString& theArg)
538 if (theArg == "-vertex"
539 || theArg == "-vert")
541 theType = Graphic3d_TOS_VERTEX;
543 else if (theArg == "-tessevaluation"
544 || theArg == "-tesseval"
545 || theArg == "-evaluation"
546 || theArg == "-eval")
548 theType = Graphic3d_TOS_TESS_EVALUATION;
550 else if (theArg == "-tesscontrol"
551 || theArg == "-tessctrl"
552 || theArg == "-control"
553 || theArg == "-ctrl")
555 theType = Graphic3d_TOS_TESS_CONTROL;
557 else if (theArg == "-geometry"
558 || theArg == "-geom")
560 theType = Graphic3d_TOS_GEOMETRY;
562 else if (theArg == "-fragment"
563 || theArg == "-frag")
565 theType = Graphic3d_TOS_FRAGMENT;
567 else if (theArg == "-compute"
568 || theArg == "-comp")
570 theType = Graphic3d_TOS_COMPUTE;
579 //==============================================================================
580 //function : VShaderProg
581 //purpose : Sets the pair of vertex and fragment shaders for the object
582 //==============================================================================
583 static Standard_Integer VShaderProg (Draw_Interpretor& theDI,
584 Standard_Integer theArgNb,
585 const char** theArgVec)
587 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
590 std::cout << "Error: no active view.\n";
593 else if (theArgNb < 2)
595 std::cout << "Syntax error: lack of arguments\n";
599 bool isExplicitShaderType = false;
600 Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();
601 NCollection_Sequence<Handle(AIS_InteractiveObject)> aPrsList;
602 Graphic3d_GroupAspect aGroupAspect = Graphic3d_ASPECT_FILL_AREA;
603 bool isSetGroupAspect = false;
604 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
606 TCollection_AsciiString anArg (theArgVec[anArgIter]);
608 Graphic3d_TypeOfShaderObject aShaderTypeArg = Graphic3d_TypeOfShaderObject(-1);
610 || ((anArg == "-update"
613 || anArg == "-reload"
615 && anArgIter + 1 < theArgNb))
617 Handle(OpenGl_Context) aGlCtx;
618 if (Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aCtx->CurrentViewer()->Driver()))
620 aGlCtx = aDriver->GetSharedContext();
624 std::cout << "Error: no OpenGl_Context\n";
628 if (anArg == "-list")
630 for (OpenGl_Context::OpenGl_ResourcesMap::Iterator aResIter (aGlCtx->SharedResources()); aResIter.More(); aResIter.Next())
632 if (Handle(OpenGl_ShaderProgram) aResProg = Handle(OpenGl_ShaderProgram)::DownCast (aResIter.Value()))
634 theDI << aResProg->ResourceId() << " ";
640 TCollection_AsciiString aShaderName = theArgVec[++anArgIter];
641 Handle(OpenGl_ShaderProgram) aResProg;
642 if (!aGlCtx->GetResource (aShaderName, aResProg))
644 std::cout << "Syntax error: shader resource '" << aShaderName << "' is not found\n";
647 if (aResProg->UpdateDebugDump (aGlCtx, "", false, anArg == "-dump"))
649 aCtx->UpdateCurrentViewer();
652 if (anArgIter + 1 < theArgNb)
654 std::cout << "Syntax error: wrong number of arguments\n";
659 else if (!aProgram.IsNull()
660 && aProgram->ShaderObjects().IsEmpty()
666 else if (!aProgram.IsNull()
667 && aProgram->ShaderObjects().IsEmpty()
668 && (anArg == "-phong"
669 || anArg == "phong"))
671 const TCollection_AsciiString& aShadersRoot = Graphic3d_ShaderProgram::ShadersFolder();
672 if (aShadersRoot.IsEmpty())
674 std::cout << "Error: both environment variables CSF_ShadersDirectory and CASROOT are undefined!\n"
675 "At least one should be defined to load Phong program.\n";
679 const TCollection_AsciiString aSrcVert = aShadersRoot + "/PhongShading.vs";
680 const TCollection_AsciiString aSrcFrag = aShadersRoot + "/PhongShading.fs";
681 if (!aSrcVert.IsEmpty()
682 && !OSD_File (aSrcVert).Exists())
684 std::cout << "Error: PhongShading.vs is not found\n";
687 if (!aSrcFrag.IsEmpty()
688 && !OSD_File (aSrcFrag).Exists())
690 std::cout << "Error: PhongShading.fs is not found\n";
694 aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aSrcVert));
695 aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, aSrcFrag));
697 else if (aPrsList.IsEmpty()
702 else if (!isSetGroupAspect
703 && anArgIter + 1 < theArgNb
704 && (anArg == "-primtype"
705 || anArg == "-primitivetype"
706 || anArg == "-groupaspect"
707 || anArg == "-aspecttype"
708 || anArg == "-aspect"))
710 isSetGroupAspect = true;
711 TCollection_AsciiString aPrimTypeStr (theArgVec[++anArgIter]);
712 aPrimTypeStr.LowerCase();
713 if (aPrimTypeStr == "line")
715 aGroupAspect = Graphic3d_ASPECT_LINE;
717 else if (aPrimTypeStr == "tris"
718 || aPrimTypeStr == "triangles"
719 || aPrimTypeStr == "fill"
720 || aPrimTypeStr == "fillarea"
721 || aPrimTypeStr == "shading"
722 || aPrimTypeStr == "shade")
724 aGroupAspect = Graphic3d_ASPECT_FILL_AREA;
726 else if (aPrimTypeStr == "text")
728 aGroupAspect = Graphic3d_ASPECT_TEXT;
730 else if (aPrimTypeStr == "marker"
731 || aPrimTypeStr == "point"
732 || aPrimTypeStr == "pnt")
734 aGroupAspect = Graphic3d_ASPECT_MARKER;
738 std::cerr << "Syntax error at '" << aPrimTypeStr << "'\n";
742 else if (anArgIter + 1 < theArgNb
743 && !aProgram.IsNull()
744 && aProgram->Header().IsEmpty()
745 && (anArg == "-version"
746 || anArg == "-glslversion"
747 || anArg == "-header"
748 || anArg == "-glslheader"))
750 TCollection_AsciiString aHeader (theArgVec[++anArgIter]);
751 if (aHeader.IsIntegerValue())
753 aHeader = TCollection_AsciiString ("#version ") + aHeader;
755 aProgram->SetHeader (aHeader);
757 else if (!anArg.StartsWith ("-")
758 && GetMapOfAIS().IsBound2 (theArgVec[anArgIter]))
760 Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (theArgVec[anArgIter]);
763 std::cerr << "Syntax error: " << theArgVec[anArgIter] << " is not an AIS object\n";
766 aPrsList.Append (anIO);
768 else if (!aProgram.IsNull()
769 && ((anArgIter + 1 < theArgNb && parseShaderTypeArg (aShaderTypeArg, anArg))
770 || (!isExplicitShaderType && aProgram->ShaderObjects().Size() < 2)))
772 TCollection_AsciiString aShaderPath (theArgVec[anArgIter]);
773 if (aShaderTypeArg != Graphic3d_TypeOfShaderObject(-1))
775 aShaderPath = (theArgVec[++anArgIter]);
776 isExplicitShaderType = true;
779 const bool isSrcFile = OSD_File (aShaderPath).Exists();
780 Handle(Graphic3d_ShaderObject) aShader = isSrcFile
781 ? Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aShaderPath)
782 : Graphic3d_ShaderObject::CreateFromSource(Graphic3d_TOS_VERTEX, aShaderPath);
783 const TCollection_AsciiString& aShaderSrc = aShader->Source();
785 const bool hasVertPos = aShaderSrc.Search ("gl_Position") != -1;
786 const bool hasFragColor = aShaderSrc.Search ("occSetFragColor") != -1
787 || aShaderSrc.Search ("occFragColor") != -1
788 || aShaderSrc.Search ("gl_FragColor") != -1
789 || aShaderSrc.Search ("gl_FragData") != -1;
790 Graphic3d_TypeOfShaderObject aShaderType = aShaderTypeArg;
791 if (aShaderType == Graphic3d_TypeOfShaderObject(-1))
796 aShaderType = Graphic3d_TOS_VERTEX;
801 aShaderType = Graphic3d_TOS_FRAGMENT;
804 if (aShaderType == Graphic3d_TypeOfShaderObject(-1))
806 std::cerr << "Error: non-existing or invalid shader source\n";
810 aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromSource (aShaderType, aShaderSrc));
814 std::cerr << "Syntax error at '" << anArg << "'\n";
819 if (!aProgram.IsNull()
820 && ViewerTest::CurrentView()->RenderingParams().TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
822 aProgram->SetNbFragmentOutputs (2);
823 aProgram->SetWeightOitOutput (true);
826 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aGlobalPrsIter (GetMapOfAIS());
827 NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator aPrsIter (aPrsList);
828 const bool isGlobalList = aPrsList.IsEmpty();
831 Handle(AIS_InteractiveObject) anIO;
834 if (!aGlobalPrsIter.More())
838 anIO = aGlobalPrsIter.Key1();
839 aGlobalPrsIter.Next();
847 if (!aPrsIter.More())
851 anIO = aPrsIter.Value();
855 if (anIO->Attributes()->SetShaderProgram (aProgram, aGroupAspect, true))
857 aCtx->Redisplay (anIO, Standard_False);
861 anIO->SynchronizeAspects();
865 aCtx->UpdateCurrentViewer();
869 //=======================================================================
870 //function : OpenGlCommands
872 //=======================================================================
874 void ViewerTest::OpenGlCommands(Draw_Interpretor& theCommands)
876 const char* aGroup ="Commands for low-level TKOpenGl features";
878 theCommands.Add("vuserdraw",
879 "vuserdraw : name - simulates drawing with help of UserDraw",
880 __FILE__, VUserDraw, aGroup);
881 theCommands.Add("vfeedback",
882 "vfeedback : perform test GL feedback rendering",
883 __FILE__, VFeedback, aGroup);
884 theCommands.Add("vimmediatefront",
885 "vimmediatefront : render immediate mode to front buffer or to back buffer",
886 __FILE__, VImmediateFront, aGroup);
887 theCommands.Add("vglinfo",
888 "vglinfo [-short|-basic|-complete]"
889 "\n\t\t: [GL_VENDOR] [GL_RENDERER] [GL_VERSION]"
890 "\n\t\t: [GL_SHADING_LANGUAGE_VERSION] [GL_EXTENSIONS]"
891 "\n\t\t: print OpenGL info",
892 __FILE__, VGlInfo, aGroup);
893 theCommands.Add("vshader",
894 "vshader name -vert VertexShader -frag FragmentShader [-geom GeometryShader]"
895 "\n\t\t: [-off] [-phong] [-aspect {shading|line|point|text}=shading]"
896 "\n\t\t: [-header VersionHeader]"
897 "\n\t\t: [-tessControl TessControlShader -tesseval TessEvaluationShader]"
898 "\n\t\t: Assign custom GLSL program to presentation aspects."
899 "\nvshader [-list] [-dump] [-reload] ShaderId"
900 "\n\t\t: -list prints the list of registered GLSL programs"
901 "\n\t\t: -dump dumps specified GLSL program (for debugging)"
902 "\n\t\t: -reload restores dump of specified GLSL program",
903 __FILE__, VShaderProg, aGroup);
904 theCommands.Add("vshaderprog", "Alias for vshader", __FILE__, VShaderProg, aGroup);