Debian Codegraph @

src/GUI/gui.cxx

raw symbols SCIP
1 /**************************************************************************
2 * gui.cxx
3 *
4 * Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
5 * project.
6 *
7 * Additional mouse supported added by David Megginson, 1999.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 *
23 * $Id$
24 **************************************************************************/
25
26
27 #include <config.h>
28
29 #include <simgear/compiler.h>
30
31 #include <string>
32
33 #include <simgear/structure/exception.hxx>
34 #include <simgear/structure/commands.hxx>
35
36 #include <simgear/misc/sg_path.hxx>
37 #include <simgear/props/props.hxx>
38 #include <simgear/props/props_io.hxx>
39
40 #include <Main/main.hxx>
41 #include <Main/globals.hxx>
42 #include <Main/locale.hxx>
43 #include <Main/fg_props.hxx>
44 #include <Viewer/WindowSystemAdapter.hxx>
45 #include <Viewer/CameraGroup.hxx>
46 #include <GUI/new_gui.hxx>
47 #include <GUI/FGFontCache.hxx>
48 #include <Viewer/PUICamera.hxx>
49
50 #include "gui.h"
51 #include "layout.hxx"
52
53 #include <osg/GraphicsContext>
54 #include <osg/GLExtensions>
55
56 using namespace flightgear;
57
58 #if defined(HAVE_PUI)
59
60 puFont guiFnt = 0;
61
62 // this is declared in puLocal.h, re-declare here so we can call it ourselves
63 void puSetPasteBuffer ( const char *ch ) ;
64
65 #endif
66
67 /* -------------------------------------------------------------------------
68 init the gui
69 _____________________________________________________________________*/
70
71 namespace
72 {
73
74 #if defined(HAVE_PUI)
75 class PUIInitOperation : public GraphicsContextOperation
76 {
77 public:
78 PUIInitOperation() : GraphicsContextOperation(std::string("GUI init"))
79 {
80 }
81 void run(osg::GraphicsContext* gc)
82 {
83 flightgear::PUICamera::initPUI();
84
85 puSetDefaultStyle ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT
86 puSetDefaultColourScheme (0.8, 0.8, 0.9, 1);
87
88 // ensure we set a non-NULL paste buffer so Ctrl-V doesn't crash us,
89 // with older versions of PLIB (pre 1.8.6)
90 puSetPasteBuffer(" ");
91
92 // OSG Texture2D sets this, which breaks PLIB fntLoadTXF
93 // force it back to zero so width passed to glTexImage2D is used
94 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
95
96 FGFontCache *fc = FGFontCache::instance();
97 fc->initializeFonts();
98 puFont *GuiFont
99 = fc->get(globals->get_locale()->getDefaultFont("typewriter.txf"),
100 15);
101 puSetDefaultFonts(*GuiFont, *GuiFont);
102 guiFnt = puGetDefaultLabelFont();
103
104 LayoutWidget::setDefaultFont(GuiFont, 15);
105
106 if (!fgHasNode("/sim/startup/mouse-pointer")) {
107 // no preference specified for mouse pointer
108 } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
109 // don't show pointer
110 } else {
111 // force showing pointer
112 puShowCursor();
113 }
114 }
115 };
116
117 osg::ref_ptr<PUIInitOperation> initOp;
118
119 #endif
120
121 // Operation for querying OpenGL parameters. This must be done in a
122 // valid OpenGL context, potentially in another thread.
123
124 struct GeneralInitOperation : public GraphicsContextOperation
125 {
126 GeneralInitOperation()
127 : GraphicsContextOperation(std::string("General init"))
128 {
129 }
130 void run(osg::GraphicsContext* gc)
131 {
132 SGPropertyNode* simRendering = fgGetNode("/sim/rendering");
133
134 simRendering->setStringValue("gl-vendor", (char*) glGetString(GL_VENDOR));
135 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VENDOR));
136
137 simRendering->setStringValue("gl-renderer", (char*) glGetString(GL_RENDERER));
138 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_RENDERER));
139
140 simRendering->setStringValue("gl-version", (char*) glGetString(GL_VERSION));
141 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VERSION));
142
143 // Old hardware without support for OpenGL 2.0 does not support GLSL and
144 // glGetString returns NULL for GL_SHADING_LANGUAGE_VERSION.
145 //
146 // See http://flightgear.org/forums/viewtopic.php?f=17&t=19670&start=15#p181945
147 const char* glsl_version = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
148 if( !glsl_version )
149 glsl_version = "UNSUPPORTED";
150 simRendering->setStringValue("gl-shading-language-version", glsl_version);
151 SG_LOG( SG_GENERAL, SG_INFO, glsl_version);
152
153 GLint tmp;
154 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
155 simRendering->setIntValue("max-texture-size", tmp);
156
157 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &tmp);
158 simRendering->setIntValue("max-texture-units", tmp);
159
160 glGetIntegerv( GL_DEPTH_BITS, &tmp );
161 simRendering->setIntValue("depth-buffer-bits", tmp);
162
163 const osg::GLExtensions* extensions = gc->getState()->get<osg::GLExtensions>();
164 if (extensions->glVertexAttribDivisor) {
165 SG_LOG( SG_GENERAL, SG_INFO, "VertexAttribDivisor supported");
166 }
167
168 }
169 };
170
171 }
172
173 /** Initializes GUI.
174 * Returns true when done, false when still busy (call again). */
175 bool guiInit(osg::GraphicsContext* gc)
176 {
177 static osg::ref_ptr<GeneralInitOperation> genOp;
178 static bool didInit = false;
179
180 if (didInit) {
181 return true;
182 }
183
184 if (!genOp.valid())
185 {
186 // Pick some window on which to do queries.
187 // XXX Perhaps all this graphics initialization code should be
188 // moved to renderer.cxx?
189 genOp = new GeneralInitOperation;
190 if (gc) {
191 gc->add(genOp.get());
192 #if defined(HAVE_PUI)
193 initOp = new PUIInitOperation;
194 gc->add(initOp.get());
195 #endif
196 } else {
197 WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
198 wsa->windows[0]->gc->add(genOp.get());
199 }
200 return false; // not ready yet
201 }
202 else
203 {
204 if (!genOp->isFinished())
205 return false;
206 #if defined(HAVE_PUI)
207 if (!initOp.valid())
208 return true;
209 if (!initOp->isFinished())
210 return false;
211 initOp = 0;
212 #endif
213 genOp = 0;
214 didInit = true;
215 // we're done
216 return true;
217 }
218 }
219
220 void syncPausePopupState()
221 {
222 bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
223 SGPropertyNode_ptr args(new SGPropertyNode);
224 args->setStringValue("id", "sim-pause");
225 if (paused && fgGetBool("/sim/view-name-popup")) {
226 args->setStringValue("label", "Simulation is paused");
227 globals->get_commands()->execute("show-message", args, nullptr);
228 } else {
229 globals->get_commands()->execute("clear-message", args, nullptr);
230 }
231
232 }