Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-08-05 |
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 | 20 | |
5f8b738e | 21 | #include <OpenGl_GlCore11.hxx> |
22 | ||
2166f0fa SK |
23 | #include <OpenGl_Workspace.hxx> |
24 | ||
25 | #include <OpenGl_AspectLine.hxx> | |
26 | #include <OpenGl_AspectFace.hxx> | |
27 | #include <OpenGl_AspectMarker.hxx> | |
28 | #include <OpenGl_AspectText.hxx> | |
29 | ||
498ce577 | 30 | #ifdef HAVE_CONFIG_H |
31 | # include <config.h> | |
32 | #endif | |
33 | ||
2166f0fa SK |
34 | /* OCC22218 NOTE: project dependency on gl2ps is specified by macro */ |
35 | #ifdef HAVE_GL2PS | |
36 | #include <gl2ps.h> | |
bf75be98 | 37 | /* OCC22216 NOTE: linker dependency can be switched off by undefining macro. |
38 | Pragma comment for gl2ps.lib is defined only here. */ | |
39 | #ifdef _MSC_VER | |
2166f0fa SK |
40 | #pragma comment( lib, "gl2ps.lib" ) |
41 | #endif | |
42 | #endif | |
43 | ||
2166f0fa | 44 | #include <Aspect_PolygonOffsetMode.hxx> |
2166f0fa SK |
45 | #include <OpenGl_View.hxx> |
46 | ||
47 | /*----------------------------------------------------------------------*/ | |
48 | ||
49 | static void TelUpdatePolygonOffsets( const TEL_POFFSET_PARAM *pdata ) | |
50 | { | |
51 | if ( ( pdata->mode & Aspect_POM_Fill ) == Aspect_POM_Fill ) | |
52 | glEnable ( GL_POLYGON_OFFSET_FILL ); | |
bf75be98 | 53 | else |
2166f0fa SK |
54 | glDisable ( GL_POLYGON_OFFSET_FILL ); |
55 | ||
56 | if ( ( pdata->mode & Aspect_POM_Line ) == Aspect_POM_Line ) | |
57 | glEnable ( GL_POLYGON_OFFSET_LINE ); | |
58 | else | |
59 | glDisable( GL_POLYGON_OFFSET_LINE ); | |
60 | ||
61 | if ( ( pdata->mode & Aspect_POM_Point ) == Aspect_POM_Point ) | |
62 | glEnable ( GL_POLYGON_OFFSET_POINT ); | |
63 | else | |
64 | glDisable( GL_POLYGON_OFFSET_POINT ); | |
65 | ||
66 | glPolygonOffset( pdata->factor, pdata->units ); | |
67 | } | |
68 | ||
69 | /*----------------------------------------------------------------------*/ | |
70 | ||
71 | void OpenGl_Workspace::UpdateMaterial( const int flag ) | |
72 | { | |
73 | // Case of Hiddenline | |
bf75be98 | 74 | if (AspectFace_set->InteriorStyle == Aspect_IS_HIDDENLINE) |
2166f0fa | 75 | { |
bf75be98 | 76 | myAspectFaceHl = *AspectFace_set; // copy all values including line edge aspect |
77 | myAspectFaceHl.IntFront.matcol = BackgroundColor(); | |
78 | myAspectFaceHl.IntFront.color_mask = 0; | |
79 | myAspectFaceHl.IntBack.color_mask = 0; | |
2166f0fa | 80 | |
bf75be98 | 81 | AspectFace_set = &myAspectFaceHl; |
2166f0fa SK |
82 | return; |
83 | } | |
84 | ||
85 | const OPENGL_SURF_PROP *prop = NULL; | |
86 | GLenum face = 0; | |
87 | if ( flag == TEL_FRONT_MATERIAL ) | |
88 | { | |
bf75be98 | 89 | prop = &AspectFace_set->IntFront; |
2166f0fa SK |
90 | face = GL_FRONT_AND_BACK; |
91 | } | |
92 | else | |
93 | { | |
bf75be98 | 94 | prop = &AspectFace_set->IntBack; |
2166f0fa SK |
95 | face = GL_BACK; |
96 | } | |
97 | ||
98 | const unsigned int rm = prop->color_mask; | |
99 | ||
100 | if ( !rm ) return; | |
101 | ||
102 | // Handling transparency | |
103 | if ( (NamedStatus & OPENGL_NS_2NDPASSDO) == 0 ) | |
104 | { | |
105 | if ( myUseTransparency && prop->trans != 1.0F ) | |
106 | { | |
107 | // Render transparent | |
bf75be98 | 108 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2166f0fa SK |
109 | glEnable (GL_BLEND); |
110 | glDepthMask (GL_FALSE); | |
111 | } | |
bf75be98 | 112 | else |
2166f0fa SK |
113 | { |
114 | // Render opaque | |
115 | if ( (NamedStatus & OPENGL_NS_ANTIALIASING) == 0 ) | |
116 | { | |
117 | glBlendFunc (GL_ONE, GL_ZERO); | |
118 | glDisable (GL_BLEND); | |
119 | } | |
120 | glDepthMask (GL_TRUE); | |
bf75be98 | 121 | } |
2166f0fa SK |
122 | } |
123 | ||
124 | static float mAmb[4]; | |
125 | static float mDiff[4]; | |
126 | static float mSpec[4]; | |
127 | static float mEmsv[4]; | |
128 | static float mShin; | |
129 | ||
130 | static const float defspeccol[4] = { 1.F, 1.F, 1.F, 1.F }; | |
131 | ||
132 | // Reset material | |
133 | if ( NamedStatus & OPENGL_NS_RESMAT ) | |
bf75be98 | 134 | { |
2166f0fa SK |
135 | // Ambient component |
136 | if( rm & OPENGL_AMBIENT_MASK ) | |
137 | { | |
138 | const float *c = prop->isphysic? prop->ambcol.rgb : prop->matcol.rgb; | |
139 | ||
140 | mAmb[0] = prop->amb * c[0]; | |
141 | mAmb[1] = prop->amb * c[1]; | |
142 | mAmb[2] = prop->amb * c[2]; | |
143 | } | |
144 | else | |
145 | { | |
146 | mAmb[0] = 0.F; | |
147 | mAmb[1] = 0.F; | |
148 | mAmb[2] = 0.F; | |
149 | } | |
150 | mAmb[3] = 1.F; | |
151 | ||
152 | // Diffusion component | |
153 | if( rm & OPENGL_DIFFUSE_MASK ) | |
154 | { | |
155 | const float *c = prop->isphysic? prop->difcol.rgb : prop->matcol.rgb; | |
156 | ||
157 | mDiff[0] = prop->diff * c[0]; | |
158 | mDiff[1] = prop->diff * c[1]; | |
159 | mDiff[2] = prop->diff * c[2]; | |
160 | } | |
161 | else | |
162 | { | |
163 | mDiff[0] = 0.F; | |
164 | mDiff[1] = 0.F; | |
165 | mDiff[2] = 0.F; | |
166 | } | |
167 | mDiff[3] = 1.F; | |
168 | ||
169 | if (NamedStatus & OPENGL_NS_2NDPASSDO) | |
170 | { | |
bf75be98 | 171 | mDiff[3] = prop->env_reflexion; |
2166f0fa SK |
172 | } |
173 | else | |
174 | { | |
175 | if (myUseTransparency) mDiff[3] = prop->trans; | |
176 | // If the material reflects the environment scene, the second pass is needed | |
177 | if (prop->env_reflexion != 0.0) NamedStatus |= OPENGL_NS_2NDPASSNEED; | |
178 | } | |
179 | ||
180 | // Specular component | |
181 | if( rm & OPENGL_SPECULAR_MASK ) | |
182 | { | |
183 | const float *c = prop->isphysic? prop->speccol.rgb : defspeccol; | |
184 | ||
185 | mSpec[0] = prop->spec * c[0]; | |
186 | mSpec[1] = prop->spec * c[1]; | |
187 | mSpec[2] = prop->spec * c[2]; | |
bf75be98 | 188 | } |
2166f0fa SK |
189 | else { |
190 | mSpec[0] = 0.F; | |
191 | mSpec[1] = 0.F; | |
192 | mSpec[2] = 0.F; | |
193 | } | |
194 | mSpec[3] = 1.F; | |
195 | ||
196 | // Emissive component | |
197 | if( rm & OPENGL_EMISSIVE_MASK ) | |
bf75be98 | 198 | { |
2166f0fa SK |
199 | const float *c = prop->isphysic? prop->emscol.rgb : prop->matcol.rgb; |
200 | ||
201 | mEmsv[0] = prop->emsv * c[0]; | |
202 | mEmsv[1] = prop->emsv * c[1]; | |
203 | mEmsv[2] = prop->emsv * c[2]; | |
204 | } | |
205 | else { | |
206 | mEmsv[0] = 0.F; | |
207 | mEmsv[1] = 0.F; | |
208 | mEmsv[2] = 0.F; | |
209 | } | |
210 | mEmsv[3] = 1.F; | |
211 | ||
212 | /* Coeficient de brillance */ | |
213 | mShin = prop->shine; | |
214 | ||
215 | glMaterialfv(face, GL_AMBIENT, mAmb ); | |
216 | glMaterialfv(face, GL_DIFFUSE, mDiff ); | |
217 | glMaterialfv(face, GL_SPECULAR, mSpec); | |
218 | glMaterialfv(face, GL_EMISSION, mEmsv); | |
219 | glMaterialf(face, GL_SHININESS, mShin); | |
220 | ||
221 | NamedStatus &= ~OPENGL_NS_RESMAT; | |
bf75be98 | 222 | } |
2166f0fa SK |
223 | |
224 | // Set Material Optimize | |
bf75be98 | 225 | else |
2166f0fa SK |
226 | { |
227 | // Ambient component | |
228 | if( rm & OPENGL_AMBIENT_MASK ) | |
229 | { | |
230 | const float *c = prop->isphysic? prop->ambcol.rgb : prop->matcol.rgb; | |
231 | ||
232 | if (mAmb[0] != prop->amb * c[0] || | |
233 | mAmb[1] != prop->amb * c[1] || | |
234 | mAmb[2] != prop->amb * c[2] ) | |
235 | { | |
236 | mAmb[0] = prop->amb * c[0]; | |
237 | mAmb[1] = prop->amb * c[1]; | |
238 | mAmb[2] = prop->amb * c[2]; | |
239 | mAmb[3] = 1.F; | |
240 | ||
241 | glMaterialfv(face, GL_AMBIENT, mAmb); | |
242 | } | |
243 | } | |
244 | else | |
245 | { | |
246 | if ( mAmb[0] != 0.F || mAmb[1] != 0.F || mAmb[2] != 0.F ) | |
247 | { | |
248 | mAmb[0] = 0.F; | |
249 | mAmb[1] = 0.F; | |
250 | mAmb[2] = 0.F; | |
251 | mAmb[3] = 1.F; | |
252 | ||
253 | glMaterialfv(face, GL_AMBIENT, mAmb); | |
254 | } | |
255 | } | |
256 | ||
257 | // Diffusion component | |
258 | if( rm & OPENGL_DIFFUSE_MASK ) | |
259 | { | |
260 | const float *c = prop->isphysic? prop->difcol.rgb : prop->matcol.rgb; | |
261 | ||
262 | if (mDiff[0] != prop->diff * c[0] || | |
263 | mDiff[1] != prop->diff * c[1] || | |
264 | mDiff[2] != prop->diff * c[2] || | |
265 | mDiff[3] != ((NamedStatus & OPENGL_NS_2NDPASSDO)? prop->env_reflexion : (myUseTransparency? prop->trans : 1.0F))) | |
266 | { | |
267 | mDiff[0] = prop->diff * c[0]; | |
268 | mDiff[1] = prop->diff * c[1]; | |
269 | mDiff[2] = prop->diff * c[2]; | |
270 | mDiff[3] = 1.F; | |
271 | ||
272 | if (NamedStatus & OPENGL_NS_2NDPASSDO) | |
273 | { | |
bf75be98 | 274 | mDiff[3] = prop->env_reflexion; |
2166f0fa SK |
275 | } |
276 | else | |
277 | { | |
278 | if (myUseTransparency) mDiff[3] = prop->trans; | |
279 | // If the material reflects the environment scene, the second pass is needed | |
280 | if (prop->env_reflexion != 0.0) NamedStatus |= OPENGL_NS_2NDPASSNEED; | |
281 | } | |
282 | ||
283 | glMaterialfv(face, GL_DIFFUSE, mDiff ); | |
284 | } | |
285 | } | |
286 | else | |
287 | { | |
288 | Tfloat newDiff3 = 1.F; | |
289 | ||
290 | if (NamedStatus & OPENGL_NS_2NDPASSDO) | |
291 | { | |
bf75be98 | 292 | newDiff3 = prop->env_reflexion; |
2166f0fa SK |
293 | } |
294 | else | |
295 | { | |
296 | if (myUseTransparency) newDiff3 = prop->trans; | |
297 | // If the material reflects the environment scene, the second pass is needed | |
298 | if (prop->env_reflexion != 0.0) NamedStatus |= OPENGL_NS_2NDPASSNEED; | |
299 | } | |
300 | ||
301 | /* OCC19915: Even if diffuse reflectance is disabled, | |
302 | still trying to update the current transparency if it | |
303 | differs from the previous value */ | |
304 | if ( mDiff[0] != 0.F || mDiff[1] != 0.F || mDiff[2] != 0.F || fabs(mDiff[3] - newDiff3) > 0.01F ) | |
305 | { | |
306 | mDiff[0] = 0.F; | |
307 | mDiff[1] = 0.F; | |
308 | mDiff[2] = 0.F; | |
309 | mDiff[3] = newDiff3; | |
310 | ||
311 | glMaterialfv(face, GL_DIFFUSE, mDiff); | |
312 | } | |
313 | } | |
314 | ||
315 | // Specular component | |
316 | if( rm & OPENGL_SPECULAR_MASK ) | |
bf75be98 | 317 | { |
2166f0fa SK |
318 | const float *c = prop->isphysic? prop->speccol.rgb : defspeccol; |
319 | ||
320 | if (mSpec[0] != prop->spec * c[0] || | |
321 | mSpec[1] != prop->spec * c[1] || | |
322 | mSpec[2] != prop->spec * c[2]) | |
323 | { | |
324 | mSpec[0] = prop->spec * c[0]; | |
325 | mSpec[1] = prop->spec * c[1]; | |
326 | mSpec[2] = prop->spec * c[2]; | |
327 | mSpec[3] = 1.F; | |
328 | ||
329 | glMaterialfv(face, GL_SPECULAR, mSpec); | |
330 | } | |
331 | } | |
332 | else | |
333 | { | |
334 | if ( mSpec[0] != 0.F || mSpec[1] != 0.F || mSpec[2] != 0.F ) | |
335 | { | |
336 | mSpec[0] = 0.F; | |
337 | mSpec[1] = 0.F; | |
338 | mSpec[2] = 0.F; | |
339 | mSpec[3] = 1.F; | |
340 | ||
341 | glMaterialfv(face, GL_SPECULAR, mSpec); | |
342 | } | |
343 | } | |
344 | ||
345 | // Emissive component | |
346 | if( rm & OPENGL_EMISSIVE_MASK ) | |
347 | { | |
348 | const float *c = prop->isphysic? prop->emscol.rgb : prop->matcol.rgb; | |
349 | ||
350 | if (mEmsv[0] != prop->emsv * c[0] || | |
351 | mEmsv[1] != prop->emsv * c[1] || | |
352 | mEmsv[2] != prop->emsv * c[2]) | |
353 | { | |
354 | mEmsv[0] = prop->emsv * c[0]; | |
355 | mEmsv[1] = prop->emsv * c[1]; | |
356 | mEmsv[2] = prop->emsv * c[2]; | |
357 | mEmsv[3] = 1.F; | |
358 | ||
359 | glMaterialfv(face, GL_EMISSION, mEmsv); | |
360 | } | |
361 | } | |
bf75be98 | 362 | else |
363 | { | |
2166f0fa SK |
364 | if ( mEmsv[0] != 0.F || mEmsv[1] != 0.F || mEmsv[2] != 0.F ) |
365 | { | |
366 | mEmsv[0] = 0.F; | |
367 | mEmsv[1] = 0.F; | |
368 | mEmsv[2] = 0.F; | |
369 | mEmsv[3] = 1.F; | |
370 | ||
371 | glMaterialfv(face, GL_EMISSION, mEmsv); | |
372 | } | |
373 | } | |
374 | ||
375 | // Shining coefficient | |
376 | if( mShin != prop->shine ) | |
377 | { | |
378 | mShin = prop->shine; | |
379 | glMaterialf(face, GL_SHININESS, mShin); | |
380 | } | |
381 | } | |
382 | } | |
383 | ||
384 | /*----------------------------------------------------------------------*/ | |
385 | ||
386 | const OpenGl_AspectLine * OpenGl_Workspace::SetAspectLine(const OpenGl_AspectLine *AnAspect) | |
387 | { | |
388 | const OpenGl_AspectLine *AspectLine_old = AspectLine_set; | |
389 | AspectLine_set = AnAspect; | |
390 | return AspectLine_old; | |
391 | } | |
392 | ||
393 | /*----------------------------------------------------------------------*/ | |
394 | ||
395 | const OpenGl_AspectFace * OpenGl_Workspace::SetAspectFace(const OpenGl_AspectFace *AnAspect) | |
396 | { | |
397 | const OpenGl_AspectFace *AspectFace_old = AspectFace_set; | |
398 | AspectFace_set = AnAspect; | |
399 | return AspectFace_old; | |
400 | } | |
401 | ||
402 | /*----------------------------------------------------------------------*/ | |
403 | ||
404 | const OpenGl_AspectMarker * OpenGl_Workspace::SetAspectMarker(const OpenGl_AspectMarker *AnAspect) | |
405 | { | |
406 | const OpenGl_AspectMarker *AspectMarker_old = AspectMarker_set; | |
407 | AspectMarker_set = AnAspect; | |
408 | return AspectMarker_old; | |
409 | } | |
410 | ||
411 | /*----------------------------------------------------------------------*/ | |
412 | ||
413 | const OpenGl_AspectText * OpenGl_Workspace::SetAspectText(const OpenGl_AspectText *AnAspect) | |
414 | { | |
415 | const OpenGl_AspectText *AspectText_old = AspectText_set; | |
416 | AspectText_set = AnAspect; | |
417 | return AspectText_old; | |
418 | } | |
419 | ||
420 | /*----------------------------------------------------------------------*/ | |
421 | ||
422 | const OpenGl_Matrix * OpenGl_Workspace::SetViewMatrix(const OpenGl_Matrix *AMatrix) | |
423 | { | |
424 | const OpenGl_Matrix *ViewMatrix_old = ViewMatrix_applied; | |
425 | ViewMatrix_applied = AMatrix; | |
426 | ||
427 | OpenGl_Matrix lmat; | |
428 | OpenGl_Transposemat3( &lmat, StructureMatrix_applied ); | |
429 | ||
430 | glMatrixMode (GL_MODELVIEW); | |
431 | ||
432 | if ( (NamedStatus & OPENGL_NS_ANIMATION) == 0 ) | |
433 | { | |
434 | OpenGl_Matrix rmat; | |
435 | OpenGl_Multiplymat3( &rmat, &lmat, ViewMatrix_applied ); | |
436 | glLoadMatrixf((const GLfloat *) rmat.mat); | |
437 | } | |
438 | ||
439 | return ViewMatrix_old; | |
440 | } | |
441 | ||
442 | /*----------------------------------------------------------------------*/ | |
443 | ||
444 | const OpenGl_Matrix * OpenGl_Workspace::SetStructureMatrix(const OpenGl_Matrix *AMatrix) | |
445 | { | |
446 | const OpenGl_Matrix *StructureMatrix_old = StructureMatrix_applied; | |
447 | StructureMatrix_applied = AMatrix; | |
448 | ||
449 | OpenGl_Matrix lmat; | |
450 | OpenGl_Transposemat3( &lmat, AMatrix ); | |
451 | ||
452 | glMatrixMode (GL_MODELVIEW); | |
453 | ||
454 | if ( (NamedStatus & OPENGL_NS_ANIMATION) == 0 ) | |
455 | { | |
456 | OpenGl_Matrix rmat; | |
457 | OpenGl_Multiplymat3( &rmat, &lmat, ViewMatrix_applied ); | |
458 | glLoadMatrixf((const GLfloat *) rmat.mat); | |
459 | } | |
460 | else | |
461 | { | |
462 | glMultMatrixf((const GLfloat *) lmat.mat); | |
463 | } | |
464 | ||
465 | return StructureMatrix_old; | |
466 | } | |
467 | ||
468 | /*----------------------------------------------------------------------*/ | |
469 | ||
470 | const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean WithApply) | |
471 | { | |
472 | if ( WithApply && (AspectLine_set != AspectLine_applied) ) | |
473 | { | |
474 | glColor3fv(AspectLine_set->Color().rgb); | |
475 | ||
476 | if ( !AspectLine_applied || (AspectLine_set->Type() != AspectLine_applied->Type() ) ) | |
477 | { | |
478 | myDisplay->SetTypeOfLine(AspectLine_set->Type()); | |
479 | } | |
480 | ||
481 | if ( !AspectLine_applied || ( AspectLine_set->Width() != AspectLine_applied->Width() ) ) | |
482 | { | |
483 | glLineWidth( (GLfloat)AspectLine_set->Width() ); | |
484 | #ifdef HAVE_GL2PS | |
485 | gl2psLineWidth( (GLfloat)AspectLine_set->Width() ); | |
486 | #endif | |
487 | } | |
488 | ||
489 | AspectLine_applied = AspectLine_set; | |
490 | } | |
491 | return AspectLine_set; | |
492 | } | |
493 | ||
494 | /*----------------------------------------------------------------------*/ | |
495 | ||
bf75be98 | 496 | const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean theToApply) |
2166f0fa | 497 | { |
bf75be98 | 498 | if (!theToApply || (AspectFace_set == AspectFace_applied)) |
499 | { | |
500 | return AspectFace_set; | |
501 | } | |
502 | ||
503 | const Aspect_InteriorStyle anIntstyle = AspectFace_set->InteriorStyle; | |
504 | if (AspectFace_applied == NULL || AspectFace_applied->InteriorStyle != anIntstyle) | |
2166f0fa | 505 | { |
bf75be98 | 506 | switch (anIntstyle) |
2166f0fa | 507 | { |
bf75be98 | 508 | case Aspect_IS_EMPTY: |
509 | case Aspect_IS_HOLLOW: | |
2166f0fa | 510 | { |
bf75be98 | 511 | glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); |
512 | break; | |
2166f0fa | 513 | } |
bf75be98 | 514 | case Aspect_IS_HATCH: |
515 | { | |
516 | glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); | |
517 | myDisplay->SetTypeOfHatch (AspectFace_applied != NULL ? AspectFace_applied->Hatch : TEL_HS_SOLID); | |
518 | break; | |
519 | } | |
520 | case Aspect_IS_SOLID: | |
521 | case Aspect_IS_HIDDENLINE: | |
522 | { | |
523 | glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); | |
524 | glDisable (GL_POLYGON_STIPPLE); | |
525 | break; | |
526 | } | |
527 | case 5: //szvgl - no corresponding enumeration item Aspect_IS_POINT | |
2166f0fa | 528 | { |
bf75be98 | 529 | glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); |
530 | break; | |
2166f0fa SK |
531 | } |
532 | } | |
bf75be98 | 533 | } |
534 | ||
535 | if (anIntstyle == Aspect_IS_HATCH) | |
536 | { | |
537 | const Tint hatchstyle = AspectFace_set->Hatch; | |
538 | if (AspectFace_applied == NULL || AspectFace_applied->Hatch != hatchstyle) | |
539 | { | |
540 | myDisplay->SetTypeOfHatch(hatchstyle); | |
541 | } | |
542 | } | |
543 | ||
544 | if (!ActiveView()->Backfacing()) | |
545 | { | |
546 | const Tint aCullingMode = AspectFace_set->CullingMode; | |
547 | if (AspectFace_applied == NULL || AspectFace_applied->CullingMode != aCullingMode) | |
2166f0fa | 548 | { |
bf75be98 | 549 | switch ((TelCullMode )aCullingMode) |
2166f0fa | 550 | { |
bf75be98 | 551 | case TelCullNone: |
2166f0fa | 552 | { |
bf75be98 | 553 | glDisable (GL_CULL_FACE); |
554 | break; | |
555 | } | |
556 | case TelCullFront: | |
557 | { | |
558 | glCullFace (GL_FRONT); | |
559 | glEnable (GL_CULL_FACE); | |
560 | break; | |
561 | } | |
562 | case TelCullBack: | |
563 | { | |
564 | glCullFace (GL_BACK); | |
565 | glEnable (GL_CULL_FACE); | |
566 | break; | |
2166f0fa SK |
567 | } |
568 | } | |
569 | } | |
bf75be98 | 570 | } |
2166f0fa | 571 | |
bf75be98 | 572 | // Aspect_POM_None means: do not change current settings |
573 | if ((AspectFace_set->PolygonOffset.mode & Aspect_POM_None) != Aspect_POM_None) | |
574 | { | |
575 | if (PolygonOffset_applied == NULL | |
576 | || PolygonOffset_applied->mode != AspectFace_set->PolygonOffset.mode | |
577 | || PolygonOffset_applied->factor != AspectFace_set->PolygonOffset.factor | |
578 | || PolygonOffset_applied->units != AspectFace_set->PolygonOffset.units) | |
2166f0fa | 579 | { |
bf75be98 | 580 | PolygonOffset_applied = &AspectFace_set->PolygonOffset; |
581 | TelUpdatePolygonOffsets (PolygonOffset_applied); | |
2166f0fa | 582 | } |
bf75be98 | 583 | } |
2166f0fa | 584 | |
bf75be98 | 585 | UpdateMaterial (TEL_FRONT_MATERIAL); |
586 | if (AspectFace_set->DistinguishingMode == TOn) | |
587 | { | |
588 | UpdateMaterial (TEL_BACK_MATERIAL); | |
589 | } | |
2166f0fa | 590 | |
bf75be98 | 591 | if ((NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0) |
592 | { | |
593 | if (AspectFace_set->doTextureMap) | |
594 | { | |
595 | EnableTexture (AspectFace_set->TextureRes, | |
596 | AspectFace_set->TextureParams); | |
597 | } | |
598 | else | |
2166f0fa SK |
599 | { |
600 | DisableTexture(); | |
2166f0fa | 601 | } |
2166f0fa | 602 | } |
bf75be98 | 603 | |
604 | AspectFace_applied = AspectFace_set; | |
2166f0fa SK |
605 | return AspectFace_set; |
606 | } | |
607 | ||
608 | /*----------------------------------------------------------------------*/ | |
609 | ||
17f65eb2 | 610 | const OpenGl_AspectMarker* OpenGl_Workspace::AspectMarker (const Standard_Boolean theToApply) |
2166f0fa | 611 | { |
17f65eb2 | 612 | if (theToApply && (AspectMarker_set != AspectMarker_applied)) |
2166f0fa | 613 | { |
17f65eb2 | 614 | if (!AspectMarker_applied || (AspectMarker_set->Scale() != AspectMarker_applied->Scale())) |
615 | { | |
616 | glPointSize (AspectMarker_set->Scale()); | |
617 | #ifdef HAVE_GL2PS | |
618 | gl2psPointSize (AspectMarker_set->Scale()); | |
619 | #endif | |
620 | } | |
2166f0fa SK |
621 | AspectMarker_applied = AspectMarker_set; |
622 | } | |
623 | return AspectMarker_set; | |
624 | } | |
625 | ||
626 | /*----------------------------------------------------------------------*/ | |
627 | ||
628 | const OpenGl_AspectText * OpenGl_Workspace::AspectText(const Standard_Boolean WithApply) | |
629 | { | |
630 | if ( WithApply ) | |
631 | { | |
632 | Standard_Boolean toApply = Standard_False; | |
633 | if ( AspectText_set != AspectText_applied ) | |
634 | { | |
635 | if ( !AspectText_applied ) | |
636 | toApply = Standard_True; | |
637 | else if ( strcmp( AspectText_set->Font(), AspectText_applied->Font() ) || | |
638 | ( AspectText_set->FontAspect() != AspectText_applied->FontAspect() ) ) | |
639 | toApply = Standard_True; | |
640 | ||
641 | AspectText_applied = AspectText_set; | |
642 | } | |
643 | if ( TextParam_set != TextParam_applied ) | |
644 | { | |
645 | if ( !TextParam_applied ) | |
646 | toApply = Standard_True; | |
647 | else if ( TextParam_set->Height != TextParam_applied->Height ) | |
648 | toApply = Standard_True; | |
649 | ||
650 | TextParam_applied = TextParam_set; | |
651 | } | |
652 | if ( toApply ) | |
653 | { | |
654 | FindFont(AspectText_applied->Font(), AspectText_applied->FontAspect(), TextParam_applied->Height); | |
655 | } | |
656 | } | |
657 | return AspectText_set; | |
658 | } |