1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <OpenGl_GlCore11.hxx>
23 #include <OpenGl_Context.hxx>
24 #include <OpenGl_Structure.hxx>
25 #include <OpenGl_Workspace.hxx>
27 /*----------------------------------------------------------------------*/
29 /*----------------------------------------------------------------------*/
31 //call_togl_begin_ajout_mode
32 Standard_Boolean OpenGl_Workspace::BeginAddMode()
36 return Standard_False;
39 NamedStatus |= OPENGL_NS_ADD;
41 MakeFrontAndBackBufCurrent();
48 /*----------------------------------------------------------------------*/
50 //call_togl_end_ajout_mode
51 void OpenGl_Workspace::EndAddMode ()
53 if (NamedStatus & OPENGL_NS_ADD)
55 OpenGl_Workspace::MakeBackBufCurrent();
57 // Clear add mode flag
58 NamedStatus &= ~OPENGL_NS_ADD;
61 // FMN necessaire pour l'affichage sur WNT
67 /*----------------------------------------------------------------------*/
69 /*----------------------------------------------------------------------*/
71 //call_togl_clear_immediat_mode
72 void OpenGl_Workspace::ClearImmediatMode (const Graphic3d_CView& theCView,
73 const Standard_Boolean theToFlush)
75 if (myIsTransientOpen)
82 myTransientList.Clear(); // Clear current list contents
86 GLboolean isDoubleBuffer = GL_FALSE;
87 glGetBooleanv (GL_DOUBLEBUFFER, &isDoubleBuffer);
88 if (!myBackBufferRestored || !myTransientDrawToFront || !isDoubleBuffer)
90 Redraw1 (theCView, *((CALL_DEF_LAYER* )theCView.ptrUnderLayer), *((CALL_DEF_LAYER* )theCView.ptrOverLayer), theToFlush);
93 // Made the back identical to the front buffer.
94 // Always perform full copy (partial update optimization is useless on mordern hardware)!
95 if (myRetainMode && myTransientDrawToFront && isDoubleBuffer)
97 const Standard_Boolean toCopyFrontToBack = Standard_True;
98 CopyBuffers (toCopyFrontToBack);
101 myBackBufferRestored = Standard_True;
103 else if (!myTransientList.IsEmpty() && isDoubleBuffer)
105 // restore pixels from the back buffer
106 const Standard_Boolean toCopyFrontToBack = Standard_False;
107 CopyBuffers (toCopyFrontToBack);
110 myTransientList.Clear(); // clear current list contents
113 /*----------------------------------------------------------------------*/
115 //call_togl_redraw_immediat_mode
116 void OpenGl_Workspace::RedrawImmediatMode()
118 if (!myRetainMode || myTransientList.IsEmpty())
123 GLboolean isDoubleBuffer = GL_FALSE;
124 glGetBooleanv (GL_DOUBLEBUFFER, &isDoubleBuffer);
125 if (isDoubleBuffer && myTransientDrawToFront)
127 MakeFrontBufCurrent();
131 myBackBufferRestored = Standard_False;
133 glDisable (GL_LIGHTING);
135 Handle(OpenGl_Workspace) aWS (this);
136 for (Standard_Integer anIter = 1; anIter <= myTransientList.Size(); ++anIter)
138 const OpenGl_Structure* aStructure = myTransientList.Value (anIter);
139 aStructure->Render (aWS);
142 if (isDoubleBuffer && myTransientDrawToFront)
144 glFlush(); // FMN necessaire pour l'affichage sur WNT
145 MakeBackBufCurrent();
149 /*----------------------------------------------------------------------*/
151 //call_togl_begin_immediat_mode
152 Standard_Boolean OpenGl_Workspace::BeginImmediatMode (const Graphic3d_CView& theCView,
153 const Standard_Boolean theToUseDepthTest,
154 const Standard_Boolean theRetainMode)
158 return Standard_False;
161 OpenGl_Workspace::ClearImmediatMode (theCView, Standard_True);
163 NamedStatus |= OPENGL_NS_IMMEDIATE;
164 myRetainMode = theRetainMode;
166 if (myTransientDrawToFront)
168 MakeFrontBufCurrent();
175 myIsTransientOpen = Standard_True;
178 if (theToUseDepthTest)
180 glEnable (GL_DEPTH_TEST);
184 glDisable (GL_DEPTH_TEST);
187 return Standard_True;
190 /*----------------------------------------------------------------------*/
192 //call_togl_end_immediat_mode
193 void OpenGl_Workspace::EndImmediatMode()
195 if (NamedStatus & OPENGL_NS_IMMEDIATE)
197 if (myIsTransientOpen)
199 myIsTransientOpen = Standard_False;
201 if (myTransientDrawToFront)
203 MakeBackBufCurrent();
206 // Clear immediate mode flag
207 NamedStatus &= ~OPENGL_NS_IMMEDIATE;
210 if (myTransientDrawToFront)
212 // Ajout CAL : pour voir quelque chose avant le prochain begin_immediat_mode
217 GetGlContext()->SwapBuffers();
223 //call_togl_draw_structure
224 void OpenGl_Workspace::DrawStructure (const OpenGl_Structure* theStructure)
226 if (NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE))
228 Handle(OpenGl_Workspace) aWS (this);
229 theStructure->Render (aWS);
231 if (myIsTransientOpen && myRetainMode)
233 myTransientList.Append (theStructure);