26 #include <osgViewer/api/Cocoa/GraphicsWindowCocoa>
44inline int setFromProperty(T& place,
const SGPropertyNode* node,
const std::string&
name)
46 const SGPropertyNode* prop = node->getNode(
name);
48 place = prop->getValue<T>();
55GraphicsContext* attemptToCreateGraphicsContext(
const GraphicsContext::Traits* traits,
56 const std::string& contextVersion,
57 unsigned int profileMask)
61 ref_ptr<GraphicsContext::Traits> copy =
62 new GraphicsContext::Traits(*traits);
63 copy->glContextVersion = contextVersion;
64 copy->glContextProfileMask = profileMask;
65 return GraphicsContext::createGraphicsContext(copy);
90 GraphicsContext::WindowingSystemInterface* wsi
91 = osg::GraphicsContext::getWindowingSystemInterface();
95 wsi = osg::GraphicsContext::getWindowingSystemInterface(
"FlightGearQt5");
102 traits->readDISPLAY();
103 traits->setUndefinedScreenDetailsToDefaultScreen();
104 traits->vsync =
fgGetBool(
"/sim/rendering/vsync-enable", traits->vsync);
105 traits->doubleBuffer =
true;
106 traits->mipMapGeneration =
true;
116 const bool wantFullscreen =
fgGetBool(
"/sim/startup/fullscreen");
117 unsigned screenwidth = 0;
118 unsigned screenheight = 0;
120 wsi->getScreenResolution(*traits, screenwidth, screenheight);
123 traits->windowDecoration = !wantFullscreen;
124 if (!traits->windowDecoration) {
126 traits->supportsResize =
false;
127 traits->width = screenwidth;
128 traits->height = screenheight;
129 SG_LOG(SG_VIEW,SG_DEBUG,
"Using full screen size for window: " << screenwidth <<
" x " << screenheight);
132 int w =
fgGetInt(
"/sim/startup/xsize");
133 int h =
fgGetInt(
"/sim/startup/ysize");
134 traits->supportsResize =
true;
139 traits->x = ((unsigned)w>screenwidth) ? 0 : (screenwidth-w)/3;
140 traits->y = ((unsigned)h>screenheight) ? 0 : (screenheight-h)/3;
142 SG_LOG(SG_VIEW,SG_DEBUG,
"Using initial window size: " << w <<
" x " << h);
148 const SGPropertyNode* orrNode = winNode->getNode(
"overrideRedirect");
149 bool overrideRedirect = orrNode && orrNode->getBoolValue();
150 traits->overrideRedirect = overrideRedirect;
152 traits->windowDecoration =
false;
154 unsigned int width = 0;
155 unsigned int height = 0;
156 auto wsi = osg::GraphicsContext::getWindowingSystemInterface();
157 wsi->getScreenResolution(*traits, width, height);
158 traits->width = width;
159 traits->height = height;
160 traits->supportsResize =
false;
167 bool customTraits =
false;
169 const SGPropertyNode* fullscreenNode = winNode->getNode(
"fullscreen");
170 if (fullscreenNode && !fullscreenNode->getBoolValue())
172 traits->windowDecoration =
true;
175 resizable |= setFromProperty(traits->windowDecoration, winNode,
"decoration");
176 resizable |= setFromProperty(traits->width, winNode,
"width");
177 resizable |= setFromProperty(traits->height, winNode,
"height");
179 traits->supportsResize =
true;
191 int flags = osgViewer::GraphicsWindowCocoa::WindowData::CheckForEvents;
196 flags |= osgViewer::GraphicsWindowCocoa::WindowData::PoseAsStandaloneApp;
198 traits->inheritedWindowData =
new osgViewer::GraphicsWindowCocoa::WindowData(flags);
207 if (winNode->hasChild(
"window-name")) {
208 windowName = winNode->getStringValue(
"window-name");
209 }
else if (winNode->hasChild(
"name")) {
210 windowName = winNode->getStringValue(
"name");
212 SG_LOG(SG_VIEW, SG_WARN,
"WindowBuilder::buildWindow: Window needs a name");
224 ref_ptr<GraphicsContext::Traits> traits =
229 traits->sharedContext = wsa->
windows.front()->gc;
231 [[maybe_unused]]
int traitsSet = 0;
232 traitsSet |= setFromProperty(traits->hostName, winNode,
"host-name");
233 traitsSet |= setFromProperty(traits->displayNum, winNode,
"display");
234 traitsSet |= setFromProperty(traits->screenNum, winNode,
"screen");
236 const SGPropertyNode* fullscreenNode = winNode->getNode(
"fullscreen");
237 if (fullscreenNode && fullscreenNode->getBoolValue()) {
243 traitsSet |= setFromProperty(traits->x, winNode,
"x");
244 traitsSet |= setFromProperty(traits->y, winNode,
"y");
247 traits->windowName = windowName;
248 traitsSet |= setFromProperty(traits->windowName, winNode,
"title");
256 auto display_settings = osg::DisplaySettings::instance();
257 GraphicsContext* gc =
nullptr;
263 display_settings->setValue(
"FG_GLSL_VERSION",
"#version 430 core");
264 gc = attemptToCreateGraphicsContext(traits,
"4.3", 0x1);
270 display_settings->setValue(
"FG_GLSL_VERSION",
"#version 410 core");
271 gc = attemptToCreateGraphicsContext(traits,
"4.1", 0x1);
274 "Unable to create OpenGL 4.1 core profile context",
275 "FlightGear was unable to create a window supporting 3D rendering. "
276 "This is normally due to outdated graphics drivers, please check if updates are available. ",
277 "Depending on your OS and graphics chipset, updates might come from AMD, nVidia or Intel.");
void fgqt_setPoseAsStandaloneApp(bool b)
A window with a graphics context and an integer ID.
bool setWindowedTraits(const SGPropertyNode *winNode, osg::GraphicsContext::Traits *traits)
osg::ref_ptr< osg::GraphicsContext::Traits > defaultTraits
GraphicsWindow * buildWindow(const SGPropertyNode *winNode)
Create a window from its property node description.
void setMacPoseAsStandaloneApp(osg::GraphicsContext::Traits *traits) const
void setFullscreenTraits(const SGPropertyNode *winNode, osg::GraphicsContext::Traits *traits)
bool usingQtGraphicsWindow
static bool poseAsStandaloneApp
static osg::ref_ptr< WindowBuilder > windowBuilder
static void initWindowBuilder()
Initialize the singleton window builder.
static void setPoseAsStandaloneApp(bool b)
Adapter from windows system / graphics context management API to functions used by flightgear.
GraphicsWindow * findWindow(const std::string &name) const
Find a window by name.
WindowVector windows
Vector of all the registered windows.
static WindowSystemAdapter * getWSA()
Get the global WindowSystemAdapter.
GraphicsWindow * registerWindow(osg::GraphicsContext *gc, const std::string &windowName)
Register a window, assigning it an ID.
int fgGetInt(const char *name, int defaultValue)
Get an int value for a property.
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
void fatalMessageBoxThenExit(const std::string &caption, const std::string &msg, const std::string &moreText, int exitStatus, bool reportToSentry)
bool fgGetBool(char const *name, bool def)
Get a bool value for a property.