0026122: Visualization, TKOpenGl - clipping and capping is broken when ffp is disable...
[occt.git] / src / OpenGl / OpenGl_View_Redraw.cxx
CommitLineData
c357e426 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it 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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <stdio.h>
17#include <stdlib.h>
18
19#include <OpenGl_GlCore11.hxx>
20#include <OpenGl_tgl_funcs.hxx>
21
22#include <Graphic3d_GraphicDriver.hxx>
23#include <Graphic3d_TextureParams.hxx>
24#include <Graphic3d_Texture2Dmanual.hxx>
25#include <Graphic3d_TransformUtils.hxx>
26#include <Image_AlienPixMap.hxx>
27
28#include <NCollection_Mat4.hxx>
29
30#include <OpenGl_AspectLine.hxx>
31#include <OpenGl_Context.hxx>
32#include <OpenGl_Matrix.hxx>
33#include <OpenGl_Workspace.hxx>
34#include <OpenGl_View.hxx>
35#include <OpenGl_Trihedron.hxx>
36#include <OpenGl_GraduatedTrihedron.hxx>
37#include <OpenGl_PrimitiveArray.hxx>
38#include <OpenGl_PrinterContext.hxx>
39#include <OpenGl_ShaderManager.hxx>
40#include <OpenGl_ShaderProgram.hxx>
41#include <OpenGl_Structure.hxx>
42#include <OpenGl_ArbFBO.hxx>
43
44#define EPSI 0.0001
45
46namespace
47{
48 static const GLfloat THE_DEFAULT_AMBIENT[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
49 static const GLfloat THE_DEFAULT_SPOT_DIR[3] = { 0.0f, 0.0f, -1.0f };
50 static const GLfloat THE_DEFAULT_SPOT_EXPONENT = 0.0f;
51 static const GLfloat THE_DEFAULT_SPOT_CUTOFF = 180.0f;
52}
53
54extern void InitLayerProp (const int theListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx
55
56#if !defined(GL_ES_VERSION_2_0)
57
58//=======================================================================
59//function : bindLight
60//purpose :
61//=======================================================================
62static void bindLight (const OpenGl_Light& theLight,
63 GLenum& theLightGlId,
64 Graphic3d_Vec4& theAmbientColor,
65 const Handle(OpenGl_Workspace)& theWorkspace)
66{
67 // Only 8 lights in OpenGL...
68 if (theLightGlId > GL_LIGHT7)
69 {
70 return;
71 }
72
73 if (theLight.Type == Graphic3d_TOLS_AMBIENT)
74 {
75 // add RGBA intensity of the ambient light
76 theAmbientColor += theLight.Color;
77 return;
78 }
79
80 const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
81
82 // the light is a headlight?
83 if (theLight.IsHeadlight)
84 {
85 aContext->WorldViewState.Push();
86 aContext->WorldViewState.SetIdentity();
87
88 aContext->ApplyWorldViewMatrix();
89 }
90
91 // setup light type
92 switch (theLight.Type)
93 {
94 case Graphic3d_TOLS_AMBIENT : break; // handled by separate if-clause at beginning of method
95 case Graphic3d_TOLS_DIRECTIONAL:
96 {
97 // if the last parameter of GL_POSITION, is zero, the corresponding light source is a Directional one
98 const OpenGl_Vec4 anInfDir = -theLight.Direction;
99
100 // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE.
101 glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT);
102 glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData());
103 glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData());
104 glLightfv (theLightGlId, GL_POSITION, anInfDir.GetData());
105 glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR);
106 glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT);
107 glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF);
108 break;
109 }
110 case Graphic3d_TOLS_POSITIONAL:
111 {
112 // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE
113 glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT);
114 glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData());
115 glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData());
116 glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData());
117 glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR);
118 glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT);
119 glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF);
120 glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation());
121 glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation());
122 glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0);
123 break;
124 }
125 case Graphic3d_TOLS_SPOT:
126 {
127 glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT);
128 glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData());
129 glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData());
130 glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData());
131 glLightfv (theLightGlId, GL_SPOT_DIRECTION, theLight.Direction.GetData());
132 glLightf (theLightGlId, GL_SPOT_EXPONENT, theLight.Concentration() * 128.0f);
133 glLightf (theLightGlId, GL_SPOT_CUTOFF, (theLight.Angle() * 180.0f) / GLfloat(M_PI));
134 glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation());
135 glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation());
136 glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0f);
137 break;
138 }
139 }
140
141 // restore matrix in case of headlight
142 if (theLight.IsHeadlight)
143 {
144 aContext->WorldViewState.Pop();
145 }
146
147 glEnable (theLightGlId++);
148}
149#endif
150
151//=======================================================================
a521d90d 152//function : drawBackground
c357e426 153//purpose :
154//=======================================================================
a521d90d 155void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
c357e426 156{
157 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
158
159 if ((theWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) != 0 // no background
160 || (!myBgTextureArray->IsDefined() // no texture
161 && !myBgGradientArray->IsDefined())) // no gradient
162 {
163 return;
164 }
165
166 const Standard_Boolean wasUsedZBuffer = theWorkspace->SetUseZBuffer (Standard_False);
167 if (wasUsedZBuffer)
168 {
169 aCtx->core11fwd->glDisable (GL_DEPTH_TEST);
170 }
171
172 aCtx->ProjectionState.Push();
173 aCtx->WorldViewState.Push();
174 aCtx->ModelWorldState.Push();
175 aCtx->ProjectionState.SetIdentity();
176 aCtx->WorldViewState.SetIdentity();
177 aCtx->ModelWorldState.SetIdentity();
178 aCtx->ApplyProjectionMatrix();
179 aCtx->ApplyModelViewMatrix();
180
181 // Drawing background gradient if:
182 // - gradient fill type is not Aspect_GFM_NONE and
183 // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode
184 if (myBgGradientArray->IsDefined()
185 && (!myTextureParams->DoTextureMap()
186 || myBgTextureArray->TextureFillMethod() == Aspect_FM_CENTERED
187 || myBgTextureArray->TextureFillMethod() == Aspect_FM_NONE))
188 {
189 #if !defined(GL_ES_VERSION_2_0)
190 GLint aShadingModelOld = GL_SMOOTH;
191 if (aCtx->core11 != NULL)
192 {
193 aCtx->core11fwd->glDisable (GL_LIGHTING);
194 aCtx->core11fwd->glGetIntegerv (GL_SHADE_MODEL, &aShadingModelOld);
195 aCtx->core11->glShadeModel (GL_SMOOTH);
196 }
197 #endif
198
199 if (myBgGradientArray->IsDataChanged())
200 {
201 myBgGradientArray->Init (theWorkspace);
202 }
203
204 myBgGradientArray->Render (theWorkspace);
205
206 #if !defined(GL_ES_VERSION_2_0)
207 if (aCtx->core11 != NULL)
208 {
209 aCtx->core11->glShadeModel (aShadingModelOld);
210 }
211 #endif
212 }
213
214 // Drawing background image if it is defined
215 // (texture is defined and fill type is not Aspect_FM_NONE)
216 if (myBgTextureArray->IsDefined()
217 && myTextureParams->DoTextureMap())
218 {
219 aCtx->core11fwd->glDisable (GL_BLEND);
220
221 const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace (myTextureParams);
222
223 if (myBgTextureArray->IsDataChanged()
224 || myBgTextureArray->IsViewSizeChanged (theWorkspace))
225 {
226 myBgTextureArray->Init (theWorkspace);
227 }
228
229 myBgTextureArray->Render (theWorkspace);
230
231 // restore aspects
232 theWorkspace->SetAspectFace (anOldAspectFace);
233 }
234
235 aCtx->ModelWorldState.Pop();
236 aCtx->WorldViewState.Pop();
237 aCtx->ProjectionState.Pop();
238 aCtx->ApplyProjectionMatrix();
239 aCtx->ApplyModelViewMatrix();
240
241 if (wasUsedZBuffer)
242 {
243 theWorkspace->SetUseZBuffer (Standard_True);
244 aCtx->core11fwd->glEnable (GL_DEPTH_TEST);
245 }
246}
247
248//=======================================================================
249//function : Redraw
250//purpose :
251//=======================================================================
252void OpenGl_View::Redraw()
253{
254 if (myRenderParams.Method == Graphic3d_RM_RAYTRACING
255 && !myCaps->vboDisable
256 && !myCaps->keepArrayData)
257 {
258 if (myWasRedrawnGL)
259 {
260 myDeviceLostFlag = Standard_True;
261 }
262
263 myCaps->keepArrayData = Standard_True;
264 }
265
266 if (!myWorkspace->Activate())
267 {
268 return;
269 }
270
271 myWindow->SetSwapInterval();
272
273 ++myFrameCounter;
274 const Graphic3d_StereoMode aStereoMode = myRenderParams.StereoMode;
275 Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType();
276 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
277
278 // release pending GL resources
279 aCtx->ReleaseDelayed();
280
281 // fetch OpenGl context state
282 aCtx->FetchState();
283
284 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )myFBO;
285 bool toSwap = aCtx->IsRender()
286 && !aCtx->caps->buffersNoSwap
287 && aFrameBuffer == NULL;
288
289 Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
290 Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
291
292 if ( aFrameBuffer == NULL
293 && !aCtx->DefaultFrameBuffer().IsNull()
294 && aCtx->DefaultFrameBuffer()->IsValid())
295 {
296 aFrameBuffer = aCtx->DefaultFrameBuffer().operator->();
297 }
298
299 if (myHasFboBlit
300 && (myTransientDrawToFront || aProjectType == Graphic3d_Camera::Projection_Stereo))
301 {
302 if (myMainSceneFbos[0]->GetVPSizeX() != aSizeX
303 || myMainSceneFbos[0]->GetVPSizeY() != aSizeY)
304 {
305 // prepare FBOs containing main scene
306 // for further blitting and rendering immediate presentations on top
307 if (aCtx->core20fwd != NULL)
308 {
309 myMainSceneFbos[0]->Init (aCtx, aSizeX, aSizeY);
310 }
311 if (!aCtx->caps->useSystemBuffer && myMainSceneFbos[0]->IsValid())
312 {
313 myImmediateSceneFbos[0]->InitLazy (aCtx, aSizeX, aSizeY);
314 }
315 }
316 }
317 else
318 {
319 myMainSceneFbos [0]->Release (aCtx.operator->());
320 myMainSceneFbos [1]->Release (aCtx.operator->());
321 myImmediateSceneFbos[0]->Release (aCtx.operator->());
322 myImmediateSceneFbos[1]->Release (aCtx.operator->());
323 myMainSceneFbos [0]->ChangeViewport (0, 0);
324 myMainSceneFbos [1]->ChangeViewport (0, 0);
325 myImmediateSceneFbos[0]->ChangeViewport (0, 0);
326 myImmediateSceneFbos[1]->ChangeViewport (0, 0);
327 }
328
329 if (aProjectType == Graphic3d_Camera::Projection_Stereo
330 && myMainSceneFbos[0]->IsValid())
331 {
332 myMainSceneFbos[1]->InitLazy (aCtx, aSizeX, aSizeY);
333 if (!myMainSceneFbos[1]->IsValid())
334 {
335 // no enough memory?
336 aProjectType = Graphic3d_Camera::Projection_Perspective;
337 }
338 else if (!myTransientDrawToFront)
339 {
340 //
341 }
342 else if (!aCtx->HasStereoBuffers() || aStereoMode != Graphic3d_StereoMode_QuadBuffer)
343 {
344 myImmediateSceneFbos[0]->InitLazy (aCtx, aSizeX, aSizeY);
345 myImmediateSceneFbos[1]->InitLazy (aCtx, aSizeX, aSizeY);
346 if (!myImmediateSceneFbos[0]->IsValid()
347 || !myImmediateSceneFbos[1]->IsValid())
348 {
349 aProjectType = Graphic3d_Camera::Projection_Perspective;
350 }
351 }
352 }
353
354 if (aProjectType == Graphic3d_Camera::Projection_Stereo)
355 {
356 OpenGl_FrameBuffer* aMainFbos[2] =
357 {
358 myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL,
359 myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL
360 };
361 OpenGl_FrameBuffer* anImmFbos[2] =
362 {
363 myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
364 myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
365 };
366
367 if (!myTransientDrawToFront)
368 {
369 anImmFbos[0] = aMainFbos[0];
370 anImmFbos[1] = aMainFbos[1];
371 }
372 else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
373 || aStereoMode == Graphic3d_StereoMode_QuadBuffer)
374 {
375 anImmFbos[0] = NULL;
376 anImmFbos[1] = NULL;
377 }
378
379 #if !defined(GL_ES_VERSION_2_0)
380 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
381 #endif
382 redraw (Graphic3d_Camera::Projection_MonoLeftEye, aMainFbos[0]);
383 myBackBufferRestored = Standard_True;
384 myIsImmediateDrawn = Standard_False;
385 #if !defined(GL_ES_VERSION_2_0)
386 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
387 #endif
b0dc79bc 388 if (!redrawImmediate (Graphic3d_Camera::Projection_MonoLeftEye, aMainFbos[0], anImmFbos[0]))
c357e426 389 {
390 toSwap = false;
391 }
392 else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip && toSwap)
393 {
394 aCtx->SwapBuffers();
395 }
396
397 #if !defined(GL_ES_VERSION_2_0)
398 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
399 #endif
400 redraw (Graphic3d_Camera::Projection_MonoRightEye, aMainFbos[1]);
401 myBackBufferRestored = Standard_True;
402 myIsImmediateDrawn = Standard_False;
b0dc79bc 403 if (!redrawImmediate (Graphic3d_Camera::Projection_MonoRightEye, aMainFbos[1], anImmFbos[1]))
c357e426 404 {
405 toSwap = false;
406 }
407
408 if (anImmFbos[0] != NULL)
409 {
410 bindDefaultFbo (aFrameBuffer);
411 drawStereoPair();
412 }
413 }
414 else
415 {
416 OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
417 OpenGl_FrameBuffer* anImmFbo = aFrameBuffer;
418 if (!aCtx->caps->useSystemBuffer && myImmediateSceneFbos[0]->IsValid())
419 {
420 anImmFbo = myImmediateSceneFbos[0].operator->();
421 }
422
423 #if !defined(GL_ES_VERSION_2_0)
424 if (aMainFbo == NULL
425 && aFrameBuffer == NULL)
426 {
427 aCtx->SetReadDrawBuffer (GL_BACK);
428 }
429 #endif
430 redraw (aProjectType, aMainFbo != NULL ? aMainFbo : aFrameBuffer);
431 myBackBufferRestored = Standard_True;
432 myIsImmediateDrawn = Standard_False;
433 if (!redrawImmediate (aProjectType, aMainFbo, anImmFbo))
434 {
435 toSwap = false;
436 }
437
438 if (anImmFbo != NULL
439 && anImmFbo != aFrameBuffer)
440 {
441 blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput);
442 }
443 }
444
445#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
446 if (OpenGl_AVIWriter_AllowWriting (myWindow->PlatformWindow()->NativeHandle()))
447 {
448 GLint params[4];
449 glGetIntegerv (GL_VIEWPORT, params);
450 int nWidth = params[2] & ~0x7;
451 int nHeight = params[3] & ~0x7;
452
453 const int nBitsPerPixel = 24;
454 GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8];
455
456 glPixelStorei (GL_PACK_ALIGNMENT, 1);
457 glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData);
458 OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel);
459 delete[] aDumpData;
460 }
461#endif
462
463 // bind default FBO
464 bindDefaultFbo();
465
466 // Swap the buffers
467 if (toSwap)
468 {
469 aCtx->SwapBuffers();
470 if (!myMainSceneFbos[0]->IsValid())
471 {
472 myBackBufferRestored = Standard_False;
473 }
474 }
475 else
476 {
477 aCtx->core11fwd->glFlush();
478 }
479
480 // reset render mode state
481 aCtx->FetchState();
482
483 myWasRedrawnGL = Standard_True;
484}
485
486// =======================================================================
487// function : RedrawImmediate
488// purpose :
489// =======================================================================
490void OpenGl_View::RedrawImmediate()
491{
492 if (!myWorkspace->Activate())
493 return;
494
495 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
496 if (!myTransientDrawToFront
497 || !myBackBufferRestored
498 || (aCtx->caps->buffersNoSwap && !myMainSceneFbos[0]->IsValid()))
499 {
500 Redraw();
501 return;
502 }
503
504 const Graphic3d_StereoMode aStereoMode = myRenderParams.StereoMode;
505 Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType();
506 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )myFBO;
507
508 if ( aFrameBuffer == NULL
509 && !aCtx->DefaultFrameBuffer().IsNull()
510 && aCtx->DefaultFrameBuffer()->IsValid())
511 {
512 aFrameBuffer = aCtx->DefaultFrameBuffer().operator->();
513 }
514
515 if (aProjectType == Graphic3d_Camera::Projection_Stereo)
516 {
517 if (myMainSceneFbos[0]->IsValid()
518 && !myMainSceneFbos[1]->IsValid())
519 {
520 aProjectType = Graphic3d_Camera::Projection_Perspective;
521 }
522 }
523
524 bool toSwap = false;
525 if (aProjectType == Graphic3d_Camera::Projection_Stereo)
526 {
527 OpenGl_FrameBuffer* aMainFbos[2] =
528 {
529 myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL,
530 myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL
531 };
532 OpenGl_FrameBuffer* anImmFbos[2] =
533 {
534 myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
535 myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
536 };
537 if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
538 || aStereoMode == Graphic3d_StereoMode_QuadBuffer)
539 {
540 anImmFbos[0] = NULL;
541 anImmFbos[1] = NULL;
542 }
543
544 if (aCtx->arbFBO != NULL)
545 {
546 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
547 }
548 #if !defined(GL_ES_VERSION_2_0)
549 if (anImmFbos[0] == NULL)
550 {
551 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
552 }
553 #endif
554 toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoLeftEye,
555 aMainFbos[0],
556 anImmFbos[0],
557 Standard_True) || toSwap;
558 if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
559 && toSwap
560 && !aCtx->caps->buffersNoSwap)
561 {
562 aCtx->SwapBuffers();
563 }
564
565 if (aCtx->arbFBO != NULL)
566 {
567 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
568 }
569 #if !defined(GL_ES_VERSION_2_0)
570 if (anImmFbos[1] == NULL)
571 {
572 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
573 }
574 #endif
575 toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoRightEye,
576 aMainFbos[1],
577 anImmFbos[1],
578 Standard_True) || toSwap;
579 if (anImmFbos[0] != NULL)
580 {
581 bindDefaultFbo (aFrameBuffer);
582 drawStereoPair();
583 }
584 }
585 else
586 {
587 OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
588 OpenGl_FrameBuffer* anImmFbo = aFrameBuffer;
589 if (!aCtx->caps->useSystemBuffer && myImmediateSceneFbos[0]->IsValid())
590 {
591 anImmFbo = myImmediateSceneFbos[0].operator->();
592 }
593 #if !defined(GL_ES_VERSION_2_0)
594 if (aMainFbo == NULL)
595 {
596 aCtx->SetReadDrawBuffer (GL_BACK);
597 }
598 #endif
599 toSwap = redrawImmediate (aProjectType,
600 aMainFbo,
601 anImmFbo,
602 Standard_True) || toSwap;
603 if (anImmFbo != NULL
604 && anImmFbo != aFrameBuffer)
605 {
606 blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput);
607 }
608 }
609
610 // bind default FBO
611 bindDefaultFbo();
612
613 if (toSwap && !aCtx->caps->buffersNoSwap)
614 {
615 aCtx->SwapBuffers();
616 }
617 else
618 {
619 aCtx->core11fwd->glFlush();
620 }
621
622 myWasRedrawnGL = Standard_True;
623}
624
625// =======================================================================
626// function : redraw
627// purpose :
628// =======================================================================
629void OpenGl_View::redraw (const Graphic3d_Camera::Projection theProjection, OpenGl_FrameBuffer* theReadDrawFbo)
630{
631 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
632 if (theReadDrawFbo != NULL)
633 {
634 theReadDrawFbo->BindBuffer (aCtx);
635 theReadDrawFbo->SetupViewport (aCtx);
636 }
637 else
638 {
639 aCtx->core11fwd->glViewport (0, 0, myWindow->Width(), myWindow->Height());
640 }
641
642 // request reset of material
643 myWorkspace->NamedStatus |= OPENGL_NS_RESMAT;
644 myWorkspace->UseZBuffer() = Standard_True;
645 myWorkspace->UseDepthWrite() = Standard_True;
646 GLbitfield toClear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
647 glDepthFunc (GL_LEQUAL);
648 glDepthMask (GL_TRUE);
649 glEnable (GL_DEPTH_TEST);
650
651#if !defined(GL_ES_VERSION_2_0)
652 glClearDepth (1.0);
653#else
654 glClearDepthf (1.0f);
655#endif
656
657 if (myWorkspace->NamedStatus & OPENGL_NS_WHITEBACK)
658 {
659 // set background to white
660 glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
661 }
662 else
663 {
664 glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
665 }
666
667 glClear (toClear);
668
669 render (theProjection, theReadDrawFbo, Standard_False);
670}
671
672// =======================================================================
673// function : redrawMonoImmediate
674// purpose :
675// =======================================================================
676bool OpenGl_View::redrawImmediate (const Graphic3d_Camera::Projection theProjection,
677 OpenGl_FrameBuffer* theReadFbo,
678 OpenGl_FrameBuffer* theDrawFbo,
679 const Standard_Boolean theIsPartialUpdate)
680{
681 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
682 GLboolean toCopyBackToFront = GL_FALSE;
683 if (!myTransientDrawToFront)
684 {
685 myBackBufferRestored = Standard_False;
686 }
687 else if (theReadFbo != NULL
688 && theReadFbo->IsValid()
689 && aCtx->IsRender())
690 {
691 if (!blitBuffers (theReadFbo, theDrawFbo))
692 {
693 return true;
694 }
695 }
696 else if (theDrawFbo == NULL)
697 {
698 #if !defined(GL_ES_VERSION_2_0)
699 aCtx->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront);
700 #endif
701 if (toCopyBackToFront)
702 {
703 if (!HasImmediateStructures()
704 && !theIsPartialUpdate)
705 {
706 // prefer Swap Buffers within Redraw in compatibility mode (without FBO)
707 return true;
708 }
709 copyBackToFront();
710 }
711 else
712 {
713 myBackBufferRestored = Standard_False;
714 }
715 }
716 else
717 {
718 myBackBufferRestored = Standard_False;
719 }
720 myIsImmediateDrawn = Standard_True;
721
722 myWorkspace->UseZBuffer() = Standard_True;
723 myWorkspace->UseDepthWrite() = Standard_True;
724 glDepthFunc (GL_LEQUAL);
725 glDepthMask (GL_TRUE);
726 glEnable (GL_DEPTH_TEST);
727#if !defined(GL_ES_VERSION_2_0)
728 glClearDepth (1.0);
729#else
730 glClearDepthf (1.0f);
731#endif
732
733 render (theProjection, theDrawFbo, Standard_True);
734
735 return !toCopyBackToFront;
736}
737
738//=======================================================================
739//function : Render
740//purpose :
741//=======================================================================
742void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
743 OpenGl_FrameBuffer* theOutputFBO,
744 const Standard_Boolean theToDrawImmediate)
745{
746 // ==================================
747 // Step 1: Prepare for render
748 // ==================================
749
750 const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
751
752#if !defined(GL_ES_VERSION_2_0)
753 // Disable current clipping planes
754 if (aContext->core11 != NULL)
755 {
756 const Standard_Integer aMaxPlanes = aContext->MaxClipPlanes();
757 for (Standard_Integer aClipPlaneId = GL_CLIP_PLANE0; aClipPlaneId < GL_CLIP_PLANE0 + aMaxPlanes; ++aClipPlaneId)
758 {
759 aContext->core11fwd->glDisable (aClipPlaneId);
760 }
761 }
762#endif
763
764 // Update states of OpenGl_BVHTreeSelector (frustum culling algorithm).
765 myBVHSelector.SetViewVolume (myCamera);
766
767 const Handle(OpenGl_ShaderManager)& aManager = aContext->ShaderManager();
768 if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState)
769 {
770 aManager->UpdateLightSourceStateTo (myShadingModel == Graphic3d_TOSM_NONE ? &OpenGl_NoShadingLight() : &myLights);
771 myLastLightSourceState = StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index());
772 }
773
774 // Update matrices if camera has changed.
775 Graphic3d_WorldViewProjState aWVPState = myCamera->WorldViewProjState();
776 const Standard_Boolean isCameraChanged = myWorldViewProjState != aWVPState;
777 const Standard_Boolean isSameView = aManager->IsSameView (this);
778 if (isCameraChanged)
779 {
780 aContext->ProjectionState.SetCurrent (myCamera->ProjectionMatrixF());
781 aContext->WorldViewState .SetCurrent (myCamera->OrientationMatrixF());
782 }
783
784 // Apply new matrix state if camera has changed or this view differs from the one
785 // that was previously used for configuring matrices of shader manager
786 // (ApplyProjectionMatrix and ApplyWorldViewMatrix will affect the manager).
787 if (isCameraChanged || !isSameView)
788 {
789 aContext->ApplyProjectionMatrix();
790 aContext->ApplyWorldViewMatrix();
791 }
792
793 if (aManager->ModelWorldState().Index() == 0)
794 {
795 aContext->ShaderManager()->UpdateModelWorldStateTo (OpenGl_Mat4());
796 }
797
798 myWorldViewProjState = aWVPState;
799
800 // ====================================
801 // Step 2: Redraw background
802 // ====================================
803
804 // Render background
805 if (!theToDrawImmediate)
806 {
a521d90d 807 drawBackground (myWorkspace);
c357e426 808 }
809
810#if !defined(GL_ES_VERSION_2_0)
811 // Switch off lighting by default
812 if (aContext->core11 != NULL)
813 {
814 glDisable(GL_LIGHTING);
815 }
816#endif
817
818 // =================================
819 // Step 3: Redraw main plane
820 // =================================
821
822 // Setup face culling
823 GLboolean isCullFace = GL_FALSE;
824 if (myBackfacing != Graphic3d_TOBM_AUTOMATIC)
825 {
826 isCullFace = glIsEnabled (GL_CULL_FACE);
827 if (myBackfacing == Graphic3d_TOBM_DISABLE)
828 {
829 glEnable (GL_CULL_FACE);
830 glCullFace (GL_BACK);
831 }
832 else
833 glDisable (GL_CULL_FACE);
834 }
835
836#if !defined(GL_ES_VERSION_2_0)
837 // if the view is scaled normal vectors are scaled to unit
838 // length for correct displaying of shaded objects
839 const gp_Pnt anAxialScale = myCamera->AxialScale();
840 if (anAxialScale.X() != 1.F ||
841 anAxialScale.Y() != 1.F ||
842 anAxialScale.Z() != 1.F)
843 {
844 aContext->SetGlNormalizeEnabled (Standard_True);
845 }
846 else
847 {
848 aContext->SetGlNormalizeEnabled (Standard_False);
849 }
850
851 // Apply Fog
852 if (myFog.IsOn
853 && aContext->core11 != NULL)
854 {
855 Standard_Real aFogFrontConverted = (Standard_Real )myFog.Front + myCamera->Distance();
856 if (myCamera->ZFar() < aFogFrontConverted)
857 {
858 aFogFrontConverted = myCamera->ZFar();
859 myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance());
860 }
861
862 Standard_Real aFogBackConverted = (Standard_Real )myFog.Back + myCamera->Distance();
863 if (myCamera->ZFar() < aFogFrontConverted)
864 {
865 aFogBackConverted = myCamera->ZFar();
866 myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance());
867 }
868
869 if (aFogFrontConverted > aFogBackConverted)
870 {
871 myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance());
872 myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance());
873 }
874
875 glFogi(GL_FOG_MODE, GL_LINEAR);
876 glFogf(GL_FOG_START, (Standard_ShortReal )aFogFrontConverted);
877 glFogf(GL_FOG_END, (Standard_ShortReal )aFogBackConverted);
878 glFogfv(GL_FOG_COLOR, myFog.Color.rgb);
879 glEnable(GL_FOG);
880 }
881 else if (aContext->core11 != NULL)
882 {
883 glDisable (GL_FOG);
884 }
885
886 // Apply InteriorShadingMethod
887 if (aContext->core11 != NULL)
888 {
889 aContext->core11->glShadeModel (myShadingModel == Graphic3d_TOSM_FACET
890 || myShadingModel == Graphic3d_TOSM_NONE ? GL_FLAT : GL_SMOOTH);
891 }
892#endif
893
894 aManager->SetShadingModel (myShadingModel);
895
896 // Apply AntiAliasing
897 if (myAntiAliasing)
898 myWorkspace->NamedStatus |= OPENGL_NS_ANTIALIASING;
899 else
900 myWorkspace->NamedStatus &= ~OPENGL_NS_ANTIALIASING;
901
902 if (!aManager->IsEmpty())
903 {
904 aManager->UpdateClippingState();
905 }
906
907 // Redraw 3d scene
908 if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye)
909 {
910 aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoLeftF());
911 aContext->ApplyProjectionMatrix();
912 }
913 else if (theProjection == Graphic3d_Camera::Projection_MonoRightEye)
914 {
915 aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoRightF());
916 aContext->ApplyProjectionMatrix();
917 }
918 renderScene (theOutputFBO, theToDrawImmediate);
919
920 // ===============================
921 // Step 4: Trihedron
922 // ===============================
923
924 // Resetting GL parameters according to the default aspects
925 // in order to synchronize GL state with the graphic driver state
926 // before drawing auxiliary stuff (trihedrons, overlayer)
c357e426 927 myWorkspace->ResetAppliedAspect();
928
79f4f036 929 aContext->ChangeClipping().RemoveAll (aContext);
c357e426 930
931 if (!aManager->IsEmpty())
932 {
933 aManager->ResetMaterialStates();
934 aManager->RevertClippingState();
935
936 // We need to disable (unbind) all shaders programs to ensure
937 // that all objects without specified aspect will be drawn
938 // correctly (such as background)
939 aContext->BindProgram (NULL);
940 }
941
942 // Render trihedron
943 if (!theToDrawImmediate)
944 {
945 renderTrihedron (myWorkspace);
946
947 // Restore face culling
948 if (myBackfacing != Graphic3d_TOBM_AUTOMATIC)
949 {
950 if (isCullFace)
951 {
952 glEnable (GL_CULL_FACE);
953 glCullFace (GL_BACK);
954 }
955 else
956 glDisable (GL_CULL_FACE);
957 }
958 }
959
960 // ==============================================================
c357e426 961 // Step 6: Keep shader manager informed about last View
962 // ==============================================================
963
964 if (!aManager.IsNull())
965 {
966 aManager->SetLastView (this);
967 }
968}
969
970// =======================================================================
971// function : InvalidateBVHData
972// purpose :
973// =======================================================================
974void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId)
975{
976 myZLayers.InvalidateBVHData (theLayerId);
977}
978
979//=======================================================================
980//function : renderStructs
981//purpose :
982//=======================================================================
983void OpenGl_View::renderStructs (OpenGl_FrameBuffer* theReadDrawFbo,
984 const Standard_Boolean theToDrawImmediate)
985{
986 if ( myZLayers.NbStructures() <= 0 )
987 return;
988
989 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
990 if ( (myWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 )
991 {
992 #if !defined(GL_ES_VERSION_2_0)
993 const int anAntiAliasingMode = myWorkspace->AntiAliasingMode();
994 #endif
995
996 if ( !myAntiAliasing )
997 {
998 #if !defined(GL_ES_VERSION_2_0)
999 if (aCtx->core11 != NULL)
1000 {
1001 glDisable (GL_POINT_SMOOTH);
1002 }
1003 glDisable(GL_LINE_SMOOTH);
1004 if( anAntiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH);
1005 #endif
1006 glBlendFunc (GL_ONE, GL_ZERO);
1007 glDisable (GL_BLEND);
1008 }
1009 else
1010 {
1011 #if !defined(GL_ES_VERSION_2_0)
1012 if (aCtx->core11 != NULL)
1013 {
1014 glEnable(GL_POINT_SMOOTH);
1015 }
1016 glEnable(GL_LINE_SMOOTH);
1017 if( anAntiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
1018 #endif
1019 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1020 glEnable (GL_BLEND);
1021 }
1022 }
1023
1024 Standard_Boolean toRenderGL = theToDrawImmediate ||
1025 myRenderParams.Method != Graphic3d_RM_RAYTRACING ||
1026 myRaytraceInitStatus == OpenGl_RT_FAIL ||
1027 aCtx->IsFeedback();
1028
1029 if (!toRenderGL)
1030 {
1031 toRenderGL = !initRaytraceResources (aCtx) ||
1032 !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
1033
1034 toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL
1035
1036 if (!toRenderGL)
1037 {
1038 const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width();
1039 const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height();
1040
1041 if (myOpenGlFBO.IsNull())
1042 myOpenGlFBO = new OpenGl_FrameBuffer;
1043
1044 if (myOpenGlFBO->GetVPSizeX() != aSizeX
1045 || myOpenGlFBO->GetVPSizeY() != aSizeY)
1046 {
1047 myOpenGlFBO->Init (aCtx, aSizeX, aSizeY);
1048 }
1049
1050 if (myRaytraceFilter.IsNull())
1051 myRaytraceFilter = new OpenGl_RaytraceFilter;
1052
1053 myRaytraceFilter->SetPrevRenderFilter (myWorkspace->GetRenderFilter());
1054
1055 if (theReadDrawFbo != NULL)
1056 theReadDrawFbo->UnbindBuffer (aCtx);
1057
1058 // Prepare preliminary OpenGL output
1059 if (aCtx->arbFBOBlit != NULL)
1060 {
1061 // Render bottom OSD layer
1062 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Bottom);
1063
1064 myWorkspace->SetRenderFilter (myRaytraceFilter);
1065 {
1066 if (theReadDrawFbo != NULL)
1067 {
1068 theReadDrawFbo->BindReadBuffer (aCtx);
1069 }
1070 else
1071 {
1072 aCtx->arbFBO->glBindFramebuffer (GL_READ_FRAMEBUFFER, 0);
1073 }
1074
1075 myOpenGlFBO->BindDrawBuffer (aCtx);
1076
1077 aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, aSizeX, aSizeY,
1078 0, 0, aSizeX, aSizeY,
1079 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
1080 GL_NEAREST);
1081
1082 // Render non-polygonal elements in default layer
1083 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Default);
1084 }
1085 myWorkspace->SetRenderFilter (myRaytraceFilter->PrevRenderFilter());
1086 }
1087
1088 if (theReadDrawFbo != NULL)
1089 {
1090 theReadDrawFbo->BindBuffer (aCtx);
1091 }
1092 else
1093 {
1094 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, 0);
1095 }
1096
1097 // Ray-tracing polygonal primitive arrays
1098 raytrace (aSizeX, aSizeY, theReadDrawFbo, aCtx);
1099
1100 // Render upper (top and topmost) OpenGL layers
1101 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Upper);
1102 }
1103 }
1104
1105 // Redraw 3D scene using OpenGL in standard
1106 // mode or in case of ray-tracing failure
1107 if (toRenderGL)
1108 {
1109 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_All);
1110
1111 // Set flag that scene was redrawn by standard pipeline
1112 myWasRedrawnGL = Standard_True;
1113 }
1114}
1115
1116//=======================================================================
1117//function : renderTrihedron
1118//purpose :
1119//=======================================================================
1120void OpenGl_View::renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace)
1121{
1122 // display global trihedron
1123 if (myToShowTrihedron)
1124 {
1125 myTrihedron.Render (theWorkspace);
1126 }
1127 if (myToShowGradTrihedron)
1128 {
1129 myGraduatedTrihedron.Render (theWorkspace);
1130 }
1131}
1132
1133// =======================================================================
1134// function : Invalidate
1135// purpose :
1136// =======================================================================
1137void OpenGl_View::Invalidate()
1138{
1139 myBackBufferRestored = Standard_False;
1140}
1141
1142//=======================================================================
1143//function : renderScene
1144//purpose :
1145//=======================================================================
1146void OpenGl_View::renderScene (OpenGl_FrameBuffer* theReadDrawFbo,
1147 const Standard_Boolean theToDrawImmediate)
1148{
1149 const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
1150
1151 if (myZClip.Back.IsOn || myZClip.Front.IsOn)
1152 {
1153 Handle(Graphic3d_ClipPlane) aPlaneBack;
1154 Handle(Graphic3d_ClipPlane) aPlaneFront;
1155
1156 if (myZClip.Back.IsOn)
1157 {
1158 Standard_Real aClipBackConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance();
1159 if (myCamera->ZFar() < aClipBackConverted)
1160 {
1161 aClipBackConverted = myCamera->ZFar();
1162 myZClip.Back.Limit = (Standard_ShortReal )(aClipBackConverted - myCamera->Distance());
1163 }
1164 const Graphic3d_ClipPlane::Equation aBackEquation (0.0, 0.0, 1.0, (Standard_ShortReal )aClipBackConverted);
1165 aPlaneBack = new Graphic3d_ClipPlane (aBackEquation);
1166 }
1167
1168 if (myZClip.Front.IsOn)
1169 {
1170 Standard_Real aClipFrontConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance();
1171 if (myCamera->ZNear() > aClipFrontConverted)
1172 {
1173 aClipFrontConverted = myCamera->ZNear();
1174 myZClip.Front.Limit = (Standard_ShortReal )(aClipFrontConverted - myCamera->Distance());
1175 }
1176 const Graphic3d_ClipPlane::Equation aFrontEquation (0.0, 0.0, -1.0, (Standard_ShortReal )-aClipFrontConverted);
1177 aPlaneFront = new Graphic3d_ClipPlane (aFrontEquation);
1178 }
1179
1180 // Specify slicing planes with identity transformation
1181 if (!aPlaneBack.IsNull() || !aPlaneFront.IsNull())
1182 {
1183 Graphic3d_SequenceOfHClipPlane aSlicingPlanes;
1184 if (!aPlaneBack.IsNull())
1185 {
1186 aSlicingPlanes.Append (aPlaneBack);
1187 }
1188
1189 if (!aPlaneFront.IsNull())
1190 {
1191 aSlicingPlanes.Append (aPlaneFront);
1192 }
1193
1194 // add planes at loaded view matrix state
79f4f036 1195 aContext->ChangeClipping().AddView (aContext, aSlicingPlanes);
c357e426 1196 }
1197 }
1198
1199#ifdef _WIN32
1200 // set printing scale/tiling transformation
1201 Handle(OpenGl_PrinterContext) aPrintContext = myWorkspace->PrinterContext();
1202 if (!aPrintContext.IsNull())
1203 {
1204 aContext->ProjectionState.Push();
1205 aContext->ProjectionState.SetCurrent (aPrintContext->ProjTransformation() * aContext->ProjectionState.Current());
1206 aContext->ApplyProjectionMatrix();
1207 }
1208#endif
1209
1210 // Specify clipping planes in view transformation space
1211 if (!myClipPlanes.IsEmpty())
1212 {
1213 Graphic3d_SequenceOfHClipPlane aUserPlanes;
1214 Graphic3d_SequenceOfHClipPlane::Iterator aClippingIt (myClipPlanes);
1215 for (; aClippingIt.More(); aClippingIt.Next())
1216 {
1217 const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value();
1218 if (aClipPlane->IsOn())
1219 {
1220 aUserPlanes.Append (aClipPlane);
1221 }
1222 }
1223
1224 if (!aUserPlanes.IsEmpty())
1225 {
79f4f036 1226 aContext->ChangeClipping().AddWorldLazy (aContext, aUserPlanes);
c357e426 1227 }
1228
1229 if (!aContext->ShaderManager()->IsEmpty())
1230 {
1231 aContext->ShaderManager()->UpdateClippingState();
1232 }
1233 }
1234
1235#if !defined(GL_ES_VERSION_2_0)
1236 // Apply Lights
1237 if (aContext->core11 != NULL)
1238 {
1239 // setup lights
1240 Graphic3d_Vec4 anAmbientColor (THE_DEFAULT_AMBIENT[0],
1241 THE_DEFAULT_AMBIENT[1],
1242 THE_DEFAULT_AMBIENT[2],
1243 THE_DEFAULT_AMBIENT[3]);
1244 GLenum aLightGlId = GL_LIGHT0;
1245
1246 OpenGl_ListOfLight::Iterator aLightIt (myShadingModel == Graphic3d_TOSM_NONE ? OpenGl_NoShadingLight() : myLights);
1247 for (; aLightIt.More(); aLightIt.Next())
1248 {
1249 bindLight (aLightIt.Value(), aLightGlId, anAmbientColor, myWorkspace);
1250 }
1251
1252 // apply accumulated ambient color
1253 anAmbientColor.a() = 1.0f;
1254 glLightModelfv (GL_LIGHT_MODEL_AMBIENT, anAmbientColor.GetData());
1255
1256 if (aLightGlId != GL_LIGHT0)
1257 {
1258 glEnable (GL_LIGHTING);
1259 }
1260 // switch off unused lights
1261 for (; aLightGlId <= GL_LIGHT7; ++aLightGlId)
1262 {
1263 glDisable (aLightGlId);
1264 }
1265 }
1266#endif
1267
1268 // Clear status bitfields
1269 myWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO);
1270
1271 // Update state of surface detail level
1272 myWorkspace->GetGlContext()->ShaderManager()->UpdateSurfaceDetailStateTo (mySurfaceDetail);
1273
1274 // Added PCT for handling of textures
1275 switch (mySurfaceDetail)
1276 {
1277 case Graphic3d_TOD_NONE:
1278 myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1279 myWorkspace->DisableTexture();
1280 // Render the view
1281 renderStructs (theReadDrawFbo, theToDrawImmediate);
1282 break;
1283
1284 case Graphic3d_TOD_ENVIRONMENT:
1285 myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1286 if (myRenderParams.Method != Graphic3d_RM_RAYTRACING)
1287 {
1288 myWorkspace->EnableTexture (myTextureEnv);
1289 }
1290 // Render the view
1291 renderStructs (theReadDrawFbo, theToDrawImmediate);
1292 myWorkspace->DisableTexture();
1293 break;
1294
1295 case Graphic3d_TOD_ALL:
1296 // First pass
1297 myWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX;
1298 // Render the view
1299 renderStructs (theReadDrawFbo, theToDrawImmediate);
1300 myWorkspace->DisableTexture();
1301
1302 // Second pass
1303 if (myWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED)
1304 {
1305 myWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO;
1306 if (myRenderParams.Method != Graphic3d_RM_RAYTRACING)
1307 {
1308 myWorkspace->EnableTexture (myTextureEnv);
1309 }
1310
1311 // Remember OpenGl properties
1312 GLint aSaveBlendDst = GL_ONE_MINUS_SRC_ALPHA, aSaveBlendSrc = GL_SRC_ALPHA;
1313 GLint aSaveZbuffFunc;
1314 GLboolean aSaveZbuffWrite;
1315 glGetBooleanv (GL_DEPTH_WRITEMASK, &aSaveZbuffWrite);
1316 glGetIntegerv (GL_DEPTH_FUNC, &aSaveZbuffFunc);
1317 #if !defined(GL_ES_VERSION_2_0)
1318 glGetIntegerv (GL_BLEND_DST, &aSaveBlendDst);
1319 glGetIntegerv (GL_BLEND_SRC, &aSaveBlendSrc);
1320 #endif
1321 GLboolean wasZbuffEnabled = glIsEnabled (GL_DEPTH_TEST);
1322 GLboolean wasBlendEnabled = glIsEnabled (GL_BLEND);
1323
1324 // Change the properties for second rendering pass
1325 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1326 glEnable (GL_BLEND);
1327
1328 glDepthFunc (GL_EQUAL);
1329 glDepthMask (GL_FALSE);
1330 glEnable (GL_DEPTH_TEST);
1331
1332 myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1333
1334 // Render the view
1335 renderStructs (theReadDrawFbo, theToDrawImmediate);
1336 myWorkspace->DisableTexture();
1337
1338 // Restore properties back
1339 glBlendFunc (aSaveBlendSrc, aSaveBlendDst);
1340 if (!wasBlendEnabled)
1341 glDisable (GL_BLEND);
1342
1343 glDepthFunc (aSaveZbuffFunc);
1344 glDepthMask (aSaveZbuffWrite);
1345 if (!wasZbuffEnabled)
1346 glDisable (GL_DEPTH_FUNC);
1347 }
1348 break;
1349 }
1350
1351 // Apply restored view matrix.
1352 aContext->ApplyWorldViewMatrix();
1353
1354#ifdef _WIN32
1355 // set printing scale/tiling transformation
1356 if (!aPrintContext.IsNull())
1357 {
1358 aContext->ProjectionState.Pop();
1359 aContext->ApplyProjectionMatrix();
1360 }
1361#endif
1362}
1363
1364// =======================================================================
1365// function : bindDefaultFbo
1366// purpose :
1367// =======================================================================
1368void OpenGl_View::bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo)
1369{
1370 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
1371 OpenGl_FrameBuffer* anFbo = (theCustomFbo != NULL && theCustomFbo->IsValid())
1372 ? theCustomFbo
1373 : (!aCtx->DefaultFrameBuffer().IsNull()
1374 && aCtx->DefaultFrameBuffer()->IsValid()
1375 ? aCtx->DefaultFrameBuffer().operator->()
1376 : NULL);
1377 if (anFbo != NULL)
1378 {
1379 anFbo->BindBuffer (aCtx);
1380 }
1381 else
1382 {
1383 #if !defined(GL_ES_VERSION_2_0)
1384 aCtx->SetReadDrawBuffer (GL_BACK);
1385 #else
1386 if (aCtx->arbFBO != NULL)
1387 {
1388 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1389 }
1390 #endif
1391 }
1392 aCtx->core11fwd->glViewport (0, 0, myWindow->Width(), myWindow->Height());
1393}
1394
1395// =======================================================================
1396// function : initBlitQuad
1397// purpose :
1398// =======================================================================
1399OpenGl_VertexBuffer* OpenGl_View::initBlitQuad (const Standard_Boolean theToFlip)
1400{
1401 OpenGl_VertexBuffer* aVerts = NULL;
1402 if (!theToFlip)
1403 {
1404 aVerts = &myFullScreenQuad;
1405 if (!aVerts->IsValid())
1406 {
1407 OpenGl_Vec4 aQuad[4] =
1408 {
1409 OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f),
1410 OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 1.0f),
1411 OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f),
1412 OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 1.0f)
1413 };
1414 aVerts->Init (myWorkspace->GetGlContext(), 4, 4, aQuad[0].GetData());
1415 }
1416 }
1417 else
1418 {
1419 aVerts = &myFullScreenQuadFlip;
1420 if (!aVerts->IsValid())
1421 {
1422 OpenGl_Vec4 aQuad[4] =
1423 {
1424 OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 1.0f),
1425 OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 0.0f),
1426 OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
1427 OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 0.0f)
1428 };
1429 aVerts->Init (myWorkspace->GetGlContext(), 4, 4, aQuad[0].GetData());
1430 }
1431 }
1432 return aVerts;
1433}
1434
1435// =======================================================================
1436// function : blitBuffers
1437// purpose :
1438// =======================================================================
1439bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer* theReadFbo,
1440 OpenGl_FrameBuffer* theDrawFbo,
1441 const Standard_Boolean theToFlip)
1442{
1443 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
1444 if (theReadFbo == NULL || aCtx->IsFeedback())
1445 {
1446 return false;
1447 }
1448 else if (theReadFbo == theDrawFbo)
1449 {
1450 return true;
1451 }
1452
1453 // clear destination before blitting
1454 if (theDrawFbo != NULL
1455 && theDrawFbo->IsValid())
1456 {
1457 theDrawFbo->BindBuffer (aCtx);
1458 }
1459 else
1460 {
1461 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1462 }
1463#if !defined(GL_ES_VERSION_2_0)
1464 aCtx->core20fwd->glClearDepth (1.0);
1465#else
1466 aCtx->core20fwd->glClearDepthf (1.0f);
1467#endif
1468 aCtx->core20fwd->glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1469
1470/*#if !defined(GL_ES_VERSION_2_0)
1471 if (aCtx->arbFBOBlit != NULL)
1472 {
1473 theReadFbo->BindReadBuffer (aCtx);
1474 if (theDrawFbo != NULL
1475 && theDrawFbo->IsValid())
1476 {
1477 theDrawFbo->BindDrawBuffer (aCtx);
1478 }
1479 else
1480 {
1481 aCtx->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1482 }
1483 // we don't copy stencil buffer here... does it matter for performance?
1484 aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(),
1485 0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(),
1486 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
1487
1488 if (theDrawFbo != NULL
1489 && theDrawFbo->IsValid())
1490 {
1491 theDrawFbo->BindBuffer (aCtx);
1492 }
1493 else
1494 {
1495 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1496 }
1497 }
1498 else
1499#endif*/
1500 {
1501 aCtx->core20fwd->glDepthFunc (GL_ALWAYS);
1502 aCtx->core20fwd->glDepthMask (GL_TRUE);
1503 aCtx->core20fwd->glEnable (GL_DEPTH_TEST);
1504
1505 myWorkspace->DisableTexture();
1506
1507 OpenGl_VertexBuffer* aVerts = initBlitQuad (theToFlip);
1508 const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
1509 if (aVerts->IsValid()
1510 && aManager->BindFboBlitProgram())
1511 {
1512 theReadFbo->ColorTexture() ->Bind (aCtx, GL_TEXTURE0 + 0);
1513 theReadFbo->DepthStencilTexture()->Bind (aCtx, GL_TEXTURE0 + 1);
1514 aVerts->BindVertexAttrib (aCtx, Graphic3d_TOA_POS);
1515
1516 aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
1517
1518 aVerts->UnbindVertexAttrib (aCtx, Graphic3d_TOA_POS);
1519 theReadFbo->DepthStencilTexture()->Unbind (aCtx, GL_TEXTURE0 + 1);
1520 theReadFbo->ColorTexture() ->Unbind (aCtx, GL_TEXTURE0 + 0);
a521d90d 1521 aCtx->BindProgram (NULL);
c357e426 1522 }
1523 else
1524 {
1525 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
1526 + "Error! FBO blitting has failed";
1527 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
1528 GL_DEBUG_TYPE_ERROR_ARB,
1529 0,
1530 GL_DEBUG_SEVERITY_HIGH_ARB,
1531 aMsg);
1532 myHasFboBlit = Standard_False;
1533 theReadFbo->Release (aCtx.operator->());
1534 return true;
1535 }
1536 }
1537 return true;
1538}
1539
1540// =======================================================================
1541// function : drawStereoPair
1542// purpose :
1543// =======================================================================
1544void OpenGl_View::drawStereoPair()
1545{
1546 OpenGl_FrameBuffer* aPair[2] =
1547 {
1548 myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
1549 myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
1550 };
1551 if (aPair[0] == NULL
1552 || aPair[1] == NULL
1553 || !myTransientDrawToFront)
1554 {
1555 aPair[0] = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
1556 aPair[1] = myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL;
1557 }
1558
1559 if (aPair[0] == NULL
1560 || aPair[1] == NULL)
1561 {
1562 return;
1563 }
1564
1565 struct
1566 {
1567 Standard_Integer left;
1568 Standard_Integer top;
1569 Standard_Integer right;
1570 Standard_Integer bottom;
1571 Standard_Integer dx() { return right - left; }
1572 Standard_Integer dy() { return bottom - top; }
1573 } aGeom;
1574
1575 myWindow->PlatformWindow()->Position (aGeom.left, aGeom.top, aGeom.right, aGeom.bottom);
1576
1577 Standard_Boolean toReverse = myRenderParams.ToReverseStereo;
1578 const Standard_Boolean isOddY = (aGeom.top + aGeom.dy()) % 2 == 1;
1579 const Standard_Boolean isOddX = aGeom.left % 2 == 1;
1580 if (isOddY
1581 && (myRenderParams.StereoMode == Graphic3d_StereoMode_RowInterlaced
1582 || myRenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard))
1583 {
1584 toReverse = !toReverse;
1585 }
1586 if (isOddX
1587 && (myRenderParams.StereoMode == Graphic3d_StereoMode_ColumnInterlaced
1588 || myRenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard))
1589 {
1590 toReverse = !toReverse;
1591 }
1592
1593 if (toReverse)
1594 {
1595 std::swap (aPair[0], aPair[1]);
1596 }
1597
1598 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
1599 aCtx->core20fwd->glDepthFunc (GL_ALWAYS);
1600 aCtx->core20fwd->glDepthMask (GL_TRUE);
1601 aCtx->core20fwd->glEnable (GL_DEPTH_TEST);
1602
1603 myWorkspace->DisableTexture();
1604 OpenGl_VertexBuffer* aVerts = initBlitQuad (myToFlipOutput);
1605
1606 const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
1607 if (aVerts->IsValid()
1608 && aManager->BindStereoProgram (myRenderParams.StereoMode))
1609 {
1610 if (myRenderParams.StereoMode == Graphic3d_StereoMode_Anaglyph)
1611 {
1612 OpenGl_Mat4 aFilterL, aFilterR;
1613 aFilterL.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
1614 aFilterR.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
1615 switch (myRenderParams.AnaglyphFilter)
1616 {
1617 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple:
1618 {
1619 aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
1620 aFilterR.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
1621 aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
1622 break;
1623 }
1624 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized:
1625 {
1626 aFilterL.SetRow (0, Graphic3d_Vec4 ( 0.4154f, 0.4710f, 0.16666667f, 0.0f));
1627 aFilterL.SetRow (1, Graphic3d_Vec4 (-0.0458f, -0.0484f, -0.0257f, 0.0f));
1628 aFilterL.SetRow (2, Graphic3d_Vec4 (-0.0547f, -0.0615f, 0.0128f, 0.0f));
1629 aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1630 aFilterR.SetRow (0, Graphic3d_Vec4 (-0.01090909f, -0.03636364f, -0.00606061f, 0.0f));
1631 aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.37560000f, 0.73333333f, 0.01111111f, 0.0f));
1632 aFilterR.SetRow (2, Graphic3d_Vec4 (-0.06510000f, -0.12870000f, 1.29710000f, 0.0f));
1633 aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1634 break;
1635 }
1636 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple:
1637 {
1638 aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
1639 aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
1640 aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
1641 break;
1642 }
1643 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized:
1644 {
1645 aFilterL.SetRow (0, Graphic3d_Vec4 ( 1.062f, -0.205f, 0.299f, 0.0f));
1646 aFilterL.SetRow (1, Graphic3d_Vec4 (-0.026f, 0.908f, 0.068f, 0.0f));
1647 aFilterL.SetRow (2, Graphic3d_Vec4 (-0.038f, -0.173f, 0.022f, 0.0f));
1648 aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1649 aFilterR.SetRow (0, Graphic3d_Vec4 (-0.016f, -0.123f, -0.017f, 0.0f));
1650 aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.006f, 0.062f, -0.017f, 0.0f));
1651 aFilterR.SetRow (2, Graphic3d_Vec4 ( 0.094f, 0.185f, 0.911f, 0.0f));
1652 aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1653 break;
1654 }
1655 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple:
1656 {
1657 aFilterR.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
1658 aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
1659 aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
1660 break;
1661 }
1662 case Graphic3d_RenderingParams::Anaglyph_UserDefined:
1663 {
1664 aFilterL = myRenderParams.AnaglyphLeft;
1665 aFilterR = myRenderParams.AnaglyphRight;
1666 break;
1667 }
1668 }
1669 aCtx->ActiveProgram()->SetUniform (aCtx, "uMultL", aFilterL);
1670 aCtx->ActiveProgram()->SetUniform (aCtx, "uMultR", aFilterR);
1671 }
1672
1673 aPair[0]->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 0);
1674 aPair[1]->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 1);
1675 aVerts->BindVertexAttrib (aCtx, 0);
1676
1677 aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
1678
1679 aVerts->UnbindVertexAttrib (aCtx, 0);
1680 aPair[1]->ColorTexture()->Unbind (aCtx, GL_TEXTURE0 + 1);
1681 aPair[0]->ColorTexture()->Unbind (aCtx, GL_TEXTURE0 + 0);
1682 }
1683 else
1684 {
1685 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
1686 + "Error! Anaglyph has failed";
1687 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
1688 GL_DEBUG_TYPE_ERROR_ARB,
1689 0,
1690 GL_DEBUG_SEVERITY_HIGH_ARB,
1691 aMsg);
1692 }
1693}
1694
1695// =======================================================================
1696// function : copyBackToFront
1697// purpose :
1698// =======================================================================
1699void OpenGl_View::copyBackToFront()
1700{
1701#if !defined(GL_ES_VERSION_2_0)
1702
1703 OpenGl_Mat4 aProjectMat;
1704 Graphic3d_TransformUtils::Ortho2D (aProjectMat,
1705 0.f, static_cast<GLfloat> (myWindow->Width()), 0.f, static_cast<GLfloat> (myWindow->Height()));
1706
1707 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
1708 aCtx->WorldViewState.Push();
1709 aCtx->ProjectionState.Push();
1710
1711 aCtx->WorldViewState.SetIdentity();
1712 aCtx->ProjectionState.SetCurrent (aProjectMat);
1713
1714 aCtx->ApplyProjectionMatrix();
1715 aCtx->ApplyWorldViewMatrix();
1716
1717 aCtx->DisableFeatures();
1718
1719 switch (aCtx->DrawBuffer())
1720 {
1721 case GL_BACK_LEFT:
1722 {
1723 aCtx->SetReadBuffer (GL_BACK_LEFT);
1724 aCtx->SetDrawBuffer (GL_FRONT_LEFT);
1725 break;
1726 }
1727 case GL_BACK_RIGHT:
1728 {
1729 aCtx->SetReadBuffer (GL_BACK_RIGHT);
1730 aCtx->SetDrawBuffer (GL_FRONT_RIGHT);
1731 break;
1732 }
1733 default:
1734 {
1735 aCtx->SetReadBuffer (GL_BACK);
1736 aCtx->SetDrawBuffer (GL_FRONT);
1737 break;
1738 }
1739 }
1740
1741 glRasterPos2i (0, 0);
1742 glCopyPixels (0, 0, myWindow->Width() + 1, myWindow->Height() + 1, GL_COLOR);
1743 //glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH);
1744
1745 aCtx->EnableFeatures();
1746
1747 aCtx->WorldViewState.Pop();
1748 aCtx->ProjectionState.Pop();
1749 aCtx->ApplyProjectionMatrix();
1750
1751 // read/write from front buffer now
1752 aCtx->SetReadBuffer (aCtx->DrawBuffer());
1753#endif
1754 myIsImmediateDrawn = Standard_False;
1755}