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.
20 #include <OpenGl_GlCore11.hxx>
22 #include <OpenGl_Display.hxx>
23 #include <OpenGl_Context.hxx>
24 #include <OpenGl_Light.hxx>
26 #include <OSD_Environment.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <Aspect_GraphicDeviceDefinitionError.hxx>
30 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
31 #include <X11/Xlib.h> // XOpenDisplay()
34 IMPLEMENT_STANDARD_HANDLE(OpenGl_Display,MMgt_TShared)
35 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Display,MMgt_TShared)
39 #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
40 static char* TheDummyDisplay = "DISPLAY";
43 static const OpenGl_Facilities myDefaultFacilities = { 1, 1, 1, 1, OpenGLMaxLights, 10000 };
46 /*----------------------------------------------------------------------*/
47 #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
48 OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& )
50 OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
53 myFacilities(myDefaultFacilities),
54 myDBuffer(Standard_True),
55 myDither(Standard_True),
56 myBackDither(Standard_False),
57 myWalkthrough(Standard_False),
58 mySymPerspective(Standard_False),
61 myAntiAliasingMode(3),
65 #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
66 myDisplay = TheDummyDisplay;
68 myDisplay = theDisplayConnection->GetDisplay();
74 /*----------------------------------------------------------------------*/
76 OpenGl_Display::~OpenGl_Display ()
78 ReleaseAttributes (NULL);
82 void OpenGl_Display::ReleaseAttributes (const OpenGl_Context* theGlCtx)
85 if (myLinestyleBase != 0)
87 if (theGlCtx->IsValid())
89 glDeleteLists ((GLuint )myLinestyleBase, 5);
93 // Delete surface patterns
94 if (myPatternBase != 0)
96 if (theGlCtx->IsValid())
98 glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
104 /*----------------------------------------------------------------------*/
106 void OpenGl_Display::Init()
108 if (myDisplay != NULL)
110 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
111 XSynchronize ((Display* )myDisplay, (getenv("CALL_SYNCHRO_X") != NULL) ? 1 : 0);
113 if (getenv("CSF_GraphicSync") != NULL)
114 XSynchronize ((Display* )myDisplay, 1);
116 // does the server know about OpenGL & GLX?
118 if (!XQueryExtension ((Display* )myDisplay, "GLX", &aDummy, &aDummy, &aDummy))
121 std::cerr << "This system doesn't appear to support OpenGL\n";
128 TCollection_AsciiString msg("OpenGl_Display::Init");
129 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
130 msg += " : Cannot connect to X server ";
131 msg += XDisplayName ((char*) NULL);
133 Aspect_GraphicDeviceDefinitionError::Raise(msg.ToCString());
136 if (getenv("CALL_OPENGL_NO_DBF") != NULL)
137 myDBuffer = Standard_False;
139 if (getenv("CALL_OPENGL_NO_DITHER") != NULL)
140 myDither = Standard_False;
142 if (getenv("CALL_OPENGL_NO_BACKDITHER") != NULL)
143 myBackDither = Standard_False;
145 if (getenv("CSF_WALKTHROUGH") != NULL)
146 myWalkthrough = Standard_True;
148 /* OCC18942: Test if symmetric perspective projection should be turned on */
149 if (getenv("CSF_SYM_PERSPECTIVE") != NULL)
150 mySymPerspective = Standard_True;
152 const char* pvalue = getenv("CALL_OPENGL_POLYGON_OFFSET");
156 const int n = sscanf(pvalue, "%f %f", &v1, &v2);
157 if (n > 0) myOffsetFactor = v1;
158 if (n > 1) myOffsetUnits = v2;
161 pvalue = getenv("CALL_OPENGL_ANTIALIASING_MODE");
165 if ( sscanf(pvalue,"%d",&v) > 0 ) myAntiAliasingMode = v;