1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-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.
20 #include <OpenGl_GlCore15.hxx>
22 #include <InterfaceGraphic.hxx>
24 #include <OpenGl_AspectLine.hxx>
25 #include <OpenGl_AspectFace.hxx>
26 #include <OpenGl_AspectMarker.hxx>
27 #include <OpenGl_AspectText.hxx>
28 #include <OpenGl_Context.hxx>
29 #include <OpenGl_Element.hxx>
30 #include <OpenGl_FrameBuffer.hxx>
31 #include <OpenGl_Structure.hxx>
32 #include <OpenGl_Texture.hxx>
33 #include <OpenGl_View.hxx>
34 #include <OpenGl_Workspace.hxx>
36 #include <Graphic3d_TextureParams.hxx>
38 #if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
39 #include <OpenGl_AVIWriter.hxx>
42 IMPLEMENT_STANDARD_HANDLE(OpenGl_Workspace,OpenGl_Window)
43 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,OpenGl_Window)
47 static const TEL_COLOUR THE_WHITE_COLOR = { { 1.0f, 1.0f, 1.0f, 1.0f } };
48 static const OpenGl_Vec4 THE_BLACK_COLOR (0.0f, 0.0f, 0.0f, 1.0f);
50 static const OpenGl_AspectLine myDefaultAspectLine;
51 static const OpenGl_AspectFace myDefaultAspectFace;
52 static const OpenGl_AspectMarker myDefaultAspectMarker;
53 static const OpenGl_AspectText myDefaultAspectText;
55 static const OpenGl_TextParam myDefaultTextParam =
57 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
60 static const OpenGl_Matrix myDefaultMatrix =
62 {{ 1.0F, 0.0F, 0.0F, 0.0F },
63 { 0.0F, 1.0F, 0.0F, 0.0F },
64 { 0.0F, 0.0F, 1.0F, 0.0F },
65 { 0.0F, 0.0F, 0.0F, 1.0F }}
70 // =======================================================================
73 // =======================================================================
74 void OpenGl_Material::Init (const OPENGL_SURF_PROP& theProp)
77 if (theProp.color_mask & OPENGL_AMBIENT_MASK)
79 const float* aSrcAmb = theProp.isphysic ? theProp.ambcol.rgb : theProp.matcol.rgb;
80 Ambient = OpenGl_Vec4 (aSrcAmb[0] * theProp.amb,
81 aSrcAmb[1] * theProp.amb,
82 aSrcAmb[2] * theProp.amb,
87 Ambient = THE_BLACK_COLOR;
90 // diffusion component
91 if (theProp.color_mask & OPENGL_DIFFUSE_MASK)
93 const float* aSrcDif = theProp.isphysic ? theProp.difcol.rgb : theProp.matcol.rgb;
94 Diffuse = OpenGl_Vec4 (aSrcDif[0] * theProp.diff,
95 aSrcDif[1] * theProp.diff,
96 aSrcDif[2] * theProp.diff,
101 Diffuse = THE_BLACK_COLOR;
104 // specular component
105 if (theProp.color_mask & OPENGL_SPECULAR_MASK)
107 const float* aSrcSpe = theProp.isphysic ? theProp.speccol.rgb : THE_WHITE_COLOR.rgb;
108 Specular = OpenGl_Vec4 (aSrcSpe[0] * theProp.spec,
109 aSrcSpe[1] * theProp.spec,
110 aSrcSpe[2] * theProp.spec,
115 Specular = THE_BLACK_COLOR;
118 // emission component
119 if (theProp.color_mask & OPENGL_EMISSIVE_MASK)
121 const float* aSrcEms = theProp.isphysic ? theProp.emscol.rgb : theProp.matcol.rgb;
122 Emission = OpenGl_Vec4 (aSrcEms[0] * theProp.emsv,
123 aSrcEms[1] * theProp.emsv,
124 aSrcEms[2] * theProp.emsv,
129 Emission = THE_BLACK_COLOR;
132 ChangeShine() = theProp.shine;
133 ChangeTransparency() = theProp.trans;
136 // =======================================================================
137 // function : OpenGl_Workspace
139 // =======================================================================
140 OpenGl_Workspace::OpenGl_Workspace (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
141 const CALL_DEF_WINDOW& theCWindow,
142 Aspect_RenderingContext theGContext,
143 const Handle(OpenGl_Caps)& theCaps,
144 const Handle(OpenGl_Context)& theShareCtx)
145 : OpenGl_Window (theDisplayConnection, theCWindow, theGContext, theCaps, theShareCtx),
147 HighlightColor (&THE_WHITE_COLOR),
149 myComputeInitStatus (OpenGl_RT_NONE),
150 myIsRaytraceDataValid (Standard_False),
151 myTraversalStackSize (THE_DEFAULT_STACK_SIZE),
152 myViewModificationStatus (0),
153 myLayersModificationStatus (0),
155 myAntiAliasingMode (3),
156 myTransientDrawToFront (Standard_True),
157 myBackBufferRestored (Standard_False),
158 myIsImmediateDrawn (Standard_False),
159 myUseTransparency (Standard_False),
160 myUseZBuffer (Standard_False),
161 myUseDepthTest (Standard_True),
162 myUseGLLight (Standard_True),
164 AspectLine_set (&myDefaultAspectLine),
165 AspectLine_applied (NULL),
166 AspectFace_set (&myDefaultAspectFace),
167 AspectFace_applied (NULL),
168 AspectMarker_set (&myDefaultAspectMarker),
169 AspectMarker_applied (NULL),
170 AspectText_set (&myDefaultAspectText),
171 AspectText_applied (NULL),
172 TextParam_set (&myDefaultTextParam),
173 TextParam_applied (NULL),
174 ViewMatrix_applied (&myDefaultMatrix),
175 StructureMatrix_applied (&myDefaultMatrix),
176 myCullingMode (TelCullUndefined),
177 myModelViewMatrix (myDefaultMatrix),
178 PolygonOffset_applied (NULL)
180 myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
182 if (!myGlContext->GetResource ("OpenGl_LineAttributes", myLineAttribs))
184 // share and register for release once the resource is no longer used
185 myLineAttribs = new OpenGl_LineAttributes();
186 myGlContext->ShareResource ("OpenGl_LineAttributes", myLineAttribs);
187 myLineAttribs->Init (myGlContext);
190 // General initialization of the context
192 // Eviter d'avoir les faces mal orientees en noir.
193 // Pourrait etre utiliser pour detecter les problemes d'orientation
194 glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
196 // Optimisation pour le Fog et l'antialiasing
197 glHint (GL_FOG_HINT, GL_FASTEST);
198 glHint (GL_POINT_SMOOTH_HINT, GL_FASTEST);
199 glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST);
200 glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
203 const char* anAaEnv = ::getenv ("CALL_OPENGL_ANTIALIASING_MODE");
207 if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasingMode = v;
211 // =======================================================================
212 // function : SetImmediateModeDrawToFront
214 // =======================================================================
215 Standard_Boolean OpenGl_Workspace::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
217 const Standard_Boolean aPrevMode = myTransientDrawToFront;
218 myTransientDrawToFront = theDrawToFrontBuffer;
222 // =======================================================================
223 // function : ~OpenGl_Workspace
225 // =======================================================================
226 OpenGl_Workspace::~OpenGl_Workspace()
228 if (!myLineAttribs.IsNull())
230 myLineAttribs.Nullify();
231 myGlContext->ReleaseResource ("OpenGl_LineAttributes", Standard_True);
234 ReleaseRaytraceResources();
237 // =======================================================================
238 // function : Activate
240 // =======================================================================
241 Standard_Boolean OpenGl_Workspace::Activate()
243 if (!OpenGl_Window::Activate())
244 return Standard_False;
246 ViewMatrix_applied = &myDefaultMatrix;
247 StructureMatrix_applied = &myDefaultMatrix;
249 ResetAppliedAspect();
251 return Standard_True;
254 // =======================================================================
255 // function : UseTransparency
256 // purpose : call_togl_transparency
257 // =======================================================================
258 void OpenGl_Workspace::UseTransparency (const Standard_Boolean theFlag)
260 myUseTransparency = theFlag;
263 //=======================================================================
264 //function : ResetAppliedAspect
265 //purpose : Sets default values of GL parameters in accordance with default aspects
266 //=======================================================================
267 void OpenGl_Workspace::ResetAppliedAspect()
269 NamedStatus = !myTextureBound.IsNull() ? OPENGL_NS_TEXTURE : 0;
270 HighlightColor = &THE_WHITE_COLOR;
271 AspectLine_set = &myDefaultAspectLine;
272 AspectLine_applied = NULL;
273 AspectFace_set = &myDefaultAspectFace;
274 AspectFace_applied = NULL;
275 AspectMarker_set = &myDefaultAspectMarker;
276 AspectMarker_applied = NULL;
277 AspectText_set = &myDefaultAspectText;
278 AspectText_applied = NULL;
279 TextParam_set = &myDefaultTextParam;
280 TextParam_applied = NULL;
281 PolygonOffset_applied = NULL;
282 myCullingMode = TelCullUndefined;
284 AspectLine(Standard_True);
285 AspectFace(Standard_True);
286 AspectMarker(Standard_True);
287 AspectText(Standard_True);
290 // =======================================================================
291 // function : DisableTexture
293 // =======================================================================
294 Handle(OpenGl_Texture) OpenGl_Workspace::DisableTexture()
296 if (myTextureBound.IsNull())
298 return myTextureBound;
301 // reset texture matrix because some code may expect it is identity
302 GLint aMatrixMode = GL_TEXTURE;
303 glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
304 glMatrixMode (GL_TEXTURE);
306 glMatrixMode (aMatrixMode);
308 myTextureBound->Unbind (myGlContext);
309 switch (myTextureBound->GetTarget())
313 if (myTextureBound->GetParams()->GenMode() != GL_NONE)
315 glDisable (GL_TEXTURE_GEN_S);
317 glDisable (GL_TEXTURE_1D);
322 if (myTextureBound->GetParams()->GenMode() != GL_NONE)
324 glDisable (GL_TEXTURE_GEN_S);
325 glDisable (GL_TEXTURE_GEN_T);
326 if (myTextureBound->GetParams()->GenMode() == Graphic3d_TOTM_SPRITE)
328 glDisable (GL_POINT_SPRITE);
331 glDisable (GL_TEXTURE_2D);
337 Handle(OpenGl_Texture) aPrevTexture = myTextureBound;
338 myTextureBound.Nullify();
342 // =======================================================================
343 // function : setTextureParams
345 // =======================================================================
346 void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)& theTexture,
347 const Handle(Graphic3d_TextureParams)& theParams)
349 const Handle(Graphic3d_TextureParams)& aParams = theParams.IsNull() ? theTexture->GetParams() : theParams;
350 if (aParams.IsNull())
355 GLint aMatrixMode = GL_TEXTURE;
356 glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
358 // setup texture matrix
359 glMatrixMode (GL_TEXTURE);
361 const Graphic3d_Vec2& aScale = aParams->Scale();
362 const Graphic3d_Vec2& aTrans = aParams->Translation();
363 glScalef ( aScale.x(), aScale.y(), 1.0f);
364 glTranslatef (-aTrans.x(), -aTrans.y(), 0.0f);
365 glRotatef (-aParams->Rotation(), 0.0f, 0.0f, 1.0f);
367 // setup generation of texture coordinates
368 switch (aParams->GenMode())
370 case Graphic3d_TOTM_OBJECT:
372 glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
373 glTexGenfv (GL_S, GL_OBJECT_PLANE, aParams->GenPlaneS().GetData());
374 if (theTexture->GetTarget() != GL_TEXTURE_1D)
376 glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
377 glTexGenfv (GL_T, GL_OBJECT_PLANE, aParams->GenPlaneT().GetData());
381 case Graphic3d_TOTM_SPHERE:
383 glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
384 if (theTexture->GetTarget() != GL_TEXTURE_1D)
386 glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
390 case Graphic3d_TOTM_EYE:
392 glMatrixMode (GL_MODELVIEW);
396 glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
397 glTexGenfv (GL_S, GL_EYE_PLANE, aParams->GenPlaneS().GetData());
399 if (theTexture->GetTarget() != GL_TEXTURE_1D)
401 glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
402 glTexGenfv (GL_T, GL_EYE_PLANE, aParams->GenPlaneT().GetData());
407 case Graphic3d_TOTM_SPRITE:
409 if (GetGlContext()->core20 != NULL)
411 glEnable (GL_POINT_SPRITE);
412 glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
413 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
414 GetGlContext()->core15->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
418 case Graphic3d_TOTM_MANUAL:
423 if (aParams->GenMode() != Graphic3d_TOTM_SPRITE)
425 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aParams->IsModulate() ? GL_MODULATE : GL_DECAL);
428 // setup texture filtering and wrapping
429 //if (theTexture->GetParams() != theParams)
430 const GLenum aFilter = (aParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
431 const GLenum aWrapMode = aParams->IsRepeat() ? GL_REPEAT : GL_CLAMP;
432 switch (theTexture->GetTarget())
436 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, aFilter);
437 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, aFilter);
438 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, aWrapMode);
443 GLenum aFilterMin = aFilter;
444 if (theTexture->HasMipmaps())
446 aFilterMin = GL_NEAREST_MIPMAP_NEAREST;
447 if (aParams->Filter() == Graphic3d_TOTF_BILINEAR)
449 aFilterMin = GL_LINEAR_MIPMAP_NEAREST;
451 else if (aParams->Filter() == Graphic3d_TOTF_TRILINEAR)
453 aFilterMin = GL_LINEAR_MIPMAP_LINEAR;
456 if (myGlContext->extAnis)
458 // setup degree of anisotropy filter
459 const GLint aMaxDegree = myGlContext->MaxDegreeOfAnisotropy();
460 switch (aParams->AnisoFilter())
462 case Graphic3d_LOTA_QUALITY:
464 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aMaxDegree);
467 case Graphic3d_LOTA_MIDDLE:
470 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (aMaxDegree <= 4) ? 2 : (aMaxDegree / 2));
473 case Graphic3d_LOTA_FAST:
475 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2);
478 case Graphic3d_LOTA_OFF:
481 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
487 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterMin);
488 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilter);
489 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aWrapMode);
490 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aWrapMode);
496 switch (theTexture->GetTarget())
500 if (aParams->GenMode() != Graphic3d_TOTM_MANUAL)
502 glEnable (GL_TEXTURE_GEN_S);
504 glEnable (GL_TEXTURE_1D);
509 if (aParams->GenMode() != Graphic3d_TOTM_MANUAL)
511 glEnable (GL_TEXTURE_GEN_S);
512 glEnable (GL_TEXTURE_GEN_T);
514 glEnable (GL_TEXTURE_2D);
520 glMatrixMode (aMatrixMode); // turn back active matrix
521 theTexture->SetParams (aParams);
524 // =======================================================================
525 // function : EnableTexture
527 // =======================================================================
528 Handle(OpenGl_Texture) OpenGl_Workspace::EnableTexture (const Handle(OpenGl_Texture)& theTexture,
529 const Handle(Graphic3d_TextureParams)& theParams)
531 if (theTexture.IsNull() || !theTexture->IsValid())
533 return DisableTexture();
536 if (myTextureBound == theTexture
537 && (theParams.IsNull() || theParams == theTexture->GetParams()))
540 return myTextureBound;
543 Handle(OpenGl_Texture) aPrevTexture = DisableTexture();
544 myTextureBound = theTexture;
545 myTextureBound->Bind (myGlContext);
546 setTextureParams (myTextureBound, theParams);
551 // =======================================================================
554 // =======================================================================
555 void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
556 const Aspect_CLayer2d& theCUnderLayer,
557 const Aspect_CLayer2d& theCOverLayer)
564 // release pending GL resources
565 Handle(OpenGl_Context) aGlCtx = GetGlContext();
566 aGlCtx->ReleaseDelayed();
568 // fetch OpenGl context state
569 aGlCtx->FetchState();
571 Tint toSwap = (aGlCtx->IsRender()); // swap buffers
572 GLint aViewPortBack[4];
573 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO;
574 if (aFrameBuffer != NULL)
576 glGetIntegerv (GL_VIEWPORT, aViewPortBack);
577 aFrameBuffer->SetupViewport (aGlCtx);
578 aFrameBuffer->BindBuffer (aGlCtx);
579 toSwap = 0; // no need to swap buffers
582 if (!theCView.IsRaytracing || myComputeInitStatus == OpenGl_RT_FAIL)
584 const Standard_Boolean isImmediate = !myView->ImmediateStructures().IsEmpty();
585 redraw1 (theCView, theCUnderLayer, theCOverLayer, isImmediate ? 0 : toSwap);
588 RedrawImmediate (theCView, theCUnderLayer, theCOverLayer, Standard_True);
591 theCView.WasRedrawnGL = Standard_True;
595 int aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWidth;
596 int aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myHeight;
598 Raytrace (theCView, aSizeX, aSizeY, toSwap, aFrameBuffer);
600 theCView.WasRedrawnGL = Standard_False;
603 if (aFrameBuffer != NULL)
605 aFrameBuffer->UnbindBuffer (aGlCtx);
606 // move back original viewport
607 glViewport (aViewPortBack[0], aViewPortBack[1], aViewPortBack[2], aViewPortBack[3]);
610 #if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
611 if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow))
614 glGetIntegerv (GL_VIEWPORT, params);
615 int nWidth = params[2] & ~0x7;
616 int nHeight = params[3] & ~0x7;
618 const int nBitsPerPixel = 24;
619 GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8];
621 glPixelStorei (GL_PACK_ALIGNMENT, 1);
622 glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData);
623 OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel);
628 // reset render mode state
629 aGlCtx->FetchState();
632 // =======================================================================
633 // function : redraw1
635 // =======================================================================
636 void OpenGl_Workspace::redraw1 (const Graphic3d_CView& theCView,
637 const Aspect_CLayer2d& theCUnderLayer,
638 const Aspect_CLayer2d& theCOverLayer,
646 // request reset of material
647 NamedStatus |= OPENGL_NS_RESMAT;
649 GLbitfield toClear = GL_COLOR_BUFFER_BIT;
652 glDepthFunc (GL_LEQUAL);
653 glDepthMask (GL_TRUE);
656 glEnable (GL_DEPTH_TEST);
660 glDisable (GL_DEPTH_TEST);
664 toClear |= GL_DEPTH_BUFFER_BIT;
668 glDisable (GL_DEPTH_TEST);
671 if (NamedStatus & OPENGL_NS_WHITEBACK)
673 // set background to white
674 glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
675 toClear |= GL_DEPTH_BUFFER_BIT;
679 glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
683 Handle(OpenGl_Workspace) aWS (this);
684 myView->Render (myPrintContext, aWS, theCView, theCUnderLayer, theCOverLayer);
689 GetGlContext()->SwapBuffers();
690 myBackBufferRestored = Standard_False;
691 myIsImmediateDrawn = Standard_False;
696 myBackBufferRestored = Standard_True;
697 myIsImmediateDrawn = Standard_False;
701 // =======================================================================
702 // function : copyBackToFront
704 // =======================================================================
705 void OpenGl_Workspace::copyBackToFront()
707 glMatrixMode (GL_PROJECTION);
710 gluOrtho2D (0.0, (GLdouble )myWidth, 0.0, (GLdouble )myHeight);
711 glMatrixMode (GL_MODELVIEW);
717 glDrawBuffer (GL_FRONT);
718 glReadBuffer (GL_BACK);
720 glRasterPos2i (0, 0);
721 glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_COLOR);
725 glMatrixMode (GL_PROJECTION);
727 glMatrixMode (GL_MODELVIEW);
730 glDrawBuffer (GL_BACK);
732 myIsImmediateDrawn = Standard_False;
735 // =======================================================================
736 // function : DisplayCallback
738 // =======================================================================
739 void OpenGl_Workspace::DisplayCallback (const Graphic3d_CView& theCView,
740 Standard_Integer theReason)
742 if (theCView.GDisplayCB == NULL)
747 Aspect_GraphicCallbackStruct aCallData;
748 aCallData.reason = theReason;
749 aCallData.glContext = GetGlContext();
750 aCallData.wsID = theCView.WsId;
751 aCallData.viewID = theCView.ViewId;
752 theCView.GDisplayCB (theCView.DefWindow.XWindow, theCView.GClientData, &aCallData);
755 // =======================================================================
756 // function : RedrawImmediate
758 // =======================================================================
759 void OpenGl_Workspace::RedrawImmediate (const Graphic3d_CView& theCView,
760 const Aspect_CLayer2d& theCUnderLayer,
761 const Aspect_CLayer2d& theCOverLayer,
762 const Standard_Boolean theToForce)
769 GLboolean isDoubleBuffer = GL_FALSE;
770 glGetBooleanv (GL_DOUBLEBUFFER, &isDoubleBuffer);
771 if (myView->ImmediateStructures().IsEmpty())
774 || !myIsImmediateDrawn)
776 myIsImmediateDrawn = Standard_False;
780 if (myBackBufferRestored
788 Redraw (theCView, theCUnderLayer, theCOverLayer);
793 if (isDoubleBuffer && myTransientDrawToFront)
795 if (!myBackBufferRestored)
797 Redraw (theCView, theCUnderLayer, theCOverLayer);
801 MakeFrontBufCurrent();
805 myBackBufferRestored = Standard_False;
807 myIsImmediateDrawn = Standard_True;
809 NamedStatus |= OPENGL_NS_IMMEDIATE;
810 ///glDisable (GL_LIGHTING);
811 glDisable (GL_DEPTH_TEST);
813 Handle(OpenGl_Workspace) aWS (this);
814 for (OpenGl_SequenceOfStructure::Iterator anIter (myView->ImmediateStructures());
815 anIter.More(); anIter.Next())
817 const OpenGl_Structure* aStructure = anIter.Value();
818 aStructure->Render (aWS);
821 NamedStatus &= ~OPENGL_NS_IMMEDIATE;
823 if (isDoubleBuffer && myTransientDrawToFront)
826 MakeBackBufCurrent();