0025951: Exception in intersection operation.
[occt.git] / src / OpenGl / OpenGl_Workspace.cxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
a577aaab 16#include <OpenGl_GlCore15.hxx>
b86bb3df 17#include <OpenGl_ArbFBO.hxx>
5f8b738e 18
2166f0fa
SK
19#include <InterfaceGraphic.hxx>
20
2166f0fa
SK
21#include <OpenGl_AspectLine.hxx>
22#include <OpenGl_AspectFace.hxx>
23#include <OpenGl_AspectMarker.hxx>
24#include <OpenGl_AspectText.hxx>
bf75be98 25#include <OpenGl_Context.hxx>
679ecdee 26#include <OpenGl_Element.hxx>
a174a3c5 27#include <OpenGl_FrameBuffer.hxx>
679ecdee 28#include <OpenGl_Structure.hxx>
25ef750e 29#include <OpenGl_Sampler.hxx>
b86bb3df 30#include <OpenGl_ShaderManager.hxx>
bf75be98 31#include <OpenGl_Texture.hxx>
c827ea3a 32#include <OpenGl_Utils.hxx>
e276548b 33#include <OpenGl_View.hxx>
a174a3c5 34#include <OpenGl_Workspace.hxx>
2166f0fa 35
bf75be98 36#include <Graphic3d_TextureParams.hxx>
2166f0fa 37
58655684 38#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
a174a3c5 39 #include <OpenGl_AVIWriter.hxx>
40#endif
41
2166f0fa
SK
42IMPLEMENT_STANDARD_HANDLE(OpenGl_Workspace,OpenGl_Window)
43IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,OpenGl_Window)
44
45namespace
46{
0adbd30f 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);
2166f0fa
SK
49
50 static const OpenGl_AspectLine myDefaultAspectLine;
51 static const OpenGl_AspectFace myDefaultAspectFace;
52 static const OpenGl_AspectMarker myDefaultAspectMarker;
53 static const OpenGl_AspectText myDefaultAspectText;
54
55 static const OpenGl_TextParam myDefaultTextParam =
56 {
57 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
58 };
59
60 static const OpenGl_Matrix myDefaultMatrix =
61 {
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 }}
66 };
bf75be98 67
2166f0fa
SK
68};
69
0adbd30f 70// =======================================================================
71// function : Init
72// purpose :
73// =======================================================================
74void OpenGl_Material::Init (const OPENGL_SURF_PROP& theProp)
75{
76 // ambient component
77 if (theProp.color_mask & OPENGL_AMBIENT_MASK)
78 {
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,
83 1.0f);
84 }
85 else
86 {
87 Ambient = THE_BLACK_COLOR;
88 }
89
90 // diffusion component
91 if (theProp.color_mask & OPENGL_DIFFUSE_MASK)
92 {
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,
97 1.0f);
98 }
99 else
100 {
101 Diffuse = THE_BLACK_COLOR;
102 }
103
104 // specular component
105 if (theProp.color_mask & OPENGL_SPECULAR_MASK)
106 {
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,
111 1.0f);
112 }
113 else
114 {
115 Specular = THE_BLACK_COLOR;
116 }
117
118 // emission component
119 if (theProp.color_mask & OPENGL_EMISSIVE_MASK)
120 {
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,
125 1.0f);
126 }
127 else
128 {
129 Emission = THE_BLACK_COLOR;
130 }
131
132 ChangeShine() = theProp.shine;
133 ChangeTransparency() = theProp.trans;
134}
135
2166f0fa
SK
136// =======================================================================
137// function : OpenGl_Workspace
138// purpose :
139// =======================================================================
25b97fac 140OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver,
2166f0fa 141 const CALL_DEF_WINDOW& theCWindow,
5e27df78 142 Aspect_RenderingContext theGContext,
58655684 143 const Handle(OpenGl_Caps)& theCaps,
5e27df78 144 const Handle(OpenGl_Context)& theShareCtx)
25b97fac 145: OpenGl_Window (theDriver, theCWindow, theGContext, theCaps, theShareCtx),
a174a3c5 146 NamedStatus (0),
0adbd30f 147 HighlightColor (&THE_WHITE_COLOR),
a174a3c5 148 //
fc73a202 149 myComputeInitStatus (OpenGl_RT_NONE),
150 myIsRaytraceDataValid (Standard_False),
25ef750e 151 myIsRaytraceWarnTextures (Standard_False),
ee51a9fe 152 myHasFboBlit (Standard_True),
fc73a202 153 myViewModificationStatus (0),
154 myLayersModificationStatus (0),
155 //
a89742cf 156 myRaytraceFilter (new OpenGl_RaytraceFilter()),
157 myToRedrawGL (Standard_True),
a272ed94 158 myViewId (-1),
73192b37 159 myAntiAliasingMode (3),
a174a3c5 160 myTransientDrawToFront (Standard_True),
679ecdee 161 myBackBufferRestored (Standard_False),
162 myIsImmediateDrawn (Standard_False),
2166f0fa
SK
163 myUseZBuffer (Standard_False),
164 myUseDepthTest (Standard_True),
165 myUseGLLight (Standard_True),
b7cd4ba7 166 myIsCullingEnabled (Standard_False),
a89742cf 167 myFrameCounter (0),
2166f0fa 168 //
2166f0fa
SK
169 AspectLine_set (&myDefaultAspectLine),
170 AspectLine_applied (NULL),
171 AspectFace_set (&myDefaultAspectFace),
172 AspectFace_applied (NULL),
173 AspectMarker_set (&myDefaultAspectMarker),
174 AspectMarker_applied (NULL),
175 AspectText_set (&myDefaultAspectText),
176 AspectText_applied (NULL),
177 TextParam_set (&myDefaultTextParam),
178 TextParam_applied (NULL),
179 ViewMatrix_applied (&myDefaultMatrix),
180 StructureMatrix_applied (&myDefaultMatrix),
3b1817a9 181 myCullingMode (TelCullUndefined),
0f8c0fb8 182 myModelViewMatrix (myDefaultMatrix),
550f3b8b 183 PolygonOffset_applied (THE_DEFAULT_POFFSET)
2166f0fa 184{
73192b37 185 myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
b86bb3df 186 myResultFBO = new OpenGl_FrameBuffer();
73192b37 187
188 if (!myGlContext->GetResource ("OpenGl_LineAttributes", myLineAttribs))
189 {
190 // share and register for release once the resource is no longer used
191 myLineAttribs = new OpenGl_LineAttributes();
192 myGlContext->ShareResource ("OpenGl_LineAttributes", myLineAttribs);
193 myLineAttribs->Init (myGlContext);
194 }
2166f0fa
SK
195
196 // General initialization of the context
197
ca3c13d1 198#if !defined(GL_ES_VERSION_2_0)
4e1523ef 199 if (myGlContext->core11 != NULL)
200 {
201 // Eviter d'avoir les faces mal orientees en noir.
202 // Pourrait etre utiliser pour detecter les problemes d'orientation
203 glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
204
205 // Optimisation pour le Fog et l'antialiasing
206 glHint (GL_FOG_HINT, GL_FASTEST);
207 glHint (GL_POINT_SMOOTH_HINT, GL_FASTEST);
208 }
2166f0fa 209
2166f0fa
SK
210 glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST);
211 glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
ca3c13d1 212#endif
2166f0fa 213
73192b37 214 // AA mode
215 const char* anAaEnv = ::getenv ("CALL_OPENGL_ANTIALIASING_MODE");
216 if (anAaEnv != NULL)
217 {
218 int v;
219 if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasingMode = v;
220 }
2166f0fa
SK
221}
222
1981cb22 223// =======================================================================
224// function : SetImmediateModeDrawToFront
225// purpose :
226// =======================================================================
227Standard_Boolean OpenGl_Workspace::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
228{
229 const Standard_Boolean aPrevMode = myTransientDrawToFront;
230 myTransientDrawToFront = theDrawToFrontBuffer;
231 return aPrevMode;
232}
233
2166f0fa
SK
234// =======================================================================
235// function : ~OpenGl_Workspace
236// purpose :
237// =======================================================================
238OpenGl_Workspace::~OpenGl_Workspace()
239{
73192b37 240 if (!myLineAttribs.IsNull())
241 {
242 myLineAttribs.Nullify();
243 myGlContext->ReleaseResource ("OpenGl_LineAttributes", Standard_True);
244 }
245
b86bb3df 246 if (!myResultFBO.IsNull())
247 {
248 myResultFBO->Release (myGlContext.operator->());
249 myResultFBO.Nullify();
250 }
251 if (myFullScreenQuad.IsValid())
252 {
253 myFullScreenQuad.Release (myGlContext.operator->());
254 }
255
fc73a202 256 ReleaseRaytraceResources();
2166f0fa
SK
257}
258
259// =======================================================================
260// function : Activate
261// purpose :
262// =======================================================================
263Standard_Boolean OpenGl_Workspace::Activate()
264{
265 if (!OpenGl_Window::Activate())
266 return Standard_False;
267
2166f0fa
SK
268 ViewMatrix_applied = &myDefaultMatrix;
269 StructureMatrix_applied = &myDefaultMatrix;
26395493 270
271 ResetAppliedAspect();
272
273 return Standard_True;
2166f0fa
SK
274}
275
26395493 276//=======================================================================
277//function : ResetAppliedAspect
278//purpose : Sets default values of GL parameters in accordance with default aspects
279//=======================================================================
280void OpenGl_Workspace::ResetAppliedAspect()
281{
4e1523ef 282 myGlContext->BindDefaultVao();
283
bf75be98 284 NamedStatus = !myTextureBound.IsNull() ? OPENGL_NS_TEXTURE : 0;
0adbd30f 285 HighlightColor = &THE_WHITE_COLOR;
26395493 286 AspectLine_set = &myDefaultAspectLine;
287 AspectLine_applied = NULL;
288 AspectFace_set = &myDefaultAspectFace;
289 AspectFace_applied = NULL;
290 AspectMarker_set = &myDefaultAspectMarker;
291 AspectMarker_applied = NULL;
292 AspectText_set = &myDefaultAspectText;
293 AspectText_applied = NULL;
294 TextParam_set = &myDefaultTextParam;
295 TextParam_applied = NULL;
550f3b8b 296 PolygonOffset_applied = THE_DEFAULT_POFFSET;
3b1817a9 297 myCullingMode = TelCullUndefined;
26395493 298
299 AspectLine(Standard_True);
300 AspectFace(Standard_True);
301 AspectMarker(Standard_True);
302 AspectText(Standard_True);
303}
bf75be98 304
305// =======================================================================
306// function : DisableTexture
307// purpose :
308// =======================================================================
309Handle(OpenGl_Texture) OpenGl_Workspace::DisableTexture()
310{
311 if (myTextureBound.IsNull())
312 {
313 return myTextureBound;
314 }
315
e3414ada 316 const Handle(OpenGl_Sampler)& aSampler = myGlContext->TextureSampler();
317 if (!aSampler.IsNull())
318 {
319 aSampler->Unbind (*myGlContext);
320 }
321
ca3c13d1 322#if !defined(GL_ES_VERSION_2_0)
bf75be98 323 // reset texture matrix because some code may expect it is identity
4e1523ef 324 if (myGlContext->core11 != NULL)
325 {
326 GLint aMatrixMode = GL_TEXTURE;
327 glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
328 glMatrixMode (GL_TEXTURE);
329 glLoadIdentity();
330 glMatrixMode (aMatrixMode);
331 }
ca3c13d1 332#endif
bf75be98 333
334 myTextureBound->Unbind (myGlContext);
335 switch (myTextureBound->GetTarget())
336 {
ca3c13d1 337 #if !defined(GL_ES_VERSION_2_0)
bf75be98 338 case GL_TEXTURE_1D:
339 {
4e1523ef 340 if (myGlContext->core11 != NULL)
bf75be98 341 {
4e1523ef 342 if (myTextureBound->GetParams()->GenMode() != GL_NONE)
343 {
344 glDisable (GL_TEXTURE_GEN_S);
345 }
346 glDisable (GL_TEXTURE_1D);
bf75be98 347 }
bf75be98 348 break;
349 }
ca3c13d1 350 #endif
bf75be98 351 case GL_TEXTURE_2D:
352 {
ca3c13d1 353 #if !defined(GL_ES_VERSION_2_0)
4e1523ef 354 if (myGlContext->core11 != NULL)
bf75be98 355 {
4e1523ef 356 if (myTextureBound->GetParams()->GenMode() != GL_NONE)
a577aaab 357 {
4e1523ef 358 glDisable (GL_TEXTURE_GEN_S);
359 glDisable (GL_TEXTURE_GEN_T);
360 if (myTextureBound->GetParams()->GenMode() == Graphic3d_TOTM_SPRITE)
361 {
362 glDisable (GL_POINT_SPRITE);
363 }
a577aaab 364 }
4e1523ef 365 glDisable (GL_TEXTURE_2D);
bf75be98 366 }
05e2200b 367 #endif
bf75be98 368 break;
369 }
370 default: break;
371 }
372
373 Handle(OpenGl_Texture) aPrevTexture = myTextureBound;
374 myTextureBound.Nullify();
375 return aPrevTexture;
376}
377
378// =======================================================================
379// function : setTextureParams
380// purpose :
381// =======================================================================
382void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)& theTexture,
383 const Handle(Graphic3d_TextureParams)& theParams)
384{
385 const Handle(Graphic3d_TextureParams)& aParams = theParams.IsNull() ? theTexture->GetParams() : theParams;
386 if (aParams.IsNull())
387 {
388 return;
389 }
390
ca3c13d1 391#if !defined(GL_ES_VERSION_2_0)
bf75be98 392 GLint aMatrixMode = GL_TEXTURE;
4e1523ef 393 if (myGlContext->core11 != NULL)
394 {
395 glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
396
397 // setup texture matrix
398 glMatrixMode (GL_TEXTURE);
399 OpenGl_Mat4 aTextureMat;
400 const Graphic3d_Vec2& aScale = aParams->Scale();
401 const Graphic3d_Vec2& aTrans = aParams->Translation();
402 OpenGl_Utils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f);
403 OpenGl_Utils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f);
404 OpenGl_Utils::Rotate (aTextureMat, -aParams->Rotation(), 0.0f, 0.0f, 1.0f);
405 glLoadMatrixf (aTextureMat);
406
407 GLint anEnvMode = GL_MODULATE; // lighting mode
408 if (!aParams->IsModulate())
076ca35c 409 {
4e1523ef 410 anEnvMode = GL_DECAL;
411 if (theTexture->GetFormat() == GL_ALPHA
412 || theTexture->GetFormat() == GL_LUMINANCE)
413 {
414 anEnvMode = GL_REPLACE;
415 }
076ca35c 416 }
076ca35c 417
4e1523ef 418 // setup generation of texture coordinates
419 switch (aParams->GenMode())
bf75be98 420 {
4e1523ef 421 case Graphic3d_TOTM_OBJECT:
bf75be98 422 {
4e1523ef 423 glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
424 glTexGenfv (GL_S, GL_OBJECT_PLANE, aParams->GenPlaneS().GetData());
425 if (theTexture->GetTarget() != GL_TEXTURE_1D)
426 {
427 glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
428 glTexGenfv (GL_T, GL_OBJECT_PLANE, aParams->GenPlaneT().GetData());
429 }
430 break;
bf75be98 431 }
4e1523ef 432 case Graphic3d_TOTM_SPHERE:
bf75be98 433 {
4e1523ef 434 glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
435 if (theTexture->GetTarget() != GL_TEXTURE_1D)
436 {
437 glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
438 }
439 break;
bf75be98 440 }
4e1523ef 441 case Graphic3d_TOTM_EYE:
442 {
443 myGlContext->WorldViewState.Push();
c827ea3a 444
4e1523ef 445 myGlContext->WorldViewState.SetIdentity();
446 myGlContext->ApplyWorldViewMatrix();
bf75be98 447
4e1523ef 448 glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
449 glTexGenfv (GL_S, GL_EYE_PLANE, aParams->GenPlaneS().GetData());
bf75be98 450
4e1523ef 451 if (theTexture->GetTarget() != GL_TEXTURE_1D)
452 {
453 glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
454 glTexGenfv (GL_T, GL_EYE_PLANE, aParams->GenPlaneT().GetData());
455 }
c827ea3a 456
4e1523ef 457 myGlContext->WorldViewState.Pop();
c827ea3a 458
4e1523ef 459 break;
460 }
461 case Graphic3d_TOTM_SPRITE:
a577aaab 462 {
4e1523ef 463 if (GetGlContext()->core20fwd != NULL)
464 {
465 glEnable (GL_POINT_SPRITE);
466 glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
467 anEnvMode = GL_REPLACE;
468 GetGlContext()->core15->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
469 }
470 break;
a577aaab 471 }
4e1523ef 472 case Graphic3d_TOTM_MANUAL:
473 default: break;
a577aaab 474 }
bf75be98 475
4e1523ef 476 // setup lighting
477 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, anEnvMode);
478 }
ca3c13d1 479#endif
bf75be98 480
25ef750e 481 // get active sampler object to override default texture parameters
482 const Handle(OpenGl_Sampler)& aSampler = myGlContext->TextureSampler();
483
bf75be98 484 // setup texture filtering and wrapping
485 //if (theTexture->GetParams() != theParams)
486 const GLenum aFilter = (aParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
ca3c13d1 487 const GLenum aWrapMode = aParams->IsRepeat() ? GL_REPEAT : myGlContext->TextureWrapClamp();
bf75be98 488 switch (theTexture->GetTarget())
489 {
ca3c13d1 490 #if !defined(GL_ES_VERSION_2_0)
bf75be98 491 case GL_TEXTURE_1D:
492 {
25ef750e 493 if (aSampler.IsNull() || !aSampler->IsValid())
494 {
495 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, aFilter);
496 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, aFilter);
497 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, aWrapMode);
498 }
499 else
500 {
501 aSampler->SetParameter (*myGlContext, GL_TEXTURE_MAG_FILTER, aFilter);
502 aSampler->SetParameter (*myGlContext, GL_TEXTURE_MIN_FILTER, aFilter);
503 aSampler->SetParameter (*myGlContext, GL_TEXTURE_WRAP_S, aWrapMode);
504 }
505
bf75be98 506 break;
507 }
ca3c13d1 508 #endif
bf75be98 509 case GL_TEXTURE_2D:
510 {
511 GLenum aFilterMin = aFilter;
512 if (theTexture->HasMipmaps())
513 {
514 aFilterMin = GL_NEAREST_MIPMAP_NEAREST;
515 if (aParams->Filter() == Graphic3d_TOTF_BILINEAR)
516 {
517 aFilterMin = GL_LINEAR_MIPMAP_NEAREST;
518 }
519 else if (aParams->Filter() == Graphic3d_TOTF_TRILINEAR)
520 {
521 aFilterMin = GL_LINEAR_MIPMAP_LINEAR;
522 }
523
524 if (myGlContext->extAnis)
525 {
526 // setup degree of anisotropy filter
527 const GLint aMaxDegree = myGlContext->MaxDegreeOfAnisotropy();
25ef750e 528 GLint aDegree;
bf75be98 529 switch (aParams->AnisoFilter())
530 {
531 case Graphic3d_LOTA_QUALITY:
532 {
25ef750e 533 aDegree = aMaxDegree;
bf75be98 534 break;
535 }
536 case Graphic3d_LOTA_MIDDLE:
537 {
25ef750e 538 aDegree = (aMaxDegree <= 4) ? 2 : (aMaxDegree / 2);
bf75be98 539 break;
540 }
541 case Graphic3d_LOTA_FAST:
542 {
25ef750e 543 aDegree = 2;
bf75be98 544 break;
545 }
546 case Graphic3d_LOTA_OFF:
547 default:
548 {
25ef750e 549 aDegree = 1;
bf75be98 550 break;
551 }
552 }
25ef750e 553
554 if (aSampler.IsNull() || !aSampler->IsValid())
555 {
556 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aDegree);
557 }
558 else
559 {
560 aSampler->SetParameter (*myGlContext, GL_TEXTURE_MAX_ANISOTROPY_EXT, aDegree);
561 }
bf75be98 562 }
563 }
25ef750e 564
565 if (aSampler.IsNull() || !aSampler->IsValid())
566 {
567 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterMin);
568 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilter);
569 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aWrapMode);
570 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aWrapMode);
571 }
572 else
573 {
574 aSampler->SetParameter (*myGlContext, GL_TEXTURE_MIN_FILTER, aFilterMin);
575 aSampler->SetParameter (*myGlContext, GL_TEXTURE_MAG_FILTER, aFilter);
576 aSampler->SetParameter (*myGlContext, GL_TEXTURE_WRAP_S, aWrapMode);
577 aSampler->SetParameter (*myGlContext, GL_TEXTURE_WRAP_T, aWrapMode);
578 }
579
bf75be98 580 break;
581 }
582 default: break;
583 }
584
585 switch (theTexture->GetTarget())
586 {
ca3c13d1 587 #if !defined(GL_ES_VERSION_2_0)
bf75be98 588 case GL_TEXTURE_1D:
589 {
4e1523ef 590 if (myGlContext->core11 != NULL)
bf75be98 591 {
4e1523ef 592 if (aParams->GenMode() != Graphic3d_TOTM_MANUAL)
593 {
594 glEnable (GL_TEXTURE_GEN_S);
595 }
596 glEnable (GL_TEXTURE_1D);
bf75be98 597 }
bf75be98 598 break;
599 }
ca3c13d1 600 #endif
bf75be98 601 case GL_TEXTURE_2D:
602 {
ca3c13d1 603 #if !defined(GL_ES_VERSION_2_0)
4e1523ef 604 if (myGlContext->core11 != NULL)
bf75be98 605 {
4e1523ef 606 if (aParams->GenMode() != Graphic3d_TOTM_MANUAL)
607 {
608 glEnable (GL_TEXTURE_GEN_S);
609 glEnable (GL_TEXTURE_GEN_T);
610 }
611 glEnable (GL_TEXTURE_2D);
bf75be98 612 }
05e2200b 613 #endif
bf75be98 614 break;
615 }
616 default: break;
617 }
618
ca3c13d1 619#if !defined(GL_ES_VERSION_2_0)
4e1523ef 620 if (myGlContext->core11 != NULL)
621 {
622 glMatrixMode (aMatrixMode); // turn back active matrix
623 }
ca3c13d1 624#endif
bf75be98 625 theTexture->SetParams (aParams);
626}
627
628// =======================================================================
629// function : EnableTexture
630// purpose :
631// =======================================================================
632Handle(OpenGl_Texture) OpenGl_Workspace::EnableTexture (const Handle(OpenGl_Texture)& theTexture,
633 const Handle(Graphic3d_TextureParams)& theParams)
634{
635 if (theTexture.IsNull() || !theTexture->IsValid())
636 {
637 return DisableTexture();
638 }
639
bca1d6e2 640 if (myTextureBound == theTexture
641 && (theParams.IsNull() || theParams == theTexture->GetParams()))
bf75be98 642 {
bca1d6e2 643 // already bound
644 return myTextureBound;
bf75be98 645 }
646
647 Handle(OpenGl_Texture) aPrevTexture = DisableTexture();
648 myTextureBound = theTexture;
649 myTextureBound->Bind (myGlContext);
650 setTextureParams (myTextureBound, theParams);
651
25ef750e 652 // If custom sampler object is available it will be
653 // used for overriding default texture parameters
654 const Handle(OpenGl_Sampler)& aSampler = myGlContext->TextureSampler();
655
656 if (!aSampler.IsNull() && aSampler->IsValid())
657 {
658 aSampler->Bind (*myGlContext);
659 }
660
bf75be98 661 return aPrevTexture;
662}
a174a3c5 663
664// =======================================================================
665// function : Redraw
666// purpose :
667// =======================================================================
668void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
669 const Aspect_CLayer2d& theCUnderLayer,
670 const Aspect_CLayer2d& theCOverLayer)
671{
672 if (!Activate())
673 {
674 return;
675 }
676
a89742cf 677 ++myFrameCounter;
b7cd4ba7 678 myIsCullingEnabled = theCView.IsCullingEnabled;
679
a174a3c5 680 // release pending GL resources
ee51a9fe 681 myGlContext->ReleaseDelayed();
a174a3c5 682
b5ac8292 683 // fetch OpenGl context state
ee51a9fe 684 myGlContext->FetchState();
a174a3c5 685
a174a3c5 686 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO;
687 if (aFrameBuffer != NULL)
688 {
ee51a9fe 689 aFrameBuffer->SetupViewport (myGlContext);
a174a3c5 690 }
e3573bb9 691 else
692 {
ee51a9fe 693 myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight);
e3573bb9 694 }
ee51a9fe 695 bool toSwap = myGlContext->IsRender()
696 && !myGlContext->caps->buffersNoSwap
697 && aFrameBuffer == NULL;
a174a3c5 698
b86bb3df 699 Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWidth;
700 Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myHeight;
701
ee51a9fe 702 if (myHasFboBlit
703 && myTransientDrawToFront)
b86bb3df 704 {
ee51a9fe 705 if (myResultFBO->GetVPSizeX() != aSizeX
706 || myResultFBO->GetVPSizeY() != aSizeY)
760c21c2 707 {
ee51a9fe 708 // prepare FBOs containing main scene
709 // for further blitting and rendering immediate presentations on top
710 if (myGlContext->core20fwd != NULL)
711 {
712 myResultFBO->Init (myGlContext, aSizeX, aSizeY);
713 }
714 }
715
716 if (myResultFBO->IsValid())
717 {
718 myResultFBO->SetupViewport (myGlContext);
760c21c2 719 }
b86bb3df 720 }
ee51a9fe 721 else
b86bb3df 722 {
ee51a9fe 723 myResultFBO->Release (myGlContext.operator->());
b86bb3df 724 }
725
a89742cf 726 myToRedrawGL = Standard_True;
727 if (theCView.RenderParams.Method == Graphic3d_RM_RAYTRACING
728 && myComputeInitStatus != OpenGl_RT_FAIL)
e276548b 729 {
a89742cf 730 if (UpdateRaytraceGeometry (OpenGl_GUM_CHECK) && myIsRaytraceDataValid)
731 {
732 myToRedrawGL = Standard_False;
733
734 // Only non-raytracable structures should be rendered in OpenGL mode.
735 Handle(OpenGl_RenderFilter) aRenderFilter = GetRenderFilter();
736 myRaytraceFilter->SetPrevRenderFilter (aRenderFilter);
737 SetRenderFilter (myRaytraceFilter);
738
a89742cf 739 if (myOpenGlFBO.IsNull())
740 {
741 myOpenGlFBO = new OpenGl_FrameBuffer();
742 }
743 if (myOpenGlFBO->GetVPSizeX() != aSizeX
744 || myOpenGlFBO->GetVPSizeY() != aSizeY)
745 {
ee51a9fe 746 myOpenGlFBO->Init (myGlContext, aSizeX, aSizeY);
a89742cf 747 }
748
749 // OverLayer and UnderLayer shouldn't be drawn by OpenGL.
750 // They will be drawn during ray-tracing.
751 Aspect_CLayer2d anEmptyCLayer;
752 anEmptyCLayer.ptrLayer = NULL;
753
ee51a9fe 754 myOpenGlFBO->BindBuffer (myGlContext);
755 redraw1 (theCView, anEmptyCLayer, anEmptyCLayer);
756 myOpenGlFBO->UnbindBuffer (myGlContext);
a89742cf 757
ee51a9fe 758 Raytrace (theCView, aSizeX, aSizeY,
b86bb3df 759 theCOverLayer, theCUnderLayer,
760 myResultFBO->IsValid() ? myResultFBO.operator->() : aFrameBuffer);
ee51a9fe 761 myBackBufferRestored = Standard_True;
762 myIsImmediateDrawn = Standard_False;
763 if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aFrameBuffer))
a89742cf 764 {
ee51a9fe 765 toSwap = false;
a89742cf 766 }
767
768 SetRenderFilter (aRenderFilter);
769
770 theCView.WasRedrawnGL = Standard_False;
771 }
772 }
773
774 if (myToRedrawGL)
775 {
776 // draw entire frame using normal OpenGL pipeline
b86bb3df 777 if (myResultFBO->IsValid())
778 {
ee51a9fe 779 myResultFBO->BindBuffer (myGlContext);
b86bb3df 780 }
781 else if (aFrameBuffer != NULL)
a89742cf 782 {
ee51a9fe 783 aFrameBuffer->BindBuffer (myGlContext);
a89742cf 784 }
785
ee51a9fe 786 redraw1 (theCView, theCUnderLayer, theCOverLayer);
787 myBackBufferRestored = Standard_True;
788 myIsImmediateDrawn = Standard_False;
789 if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aFrameBuffer))
e276548b 790 {
ee51a9fe 791 toSwap = false;
e276548b 792 }
793
794 theCView.WasRedrawnGL = Standard_True;
e276548b 795 }
a174a3c5 796
797 if (aFrameBuffer != NULL)
798 {
ee51a9fe 799 aFrameBuffer->UnbindBuffer (myGlContext);
a174a3c5 800 // move back original viewport
ee51a9fe 801 myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight);
a174a3c5 802 }
803
679ecdee 804#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
a174a3c5 805 if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow))
806 {
807 GLint params[4];
808 glGetIntegerv (GL_VIEWPORT, params);
809 int nWidth = params[2] & ~0x7;
810 int nHeight = params[3] & ~0x7;
811
812 const int nBitsPerPixel = 24;
813 GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8];
814
815 glPixelStorei (GL_PACK_ALIGNMENT, 1);
816 glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData);
817 OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel);
818 delete[] aDumpData;
819 }
820#endif
821
ee51a9fe 822 // Swap the buffers
823 if (toSwap)
824 {
825 GetGlContext()->SwapBuffers();
826 if (!myResultFBO->IsValid())
827 {
828 myBackBufferRestored = Standard_False;
829 }
830 }
831 else
832 {
833 myGlContext->core11fwd->glFlush();
834 }
835
a174a3c5 836 // reset render mode state
ee51a9fe 837 myGlContext->FetchState();
a174a3c5 838}
679ecdee 839
840// =======================================================================
841// function : redraw1
842// purpose :
843// =======================================================================
844void OpenGl_Workspace::redraw1 (const Graphic3d_CView& theCView,
845 const Aspect_CLayer2d& theCUnderLayer,
ee51a9fe 846 const Aspect_CLayer2d& theCOverLayer)
679ecdee 847{
73192b37 848 if (myView.IsNull())
679ecdee 849 {
850 return;
851 }
852
853 // request reset of material
854 NamedStatus |= OPENGL_NS_RESMAT;
855
679ecdee 856 GLbitfield toClear = GL_COLOR_BUFFER_BIT;
857 if (myUseZBuffer)
858 {
859 glDepthFunc (GL_LEQUAL);
860 glDepthMask (GL_TRUE);
861 if (myUseDepthTest)
862 {
863 glEnable (GL_DEPTH_TEST);
864 }
865 else
866 {
867 glDisable (GL_DEPTH_TEST);
868 }
869
ca3c13d1 870 #if !defined(GL_ES_VERSION_2_0)
679ecdee 871 glClearDepth (1.0);
ca3c13d1 872 #else
873 glClearDepthf (1.0f);
874 #endif
679ecdee 875 toClear |= GL_DEPTH_BUFFER_BIT;
876 }
877 else
878 {
879 glDisable (GL_DEPTH_TEST);
880 }
881
a89742cf 882 if (!ToRedrawGL())
679ecdee 883 {
a89742cf 884 // set background to black
885 glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
886 toClear |= GL_DEPTH_BUFFER_BIT; //
679ecdee 887 }
888 else
889 {
a89742cf 890 if (NamedStatus & OPENGL_NS_WHITEBACK)
891 {
892 // set background to white
893 glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
894 toClear |= GL_DEPTH_BUFFER_BIT;
895 }
896 else
897 {
898 glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
899 }
679ecdee 900 }
901 glClear (toClear);
902
903 Handle(OpenGl_Workspace) aWS (this);
a1954302 904 myView->Render (myPrintContext, aWS, theCView, theCUnderLayer, theCOverLayer, Standard_False);
679ecdee 905}
906
907// =======================================================================
908// function : copyBackToFront
909// purpose :
910// =======================================================================
911void OpenGl_Workspace::copyBackToFront()
912{
ca3c13d1 913#if !defined(GL_ES_VERSION_2_0)
ca3c13d1 914
c827ea3a 915 OpenGl_Mat4 aProjectMat;
916 OpenGl_Utils::Ortho2D<Standard_ShortReal> (aProjectMat,
917 0.f, static_cast<GLfloat> (myWidth), 0.f, static_cast<GLfloat> (myHeight));
918
919 myGlContext->WorldViewState.Push();
920 myGlContext->ProjectionState.Push();
921
922 myGlContext->WorldViewState.SetIdentity();
923 myGlContext->ProjectionState.SetCurrent (aProjectMat);
924
925 myGlContext->ApplyProjectionMatrix();
926 myGlContext->ApplyWorldViewMatrix();
679ecdee 927
928 DisableFeatures();
929
930 glDrawBuffer (GL_FRONT);
931 glReadBuffer (GL_BACK);
932
933 glRasterPos2i (0, 0);
934 glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_COLOR);
a1954302 935 //glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH);
679ecdee 936
937 EnableFeatures();
938
c827ea3a 939 myGlContext->WorldViewState.Pop();
940 myGlContext->ProjectionState.Pop();
941 myGlContext->ApplyProjectionMatrix();
679ecdee 942 glDrawBuffer (GL_BACK);
943
ca3c13d1 944#endif
679ecdee 945 myIsImmediateDrawn = Standard_False;
946}
947
948// =======================================================================
949// function : DisplayCallback
950// purpose :
951// =======================================================================
952void OpenGl_Workspace::DisplayCallback (const Graphic3d_CView& theCView,
953 Standard_Integer theReason)
954{
955 if (theCView.GDisplayCB == NULL)
956 {
957 return;
958 }
959
960 Aspect_GraphicCallbackStruct aCallData;
961 aCallData.reason = theReason;
4e1523ef 962 aCallData.glContext = myGlContext;
679ecdee 963 aCallData.wsID = theCView.WsId;
964 aCallData.viewID = theCView.ViewId;
4e1523ef 965 aCallData.IsCoreProfile = (myGlContext->core11 == NULL);
679ecdee 966 theCView.GDisplayCB (theCView.DefWindow.XWindow, theCView.GClientData, &aCallData);
967}
968
969// =======================================================================
970// function : RedrawImmediate
971// purpose :
972// =======================================================================
973void OpenGl_Workspace::RedrawImmediate (const Graphic3d_CView& theCView,
974 const Aspect_CLayer2d& theCUnderLayer,
ee51a9fe 975 const Aspect_CLayer2d& theCOverLayer)
679ecdee 976{
ee51a9fe 977 if (!myTransientDrawToFront
978 || !myBackBufferRestored
979 || (myGlContext->caps->buffersNoSwap && !myResultFBO->IsValid()))
679ecdee 980 {
ee51a9fe 981 Redraw (theCView, theCUnderLayer, theCOverLayer);
679ecdee 982 return;
983 }
ee51a9fe 984 else if (!Activate())
679ecdee 985 {
679ecdee 986 return;
987 }
988
ee51a9fe 989 if (redrawImmediate (theCView, theCUnderLayer, theCOverLayer, NULL, Standard_True))
b86bb3df 990 {
ee51a9fe 991 myGlContext->SwapBuffers();
992 }
993 else
994 {
995 myGlContext->core11fwd->glFlush();
996 MakeBackBufCurrent();
997 }
998}
b86bb3df 999
ee51a9fe 1000// =======================================================================
1001// function : redrawImmediate
1002// purpose :
1003// =======================================================================
1004bool OpenGl_Workspace::redrawImmediate (const Graphic3d_CView& theCView,
1005 const Aspect_CLayer2d& theCUnderLayer,
1006 const Aspect_CLayer2d& theCOverLayer,
1007 OpenGl_FrameBuffer* theTargetFBO,
1008 const Standard_Boolean theIsPartialUpdate)
1009{
1010 GLboolean toCopyBackToFront = GL_FALSE;
1011 if (!myTransientDrawToFront)
1012 {
1013 myBackBufferRestored = Standard_False;
1014 }
1015 else if (myResultFBO->IsValid()
1016 && myGlContext->IsRender())
1017 {
b86bb3df 1018 // clear destination before blitting
1019 if (theTargetFBO != NULL)
1020 {
1021 theTargetFBO->BindBuffer (myGlContext);
1022 }
1023 else
1024 {
1025 myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1026 }
1027 #if !defined(GL_ES_VERSION_2_0)
1028 myGlContext->core20fwd->glClearDepth (1.0);
1029 #else
1030 myGlContext->core20fwd->glClearDepthf (1.0f);
1031 #endif
1032 myGlContext->core20fwd->glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1033
1034 /*#if !defined(GL_ES_VERSION_2_0)
1035 if (myGlContext->arbFBOBlit != NULL)
1036 {
1037 myResultFBO->BindReadBuffer (myGlContext);
1038 if (theTargetFBO != NULL)
1039 {
1040 theTargetFBO->BindDrawBuffer (myGlContext);
1041 }
1042 else
1043 {
1044 myGlContext->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1045 }
1046 // we don't copy stencil buffer here... does it matter for performance?
1047 myGlContext->arbFBOBlit->glBlitFramebuffer (0, 0, myResultFBO->GetVPSizeX(), myResultFBO->GetVPSizeY(),
1048 0, 0, myResultFBO->GetVPSizeX(), myResultFBO->GetVPSizeY(),
1049 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
1050
1051 if (theTargetFBO != NULL)
1052 {
1053 theTargetFBO->BindBuffer (myGlContext);
1054 }
1055 else
1056 {
1057 myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1058 }
1059 }
1060 else
1061 #endif*/
1062 {
1063 myGlContext->core20fwd->glDepthFunc (GL_ALWAYS);
1064 myGlContext->core20fwd->glDepthMask (GL_TRUE);
1065 myGlContext->core20fwd->glEnable (GL_DEPTH_TEST);
1066
1067 DisableTexture();
1068 if (!myFullScreenQuad.IsValid())
1069 {
1070 OpenGl_Vec4 aQuad[4] =
1071 {
1072 OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f),
1073 OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 1.0f),
1074 OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f),
1075 OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 1.0f)
1076 };
1077 myFullScreenQuad.Init (myGlContext, 4, 4, aQuad[0].GetData());
1078 }
1079
1080 const Handle(OpenGl_ShaderManager)& aManager = myGlContext->ShaderManager();
1081 if (myFullScreenQuad.IsValid()
1082 && aManager->BindFboBlitProgram())
1083 {
1084 myResultFBO->ColorTexture() ->Bind (myGlContext, GL_TEXTURE0 + 0);
1085 myResultFBO->DepthStencilTexture()->Bind (myGlContext, GL_TEXTURE0 + 1);
1086 myFullScreenQuad.BindVertexAttrib (myGlContext, 0);
1087
1088 myGlContext->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
1089
1090 myFullScreenQuad.UnbindVertexAttrib (myGlContext, 0);
1091 myResultFBO->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + 1);
1092 myResultFBO->ColorTexture() ->Unbind (myGlContext, GL_TEXTURE0 + 0);
1093 }
ee51a9fe 1094 else
1095 {
1096 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
1097 + "Error! FBO blitting has failed";
1098 myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
1099 GL_DEBUG_TYPE_ERROR_ARB,
1100 0,
1101 GL_DEBUG_SEVERITY_HIGH_ARB,
1102 aMsg);
1103 myHasFboBlit = Standard_False;
1104 myResultFBO->Release (myGlContext.operator->());
1105 return true;
1106 }
b86bb3df 1107 }
1108 }
ee51a9fe 1109 else if (theTargetFBO == NULL)
679ecdee 1110 {
ee51a9fe 1111 #if !defined(GL_ES_VERSION_2_0)
1112 myGlContext->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront);
1113 #endif
1114 if (toCopyBackToFront)
679ecdee 1115 {
ee51a9fe 1116 if (!myView->HasImmediateStructures()
1117 && !theIsPartialUpdate)
1118 {
1119 // prefer Swap Buffers within Redraw in compatibility mode (without FBO)
1120 return true;
1121 }
1122 copyBackToFront();
1123 MakeFrontBufCurrent();
1124 }
1125 else
1126 {
1127 myBackBufferRestored = Standard_False;
679ecdee 1128 }
679ecdee 1129 }
1130 else
1131 {
1132 myBackBufferRestored = Standard_False;
1133 }
1134 myIsImmediateDrawn = Standard_True;
1135
679ecdee 1136 Handle(OpenGl_Workspace) aWS (this);
a1954302 1137
1138 if (myUseZBuffer)
1139 {
1140 glDepthFunc (GL_LEQUAL);
1141 glDepthMask (GL_TRUE);
1142 if (myUseDepthTest)
1143 {
1144 glEnable (GL_DEPTH_TEST);
1145 }
1146 else
1147 {
1148 glDisable (GL_DEPTH_TEST);
1149 }
1150
1151 #if !defined(GL_ES_VERSION_2_0)
1152 glClearDepth (1.0);
1153 #else
1154 glClearDepthf (1.0f);
1155 #endif
1156 }
1157 else
1158 {
1159 glDisable (GL_DEPTH_TEST);
1160 }
1161
1162 myView->Render (myPrintContext, aWS, theCView, theCUnderLayer, theCOverLayer, Standard_True);
1163 if (!myView->ImmediateStructures().IsEmpty())
1164 {
1165 glDisable (GL_DEPTH_TEST);
1166 }
679ecdee 1167 for (OpenGl_SequenceOfStructure::Iterator anIter (myView->ImmediateStructures());
1168 anIter.More(); anIter.Next())
1169 {
1170 const OpenGl_Structure* aStructure = anIter.Value();
a1954302 1171 if (!aStructure->IsVisible())
1172 {
1173 continue;
1174 }
1175
679ecdee 1176 aStructure->Render (aWS);
1177 }
1178
ee51a9fe 1179 if (toCopyBackToFront)
679ecdee 1180 {
679ecdee 1181 MakeBackBufCurrent();
ee51a9fe 1182 return false;
679ecdee 1183 }
ee51a9fe 1184 return true;
679ecdee 1185}