0024345: TKOpenGl - GLSL compatibility issues on NV40 (GeForce 6xxx/7xxx)
[occt.git] / src / OpenGl / OpenGl_Display.cxx
CommitLineData
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
5f8b738e 20#include <OpenGl_GlCore11.hxx>
21
2166f0fa 22#include <OpenGl_Display.hxx>
fd4a6963 23#include <OpenGl_Context.hxx>
24#include <OpenGl_Light.hxx>
2166f0fa
SK
25
26#include <OSD_Environment.hxx>
27#include <TCollection_AsciiString.hxx>
28#include <Aspect_GraphicDeviceDefinitionError.hxx>
29
4fe56619 30#if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
5f8b738e 31 #include <X11/Xlib.h> // XOpenDisplay()
32#endif
33
2166f0fa
SK
34IMPLEMENT_STANDARD_HANDLE(OpenGl_Display,MMgt_TShared)
35IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Display,MMgt_TShared)
36
2166f0fa
SK
37namespace
38{
4fe56619 39 #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
2166f0fa
SK
40 static char* TheDummyDisplay = "DISPLAY";
41 #endif
42
43 static const OpenGl_Facilities myDefaultFacilities = { 1, 1, 1, 1, OpenGLMaxLights, 10000 };
44};
45
46/*----------------------------------------------------------------------*/
35e08fe8 47#if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
48OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& )
49#else
dc3fe572 50OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
35e08fe8 51#endif
2166f0fa
SK
52: myDisplay(NULL),
53 myFacilities(myDefaultFacilities),
54 myDBuffer(Standard_True),
55 myDither(Standard_True),
56 myBackDither(Standard_False),
57 myWalkthrough(Standard_False),
58 mySymPerspective(Standard_False),
59 myOffsetFactor(1.F),
60 myOffsetUnits(0.F),
61 myAntiAliasingMode(3),
62 myLinestyleBase(0),
a577aaab 63 myPatternBase(0)
2166f0fa 64{
4fe56619 65#if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
2166f0fa
SK
66 myDisplay = TheDummyDisplay;
67#else
dc3fe572 68 myDisplay = theDisplayConnection->GetDisplay();
2166f0fa
SK
69#endif
70
71 Init();
72}
73
74/*----------------------------------------------------------------------*/
75
76OpenGl_Display::~OpenGl_Display ()
77{
fd4a6963 78 ReleaseAttributes (NULL);
2166f0fa
SK
79 myDisplay = NULL;
80}
81
fd4a6963 82void OpenGl_Display::ReleaseAttributes (const OpenGl_Context* theGlCtx)
2166f0fa 83{
fd4a6963 84 // Delete line styles
85 if (myLinestyleBase != 0)
2166f0fa 86 {
fd4a6963 87 if (theGlCtx->IsValid())
88 {
89 glDeleteLists ((GLuint )myLinestyleBase, 5);
90 }
91 myLinestyleBase = 0;
2166f0fa 92 }
fd4a6963 93 // Delete surface patterns
94 if (myPatternBase != 0)
2166f0fa 95 {
fd4a6963 96 if (theGlCtx->IsValid())
97 {
98 glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
99 }
100 myPatternBase = 0;
2166f0fa
SK
101 }
102}
103
104/*----------------------------------------------------------------------*/
105
2166f0fa
SK
106void OpenGl_Display::Init()
107{
108 if (myDisplay != NULL)
109 {
4fe56619 110 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
2166f0fa
SK
111 XSynchronize ((Display* )myDisplay, (getenv("CALL_SYNCHRO_X") != NULL) ? 1 : 0);
112
113 if (getenv("CSF_GraphicSync") != NULL)
114 XSynchronize ((Display* )myDisplay, 1);
115
116 // does the server know about OpenGL & GLX?
117 int aDummy;
118 if (!XQueryExtension ((Display* )myDisplay, "GLX", &aDummy, &aDummy, &aDummy))
119 {
120 #ifdef DEBUG
121 std::cerr << "This system doesn't appear to support OpenGL\n";
122 #endif
123 }
124 #endif
125 }
126 else
127 {
128 TCollection_AsciiString msg("OpenGl_Display::Init");
4fe56619 129 #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
2166f0fa
SK
130 msg += " : Cannot connect to X server ";
131 msg += XDisplayName ((char*) NULL);
132 #endif
133 Aspect_GraphicDeviceDefinitionError::Raise(msg.ToCString());
134 }
135
136 if (getenv("CALL_OPENGL_NO_DBF") != NULL)
137 myDBuffer = Standard_False;
138
139 if (getenv("CALL_OPENGL_NO_DITHER") != NULL)
140 myDither = Standard_False;
141
142 if (getenv("CALL_OPENGL_NO_BACKDITHER") != NULL)
143 myBackDither = Standard_False;
144
145 if (getenv("CSF_WALKTHROUGH") != NULL)
146 myWalkthrough = Standard_True;
147
148 /* OCC18942: Test if symmetric perspective projection should be turned on */
149 if (getenv("CSF_SYM_PERSPECTIVE") != NULL)
150 mySymPerspective = Standard_True;
151
152 const char* pvalue = getenv("CALL_OPENGL_POLYGON_OFFSET");
153 if (pvalue)
154 {
155 float v1, v2;
156 const int n = sscanf(pvalue, "%f %f", &v1, &v2);
157 if (n > 0) myOffsetFactor = v1;
158 if (n > 1) myOffsetUnits = v2;
159 }
160
161 pvalue = getenv("CALL_OPENGL_ANTIALIASING_MODE");
162 if (pvalue)
163 {
164 int v;
165 if ( sscanf(pvalue,"%d",&v) > 0 ) myAntiAliasingMode = v;
166 }
167}