0025992: Method Geom2dAPI_InterCurveCurve::Segment(...) requires detail revision
[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
70// =======================================================================
0adbd30f 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
136// =======================================================================
2166f0fa
SK
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
223// =======================================================================
1981cb22 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
234// =======================================================================
2166f0fa
SK
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
a2e4f780 702 if (!myGlContext->DefaultFrameBuffer().IsNull()
703 && myGlContext->DefaultFrameBuffer()->IsValid())
704 {
705 myGlContext->DefaultFrameBuffer()->BindBuffer (myGlContext);
706 }
707
ee51a9fe 708 if (myHasFboBlit
709 && myTransientDrawToFront)
b86bb3df 710 {
ee51a9fe 711 if (myResultFBO->GetVPSizeX() != aSizeX
712 || myResultFBO->GetVPSizeY() != aSizeY)
760c21c2 713 {
ee51a9fe 714 // prepare FBOs containing main scene
715 // for further blitting and rendering immediate presentations on top
716 if (myGlContext->core20fwd != NULL)
717 {
718 myResultFBO->Init (myGlContext, aSizeX, aSizeY);
719 }
720 }
721
722 if (myResultFBO->IsValid())
723 {
724 myResultFBO->SetupViewport (myGlContext);
760c21c2 725 }
b86bb3df 726 }
ee51a9fe 727 else
b86bb3df 728 {
ee51a9fe 729 myResultFBO->Release (myGlContext.operator->());
b86bb3df 730 }
731
a89742cf 732 myToRedrawGL = Standard_True;
733 if (theCView.RenderParams.Method == Graphic3d_RM_RAYTRACING
734 && myComputeInitStatus != OpenGl_RT_FAIL)
e276548b 735 {
07039714 736 if (InitRaytraceResources (theCView) && UpdateRaytraceGeometry (OpenGl_GUM_CHECK) && myIsRaytraceDataValid)
a89742cf 737 {
738 myToRedrawGL = Standard_False;
739
740 // Only non-raytracable structures should be rendered in OpenGL mode.
741 Handle(OpenGl_RenderFilter) aRenderFilter = GetRenderFilter();
742 myRaytraceFilter->SetPrevRenderFilter (aRenderFilter);
743 SetRenderFilter (myRaytraceFilter);
744
a89742cf 745 if (myOpenGlFBO.IsNull())
746 {
747 myOpenGlFBO = new OpenGl_FrameBuffer();
748 }
749 if (myOpenGlFBO->GetVPSizeX() != aSizeX
750 || myOpenGlFBO->GetVPSizeY() != aSizeY)
751 {
ee51a9fe 752 myOpenGlFBO->Init (myGlContext, aSizeX, aSizeY);
a89742cf 753 }
754
755 // OverLayer and UnderLayer shouldn't be drawn by OpenGL.
756 // They will be drawn during ray-tracing.
757 Aspect_CLayer2d anEmptyCLayer;
758 anEmptyCLayer.ptrLayer = NULL;
759
ee51a9fe 760 myOpenGlFBO->BindBuffer (myGlContext);
761 redraw1 (theCView, anEmptyCLayer, anEmptyCLayer);
762 myOpenGlFBO->UnbindBuffer (myGlContext);
a89742cf 763
ee51a9fe 764 Raytrace (theCView, aSizeX, aSizeY,
b86bb3df 765 theCOverLayer, theCUnderLayer,
766 myResultFBO->IsValid() ? myResultFBO.operator->() : aFrameBuffer);
ee51a9fe 767 myBackBufferRestored = Standard_True;
768 myIsImmediateDrawn = Standard_False;
769 if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aFrameBuffer))
a89742cf 770 {
ee51a9fe 771 toSwap = false;
a89742cf 772 }
773
774 SetRenderFilter (aRenderFilter);
775
776 theCView.WasRedrawnGL = Standard_False;
777 }
778 }
779
780 if (myToRedrawGL)
781 {
782 // draw entire frame using normal OpenGL pipeline
b86bb3df 783 if (myResultFBO->IsValid())
784 {
ee51a9fe 785 myResultFBO->BindBuffer (myGlContext);
b86bb3df 786 }
787 else if (aFrameBuffer != NULL)
a89742cf 788 {
ee51a9fe 789 aFrameBuffer->BindBuffer (myGlContext);
a89742cf 790 }
791
ee51a9fe 792 redraw1 (theCView, theCUnderLayer, theCOverLayer);
793 myBackBufferRestored = Standard_True;
794 myIsImmediateDrawn = Standard_False;
795 if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aFrameBuffer))
e276548b 796 {
ee51a9fe 797 toSwap = false;
e276548b 798 }
799
800 theCView.WasRedrawnGL = Standard_True;
e276548b 801 }
a174a3c5 802
803 if (aFrameBuffer != NULL)
804 {
ee51a9fe 805 aFrameBuffer->UnbindBuffer (myGlContext);
a174a3c5 806 // move back original viewport
ee51a9fe 807 myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight);
a174a3c5 808 }
809
679ecdee 810#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
a174a3c5 811 if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow))
812 {
813 GLint params[4];
814 glGetIntegerv (GL_VIEWPORT, params);
815 int nWidth = params[2] & ~0x7;
816 int nHeight = params[3] & ~0x7;
817
818 const int nBitsPerPixel = 24;
819 GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8];
820
821 glPixelStorei (GL_PACK_ALIGNMENT, 1);
822 glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData);
823 OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel);
824 delete[] aDumpData;
825 }
826#endif
827
ee51a9fe 828 // Swap the buffers
829 if (toSwap)
830 {
831 GetGlContext()->SwapBuffers();
832 if (!myResultFBO->IsValid())
833 {
834 myBackBufferRestored = Standard_False;
835 }
836 }
837 else
838 {
839 myGlContext->core11fwd->glFlush();
840 }
841
a174a3c5 842 // reset render mode state
ee51a9fe 843 myGlContext->FetchState();
a174a3c5 844}
679ecdee 845
846// =======================================================================
847// function : redraw1
848// purpose :
849// =======================================================================
850void OpenGl_Workspace::redraw1 (const Graphic3d_CView& theCView,
851 const Aspect_CLayer2d& theCUnderLayer,
ee51a9fe 852 const Aspect_CLayer2d& theCOverLayer)
679ecdee 853{
73192b37 854 if (myView.IsNull())
679ecdee 855 {
856 return;
857 }
858
859 // request reset of material
860 NamedStatus |= OPENGL_NS_RESMAT;
861
679ecdee 862 GLbitfield toClear = GL_COLOR_BUFFER_BIT;
863 if (myUseZBuffer)
864 {
865 glDepthFunc (GL_LEQUAL);
866 glDepthMask (GL_TRUE);
867 if (myUseDepthTest)
868 {
869 glEnable (GL_DEPTH_TEST);
870 }
871 else
872 {
873 glDisable (GL_DEPTH_TEST);
874 }
875
ca3c13d1 876 #if !defined(GL_ES_VERSION_2_0)
679ecdee 877 glClearDepth (1.0);
ca3c13d1 878 #else
879 glClearDepthf (1.0f);
880 #endif
679ecdee 881 toClear |= GL_DEPTH_BUFFER_BIT;
882 }
883 else
884 {
885 glDisable (GL_DEPTH_TEST);
886 }
887
a89742cf 888 if (!ToRedrawGL())
679ecdee 889 {
a89742cf 890 // set background to black
891 glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
892 toClear |= GL_DEPTH_BUFFER_BIT; //
679ecdee 893 }
894 else
895 {
a89742cf 896 if (NamedStatus & OPENGL_NS_WHITEBACK)
897 {
898 // set background to white
899 glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
900 toClear |= GL_DEPTH_BUFFER_BIT;
901 }
902 else
903 {
904 glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
905 }
679ecdee 906 }
907 glClear (toClear);
908
909 Handle(OpenGl_Workspace) aWS (this);
a1954302 910 myView->Render (myPrintContext, aWS, theCView, theCUnderLayer, theCOverLayer, Standard_False);
679ecdee 911}
912
913// =======================================================================
914// function : copyBackToFront
915// purpose :
916// =======================================================================
917void OpenGl_Workspace::copyBackToFront()
918{
ca3c13d1 919#if !defined(GL_ES_VERSION_2_0)
ca3c13d1 920
c827ea3a 921 OpenGl_Mat4 aProjectMat;
922 OpenGl_Utils::Ortho2D<Standard_ShortReal> (aProjectMat,
923 0.f, static_cast<GLfloat> (myWidth), 0.f, static_cast<GLfloat> (myHeight));
924
925 myGlContext->WorldViewState.Push();
926 myGlContext->ProjectionState.Push();
927
928 myGlContext->WorldViewState.SetIdentity();
929 myGlContext->ProjectionState.SetCurrent (aProjectMat);
930
931 myGlContext->ApplyProjectionMatrix();
932 myGlContext->ApplyWorldViewMatrix();
679ecdee 933
934 DisableFeatures();
935
936 glDrawBuffer (GL_FRONT);
937 glReadBuffer (GL_BACK);
938
939 glRasterPos2i (0, 0);
940 glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_COLOR);
a1954302 941 //glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH);
679ecdee 942
943 EnableFeatures();
944
c827ea3a 945 myGlContext->WorldViewState.Pop();
946 myGlContext->ProjectionState.Pop();
947 myGlContext->ApplyProjectionMatrix();
679ecdee 948 glDrawBuffer (GL_BACK);
949
ca3c13d1 950#endif
679ecdee 951 myIsImmediateDrawn = Standard_False;
952}
953
954// =======================================================================
955// function : DisplayCallback
956// purpose :
957// =======================================================================
958void OpenGl_Workspace::DisplayCallback (const Graphic3d_CView& theCView,
959 Standard_Integer theReason)
960{
961 if (theCView.GDisplayCB == NULL)
962 {
963 return;
964 }
965
966 Aspect_GraphicCallbackStruct aCallData;
967 aCallData.reason = theReason;
4e1523ef 968 aCallData.glContext = myGlContext;
679ecdee 969 aCallData.wsID = theCView.WsId;
970 aCallData.viewID = theCView.ViewId;
4e1523ef 971 aCallData.IsCoreProfile = (myGlContext->core11 == NULL);
679ecdee 972 theCView.GDisplayCB (theCView.DefWindow.XWindow, theCView.GClientData, &aCallData);
973}
974
975// =======================================================================
976// function : RedrawImmediate
977// purpose :
978// =======================================================================
979void OpenGl_Workspace::RedrawImmediate (const Graphic3d_CView& theCView,
980 const Aspect_CLayer2d& theCUnderLayer,
ee51a9fe 981 const Aspect_CLayer2d& theCOverLayer)
679ecdee 982{
ee51a9fe 983 if (!myTransientDrawToFront
984 || !myBackBufferRestored
985 || (myGlContext->caps->buffersNoSwap && !myResultFBO->IsValid()))
679ecdee 986 {
ee51a9fe 987 Redraw (theCView, theCUnderLayer, theCOverLayer);
679ecdee 988 return;
989 }
ee51a9fe 990 else if (!Activate())
679ecdee 991 {
679ecdee 992 return;
993 }
994
a2e4f780 995 if (!myGlContext->DefaultFrameBuffer().IsNull()
996 && myGlContext->DefaultFrameBuffer()->IsValid())
997 {
998 myGlContext->DefaultFrameBuffer()->BindBuffer (myGlContext);
999 }
1000
ef0bfc15 1001 if (redrawImmediate (theCView, theCUnderLayer, theCOverLayer, NULL, Standard_True)
1002 && !myGlContext->caps->buffersNoSwap)
b86bb3df 1003 {
ee51a9fe 1004 myGlContext->SwapBuffers();
1005 }
1006 else
1007 {
1008 myGlContext->core11fwd->glFlush();
1009 MakeBackBufCurrent();
1010 }
1011}
b86bb3df 1012
ee51a9fe 1013// =======================================================================
1014// function : redrawImmediate
1015// purpose :
1016// =======================================================================
1017bool OpenGl_Workspace::redrawImmediate (const Graphic3d_CView& theCView,
1018 const Aspect_CLayer2d& theCUnderLayer,
1019 const Aspect_CLayer2d& theCOverLayer,
1020 OpenGl_FrameBuffer* theTargetFBO,
1021 const Standard_Boolean theIsPartialUpdate)
1022{
1023 GLboolean toCopyBackToFront = GL_FALSE;
1024 if (!myTransientDrawToFront)
1025 {
1026 myBackBufferRestored = Standard_False;
1027 }
1028 else if (myResultFBO->IsValid()
1029 && myGlContext->IsRender())
1030 {
b86bb3df 1031 // clear destination before blitting
1032 if (theTargetFBO != NULL)
1033 {
1034 theTargetFBO->BindBuffer (myGlContext);
1035 }
a2e4f780 1036 else if (!myGlContext->DefaultFrameBuffer().IsNull()
1037 && myGlContext->DefaultFrameBuffer()->IsValid())
1038 {
1039 myGlContext->DefaultFrameBuffer()->BindBuffer (myGlContext);
1040 }
b86bb3df 1041 else
1042 {
1043 myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1044 }
1045 #if !defined(GL_ES_VERSION_2_0)
1046 myGlContext->core20fwd->glClearDepth (1.0);
1047 #else
1048 myGlContext->core20fwd->glClearDepthf (1.0f);
1049 #endif
1050 myGlContext->core20fwd->glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1051
1052 /*#if !defined(GL_ES_VERSION_2_0)
1053 if (myGlContext->arbFBOBlit != NULL)
1054 {
1055 myResultFBO->BindReadBuffer (myGlContext);
1056 if (theTargetFBO != NULL)
1057 {
1058 theTargetFBO->BindDrawBuffer (myGlContext);
1059 }
a2e4f780 1060 else if (!myGlContext->DefaultFrameBuffer().IsNull()
1061 && myGlContext->DefaultFrameBuffer()->IsValid())
1062 {
1063 myGlContext->DefaultFrameBuffer()->BindDrawBuffer (myGlContext);
1064 }
b86bb3df 1065 else
1066 {
1067 myGlContext->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1068 }
1069 // we don't copy stencil buffer here... does it matter for performance?
1070 myGlContext->arbFBOBlit->glBlitFramebuffer (0, 0, myResultFBO->GetVPSizeX(), myResultFBO->GetVPSizeY(),
1071 0, 0, myResultFBO->GetVPSizeX(), myResultFBO->GetVPSizeY(),
1072 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
1073
1074 if (theTargetFBO != NULL)
1075 {
1076 theTargetFBO->BindBuffer (myGlContext);
1077 }
a2e4f780 1078 else if (!myGlContext->DefaultFrameBuffer().IsNull()
1079 && myGlContext->DefaultFrameBuffer()->IsValid())
1080 {
1081 myGlContext->DefaultFrameBuffer()->BindBuffer (myGlContext);
1082 }
b86bb3df 1083 else
1084 {
1085 myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1086 }
1087 }
1088 else
1089 #endif*/
1090 {
1091 myGlContext->core20fwd->glDepthFunc (GL_ALWAYS);
1092 myGlContext->core20fwd->glDepthMask (GL_TRUE);
1093 myGlContext->core20fwd->glEnable (GL_DEPTH_TEST);
1094
1095 DisableTexture();
1096 if (!myFullScreenQuad.IsValid())
1097 {
1098 OpenGl_Vec4 aQuad[4] =
1099 {
1100 OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f),
1101 OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 1.0f),
1102 OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f),
1103 OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 1.0f)
1104 };
1105 myFullScreenQuad.Init (myGlContext, 4, 4, aQuad[0].GetData());
1106 }
1107
1108 const Handle(OpenGl_ShaderManager)& aManager = myGlContext->ShaderManager();
1109 if (myFullScreenQuad.IsValid()
1110 && aManager->BindFboBlitProgram())
1111 {
1112 myResultFBO->ColorTexture() ->Bind (myGlContext, GL_TEXTURE0 + 0);
1113 myResultFBO->DepthStencilTexture()->Bind (myGlContext, GL_TEXTURE0 + 1);
1114 myFullScreenQuad.BindVertexAttrib (myGlContext, 0);
1115
1116 myGlContext->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
1117
1118 myFullScreenQuad.UnbindVertexAttrib (myGlContext, 0);
1119 myResultFBO->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + 1);
1120 myResultFBO->ColorTexture() ->Unbind (myGlContext, GL_TEXTURE0 + 0);
1121 }
ee51a9fe 1122 else
1123 {
1124 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
1125 + "Error! FBO blitting has failed";
1126 myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
1127 GL_DEBUG_TYPE_ERROR_ARB,
1128 0,
1129 GL_DEBUG_SEVERITY_HIGH_ARB,
1130 aMsg);
1131 myHasFboBlit = Standard_False;
1132 myResultFBO->Release (myGlContext.operator->());
1133 return true;
1134 }
b86bb3df 1135 }
1136 }
ee51a9fe 1137 else if (theTargetFBO == NULL)
679ecdee 1138 {
ee51a9fe 1139 #if !defined(GL_ES_VERSION_2_0)
1140 myGlContext->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront);
1141 #endif
1142 if (toCopyBackToFront)
679ecdee 1143 {
ee51a9fe 1144 if (!myView->HasImmediateStructures()
1145 && !theIsPartialUpdate)
1146 {
1147 // prefer Swap Buffers within Redraw in compatibility mode (without FBO)
1148 return true;
1149 }
1150 copyBackToFront();
1151 MakeFrontBufCurrent();
1152 }
1153 else
1154 {
1155 myBackBufferRestored = Standard_False;
679ecdee 1156 }
679ecdee 1157 }
1158 else
1159 {
1160 myBackBufferRestored = Standard_False;
1161 }
1162 myIsImmediateDrawn = Standard_True;
1163
679ecdee 1164 Handle(OpenGl_Workspace) aWS (this);
a1954302 1165
1166 if (myUseZBuffer)
1167 {
1168 glDepthFunc (GL_LEQUAL);
1169 glDepthMask (GL_TRUE);
1170 if (myUseDepthTest)
1171 {
1172 glEnable (GL_DEPTH_TEST);
1173 }
1174 else
1175 {
1176 glDisable (GL_DEPTH_TEST);
1177 }
1178
1179 #if !defined(GL_ES_VERSION_2_0)
1180 glClearDepth (1.0);
1181 #else
1182 glClearDepthf (1.0f);
1183 #endif
1184 }
1185 else
1186 {
1187 glDisable (GL_DEPTH_TEST);
1188 }
1189
1190 myView->Render (myPrintContext, aWS, theCView, theCUnderLayer, theCOverLayer, Standard_True);
1191 if (!myView->ImmediateStructures().IsEmpty())
1192 {
1193 glDisable (GL_DEPTH_TEST);
1194 }
679ecdee 1195 for (OpenGl_SequenceOfStructure::Iterator anIter (myView->ImmediateStructures());
1196 anIter.More(); anIter.Next())
1197 {
1198 const OpenGl_Structure* aStructure = anIter.Value();
a1954302 1199 if (!aStructure->IsVisible())
1200 {
1201 continue;
1202 }
1203
679ecdee 1204 aStructure->Render (aWS);
1205 }
1206
ee51a9fe 1207 if (toCopyBackToFront)
679ecdee 1208 {
679ecdee 1209 MakeBackBufCurrent();
ee51a9fe 1210 return false;
679ecdee 1211 }
ee51a9fe 1212 return true;
679ecdee 1213}