6aca4d39 |
1 | // Created on: 2012-04-09 |
3946774d |
2 | // Created by: Sergey ANIKIN |
6aca4d39 |
3 | // Copyright (c) 2012-2014 OPEN CASCADE SAS |
3946774d |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
3946774d |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
3946774d |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
3946774d |
15 | |
3946774d |
16 | #include <ViewerTest.hxx> |
17 | |
5e27df78 |
18 | #include <AIS_InteractiveContext.hxx> |
3946774d |
19 | #include <AIS_InteractiveObject.hxx> |
20 | #include <Draw.hxx> |
21 | #include <Draw_Interpretor.hxx> |
22 | #include <Graphic3d_Group.hxx> |
392ac980 |
23 | #include <Graphic3d_ShaderObject.hxx> |
24 | #include <Graphic3d_ShaderProgram.hxx> |
3946774d |
25 | #include <OpenGl_AspectFace.hxx> |
26 | #include <OpenGl_AspectLine.hxx> |
27 | #include <OpenGl_AspectMarker.hxx> |
28 | #include <OpenGl_AspectText.hxx> |
3946774d |
29 | #include <OpenGl_Context.hxx> |
30 | #include <OpenGl_Element.hxx> |
3946774d |
31 | #include <OpenGl_GlCore20.hxx> |
5e27df78 |
32 | #include <OpenGl_GraphicDriver.hxx> |
3946774d |
33 | #include <OpenGl_Workspace.hxx> |
392ac980 |
34 | #include <OSD_Environment.hxx> |
35 | #include <OSD_File.hxx> |
6262338c |
36 | #include <Prs3d_Drawer.hxx> |
3946774d |
37 | #include <Prs3d_Presentation.hxx> |
38 | #include <Prs3d_Root.hxx> |
2831708b |
39 | #include <Prs3d_LineAspect.hxx> |
392ac980 |
40 | #include <Prs3d_ShadingAspect.hxx> |
3946774d |
41 | #include <Select3D_SensitiveCurve.hxx> |
42 | #include <SelectMgr_EntityOwner.hxx> |
43 | #include <SelectMgr_Selection.hxx> |
44 | #include <TCollection_AsciiString.hxx> |
3c4153af |
45 | #include <V3d_View.hxx> |
392ac980 |
46 | #include <V3d_Viewer.hxx> |
392ac980 |
47 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
48 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
92efcf78 |
49 | #include <OpenGl_Group.hxx> |
3946774d |
50 | |
51 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
52 | const Handle(AIS_InteractiveObject)& theAISObj, |
53 | Standard_Boolean theReplaceIfExists = Standard_True); |
392ac980 |
54 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
3946774d |
55 | |
c04c30b3 |
56 | namespace { |
57 | |
3946774d |
58 | //======================================================================= |
59 | //function : VUserDraw |
60 | //purpose : Checks availability and operation of UserDraw feature |
61 | //======================================================================= |
3946774d |
62 | |
63 | class VUserDrawObj : public AIS_InteractiveObject |
64 | { |
65 | public: |
66 | // CASCADE RTTI |
92efcf78 |
67 | DEFINE_STANDARD_RTTI_INLINE(VUserDrawObj,AIS_InteractiveObject); |
3946774d |
68 | |
69 | VUserDrawObj() |
70 | { |
71 | myCoords[0] = -10.; |
72 | myCoords[1] = -20.; |
73 | myCoords[2] = -30.; |
74 | myCoords[3] = 10.; |
75 | myCoords[4] = 20.; |
76 | myCoords[5] = 30.; |
77 | } |
78 | |
79 | public: |
80 | class Element : public OpenGl_Element |
81 | { |
82 | private: |
83 | Handle(VUserDrawObj) myIObj; |
84 | |
85 | public: |
a521d90d |
86 | Element (const Handle(VUserDrawObj)& theIObj) : myIObj (theIObj) {} |
3946774d |
87 | |
a521d90d |
88 | virtual ~Element() {} |
3946774d |
89 | |
90 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const |
91 | { |
92 | if (!myIObj.IsNull()) |
93 | myIObj->Render(theWorkspace); |
94 | } |
95 | |
10b9c7df |
96 | virtual void Release (OpenGl_Context*) |
5e27df78 |
97 | { |
98 | // |
99 | } |
100 | |
3946774d |
101 | public: |
102 | DEFINE_STANDARD_ALLOC |
103 | }; |
104 | |
105 | private: |
106 | // Virtual methods implementation |
107 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, |
108 | const Handle(Prs3d_Presentation)& thePresentation, |
79104795 |
109 | const Standard_Integer theMode) Standard_OVERRIDE; |
3946774d |
110 | |
111 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
79104795 |
112 | const Standard_Integer theMode) Standard_OVERRIDE; |
3946774d |
113 | |
114 | // Called by VUserDrawElement |
115 | void Render(const Handle(OpenGl_Workspace)& theWorkspace) const; |
3946774d |
116 | |
a521d90d |
117 | private: |
3946774d |
118 | GLfloat myCoords[6]; |
3946774d |
119 | friend class Element; |
120 | }; |
ec357c5c |
121 | |
a521d90d |
122 | void VUserDrawObj::Compute(const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
123 | const Handle(Prs3d_Presentation)& thePrs, |
35e08fe8 |
124 | const Standard_Integer /*theMode*/) |
3946774d |
125 | { |
a521d90d |
126 | thePrs->Clear(); |
127 | |
128 | Graphic3d_Vec4 aBndMin (myCoords[0], myCoords[1], myCoords[2], 1.0f); |
129 | Graphic3d_Vec4 aBndMax (myCoords[3], myCoords[4], myCoords[5], 1.0f); |
130 | Handle(OpenGl_Group) aGroup = Handle(OpenGl_Group)::DownCast (thePrs->NewGroup()); |
131 | aGroup->SetMinMaxValues (aBndMin.x(), aBndMin.y(), aBndMin.z(), |
132 | aBndMax.x(), aBndMax.y(), aBndMax.z()); |
2831708b |
133 | aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); |
a521d90d |
134 | VUserDrawObj::Element* anElem = new VUserDrawObj::Element (this); |
135 | aGroup->AddElement(anElem); |
136 | |
137 | // invalidate bounding box of the scene |
138 | thePrsMgr->StructureManager()->Update (thePrsMgr->StructureManager()->UpdateMode()); |
3946774d |
139 | } |
140 | |
141 | void VUserDrawObj::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
35e08fe8 |
142 | const Standard_Integer /*theMode*/) |
3946774d |
143 | { |
144 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); |
145 | Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 5); |
146 | aPnts->SetValue(1, gp_Pnt(myCoords[0], myCoords[1], myCoords[2])); |
147 | aPnts->SetValue(2, gp_Pnt(myCoords[3], myCoords[4], myCoords[2])); |
148 | aPnts->SetValue(3, gp_Pnt(myCoords[3], myCoords[4], myCoords[5])); |
149 | aPnts->SetValue(4, gp_Pnt(myCoords[0], myCoords[1], myCoords[5])); |
150 | aPnts->SetValue(5, gp_Pnt(myCoords[0], myCoords[1], myCoords[2])); |
151 | Handle(Select3D_SensitiveCurve) aSensitive = new Select3D_SensitiveCurve(anEntityOwner, aPnts); |
152 | theSelection->Add(aSensitive); |
153 | } |
154 | |
3946774d |
155 | void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const |
156 | { |
a521d90d |
157 | // this sample does not use GLSL programs - make sure it is disabled |
158 | Handle(OpenGl_Context) aCtx = theWorkspace->GetGlContext(); |
159 | aCtx->BindProgram (NULL); |
160 | |
3946774d |
161 | // To test linking against OpenGl_Workspace and all aspect classes |
f9ba5c4d |
162 | const OpenGl_AspectMarker* aMA = theWorkspace->AspectMarker(); |
b6472664 |
163 | aMA->Aspect()->Type(); |
f9ba5c4d |
164 | const OpenGl_AspectText* aTA = theWorkspace->AspectText(); |
b6472664 |
165 | aTA->Aspect()->Font(); |
166 | OpenGl_Vec4 aColor = theWorkspace->LineColor(); |
3946774d |
167 | |
1ce0716b |
168 | #if !defined(GL_ES_VERSION_2_0) |
3946774d |
169 | // Finally draw something to make sure UserDraw really works |
170 | glPushAttrib(GL_ENABLE_BIT); |
171 | glDisable(GL_LIGHTING); |
b6472664 |
172 | glColor4fv(aColor.GetData()); |
3946774d |
173 | glBegin(GL_LINE_LOOP); |
174 | glVertex3f(myCoords[0], myCoords[1], myCoords[2]); |
175 | glVertex3f(myCoords[3], myCoords[4], myCoords[2]); |
176 | glVertex3f(myCoords[3], myCoords[4], myCoords[5]); |
177 | glVertex3f(myCoords[0], myCoords[1], myCoords[5]); |
178 | glEnd(); |
179 | glPopAttrib(); |
1ce0716b |
180 | #endif |
3946774d |
181 | } |
182 | |
c04c30b3 |
183 | } // end of anonymous namespace |
184 | |
3946774d |
185 | static Standard_Integer VUserDraw (Draw_Interpretor& di, |
186 | Standard_Integer argc, |
187 | const char ** argv) |
188 | { |
189 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
190 | if (aContext.IsNull()) |
191 | { |
192 | di << argv[0] << "Call 'vinit' before!\n"; |
193 | return 1; |
194 | } |
195 | |
dc3fe572 |
196 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
5e27df78 |
197 | if (aDriver.IsNull()) |
198 | { |
199 | std::cerr << "Graphic driver not available.\n"; |
200 | return 1; |
201 | } |
202 | |
3946774d |
203 | if (argc > 2) |
204 | { |
205 | di << argv[0] << "Wrong number of arguments, only the object name expected\n"; |
206 | return 1; |
207 | } |
208 | |
209 | TCollection_AsciiString aName (argv[1]); |
210 | VDisplayAISObject(aName, Handle(AIS_InteractiveObject)()); |
211 | |
3946774d |
212 | Handle(VUserDrawObj) anIObj = new VUserDrawObj(); |
213 | VDisplayAISObject(aName, anIObj); |
214 | |
215 | return 0; |
216 | } |
217 | |
3c4153af |
218 | //============================================================================== |
219 | //function : VFeedback |
220 | //purpose : |
221 | //============================================================================== |
222 | |
223 | static int VFeedback (Draw_Interpretor& theDI, |
35e08fe8 |
224 | Standard_Integer /*theArgNb*/, |
225 | const char** /*theArgVec*/) |
3c4153af |
226 | { |
1ce0716b |
227 | #if !defined(GL_ES_VERSION_2_0) |
3c4153af |
228 | // get the active view |
229 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
230 | if (aView.IsNull()) |
231 | { |
232 | std::cerr << "No active view. Please call vinit.\n"; |
233 | return 1; |
234 | } |
235 | |
236 | unsigned int aBufferSize = 1024 * 1024; |
237 | for (;;) |
238 | { |
239 | size_t aBytes = (size_t )aBufferSize * sizeof(GLfloat); |
240 | if (aBytes / sizeof(GLfloat) != (size_t )aBufferSize) |
241 | { |
242 | // finito la commedia |
243 | std::cerr << "Can not allocate buffer - requested size (" |
244 | << (double(aBufferSize / (1024 * 1024)) * double(sizeof(GLfloat))) |
245 | << " MiB) is out of address space\n"; |
246 | return 1; |
247 | } |
248 | |
249 | GLfloat* aBuffer = (GLfloat* )Standard::Allocate (aBytes); |
250 | if (aBuffer == NULL) |
251 | { |
252 | // finito la commedia |
253 | std::cerr << "Can not allocate buffer with size (" |
254 | << (double(aBufferSize / (1024 * 1024)) * double(sizeof(GLfloat))) |
255 | << " MiB)\n"; |
256 | return 1; |
257 | } |
258 | |
259 | glFeedbackBuffer ((GLsizei )aBufferSize, GL_2D, aBuffer); |
260 | glRenderMode (GL_FEEDBACK); |
261 | |
262 | aView->Redraw(); |
263 | |
264 | GLint aResult = glRenderMode (GL_RENDER); |
265 | if (aResult < 0) |
266 | { |
267 | aBufferSize *= 2; |
268 | |
269 | void* aPtr = aBuffer; |
270 | Standard::Free (aPtr); |
271 | aBuffer = NULL; |
272 | continue; |
273 | } |
274 | |
275 | std::cout << "FeedBack result= " << aResult << "\n"; |
276 | GLint aPntNb = 0; |
277 | GLint aTriNb = 0; |
278 | GLint aQuadsNb = 0; |
279 | GLint aPolyNb = 0; |
280 | GLint aNodesNb = 0; |
281 | GLint aLinesNb = 0; |
282 | GLint aBitmapsNb = 0; |
283 | GLint aPassThrNb = 0; |
284 | GLint aUnknownNb = 0; |
285 | const GLint NODE_VALUES = 2; // GL_2D |
286 | for (GLint anIter = 0; anIter < aResult;) |
287 | { |
288 | const GLfloat aPos = aBuffer[anIter]; |
289 | switch ((GLint )aPos) |
290 | { |
291 | case GL_POINT_TOKEN: |
292 | { |
293 | ++aPntNb; |
294 | ++aNodesNb; |
295 | anIter += 1 + NODE_VALUES; |
296 | break; |
297 | } |
298 | case GL_LINE_RESET_TOKEN: |
299 | case GL_LINE_TOKEN: |
300 | { |
301 | ++aLinesNb; |
302 | aNodesNb += 2; |
303 | anIter += 1 + 2 * NODE_VALUES; |
304 | break; |
305 | } |
306 | case GL_POLYGON_TOKEN: |
307 | { |
308 | const GLint aCount = (GLint )aBuffer[++anIter]; |
309 | aNodesNb += aCount; |
310 | anIter += aCount * NODE_VALUES + 1; |
311 | if (aCount == 3) |
312 | { |
313 | ++aTriNb; |
314 | } |
315 | else if (aCount == 4) |
316 | { |
317 | ++aQuadsNb; |
318 | } |
319 | else |
320 | { |
321 | ++aPolyNb; |
322 | } |
323 | break; |
324 | } |
325 | case GL_BITMAP_TOKEN: |
326 | case GL_DRAW_PIXEL_TOKEN: |
327 | case GL_COPY_PIXEL_TOKEN: |
328 | { |
329 | ++aBitmapsNb; |
330 | anIter += 1 + NODE_VALUES; |
331 | break; |
332 | } |
333 | case GL_PASS_THROUGH_TOKEN: |
334 | { |
335 | ++aPassThrNb; |
336 | anIter += 2; // header + value |
337 | break; |
338 | } |
339 | default: |
340 | { |
341 | ++anIter; |
342 | ++aUnknownNb; |
343 | break; |
344 | } |
345 | } |
346 | } |
347 | void* aPtr = aBuffer; |
348 | Standard::Free (aPtr); |
349 | |
350 | // return statistics |
351 | theDI << "Total nodes: " << aNodesNb << "\n" |
352 | << "Points: " << aPntNb << "\n" |
353 | << "Line segments: " << aLinesNb << "\n" |
354 | << "Triangles: " << aTriNb << "\n" |
355 | << "Quads: " << aQuadsNb << "\n" |
356 | << "Polygons: " << aPolyNb << "\n" |
357 | << "Bitmap tokens: " << aBitmapsNb << "\n" |
358 | << "Pass through: " << aPassThrNb << "\n" |
359 | << "UNKNOWN: " << aUnknownNb << "\n"; |
360 | |
361 | double aLen2D = double(aNodesNb * 2 + aPntNb + aLinesNb * 2 + (aTriNb + aQuadsNb + aPolyNb) * 2 + aBitmapsNb + aPassThrNb); |
362 | double aLen3D = double(aNodesNb * 3 + aPntNb + aLinesNb * 2 + (aTriNb + aQuadsNb + aPolyNb) * 2 + aBitmapsNb + aPassThrNb); |
363 | double aLen3D_rgba = double(aNodesNb * 7 + aPntNb + aLinesNb * 2 + (aTriNb + aQuadsNb + aPolyNb) * 2 + aBitmapsNb + aPassThrNb); |
364 | theDI << "Buffer size GL_2D: " << aLen2D * double(sizeof(GLfloat)) / double(1024 * 1024) << " MiB\n" |
365 | << "Buffer size GL_3D: " << aLen3D * double(sizeof(GLfloat)) / double(1024 * 1024) << " MiB\n" |
366 | << "Buffer size GL_3D_COLOR: " << aLen3D_rgba * double(sizeof(GLfloat)) / double(1024 * 1024) << " MiB\n"; |
367 | return 0; |
368 | } |
1ce0716b |
369 | #else |
370 | (void )theDI; |
371 | std::cout << "Command is unsupported on current platform.\n"; |
372 | return 1; |
373 | #endif |
3c4153af |
374 | } |
375 | |
1981cb22 |
376 | //============================================================================== |
377 | //function : VImmediateFront |
378 | //purpose : |
379 | //============================================================================== |
380 | |
35e08fe8 |
381 | static int VImmediateFront (Draw_Interpretor& /*theDI*/, |
1981cb22 |
382 | Standard_Integer theArgNb, |
383 | const char** theArgVec) |
384 | { |
385 | // get the context |
386 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
387 | if (aContextAIS.IsNull()) |
388 | { |
389 | std::cerr << "No active view. Please call vinit.\n"; |
390 | return 1; |
391 | } |
392 | |
dc3fe572 |
393 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
394 | |
1981cb22 |
395 | if (aDriver.IsNull()) |
396 | { |
397 | std::cerr << "Graphic driver not available.\n"; |
398 | return 1; |
399 | } |
400 | |
401 | if (theArgNb < 2) |
402 | { |
1981cb22 |
403 | std::cerr << "Wrong number of arguments.\n"; |
404 | return 1; |
405 | } |
406 | |
c357e426 |
407 | ViewerTest::CurrentView()->View()->SetImmediateModeDrawToFront (atoi(theArgVec[1]) != 0); |
408 | |
1981cb22 |
409 | return 0; |
410 | } |
411 | |
26d9c835 |
412 | //! Search the info from the key. |
413 | inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict, |
414 | const TCollection_AsciiString& theKey) |
415 | { |
416 | for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next()) |
417 | { |
418 | if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False)) |
419 | { |
420 | return anIter.Value(); |
421 | } |
422 | } |
423 | return TCollection_AsciiString(); |
424 | } |
425 | |
dac04bfa |
426 | //============================================================================== |
427 | //function : VGlInfo |
428 | //purpose : |
429 | //============================================================================== |
430 | |
431 | static int VGlInfo (Draw_Interpretor& theDI, |
432 | Standard_Integer theArgNb, |
433 | const char** theArgVec) |
434 | { |
435 | // get the active view |
436 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
437 | if (aView.IsNull()) |
438 | { |
439 | std::cerr << "No active view. Please call vinit.\n"; |
440 | return 1; |
441 | } |
442 | |
26d9c835 |
443 | Standard_Integer anArgIter = 1; |
444 | Graphic3d_DiagnosticInfo anInfoLevel = Graphic3d_DiagnosticInfo_Basic; |
445 | if (theArgNb == 2) |
dac04bfa |
446 | { |
26d9c835 |
447 | TCollection_AsciiString aName (theArgVec[1]); |
448 | aName.LowerCase(); |
449 | if (aName == "-short") |
4e1523ef |
450 | { |
26d9c835 |
451 | ++anArgIter; |
452 | anInfoLevel = Graphic3d_DiagnosticInfo_Short; |
453 | } |
454 | else if (aName == "-basic") |
455 | { |
456 | ++anArgIter; |
457 | anInfoLevel = Graphic3d_DiagnosticInfo_Basic; |
4e1523ef |
458 | } |
26d9c835 |
459 | else if (aName == "-complete" |
460 | || aName == "-full") |
461 | { |
462 | ++anArgIter; |
463 | anInfoLevel = Graphic3d_DiagnosticInfo_Complete; |
464 | } |
465 | } |
466 | |
467 | TColStd_IndexedDataMapOfStringString aDict; |
468 | if (anArgIter >= theArgNb) |
469 | { |
470 | aView->DiagnosticInformation (aDict, anInfoLevel); |
471 | TCollection_AsciiString aText; |
472 | for (TColStd_IndexedDataMapOfStringString::Iterator aValueIter (aDict); aValueIter.More(); aValueIter.Next()) |
473 | { |
474 | if (!aText.IsEmpty()) |
475 | { |
476 | aText += "\n"; |
477 | } |
478 | aText += TCollection_AsciiString(" ") + aValueIter.Key() + ": " + aValueIter.Value(); |
479 | } |
480 | |
dac04bfa |
481 | theDI << "OpenGL info:\n" |
26d9c835 |
482 | << aText; |
dac04bfa |
483 | return 0; |
484 | } |
485 | |
486 | const Standard_Boolean isList = theArgNb >= 3; |
26d9c835 |
487 | aView->DiagnosticInformation (aDict, Graphic3d_DiagnosticInfo_Complete); |
488 | for (; anArgIter < theArgNb; ++anArgIter) |
dac04bfa |
489 | { |
26d9c835 |
490 | TCollection_AsciiString aName (theArgVec[anArgIter]); |
dac04bfa |
491 | aName.UpperCase(); |
26d9c835 |
492 | TCollection_AsciiString aValue; |
dac04bfa |
493 | if (aName.Search ("VENDOR") != -1) |
494 | { |
26d9c835 |
495 | aValue = searchInfo (aDict, "GLvendor"); |
dac04bfa |
496 | } |
497 | else if (aName.Search ("RENDERER") != -1) |
498 | { |
26d9c835 |
499 | aValue = searchInfo (aDict, "GLdevice"); |
dac04bfa |
500 | } |
501 | else if (aName.Search ("SHADING_LANGUAGE_VERSION") != -1 |
502 | || aName.Search ("GLSL") != -1) |
503 | { |
26d9c835 |
504 | aValue = searchInfo (aDict, "GLSLversion"); |
dac04bfa |
505 | } |
506 | else if (aName.Search ("VERSION") != -1) |
507 | { |
26d9c835 |
508 | aValue = searchInfo (aDict, "GLversion"); |
dac04bfa |
509 | } |
510 | else if (aName.Search ("EXTENSIONS") != -1) |
511 | { |
26d9c835 |
512 | aValue = searchInfo (aDict, "GLextensions"); |
dac04bfa |
513 | } |
514 | else |
515 | { |
516 | std::cerr << "Unknown key '" << aName.ToCString() << "'\n"; |
517 | return 1; |
518 | } |
519 | |
520 | if (isList) |
521 | { |
522 | theDI << "{" << aValue << "} "; |
523 | } |
524 | else |
525 | { |
526 | theDI << aValue; |
527 | } |
528 | } |
529 | |
530 | return 0; |
531 | } |
532 | |
392ac980 |
533 | |
534 | //============================================================================== |
535 | //function : VShaderProg |
536 | //purpose : Sets the pair of vertex and fragment shaders for the object |
537 | //============================================================================== |
538 | static Standard_Integer VShaderProg (Draw_Interpretor& /*theDI*/, |
539 | Standard_Integer theArgNb, |
540 | const char** theArgVec) |
541 | { |
542 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
543 | if (aCtx.IsNull()) |
544 | { |
545 | std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n"; |
546 | return 1; |
547 | } |
548 | else if (theArgNb < 2) |
549 | { |
550 | std::cerr << theArgVec[0] << " syntax error: lack of arguments\n"; |
551 | return 1; |
552 | } |
553 | |
554 | TCollection_AsciiString aLastArg (theArgVec[theArgNb - 1]); |
555 | aLastArg.UpperCase(); |
556 | const Standard_Boolean toTurnOff = aLastArg == "OFF"; |
557 | Standard_Integer anArgsNb = theArgNb - 1; |
558 | Handle(Graphic3d_ShaderProgram) aProgram; |
559 | if (!toTurnOff |
560 | && aLastArg == "PHONG") |
561 | { |
562 | aProgram = new Graphic3d_ShaderProgram (Graphic3d_ShaderProgram::ShaderName_Phong); |
563 | } |
564 | if (!toTurnOff |
565 | && aProgram.IsNull()) |
566 | { |
567 | if (theArgNb < 3) |
568 | { |
569 | std::cerr << theArgVec[0] << " syntax error: lack of arguments\n"; |
570 | return 1; |
571 | } |
572 | |
573 | const TCollection_AsciiString aSrcVert = theArgVec[theArgNb - 2]; |
574 | const TCollection_AsciiString aSrcFrag = theArgVec[theArgNb - 1]; |
575 | if (!aSrcVert.IsEmpty() |
576 | && !OSD_File (aSrcVert).Exists()) |
577 | { |
578 | std::cerr << "Non-existing vertex shader source\n"; |
579 | return 1; |
580 | } |
581 | if (!aSrcFrag.IsEmpty() |
582 | && !OSD_File (aSrcFrag).Exists()) |
583 | { |
584 | std::cerr << "Non-existing fragment shader source\n"; |
585 | return 1; |
586 | } |
587 | |
588 | aProgram = new Graphic3d_ShaderProgram(); |
589 | aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aSrcVert)); |
590 | aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, aSrcFrag)); |
591 | anArgsNb = theArgNb - 2; |
592 | } |
593 | |
594 | Handle(AIS_InteractiveObject) anIO; |
595 | if (anArgsNb <= 1 |
596 | || *theArgVec[1] == '*') |
597 | { |
598 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
599 | anIter.More(); anIter.Next()) |
600 | { |
601 | anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); |
fb66bb28 |
602 | if (anIO.IsNull()) |
392ac980 |
603 | { |
fb66bb28 |
604 | continue; |
605 | } |
606 | |
607 | if (!anIO->Attributes()->HasOwnShadingAspect()) |
608 | { |
609 | Handle(Prs3d_ShadingAspect) aNewAspect = new Prs3d_ShadingAspect(); |
610 | *aNewAspect->Aspect() = *anIO->Attributes()->ShadingAspect()->Aspect(); |
611 | aNewAspect->Aspect()->SetShaderProgram (aProgram); |
612 | anIO->Attributes()->SetShadingAspect (aNewAspect); |
392ac980 |
613 | aCtx->Redisplay (anIO, Standard_False); |
614 | } |
fb66bb28 |
615 | else |
616 | { |
617 | anIO->Attributes()->SetShaderProgram (aProgram, Graphic3d_ASPECT_FILL_AREA); |
618 | anIO->SynchronizeAspects(); |
619 | } |
392ac980 |
620 | } |
621 | aCtx->UpdateCurrentViewer(); |
622 | return 0; |
623 | } |
624 | |
625 | for (Standard_Integer anArgIter = 1; anArgIter < anArgsNb; ++anArgIter) |
626 | { |
627 | const TCollection_AsciiString aName (theArgVec[anArgIter]); |
628 | if (!GetMapOfAIS().IsBound2 (aName)) |
629 | { |
630 | std::cerr << "Warning: " << aName.ToCString() << " is not displayed\n"; |
631 | continue; |
632 | } |
633 | anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)); |
634 | if (anIO.IsNull()) |
635 | { |
636 | std::cerr << "Warning: " << aName.ToCString() << " is not an AIS object\n"; |
637 | continue; |
638 | } |
fb66bb28 |
639 | |
640 | if (!anIO->Attributes()->HasOwnShadingAspect()) |
641 | { |
642 | Handle(Prs3d_ShadingAspect) aNewAspect = new Prs3d_ShadingAspect(); |
643 | *aNewAspect->Aspect() = *anIO->Attributes()->ShadingAspect()->Aspect(); |
644 | aNewAspect->Aspect()->SetShaderProgram (aProgram); |
645 | anIO->Attributes()->SetShadingAspect (aNewAspect); |
646 | aCtx->Redisplay (anIO, Standard_False); |
647 | } |
648 | else |
649 | { |
650 | anIO->Attributes()->SetShaderProgram (aProgram, Graphic3d_ASPECT_FILL_AREA); |
651 | anIO->SynchronizeAspects(); |
652 | } |
392ac980 |
653 | } |
654 | |
655 | aCtx->UpdateCurrentViewer(); |
656 | return 0; |
657 | } |
658 | |
3946774d |
659 | //======================================================================= |
660 | //function : OpenGlCommands |
661 | //purpose : |
662 | //======================================================================= |
663 | |
664 | void ViewerTest::OpenGlCommands(Draw_Interpretor& theCommands) |
665 | { |
666 | const char* aGroup ="Commands for low-level TKOpenGl features"; |
667 | |
668 | theCommands.Add("vuserdraw", |
669 | "vuserdraw : name - simulates drawing with help of UserDraw", |
670 | __FILE__, VUserDraw, aGroup); |
3c4153af |
671 | theCommands.Add("vfeedback", |
672 | "vfeedback : perform test GL feedback rendering", |
673 | __FILE__, VFeedback, aGroup); |
1981cb22 |
674 | theCommands.Add("vimmediatefront", |
675 | "vimmediatefront : render immediate mode to front buffer or to back buffer", |
676 | __FILE__, VImmediateFront, aGroup); |
dac04bfa |
677 | theCommands.Add("vglinfo", |
26d9c835 |
678 | "vglinfo [-short|-basic|-complete]" |
679 | "\n\t\t: [GL_VENDOR] [GL_RENDERER] [GL_VERSION]" |
680 | "\n\t\t: [GL_SHADING_LANGUAGE_VERSION] [GL_EXTENSIONS]" |
681 | "\n\t\t: print OpenGL info", |
dac04bfa |
682 | __FILE__, VGlInfo, aGroup); |
392ac980 |
683 | theCommands.Add("vshaderprog", |
684 | " 'vshaderprog [name] pathToVertexShader pathToFragmentShader'" |
685 | "\n\t\t: or 'vshaderprog [name] off' to disable GLSL program" |
686 | "\n\t\t: or 'vshaderprog [name] phong' to enable per-pixel lighting calculations" |
687 | "\n\t\t: * might be used to specify all displayed objects", |
688 | __FILE__, VShaderProg, aGroup); |
3946774d |
689 | } |