0024001: Stereographic rendering support
[occt.git] / src / OpenGl / OpenGl_View_2.cxx
1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public 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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <stdio.h>
17 #include <stdlib.h>
18
19 #include <OpenGl_GlCore11.hxx>
20 #include <OpenGl_tgl_funcs.hxx>
21
22 #include <Image_AlienPixMap.hxx>
23 #include <Visual3d_Layer.hxx>
24
25 #include <NCollection_Mat4.hxx>
26
27 #include <OpenGl_AspectLine.hxx>
28 #include <OpenGl_Context.hxx>
29 #include <OpenGl_Display.hxx>
30 #include <OpenGl_Matrix.hxx>
31 #include <OpenGl_Workspace.hxx>
32 #include <OpenGl_View.hxx>
33 #include <OpenGl_Trihedron.hxx>
34 #include <OpenGl_GraduatedTrihedron.hxx>
35 #include <OpenGl_PrinterContext.hxx>
36 #include <OpenGl_ShaderManager.hxx>
37 #include <OpenGl_ShaderProgram.hxx>
38 #include <OpenGl_Structure.hxx>
39
40 #define EPSI 0.0001
41
42 namespace
43 {
44
45   static const GLfloat THE_DEFAULT_AMBIENT[4]    = { 0.0f, 0.0f, 0.0f, 1.0f };
46   static const GLfloat THE_DEFAULT_SPOT_DIR[3]   = { 0.0f, 0.0f, -1.0f };
47   static const GLfloat THE_DEFAULT_SPOT_EXPONENT = 0.0f;
48   static const GLfloat THE_DEFAULT_SPOT_CUTOFF   = 180.0f;
49
50 };
51
52 extern void InitLayerProp (const int theListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx
53
54 /*----------------------------------------------------------------------*/
55
56 struct OPENGL_CLIP_PLANE
57 {
58   GLboolean isEnabled;
59   GLdouble Equation[4];
60   DEFINE_STANDARD_ALLOC
61 };
62
63 /*----------------------------------------------------------------------*/
64 /*
65 * Fonctions privees
66 */
67
68 /*-----------------------------------------------------------------*/
69 /*
70 *  Set des lumieres
71 */
72 static void bind_light (const OpenGl_Light& theLight,
73                         GLenum&             theLightGlId,
74                         Graphic3d_Vec4&     theAmbientColor)
75 {
76   // Only 8 lights in OpenGL...
77   if (theLightGlId > GL_LIGHT7)
78   {
79     return;
80   }
81
82   if (theLight.Type == Visual3d_TOLS_AMBIENT)
83   {
84     // add RGBA intensity of the ambient light
85     theAmbientColor += theLight.Color;
86     return;
87   }
88
89   // the light is a headlight?
90   GLint aMatrixModeOld = 0;
91   if (theLight.IsHeadlight)
92   {
93     glGetIntegerv (GL_MATRIX_MODE, &aMatrixModeOld);
94     glMatrixMode  (GL_MODELVIEW);
95     glPushMatrix();
96     glLoadIdentity();
97   }
98
99   // setup light type
100   switch (theLight.Type)
101   {
102     case Visual3d_TOLS_DIRECTIONAL:
103     {
104       // if the last parameter of GL_POSITION, is zero, the corresponding light source is a Directional one
105       const OpenGl_Vec4 anInfDir = -theLight.Direction;
106
107       // to create a realistic effect,  set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE.
108       glLightfv (theLightGlId, GL_AMBIENT,               THE_DEFAULT_AMBIENT);
109       glLightfv (theLightGlId, GL_DIFFUSE,               theLight.Color.GetData());
110       glLightfv (theLightGlId, GL_SPECULAR,              theLight.Color.GetData());
111       glLightfv (theLightGlId, GL_POSITION,              anInfDir.GetData());
112       glLightfv (theLightGlId, GL_SPOT_DIRECTION,        THE_DEFAULT_SPOT_DIR);
113       glLightf  (theLightGlId, GL_SPOT_EXPONENT,         THE_DEFAULT_SPOT_EXPONENT);
114       glLightf  (theLightGlId, GL_SPOT_CUTOFF,           THE_DEFAULT_SPOT_CUTOFF);
115       break;
116     }
117     case Visual3d_TOLS_POSITIONAL:
118     {
119       // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE
120       glLightfv (theLightGlId, GL_AMBIENT,               THE_DEFAULT_AMBIENT);
121       glLightfv (theLightGlId, GL_DIFFUSE,               theLight.Color.GetData());
122       glLightfv (theLightGlId, GL_SPECULAR,              theLight.Color.GetData());
123       glLightfv (theLightGlId, GL_POSITION,              theLight.Position.GetData());
124       glLightfv (theLightGlId, GL_SPOT_DIRECTION,        THE_DEFAULT_SPOT_DIR);
125       glLightf  (theLightGlId, GL_SPOT_EXPONENT,         THE_DEFAULT_SPOT_EXPONENT);
126       glLightf  (theLightGlId, GL_SPOT_CUTOFF,           THE_DEFAULT_SPOT_CUTOFF);
127       glLightf  (theLightGlId, GL_CONSTANT_ATTENUATION,  theLight.ConstAttenuation());
128       glLightf  (theLightGlId, GL_LINEAR_ATTENUATION,    theLight.LinearAttenuation());
129       glLightf  (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0);
130       break;
131     }
132     case Visual3d_TOLS_SPOT:
133     {
134       glLightfv (theLightGlId, GL_AMBIENT,               THE_DEFAULT_AMBIENT);
135       glLightfv (theLightGlId, GL_DIFFUSE,               theLight.Color.GetData());
136       glLightfv (theLightGlId, GL_SPECULAR,              theLight.Color.GetData());
137       glLightfv (theLightGlId, GL_POSITION,              theLight.Position.GetData());
138       glLightfv (theLightGlId, GL_SPOT_DIRECTION,        theLight.Direction.GetData());
139       glLightf  (theLightGlId, GL_SPOT_EXPONENT,         theLight.Concentration() * 128.0f);
140       glLightf  (theLightGlId, GL_SPOT_CUTOFF,          (theLight.Angle() * 180.0f) / GLfloat(M_PI));
141       glLightf  (theLightGlId, GL_CONSTANT_ATTENUATION,  theLight.ConstAttenuation());
142       glLightf  (theLightGlId, GL_LINEAR_ATTENUATION,    theLight.LinearAttenuation());
143       glLightf  (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0f);
144       break;
145     }
146   }
147
148   // restore matrix in case of headlight
149   if (theLight.IsHeadlight)
150   {
151     glPopMatrix();
152     glMatrixMode (aMatrixModeOld);
153   }
154
155   glEnable (theLightGlId++);
156 }
157
158 /*----------------------------------------------------------------------*/
159
160 void OpenGl_View::DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
161 {
162   if ( (theWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) == 0 &&
163        ( myBgTexture.TexId != 0 || myBgGradient.type != Aspect_GFM_NONE ) )
164   {
165     const Standard_Integer aViewWidth = theWorkspace->Width();
166     const Standard_Integer aViewHeight = theWorkspace->Height();
167
168     glPushAttrib( GL_ENABLE_BIT | GL_TEXTURE_BIT );
169
170     glMatrixMode( GL_PROJECTION );
171     glPushMatrix();
172     glLoadIdentity();
173     glMatrixMode( GL_MODELVIEW );
174     glPushMatrix();
175     glLoadIdentity();
176
177     if ( glIsEnabled( GL_DEPTH_TEST ) )
178       glDisable( GL_DEPTH_TEST ); //push GL_ENABLE_BIT
179
180     // drawing bg gradient if:
181     // - gradient fill type is not Aspect_GFM_NONE and
182     // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode
183     if ( ( myBgGradient.type != Aspect_GFM_NONE ) &&
184       ( myBgTexture.TexId == 0 || myBgTexture.Style == Aspect_FM_CENTERED ||
185       myBgTexture.Style == Aspect_FM_NONE ) )
186     {
187       Tfloat* corner1 = 0;/* -1,-1*/
188       Tfloat* corner2 = 0;/*  1,-1*/
189       Tfloat* corner3 = 0;/*  1, 1*/
190       Tfloat* corner4 = 0;/* -1, 1*/
191       Tfloat dcorner1[3];
192       Tfloat dcorner2[3];
193
194       switch( myBgGradient.type )
195       {
196       case Aspect_GFM_HOR:
197         corner1 = myBgGradient.color1.rgb;
198         corner2 = myBgGradient.color2.rgb;
199         corner3 = myBgGradient.color2.rgb;
200         corner4 = myBgGradient.color1.rgb;
201         break;
202       case Aspect_GFM_VER:
203         corner1 = myBgGradient.color2.rgb;
204         corner2 = myBgGradient.color2.rgb;
205         corner3 = myBgGradient.color1.rgb;
206         corner4 = myBgGradient.color1.rgb;
207         break;
208       case Aspect_GFM_DIAG1:
209         corner2 = myBgGradient.color2.rgb;
210         corner4 = myBgGradient.color1.rgb;
211         dcorner1 [0] = dcorner2[0] = 0.5F * (corner2[0] + corner4[0]);
212         dcorner1 [1] = dcorner2[1] = 0.5F * (corner2[1] + corner4[1]);
213         dcorner1 [2] = dcorner2[2] = 0.5F * (corner2[2] + corner4[2]);
214         corner1 = dcorner1;
215         corner3 = dcorner2;
216         break;
217       case Aspect_GFM_DIAG2:
218         corner1 = myBgGradient.color2.rgb;
219         corner3 = myBgGradient.color1.rgb;
220         dcorner1 [0] = dcorner2[0] = 0.5F * (corner1[0] + corner3[0]);
221         dcorner1 [1] = dcorner2[1] = 0.5F * (corner1[1] + corner3[1]);
222         dcorner1 [2] = dcorner2[2] = 0.5F * (corner1[2] + corner3[2]);
223         corner2 = dcorner1;
224         corner4 = dcorner2;
225         break;
226       case Aspect_GFM_CORNER1:
227         corner1 = myBgGradient.color2.rgb;
228         corner2 = myBgGradient.color2.rgb;
229         corner3 = myBgGradient.color2.rgb;
230         corner4 = myBgGradient.color1.rgb;
231         break;
232       case Aspect_GFM_CORNER2:
233         corner1 = myBgGradient.color2.rgb;
234         corner2 = myBgGradient.color2.rgb;
235         corner3 = myBgGradient.color1.rgb;
236         corner4 = myBgGradient.color2.rgb;
237         break;
238       case Aspect_GFM_CORNER3:
239         corner1 = myBgGradient.color2.rgb;
240         corner2 = myBgGradient.color1.rgb;
241         corner3 = myBgGradient.color2.rgb;
242         corner4 = myBgGradient.color2.rgb;
243         break;
244       case Aspect_GFM_CORNER4:
245         corner1 = myBgGradient.color1.rgb;
246         corner2 = myBgGradient.color2.rgb;
247         corner3 = myBgGradient.color2.rgb;
248         corner4 = myBgGradient.color2.rgb;
249         break;
250       default:
251         //printf("gradient background type not right\n");
252         break;
253       }
254
255       // Save GL parameters
256       glDisable( GL_LIGHTING ); //push GL_ENABLE_BIT
257
258       GLint curSM;
259       glGetIntegerv( GL_SHADE_MODEL, &curSM );
260       if ( curSM != GL_SMOOTH )
261         glShadeModel( GL_SMOOTH ); //push GL_LIGHTING_BIT
262
263       glBegin(GL_TRIANGLE_FAN);
264       if( myBgGradient.type != Aspect_GFM_CORNER1 && myBgGradient.type != Aspect_GFM_CORNER3 )
265       {
266         glColor3f(corner1[0],corner1[1],corner1[2]); glVertex2f(-1.,-1.);
267         glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
268         glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
269         glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.);
270       }
271       else //if ( myBgGradient.type == Aspect_GFM_CORNER1 || myBgGradient.type == Aspect_GFM_CORNER3 )
272       {
273         glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
274         glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
275         glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.);
276         glColor3f(corner1[0],corner1[1],corner1[2]); glVertex2f(-1.,-1.);
277       }
278       glEnd();
279
280       // Restore GL parameters
281       if ( curSM != GL_SMOOTH )
282         glShadeModel( curSM );
283     }
284     // drawing bg image if:
285     // - it is defined and
286     // - fill type is not Aspect_FM_NONE
287     if ( myBgTexture.TexId != 0 && myBgTexture.Style != Aspect_FM_NONE )
288     {
289       GLfloat texX_range = 1.F; // texture <s> coordinate
290       GLfloat texY_range = 1.F; // texture <t> coordinate
291
292       // Set up for stretching or tiling
293       GLfloat x_offset, y_offset;
294       if ( myBgTexture.Style == Aspect_FM_CENTERED )
295       {
296         x_offset = (GLfloat)myBgTexture.Width / (GLfloat)aViewWidth;
297         y_offset = (GLfloat)myBgTexture.Height / (GLfloat)aViewHeight;
298       }
299       else
300       {
301         x_offset = 1.F;
302         y_offset = 1.F;
303         if ( myBgTexture.Style == Aspect_FM_TILED )
304         {
305           texX_range = (GLfloat)aViewWidth / (GLfloat)myBgTexture.Width;
306           texY_range = (GLfloat)aViewHeight / (GLfloat)myBgTexture.Height;
307         }
308       }
309
310       // OCCT issue 0023000: Improve the way the gradient and textured
311       // background is managed in 3d viewer (note 0020339)
312       // Setting this coefficient to -1.F allows to tile textures relatively
313       // to the top-left corner of the view (value 1.F corresponds to the
314       // initial behaviour - tiling from the bottom-left corner)
315       GLfloat aCoef = -1.F;
316
317       glEnable( GL_TEXTURE_2D ); //push GL_ENABLE_BIT
318       glBindTexture( GL_TEXTURE_2D, myBgTexture.TexId ); //push GL_TEXTURE_BIT
319
320       glDisable( GL_BLEND ); //push GL_ENABLE_BIT
321
322       glColor3fv (theWorkspace->BackgroundColor().rgb);
323       glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //push GL_TEXTURE_BIT
324
325       // Note that texture is mapped using GL_REPEAT wrapping mode so integer part
326       // is simply ignored, and negative multiplier is here for convenience only
327       // and does not result e.g. in texture mirroring
328       glBegin( GL_QUADS );
329       glTexCoord2f(0.F, 0.F); glVertex2f( -x_offset, -aCoef * y_offset );
330       glTexCoord2f(texX_range, 0.F); glVertex2f( x_offset, -aCoef * y_offset );
331       glTexCoord2f(texX_range, aCoef * texY_range); glVertex2f( x_offset, aCoef * y_offset );
332       glTexCoord2f(0.F, aCoef * texY_range); glVertex2f( -x_offset, aCoef * y_offset );
333       glEnd();
334     }
335
336     glPopMatrix();
337     glMatrixMode( GL_PROJECTION );
338     glPopMatrix();
339     glMatrixMode( GL_MODELVIEW );
340
341     glPopAttrib(); //GL_ENABLE_BIT | GL_TEXTURE_BIT
342
343     if (theWorkspace->UseZBuffer())
344       glEnable (GL_DEPTH_TEST);
345
346     /* GL_DITHER on/off pour le trace */
347     if (theWorkspace->Dither())
348       glEnable (GL_DITHER);
349     else
350       glDisable (GL_DITHER);
351   }
352 }
353
354 /*----------------------------------------------------------------------*/
355
356 //call_func_redraw_all_structs_proc
357 void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
358                           const Handle(OpenGl_Workspace) &theWorkspace,
359                           const Graphic3d_CView& theCView,
360                           const Aspect_CLayer2d& theCUnderLayer,
361                           const Aspect_CLayer2d& theCOverLayer)
362 {
363   // ==================================
364   //      Step 1: Prepare for redraw
365   // ==================================
366
367   const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
368
369   // Store and disable current clipping planes
370   Standard_Integer aMaxPlanes = aContext->MaxClipPlanes();
371
372   OPENGL_CLIP_PLANE *aOldPlanes = new OPENGL_CLIP_PLANE[aMaxPlanes];
373   OPENGL_CLIP_PLANE *aPtrPlane = aOldPlanes;
374
375   GLenum aClipPlaneId = GL_CLIP_PLANE0;
376   const GLenum aClipLastId = GL_CLIP_PLANE0 + aMaxPlanes;
377   for (; aClipPlaneId < aClipLastId; aClipPlaneId++, aPtrPlane++)
378   {
379     glGetClipPlane (aClipPlaneId, aPtrPlane->Equation);
380     if (aPtrPlane->isEnabled)
381     {
382       glDisable (aClipPlaneId);
383       aPtrPlane->isEnabled = GL_TRUE;
384     }
385     else
386     {
387       aPtrPlane->isEnabled = GL_FALSE;
388     }
389   }
390
391   // Set OCCT state uniform variables
392   const Handle(OpenGl_ShaderManager) aManager = aContext->ShaderManager();
393   if (!aManager->IsEmpty())
394   {
395     if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState)
396     {
397       aManager->UpdateLightSourceStateTo (&myLights);
398       myLastLightSourceState = StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index());
399     }
400
401     if (myProjectionState != myCamera->ProjectionState())
402     {
403       myProjectionState = myCamera->ProjectionState();
404       aManager->UpdateProjectionStateTo ((const Tmatrix3*)myCamera->ProjectionMatrix().GetData());
405     }
406
407     if (myModelViewState != myCamera->ModelViewState())
408     {
409       myModelViewState = myCamera->ModelViewState();
410       aManager->UpdateWorldViewStateTo ((const Tmatrix3*)myCamera->OrientationMatrix().GetData());
411     }
412
413     if (aManager->ModelWorldState().Index() == 0)
414     {
415       Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f },
416                                     { 0.f, 1.f, 0.f, 0.f },
417                                     { 0.f, 0.f, 1.f, 0.f },
418                                     { 0.f, 0.f, 0.f, 1.f } };
419
420       aContext->ShaderManager()->UpdateModelWorldStateTo (&aModelWorldState);
421     }
422   }
423
424   // ====================================
425   //      Step 2: Redraw background
426   // ====================================
427
428   // Render background
429   DrawBackground (theWorkspace);
430
431   // Switch off lighting by default
432   glDisable(GL_LIGHTING);
433
434   // =================================
435   //      Step 3: Draw underlayer
436   // =================================
437
438   RedrawLayer2d (thePrintContext, theCView, theCUnderLayer);
439
440   // =================================
441   //      Step 4: Redraw main plane
442   // =================================
443
444   // Setup face culling
445   GLboolean isCullFace = GL_FALSE;
446   if ( myBackfacing )
447   {
448     isCullFace = glIsEnabled( GL_CULL_FACE );
449     if ( myBackfacing < 0 )
450     {
451       glEnable( GL_CULL_FACE );
452       glCullFace( GL_BACK );
453     }
454     else
455       glDisable( GL_CULL_FACE );
456   }
457
458   // if the view is scaled normal vectors are scaled to unit
459   // length for correct displaying of shaded objects
460   const gp_Pnt anAxialScale = myCamera->AxialScale();
461   if(anAxialScale.X() != 1.F ||
462      anAxialScale.Y() != 1.F ||
463      anAxialScale.Z() != 1.F)
464     glEnable(GL_NORMALIZE);
465   else if(glIsEnabled(GL_NORMALIZE))
466     glDisable(GL_NORMALIZE);
467
468   // Apply Fog
469   if ( myFog.IsOn )
470   {
471     Standard_Real aFogFrontConverted = (Standard_Real )myFog.Front + myCamera->Distance();
472     if (myCamera->ZFar() < aFogFrontConverted)
473     {
474       aFogFrontConverted = myCamera->ZFar();
475       myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance());
476     }
477
478     Standard_Real aFogBackConverted = (Standard_Real )myFog.Back + myCamera->Distance();
479     if (myCamera->ZFar() < aFogFrontConverted)
480     {
481       aFogBackConverted = myCamera->ZFar();
482       myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance());
483     }
484
485     if (aFogFrontConverted > aFogBackConverted)
486     {
487       myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance());
488       myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance());
489     }    
490
491     glFogi(GL_FOG_MODE, GL_LINEAR);
492     glFogf(GL_FOG_START, (Standard_ShortReal )aFogFrontConverted);
493     glFogf(GL_FOG_END, (Standard_ShortReal )aFogBackConverted);
494     glFogfv(GL_FOG_COLOR, myFog.Color.rgb);
495     glEnable(GL_FOG);
496   }
497   else
498     glDisable(GL_FOG);
499
500   // Apply InteriorShadingMethod
501   glShadeModel( myIntShadingMethod == TEL_SM_FLAT ? GL_FLAT : GL_SMOOTH );
502
503   // Apply AntiAliasing
504   if (myAntiAliasing)
505     theWorkspace->NamedStatus |= OPENGL_NS_ANTIALIASING;
506   else
507     theWorkspace->NamedStatus &= ~OPENGL_NS_ANTIALIASING;
508
509   if (!aManager->IsEmpty())
510   {
511     aManager->UpdateClippingState();
512   }
513
514   // Redraw 3d scene
515   if (!myCamera->IsStereo() || !aContext->HasStereoBuffers())
516   {
517     // single-pass monographic rendering
518     const OpenGl_Matrix* aProj = (const OpenGl_Matrix*) &myCamera->ProjectionMatrix();
519
520     const OpenGl_Matrix* aOrient = (const OpenGl_Matrix*) &myCamera->OrientationMatrix();
521
522     // redraw scene with normal orientation and projection
523     RedrawScene (thePrintContext, theWorkspace, aProj, aOrient);
524   }
525   else
526   {
527     // two stereographic passes
528     const OpenGl_Matrix* aLProj  = (const OpenGl_Matrix*) &myCamera->ProjectionStereoLeft();
529     const OpenGl_Matrix* aRProj  = (const OpenGl_Matrix*) &myCamera->ProjectionStereoRight();
530     const OpenGl_Matrix* aOrient = (const OpenGl_Matrix*) &myCamera->OrientationMatrix();
531
532     // safely switch to left Eye buffer
533     aContext->SetDrawBufferLeft();
534
535     // redraw left Eye
536     RedrawScene (thePrintContext, theWorkspace, aLProj, aOrient);
537
538     // reset depth buffer of first rendering pass
539     if (theWorkspace->UseDepthTest())
540     {
541       glClear (GL_DEPTH_BUFFER_BIT);
542     }
543     // safely switch to right Eye buffer
544     aContext->SetDrawBufferRight();
545     
546     // redraw right Eye
547     RedrawScene (thePrintContext, theWorkspace, aRProj, aOrient);
548
549     // switch back to monographic rendering
550     aContext->SetDrawBufferMono();
551   }
552
553   // ===============================
554   //      Step 5: Trihedron
555   // ===============================
556
557   // Resetting GL parameters according to the default aspects
558   // in order to synchronize GL state with the graphic driver state
559   // before drawing auxiliary stuff (trihedrons, overlayer)
560   // and invoking optional callbacks
561   theWorkspace->ResetAppliedAspect();
562
563   aContext->ChangeClipping().RemoveAll();
564
565   if (!aManager->IsEmpty())
566   {
567     aManager->ResetMaterialStates();
568     aManager->RevertClippingState();
569
570     // We need to disable (unbind) all shaders programs to ensure
571     // that all objects without specified aspect will be drawn
572     // correctly (such as background)
573     OpenGl_ShaderProgram::Unbind (aContext);
574   }
575
576   // display global trihedron
577   if (myTrihedron != NULL)
578   {
579     myTrihedron->Render (theWorkspace);
580   }
581   if (myGraduatedTrihedron != NULL)
582   {
583     myGraduatedTrihedron->Render (theWorkspace);
584   }
585
586   // Restore face culling
587   if ( myBackfacing )
588   {
589     if ( isCullFace )
590     {
591       glEnable   ( GL_CULL_FACE );
592       glCullFace ( GL_BACK      );
593     }
594     else
595       glDisable ( GL_CULL_FACE );
596   }
597
598   // ===============================
599   //      Step 6: Redraw overlay
600   // ===============================
601
602   const int aMode = 0;
603   theWorkspace->DisplayCallback (theCView, (aMode | OCC_PRE_OVERLAY));
604
605   RedrawLayer2d (thePrintContext, theCView, theCOverLayer);
606
607   theWorkspace->DisplayCallback (theCView, aMode);
608
609   // ===============================
610   //      Step 7: Finalize
611   // ===============================
612
613   // Restore clipping planes
614   aClipPlaneId = GL_CLIP_PLANE0;
615   aPtrPlane = aOldPlanes;
616
617   for (; aClipPlaneId < aClipLastId; aClipPlaneId++, aPtrPlane++)
618   {
619     glClipPlane (aClipPlaneId, aPtrPlane->Equation);
620     if (aPtrPlane->isEnabled)
621       glEnable (aClipPlaneId);
622     else
623       glDisable (aClipPlaneId);
624   }
625
626   delete[] aOldPlanes;
627 }
628
629 /*----------------------------------------------------------------------*/
630
631 //ExecuteViewDisplay
632 void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace)
633 {
634   if ( myZLayers.NbStructures() <= 0 )
635     return;
636
637   glPushAttrib ( GL_DEPTH_BUFFER_BIT );
638
639   //TsmPushAttri(); /* save previous graphics context */
640
641   if ( (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 )
642   {
643     const int antiAliasingMode = AWorkspace->GetDisplay()->AntiAliasingMode();
644
645     if ( !myAntiAliasing )
646     {
647       glDisable(GL_POINT_SMOOTH);
648       glDisable(GL_LINE_SMOOTH);
649       if( antiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH);
650       glBlendFunc (GL_ONE, GL_ZERO);
651       glDisable (GL_BLEND);
652     }
653     else
654     {
655       glEnable(GL_POINT_SMOOTH);
656       glEnable(GL_LINE_SMOOTH);
657       if( antiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
658       glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
659       glEnable (GL_BLEND);
660     }
661   }
662
663   myZLayers.Render (AWorkspace);
664
665   //TsmPopAttri(); /* restore previous graphics context; before update lights */
666   glPopAttrib();
667 }
668
669 /*----------------------------------------------------------------------*/
670
671 //call_togl_redraw_layer2d
672 void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
673                                  const Graphic3d_CView&               ACView,
674                                  const Aspect_CLayer2d&               ACLayer)
675 {
676   if (&ACLayer == NULL
677    || ACLayer.ptrLayer == NULL
678    || ACLayer.ptrLayer->listIndex == 0) return;
679
680   GLsizei dispWidth  = (GLsizei )ACLayer.viewport[0];
681   GLsizei dispHeight = (GLsizei )ACLayer.viewport[1];
682
683   glMatrixMode( GL_MODELVIEW );
684   glPushMatrix ();
685   glLoadIdentity ();
686
687   glMatrixMode (GL_PROJECTION);
688   glPushMatrix ();
689   glLoadIdentity ();
690
691   if (!ACLayer.sizeDependent)
692     glViewport (0, 0, dispWidth, dispHeight);
693
694   float left = ACLayer.ortho[0];
695   float right = ACLayer.ortho[1];
696   float bottom = ACLayer.ortho[2];
697   float top = ACLayer.ortho[3];
698
699   int attach = ACLayer.attach;
700
701   float ratio;
702   if (!ACLayer.sizeDependent)
703     ratio = (float) dispWidth/dispHeight;
704   else
705     ratio = ACView.DefWindow.dx/ACView.DefWindow.dy;
706
707   float delta;
708   if (ratio >= 1.0) {
709     delta = (float )((top - bottom)/2.0);
710     switch (attach) {
711       case 0: /* Aspect_TOC_BOTTOM_LEFT */
712         top = bottom + 2*delta/ratio;
713         break;
714       case 1: /* Aspect_TOC_BOTTOM_RIGHT */
715         top = bottom + 2*delta/ratio;
716         break;
717       case 2: /* Aspect_TOC_TOP_LEFT */
718         bottom = top - 2*delta/ratio;
719         break;
720       case 3: /* Aspect_TOC_TOP_RIGHT */
721         bottom = top - 2*delta/ratio;
722         break;
723     }
724   }
725   else {
726     delta = (float )((right - left)/2.0);
727     switch (attach) {
728       case 0: /* Aspect_TOC_BOTTOM_LEFT */
729         right = left + 2*delta*ratio;
730         break;
731       case 1: /* Aspect_TOC_BOTTOM_RIGHT */
732         left = right - 2*delta*ratio;
733         break;
734       case 2: /* Aspect_TOC_TOP_LEFT */
735         right = left + 2*delta*ratio;
736         break;
737       case 3: /* Aspect_TOC_TOP_RIGHT */
738         left = right - 2*delta*ratio;
739         break;
740     }
741   }
742
743 #ifdef _WIN32
744   // Check printer context that exists only for print operation
745   if (!thePrintContext.IsNull())
746   {
747     // additional transformation matrix could be applied to
748     // render only those parts of viewport that will be
749     // passed to a printer as a current "frame" to provide
750     // tiling; scaling of graphics by matrix helps render a
751     // part of a view (frame) in same viewport, but with higher
752     // resolution
753     thePrintContext->LoadProjTransformation();
754
755     // printing operation also assumes other viewport dimension
756     // to comply with transformation matrix or graphics scaling
757     // factors for tiling for layer redraw
758     GLsizei anViewportX = 0;
759     GLsizei anViewportY = 0;
760     thePrintContext->GetLayerViewport (anViewportX, anViewportY);
761     if (anViewportX != 0 && anViewportY != 0)
762       glViewport (0, 0, anViewportX, anViewportY);
763   }
764 #endif
765
766   glOrtho (left, right, bottom, top, -1.0, 1.0);
767
768   glPushAttrib (
769     GL_LIGHTING_BIT | GL_LINE_BIT | GL_POLYGON_BIT |
770     GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT );
771
772   glDisable (GL_DEPTH_TEST);
773   glDisable (GL_TEXTURE_1D);
774   glDisable (GL_TEXTURE_2D);
775   glDisable (GL_LIGHTING);
776
777   // TODO: Obsolete code, the display list is always empty now, to be removed
778   glCallList (ACLayer.ptrLayer->listIndex);
779
780   //calling dynamic render of LayerItems
781   if ( ACLayer.ptrLayer->layerData )
782   {
783     InitLayerProp (ACLayer.ptrLayer->listIndex);
784     ((Visual3d_Layer*)ACLayer.ptrLayer->layerData)->RenderLayerItems();
785     InitLayerProp (0);
786   }
787
788   glPopAttrib ();
789
790   glMatrixMode (GL_PROJECTION);
791   glPopMatrix ();
792
793   glMatrixMode( GL_MODELVIEW );
794   glPopMatrix ();
795
796   if (!ACLayer.sizeDependent)
797     glViewport (0, 0, (GLsizei) ACView.DefWindow.dx, (GLsizei) ACView.DefWindow.dy);
798
799   glFlush ();
800 }
801
802 /*----------------------------------------------------------------------*/
803
804 //call_togl_create_bg_texture
805 void OpenGl_View::CreateBackgroundTexture (const Standard_CString  theFilePath,
806                                            const Aspect_FillMethod theFillStyle)
807 {
808   if (myBgTexture.TexId != 0)
809   {
810     // delete existing texture
811     glDeleteTextures (1, (GLuint* )&(myBgTexture.TexId));
812     myBgTexture.TexId = 0;
813   }
814
815   // load image from file
816   Image_AlienPixMap anImageLoaded;
817   if (!anImageLoaded.Load (theFilePath))
818   {
819     return;
820   }
821
822   Image_PixMap anImage;
823   if (anImageLoaded.RowExtraBytes() == 0 &&
824       (anImageLoaded.Format() == Image_PixMap::ImgRGB
825     || anImageLoaded.Format() == Image_PixMap::ImgRGB32
826     || anImageLoaded.Format() == Image_PixMap::ImgRGBA))
827   {
828     anImage.InitWrapper (anImageLoaded.Format(), anImageLoaded.ChangeData(),
829                          anImageLoaded.SizeX(), anImageLoaded.SizeY(), anImageLoaded.SizeRowBytes());
830   }
831   else
832   {
833     // convert image to RGB format
834     if (!anImage.InitTrash (Image_PixMap::ImgRGB, anImageLoaded.SizeX(), anImageLoaded.SizeY()))
835     {
836       return;
837     }
838
839     anImage.SetTopDown (false);
840     Image_PixMapData<Image_ColorRGB>& aDataNew = anImage.EditData<Image_ColorRGB>();
841     Quantity_Color aSrcColor;
842     for (Standard_Size aRow = 0; aRow < anImage.SizeY(); ++aRow)
843     {
844       for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol)
845       {
846         aSrcColor = anImageLoaded.PixelColor ((Standard_Integer )aCol, (Standard_Integer )aRow);
847         Image_ColorRGB& aColor = aDataNew.ChangeValue (aRow, aCol);
848         aColor.r() = Standard_Byte(255.0 * aSrcColor.Red());
849         aColor.g() = Standard_Byte(255.0 * aSrcColor.Green());
850         aColor.b() = Standard_Byte(255.0 * aSrcColor.Blue());
851       }
852     }
853     anImageLoaded.Clear();
854   }
855
856   // create MipMapped texture
857   glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
858
859   GLuint aTextureId = 0;
860   glGenTextures (1, &aTextureId);
861   glBindTexture (GL_TEXTURE_2D, aTextureId);
862
863   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_REPEAT);
864   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_REPEAT);
865   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
866   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
867
868   const GLenum aDataFormat = (anImage.Format() == Image_PixMap::ImgRGB) ? GL_RGB : GL_RGBA;
869   gluBuild2DMipmaps (GL_TEXTURE_2D, 3/*4*/,
870                      GLint(anImage.SizeX()), GLint(anImage.SizeY()),
871                      aDataFormat, GL_UNSIGNED_BYTE, anImage.Data());
872
873   myBgTexture.TexId  = aTextureId;
874   myBgTexture.Width  = (Standard_Integer )anImage.SizeX();
875   myBgTexture.Height = (Standard_Integer )anImage.SizeY();
876   myBgTexture.Style  = theFillStyle;
877 }
878
879 /*----------------------------------------------------------------------*/
880
881 //call_togl_set_bg_texture_style
882 void OpenGl_View::SetBackgroundTextureStyle (const Aspect_FillMethod AFillStyle)
883 {
884   myBgTexture.Style = AFillStyle;
885 }
886
887 /*----------------------------------------------------------------------*/
888
889 //call_togl_gradient_background
890 void OpenGl_View::SetBackgroundGradient (const Quantity_Color& AColor1,
891                                         const Quantity_Color& AColor2,
892                                         const Aspect_GradientFillMethod AType)
893 {
894   Standard_Real R,G,B;
895   AColor1.Values( R, G, B, Quantity_TOC_RGB );
896   myBgGradient.color1.rgb[0] = ( Tfloat )R;
897   myBgGradient.color1.rgb[1] = ( Tfloat )G;
898   myBgGradient.color1.rgb[2] = ( Tfloat )B;
899   myBgGradient.color1.rgb[3] = 0.F;
900
901   AColor2.Values( R, G, B, Quantity_TOC_RGB );
902   myBgGradient.color2.rgb[0] = ( Tfloat )R;
903   myBgGradient.color2.rgb[1] = ( Tfloat )G;
904   myBgGradient.color2.rgb[2] = ( Tfloat )B;
905   myBgGradient.color2.rgb[3] = 0.F;
906
907   myBgGradient.type = AType;
908 }
909
910 /*----------------------------------------------------------------------*/
911
912 //call_togl_set_gradient_type
913 void OpenGl_View::SetBackgroundGradientType (const Aspect_GradientFillMethod AType)
914 {
915   myBgGradient.type = AType;
916 }
917
918 //=======================================================================
919 //function : AddZLayer
920 //purpose  :
921 //=======================================================================
922
923 void OpenGl_View::AddZLayer (const Standard_Integer theLayerId)
924 {
925   myZLayers.AddLayer (theLayerId);
926 }
927
928 //=======================================================================
929 //function : RemoveZLayer
930 //purpose  :
931 //=======================================================================
932
933 void OpenGl_View::RemoveZLayer (const Standard_Integer theLayerId)
934 {
935   myZLayers.RemoveLayer (theLayerId);
936 }
937
938 //=======================================================================
939 //function : DisplayStructure
940 //purpose  :
941 //=======================================================================
942
943 void OpenGl_View::DisplayStructure (const OpenGl_Structure *theStructure,
944                                     const Standard_Integer  thePriority)
945 {
946   Standard_Integer aZLayer = theStructure->GetZLayer ();
947   myZLayers.AddStructure (theStructure, aZLayer, thePriority);
948 }
949
950 //=======================================================================
951 //function : EraseStructure
952 //purpose  :
953 //=======================================================================
954
955 void OpenGl_View::EraseStructure (const OpenGl_Structure *theStructure)
956 {
957   Standard_Integer aZLayer = theStructure->GetZLayer ();
958   myZLayers.RemoveStructure (theStructure, aZLayer);
959 }
960
961 //=======================================================================
962 //function : ChangeZLayer
963 //purpose  :
964 //=======================================================================
965
966 void OpenGl_View::ChangeZLayer (const OpenGl_Structure *theStructure,
967                                 const Standard_Integer  theNewLayerId)
968 {
969   Standard_Integer anOldLayer = theStructure->GetZLayer ();
970   myZLayers.ChangeLayer (theStructure, anOldLayer, theNewLayerId);
971 }
972
973 //=======================================================================
974 //function : RedrawScene
975 //purpose  :
976 //=======================================================================
977
978 void OpenGl_View::RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
979                                const Handle(OpenGl_Workspace)& theWorkspace,
980                                const OpenGl_Matrix* theProjection,
981                                const OpenGl_Matrix* theOrientation)
982 {
983   const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
984
985   if (myZClip.Back.IsOn || myZClip.Front.IsOn)
986   {
987     Handle(Graphic3d_ClipPlane) aPlaneBack;
988     Handle(Graphic3d_ClipPlane) aPlaneFront;
989
990     if (myZClip.Back.IsOn)
991     {
992       Standard_Real aClipBackConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance();
993       if (myCamera->ZFar() < aClipBackConverted)
994       {
995         aClipBackConverted = myCamera->ZFar();
996         myZClip.Back.Limit = (Standard_ShortReal )(aClipBackConverted - myCamera->Distance());
997       }
998       const Graphic3d_ClipPlane::Equation aBackEquation (0.0, 0.0, 1.0, (Standard_ShortReal )aClipBackConverted);
999       aPlaneBack = new Graphic3d_ClipPlane (aBackEquation);
1000     }
1001
1002     if (myZClip.Front.IsOn)
1003     {
1004       Standard_Real aClipFrontConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance();
1005       if (myCamera->ZNear() > aClipFrontConverted)
1006       {
1007         aClipFrontConverted = myCamera->ZNear();
1008         myZClip.Front.Limit = (Standard_ShortReal )(aClipFrontConverted - myCamera->Distance());
1009       }
1010       const Graphic3d_ClipPlane::Equation aFrontEquation (0.0, 0.0, -1.0, (Standard_ShortReal )-aClipFrontConverted);
1011       aPlaneFront = new Graphic3d_ClipPlane (aFrontEquation);
1012     }
1013
1014     // do some "memory allocation"-wise optimization
1015     if (!aPlaneBack.IsNull() || !aPlaneFront.IsNull())
1016     {
1017       Graphic3d_SequenceOfHClipPlane aSlicingPlanes;
1018       if (!aPlaneBack.IsNull())
1019       {
1020         aSlicingPlanes.Append (aPlaneBack);
1021       }
1022
1023       if (!aPlaneFront.IsNull())
1024       {
1025         aSlicingPlanes.Append (aPlaneFront);
1026       }
1027
1028       // add planes at loaded view matrix state
1029       aContext->ChangeClipping().AddView (aSlicingPlanes, theWorkspace);
1030     }
1031   }
1032
1033   // Apply user clipping planes
1034   if (!myClipPlanes.IsEmpty())
1035   {
1036     Graphic3d_SequenceOfHClipPlane aUserPlanes;
1037     Graphic3d_SequenceOfHClipPlane::Iterator aClippingIt (myClipPlanes);
1038     for (; aClippingIt.More(); aClippingIt.Next())
1039     {
1040       const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value();
1041       if (aClipPlane->IsOn())
1042       {
1043         aUserPlanes.Append (aClipPlane);
1044       }
1045     }
1046
1047     if (!aUserPlanes.IsEmpty())
1048     {
1049       // add planes at actual matrix state.
1050       aContext->ChangeClipping().AddWorld (aUserPlanes);
1051     }
1052
1053     if (!aContext->ShaderManager()->IsEmpty())
1054     {
1055       aContext->ShaderManager()->UpdateClippingState();
1056     }
1057   }
1058
1059   // Setup view projection
1060   glMatrixMode (GL_PROJECTION);
1061
1062 #ifdef _WIN32
1063   // add printing scale/tiling transformation
1064   if (!thePrintContext.IsNull())
1065   {
1066     thePrintContext->LoadProjTransformation();
1067   }
1068   else
1069 #endif
1070     glLoadIdentity();
1071
1072   glMultMatrixf ((const GLfloat*)theProjection);
1073
1074   if (!thePrintContext.IsNull())
1075   {
1076     // update shader uniform projection matrix with new data
1077     Tmatrix3 aResultProjection;
1078     glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection);
1079     aContext->ShaderManager()->UpdateProjectionStateTo (&aResultProjection);
1080
1081     // force shader uniform restore on next frame
1082     myProjectionState = 0; 
1083   }
1084
1085   // Setup view orientation
1086   theWorkspace->SetViewMatrix (theOrientation);
1087
1088   // Apply Lights
1089   {
1090     // setup lights
1091     Graphic3d_Vec4 anAmbientColor (THE_DEFAULT_AMBIENT[0],
1092                                    THE_DEFAULT_AMBIENT[1],
1093                                    THE_DEFAULT_AMBIENT[2],
1094                                    THE_DEFAULT_AMBIENT[3]);
1095     GLenum aLightGlId = GL_LIGHT0;
1096     for (OpenGl_ListOfLight::Iterator aLightIt (myLights);
1097          aLightIt.More(); aLightIt.Next())
1098     {
1099       bind_light (aLightIt.Value(), aLightGlId, anAmbientColor);
1100     }
1101
1102     // apply accumulated ambient color
1103     anAmbientColor.a() = 1.0f;
1104     glLightModelfv (GL_LIGHT_MODEL_AMBIENT, anAmbientColor.GetData());
1105
1106     if (aLightGlId != GL_LIGHT0)
1107     {
1108       glEnable (GL_LIGHTING);
1109     }
1110     // switch off unused lights
1111     for (; aLightGlId <= GL_LIGHT7; ++aLightGlId)
1112     {
1113       glDisable (aLightGlId);
1114     }
1115   }
1116
1117   // Clear status bitfields
1118   theWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO);
1119
1120   // Added PCT for handling of textures
1121   switch (mySurfaceDetail)
1122   {
1123     case Visual3d_TOD_NONE:
1124       theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1125       theWorkspace->DisableTexture();
1126       // Render the view
1127       RenderStructs (theWorkspace);
1128       break;
1129
1130     case Visual3d_TOD_ENVIRONMENT:
1131       theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1132       theWorkspace->EnableTexture (myTextureEnv);
1133       // Render the view
1134       RenderStructs (theWorkspace);
1135       theWorkspace->DisableTexture();
1136       break;
1137
1138     case Visual3d_TOD_ALL:
1139       // First pass
1140       theWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX;
1141       // Render the view
1142       RenderStructs (theWorkspace);
1143       theWorkspace->DisableTexture();
1144
1145       // Second pass
1146       if (theWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED)
1147       {
1148         theWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO;
1149         theWorkspace->EnableTexture (myTextureEnv);
1150
1151         // Remember OpenGl properties
1152         GLint aSaveBlendDst, aSaveBlendSrc;
1153         GLint aSaveZbuffFunc;
1154         GLboolean aSaveZbuffWrite;
1155         glGetBooleanv (GL_DEPTH_WRITEMASK, &aSaveZbuffWrite);
1156         glGetIntegerv (GL_DEPTH_FUNC, &aSaveZbuffFunc);
1157         glGetIntegerv (GL_BLEND_DST, &aSaveBlendDst);
1158         glGetIntegerv (GL_BLEND_SRC, &aSaveBlendSrc);
1159         GLboolean wasZbuffEnabled = glIsEnabled (GL_DEPTH_TEST);
1160         GLboolean wasBlendEnabled = glIsEnabled (GL_BLEND);
1161
1162         // Change the properties for second rendering pass
1163         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1164         glEnable (GL_BLEND);
1165
1166         glDepthFunc (GL_EQUAL);
1167         glDepthMask (GL_FALSE);
1168         glEnable (GL_DEPTH_TEST);
1169
1170         theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1171
1172         // Render the view
1173         RenderStructs (theWorkspace);
1174         theWorkspace->DisableTexture();
1175
1176         // Restore properties back
1177         glBlendFunc (aSaveBlendSrc, aSaveBlendDst);
1178         if (!wasBlendEnabled)
1179           glDisable (GL_BLEND);
1180
1181         glDepthFunc (aSaveZbuffFunc);
1182         glDepthMask (aSaveZbuffWrite);
1183         if (!wasZbuffEnabled)
1184           glDisable (GL_DEPTH_FUNC);
1185       }
1186       break;
1187   }
1188 }