Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
3 | // Copyright (c) 2011-2012 OPEN CASCADE SAS | |
4 | // | |
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. | |
9 | // | |
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. | |
12 | // | |
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. | |
19 | ||
2166f0fa SK |
20 | #include <stdio.h> |
21 | ||
5f8b738e | 22 | #include <OpenGl_GlCore11.hxx> |
2166f0fa | 23 | #include <OpenGl_Context.hxx> |
2166f0fa | 24 | #include <OpenGl_Structure.hxx> |
bf75be98 | 25 | #include <OpenGl_Workspace.hxx> |
2166f0fa | 26 | |
2166f0fa SK |
27 | /*----------------------------------------------------------------------*/ |
28 | /* Mode Ajout */ | |
29 | /*----------------------------------------------------------------------*/ | |
30 | ||
31 | //call_togl_begin_ajout_mode | |
1981cb22 | 32 | Standard_Boolean OpenGl_Workspace::BeginAddMode() |
2166f0fa SK |
33 | { |
34 | if (!Activate()) | |
1981cb22 | 35 | { |
2166f0fa | 36 | return Standard_False; |
1981cb22 | 37 | } |
2166f0fa SK |
38 | |
39 | NamedStatus |= OPENGL_NS_ADD; | |
40 | ||
41 | MakeFrontAndBackBufCurrent(); | |
42 | ||
43 | //TsmPushAttri(); | |
44 | ||
45 | return Standard_True; | |
46 | } | |
47 | ||
48 | /*----------------------------------------------------------------------*/ | |
49 | ||
50 | //call_togl_end_ajout_mode | |
51 | void OpenGl_Workspace::EndAddMode () | |
52 | { | |
53 | if (NamedStatus & OPENGL_NS_ADD) | |
54 | { | |
55 | OpenGl_Workspace::MakeBackBufCurrent(); | |
56 | ||
57 | // Clear add mode flag | |
58 | NamedStatus &= ~OPENGL_NS_ADD; | |
59 | } | |
60 | ||
1981cb22 | 61 | // FMN necessaire pour l'affichage sur WNT |
2166f0fa SK |
62 | glFlush(); |
63 | ||
64 | //TsmPopAttri(); | |
65 | } | |
66 | ||
67 | /*----------------------------------------------------------------------*/ | |
68 | /* Mode Transient */ | |
69 | /*----------------------------------------------------------------------*/ | |
70 | ||
71 | //call_togl_clear_immediat_mode | |
1981cb22 | 72 | void OpenGl_Workspace::ClearImmediatMode (const Graphic3d_CView& theCView, |
73 | const Standard_Boolean theToFlush) | |
2166f0fa | 74 | { |
1981cb22 | 75 | if (myIsTransientOpen) |
76 | { | |
2166f0fa | 77 | EndImmediatMode(); |
1981cb22 | 78 | } |
2166f0fa | 79 | |
1981cb22 | 80 | if (!Activate()) |
81 | { | |
82 | myTransientList.Clear(); // Clear current list contents | |
83 | return; | |
84 | } | |
2166f0fa | 85 | |
1981cb22 | 86 | GLboolean isDoubleBuffer = GL_FALSE; |
87 | glGetBooleanv (GL_DOUBLEBUFFER, &isDoubleBuffer); | |
88 | if (!myBackBufferRestored || !myTransientDrawToFront || !isDoubleBuffer) | |
2166f0fa SK |
89 | { |
90 | EraseAnimation(); | |
1981cb22 | 91 | Redraw1 (theCView, *((CALL_DEF_LAYER* )theCView.ptrUnderLayer), *((CALL_DEF_LAYER* )theCView.ptrOverLayer), theToFlush); |
2166f0fa SK |
92 | |
93 | // After a redraw, | |
94 | // Made the back identical to the front buffer. | |
95 | // Always perform full copy (partial update optimization is useless on mordern hardware)! | |
1981cb22 | 96 | if (myRetainMode && myTransientDrawToFront && isDoubleBuffer) |
97 | { | |
98 | const Standard_Boolean toCopyFrontToBack = Standard_True; | |
99 | CopyBuffers (toCopyFrontToBack); | |
100 | } | |
2166f0fa SK |
101 | |
102 | myBackBufferRestored = Standard_True; | |
103 | } | |
1981cb22 | 104 | else if (!myTransientList.IsEmpty() && isDoubleBuffer) |
2166f0fa | 105 | { |
1981cb22 | 106 | // restore pixels from the back buffer |
107 | const Standard_Boolean toCopyFrontToBack = Standard_False; | |
108 | CopyBuffers (toCopyFrontToBack); | |
2166f0fa SK |
109 | } |
110 | ||
1981cb22 | 111 | myTransientList.Clear(); // clear current list contents |
2166f0fa SK |
112 | } |
113 | ||
114 | /*----------------------------------------------------------------------*/ | |
115 | ||
116 | //call_togl_redraw_immediat_mode | |
1981cb22 | 117 | void OpenGl_Workspace::RedrawImmediatMode() |
2166f0fa | 118 | { |
1981cb22 | 119 | if (!myRetainMode || myTransientList.IsEmpty()) |
2166f0fa | 120 | { |
1981cb22 | 121 | return; |
2166f0fa | 122 | } |
2166f0fa | 123 | |
1981cb22 | 124 | GLboolean isDoubleBuffer = GL_FALSE; |
125 | glGetBooleanv (GL_DOUBLEBUFFER, &isDoubleBuffer); | |
126 | if (isDoubleBuffer && myTransientDrawToFront) | |
2166f0fa | 127 | { |
1981cb22 | 128 | MakeFrontBufCurrent(); |
2166f0fa | 129 | } |
2166f0fa | 130 | else |
2166f0fa | 131 | { |
1981cb22 | 132 | myBackBufferRestored = Standard_False; |
2166f0fa | 133 | } |
1981cb22 | 134 | glDisable (GL_LIGHTING); |
2166f0fa | 135 | |
1981cb22 | 136 | Handle(OpenGl_Workspace) aWS (this); |
137 | for (Standard_Integer anIter = 1; anIter <= myTransientList.Size(); ++anIter) | |
2166f0fa | 138 | { |
1981cb22 | 139 | const OpenGl_Structure* aStructure = myTransientList.Value (anIter); |
140 | aStructure->Render (aWS); | |
2166f0fa | 141 | } |
2166f0fa | 142 | |
1981cb22 | 143 | if (isDoubleBuffer && myTransientDrawToFront) |
144 | { | |
145 | glFlush(); // FMN necessaire pour l'affichage sur WNT | |
146 | MakeBackBufCurrent(); | |
2166f0fa | 147 | } |
2166f0fa SK |
148 | } |
149 | ||
150 | /*----------------------------------------------------------------------*/ | |
151 | ||
1981cb22 | 152 | //call_togl_begin_immediat_mode |
153 | Standard_Boolean OpenGl_Workspace::BeginImmediatMode (const Graphic3d_CView& theCView, | |
154 | const Standard_Boolean theToUseDepthTest, | |
155 | const Standard_Boolean theRetainMode) | |
2166f0fa | 156 | { |
1981cb22 | 157 | if (!Activate()) |
2166f0fa | 158 | { |
1981cb22 | 159 | return Standard_False; |
2166f0fa | 160 | } |
2166f0fa | 161 | |
1981cb22 | 162 | OpenGl_Workspace::ClearImmediatMode (theCView, Standard_True); |
2166f0fa | 163 | |
1981cb22 | 164 | NamedStatus |= OPENGL_NS_IMMEDIATE; |
165 | myRetainMode = theRetainMode; | |
2166f0fa | 166 | |
1981cb22 | 167 | if (myTransientDrawToFront) |
2166f0fa | 168 | { |
1981cb22 | 169 | MakeFrontBufCurrent(); |
2166f0fa | 170 | } |
2166f0fa | 171 | |
1981cb22 | 172 | //TsmPushAttri(); |
2166f0fa | 173 | |
1981cb22 | 174 | if (myRetainMode) |
2166f0fa | 175 | { |
1981cb22 | 176 | myIsTransientOpen = Standard_True; |
2166f0fa | 177 | } |
2166f0fa | 178 | |
1981cb22 | 179 | if (theToUseDepthTest) |
2166f0fa | 180 | { |
1981cb22 | 181 | glEnable (GL_DEPTH_TEST); |
2166f0fa | 182 | } |
1981cb22 | 183 | else |
2166f0fa | 184 | { |
1981cb22 | 185 | glDisable (GL_DEPTH_TEST); |
2166f0fa | 186 | } |
2166f0fa | 187 | |
1981cb22 | 188 | return Standard_True; |
2166f0fa SK |
189 | } |
190 | ||
191 | /*----------------------------------------------------------------------*/ | |
192 | ||
1981cb22 | 193 | //call_togl_end_immediat_mode |
194 | void OpenGl_Workspace::EndImmediatMode() | |
2166f0fa | 195 | { |
1981cb22 | 196 | if (NamedStatus & OPENGL_NS_IMMEDIATE) |
2166f0fa | 197 | { |
1981cb22 | 198 | if (myIsTransientOpen) |
2166f0fa | 199 | { |
1981cb22 | 200 | myIsTransientOpen = Standard_False; |
2166f0fa | 201 | } |
1981cb22 | 202 | if (myTransientDrawToFront) |
2166f0fa | 203 | { |
1981cb22 | 204 | MakeBackBufCurrent(); |
2166f0fa | 205 | } |
2166f0fa | 206 | |
1981cb22 | 207 | // Clear immediate mode flag |
208 | NamedStatus &= ~OPENGL_NS_IMMEDIATE; | |
209 | } | |
2166f0fa | 210 | |
1981cb22 | 211 | if (myTransientDrawToFront) |
2166f0fa | 212 | { |
1981cb22 | 213 | // Ajout CAL : pour voir quelque chose avant le prochain begin_immediat_mode |
214 | glFinish(); | |
2166f0fa SK |
215 | } |
216 | else | |
217 | { | |
1981cb22 | 218 | GetGlContext()->SwapBuffers(); |
2166f0fa SK |
219 | } |
220 | ||
1981cb22 | 221 | //TsmPopAttri(); |
2166f0fa SK |
222 | } |
223 | ||
1981cb22 | 224 | //call_togl_draw_structure |
225 | void OpenGl_Workspace::DrawStructure (const OpenGl_Structure* theStructure) | |
2166f0fa | 226 | { |
1981cb22 | 227 | if (NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) |
228 | { | |
229 | Handle(OpenGl_Workspace) aWS (this); | |
230 | theStructure->Render (aWS); | |
2166f0fa | 231 | |
1981cb22 | 232 | if (myIsTransientOpen && myRetainMode) |
233 | { | |
234 | myTransientList.Append (theStructure); | |
235 | } | |
236 | } | |
2166f0fa | 237 | } |