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.
21 #include <OpenGl_GlCore11.hxx>
23 #include <OpenGl_Display.hxx>
25 #include <OSD_Environment.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <Aspect_GraphicDeviceDefinitionError.hxx>
29 #include <OpenGl_Light.hxx>
31 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
32 #include <X11/Xlib.h> // XOpenDisplay()
35 IMPLEMENT_STANDARD_HANDLE(OpenGl_Display,MMgt_TShared)
36 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Display,MMgt_TShared)
38 Handle(OpenGl_Display) openglDisplay;
42 #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
43 static char* TheDummyDisplay = "DISPLAY";
46 static const OpenGl_Facilities myDefaultFacilities = { 1, 1, 1, 1, OpenGLMaxLights, 10000 };
49 /*----------------------------------------------------------------------*/
50 #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
51 OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& )
53 OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
56 myFacilities(myDefaultFacilities),
57 myDBuffer(Standard_True),
58 myDither(Standard_True),
59 myBackDither(Standard_False),
60 myWalkthrough(Standard_False),
61 mySymPerspective(Standard_False),
64 myAntiAliasingMode(3),
68 #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
69 myDisplay = TheDummyDisplay;
71 myDisplay = theDisplayConnection->GetDisplay();
77 /*----------------------------------------------------------------------*/
79 OpenGl_Display::~OpenGl_Display ()
84 glDeleteLists((GLuint)myLinestyleBase,5);
87 // Delete surface patterns
90 glDeleteLists((GLuint)myPatternBase,TEL_HS_USER_DEF_START);
97 /*----------------------------------------------------------------------*/
99 Handle(OpenGl_Window) OpenGl_Display::GetWindow (const Aspect_Drawable AParent) const
101 Handle(OpenGl_Window) aWindow;
102 if ( myMapOfWindows.IsBound( AParent ) )
104 aWindow = myMapOfWindows.Find( AParent );
109 /*----------------------------------------------------------------------*/
111 void OpenGl_Display::SetWindow (const Aspect_Drawable AParent, const Handle(OpenGl_Window) &AWindow)
113 if ( !myMapOfWindows.IsBound( AParent ) )
115 myMapOfWindows.Bind( AParent, AWindow );
119 /*----------------------------------------------------------------------*/
121 void OpenGl_Display::Init()
123 if (myDisplay != NULL)
125 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
126 XSynchronize ((Display* )myDisplay, (getenv("CALL_SYNCHRO_X") != NULL) ? 1 : 0);
128 if (getenv("CSF_GraphicSync") != NULL)
129 XSynchronize ((Display* )myDisplay, 1);
131 // does the server know about OpenGL & GLX?
133 if (!XQueryExtension ((Display* )myDisplay, "GLX", &aDummy, &aDummy, &aDummy))
136 std::cerr << "This system doesn't appear to support OpenGL\n";
143 TCollection_AsciiString msg("OpenGl_Display::Init");
144 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
145 msg += " : Cannot connect to X server ";
146 msg += XDisplayName ((char*) NULL);
148 Aspect_GraphicDeviceDefinitionError::Raise(msg.ToCString());
151 if (getenv("CALL_OPENGL_NO_DBF") != NULL)
152 myDBuffer = Standard_False;
154 if (getenv("CALL_OPENGL_NO_DITHER") != NULL)
155 myDither = Standard_False;
157 if (getenv("CALL_OPENGL_NO_BACKDITHER") != NULL)
158 myBackDither = Standard_False;
160 if (getenv("CSF_WALKTHROUGH") != NULL)
161 myWalkthrough = Standard_True;
163 /* OCC18942: Test if symmetric perspective projection should be turned on */
164 if (getenv("CSF_SYM_PERSPECTIVE") != NULL)
165 mySymPerspective = Standard_True;
167 const char* pvalue = getenv("CALL_OPENGL_POLYGON_OFFSET");
171 const int n = sscanf(pvalue, "%f %f", &v1, &v2);
172 if (n > 0) myOffsetFactor = v1;
173 if (n > 1) myOffsetUnits = v2;
176 pvalue = getenv("CALL_OPENGL_ANTIALIASING_MODE");
180 if ( sscanf(pvalue,"%d",&v) > 0 ) myAntiAliasingMode = v;