Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
973c2be1 | 7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
5f8b738e | 16 | #include <OpenGl_GlCore11.hxx> |
17 | ||
2166f0fa | 18 | #include <OpenGl_Display.hxx> |
fd4a6963 | 19 | #include <OpenGl_Context.hxx> |
20 | #include <OpenGl_Light.hxx> | |
2166f0fa SK |
21 | |
22 | #include <OSD_Environment.hxx> | |
23 | #include <TCollection_AsciiString.hxx> | |
24 | #include <Aspect_GraphicDeviceDefinitionError.hxx> | |
25 | ||
4fe56619 | 26 | #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))) |
5f8b738e | 27 | #include <X11/Xlib.h> // XOpenDisplay() |
28 | #endif | |
29 | ||
2166f0fa SK |
30 | IMPLEMENT_STANDARD_HANDLE(OpenGl_Display,MMgt_TShared) |
31 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Display,MMgt_TShared) | |
32 | ||
2166f0fa SK |
33 | namespace |
34 | { | |
4fe56619 | 35 | #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) |
2166f0fa SK |
36 | static char* TheDummyDisplay = "DISPLAY"; |
37 | #endif | |
38 | ||
39 | static const OpenGl_Facilities myDefaultFacilities = { 1, 1, 1, 1, OpenGLMaxLights, 10000 }; | |
40 | }; | |
41 | ||
42 | /*----------------------------------------------------------------------*/ | |
35e08fe8 | 43 | #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) |
44 | OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& ) | |
45 | #else | |
dc3fe572 | 46 | OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& theDisplayConnection) |
35e08fe8 | 47 | #endif |
2166f0fa SK |
48 | : myDisplay(NULL), |
49 | myFacilities(myDefaultFacilities), | |
50 | myDBuffer(Standard_True), | |
51 | myDither(Standard_True), | |
52 | myBackDither(Standard_False), | |
2166f0fa SK |
53 | mySymPerspective(Standard_False), |
54 | myOffsetFactor(1.F), | |
55 | myOffsetUnits(0.F), | |
56 | myAntiAliasingMode(3), | |
57 | myLinestyleBase(0), | |
a577aaab | 58 | myPatternBase(0) |
2166f0fa | 59 | { |
4fe56619 | 60 | #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) |
2166f0fa SK |
61 | myDisplay = TheDummyDisplay; |
62 | #else | |
dc3fe572 | 63 | myDisplay = theDisplayConnection->GetDisplay(); |
2166f0fa SK |
64 | #endif |
65 | ||
66 | Init(); | |
67 | } | |
68 | ||
69 | /*----------------------------------------------------------------------*/ | |
70 | ||
71 | OpenGl_Display::~OpenGl_Display () | |
72 | { | |
fd4a6963 | 73 | ReleaseAttributes (NULL); |
2166f0fa SK |
74 | myDisplay = NULL; |
75 | } | |
76 | ||
fd4a6963 | 77 | void OpenGl_Display::ReleaseAttributes (const OpenGl_Context* theGlCtx) |
2166f0fa | 78 | { |
fd4a6963 | 79 | // Delete line styles |
80 | if (myLinestyleBase != 0) | |
2166f0fa | 81 | { |
fd4a6963 | 82 | if (theGlCtx->IsValid()) |
83 | { | |
84 | glDeleteLists ((GLuint )myLinestyleBase, 5); | |
85 | } | |
86 | myLinestyleBase = 0; | |
2166f0fa | 87 | } |
fd4a6963 | 88 | // Delete surface patterns |
89 | if (myPatternBase != 0) | |
2166f0fa | 90 | { |
fd4a6963 | 91 | if (theGlCtx->IsValid()) |
92 | { | |
93 | glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START); | |
94 | } | |
95 | myPatternBase = 0; | |
2166f0fa SK |
96 | } |
97 | } | |
98 | ||
99 | /*----------------------------------------------------------------------*/ | |
100 | ||
2166f0fa SK |
101 | void OpenGl_Display::Init() |
102 | { | |
103 | if (myDisplay != NULL) | |
104 | { | |
4fe56619 | 105 | #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))) |
2166f0fa SK |
106 | XSynchronize ((Display* )myDisplay, (getenv("CALL_SYNCHRO_X") != NULL) ? 1 : 0); |
107 | ||
108 | if (getenv("CSF_GraphicSync") != NULL) | |
109 | XSynchronize ((Display* )myDisplay, 1); | |
110 | ||
111 | // does the server know about OpenGL & GLX? | |
112 | int aDummy; | |
113 | if (!XQueryExtension ((Display* )myDisplay, "GLX", &aDummy, &aDummy, &aDummy)) | |
114 | { | |
115 | #ifdef DEBUG | |
116 | std::cerr << "This system doesn't appear to support OpenGL\n"; | |
117 | #endif | |
118 | } | |
119 | #endif | |
120 | } | |
121 | else | |
122 | { | |
123 | TCollection_AsciiString msg("OpenGl_Display::Init"); | |
4fe56619 | 124 | #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))) |
2166f0fa SK |
125 | msg += " : Cannot connect to X server "; |
126 | msg += XDisplayName ((char*) NULL); | |
127 | #endif | |
128 | Aspect_GraphicDeviceDefinitionError::Raise(msg.ToCString()); | |
129 | } | |
130 | ||
131 | if (getenv("CALL_OPENGL_NO_DBF") != NULL) | |
132 | myDBuffer = Standard_False; | |
133 | ||
134 | if (getenv("CALL_OPENGL_NO_DITHER") != NULL) | |
135 | myDither = Standard_False; | |
136 | ||
137 | if (getenv("CALL_OPENGL_NO_BACKDITHER") != NULL) | |
138 | myBackDither = Standard_False; | |
139 | ||
2166f0fa SK |
140 | /* OCC18942: Test if symmetric perspective projection should be turned on */ |
141 | if (getenv("CSF_SYM_PERSPECTIVE") != NULL) | |
142 | mySymPerspective = Standard_True; | |
143 | ||
144 | const char* pvalue = getenv("CALL_OPENGL_POLYGON_OFFSET"); | |
145 | if (pvalue) | |
146 | { | |
147 | float v1, v2; | |
148 | const int n = sscanf(pvalue, "%f %f", &v1, &v2); | |
149 | if (n > 0) myOffsetFactor = v1; | |
150 | if (n > 1) myOffsetUnits = v2; | |
151 | } | |
152 | ||
153 | pvalue = getenv("CALL_OPENGL_ANTIALIASING_MODE"); | |
154 | if (pvalue) | |
155 | { | |
156 | int v; | |
157 | if ( sscanf(pvalue,"%d",&v) > 0 ) myAntiAliasingMode = v; | |
158 | } | |
159 | } |