GteGLXEngine.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.1 (2016/07/01)
7 
8 #include <GTEnginePCH.h>
11 #include <X11/Xlib.h>
12 #include <GL/glx.h>
13 using namespace gte;
14 
16 {
17  Terminate();
18 }
19 
20 GLXEngine::GLXEngine(Display* display, unsigned long window, GLXContext context,
21  int xSize, int ySize, bool saveDriverInfo, int requiredMajor, int requiredMinor)
22  :
23  GL4Engine(),
24  mDisplay(display),
25  mWindow(window),
26  mImmediate(context),
27  mIsComputeWindow(false)
28 {
29  mXSize = xSize;
30  mYSize = ySize;
31  Initialize(requiredMajor, requiredMinor, saveDriverInfo);
32 }
33 
34 GLXEngine::GLXEngine(bool saveDriverInfo, int requiredMajor, int requiredMinor)
35  :
36  GL4Engine(),
37  mDisplay(nullptr),
38  mWindow(0),
39  mImmediate(nullptr),
40  mIsComputeWindow(false)
41 {
43  {
44  mIsComputeWindow = true;
45  Initialize(requiredMajor, requiredMinor, saveDriverInfo);
46  }
47 }
48 
49 bool GLXEngine::IsActive() const
50 {
51  return mImmediate == glXGetCurrentContext();
52 }
53 
55 {
56  if (mImmediate != glXGetCurrentContext())
57  {
58  glXMakeCurrent(mDisplay, mWindow, mImmediate);
59  }
60 }
61 
62 void GLXEngine::DisplayColorBuffer(unsigned int syncInterval)
63 {
64  // TODO: Disable vertical sync if possible.
65  (void)syncInterval;
66 
67  glXSwapBuffers(mDisplay, mWindow);
68 }
69 
70 bool GLXEngine::Initialize(int requiredMajor, int requiredMinor, bool saveDriverInfo)
71 {
72  if (!glXMakeCurrent(mDisplay, mWindow, mImmediate))
73  {
74  LogError("glXMakeCurrent failed.");
75  glXDestroyContext(mDisplay, mImmediate);
76  mDisplay = nullptr;
77  mWindow = 0;
78  mImmediate = nullptr;
79  return false;
80  }
81 
82  // Get the function pointers for OpenGL; initialize the viewport,
83  // default global state, and default font.
84  return GL4Engine::Initialize(requiredMajor, requiredMinor, saveDriverInfo);
85 }
86 
88 {
90 
91  if (mDisplay && mImmediate)
92  {
93  glXDestroyContext(mDisplay, mImmediate);
94  }
95 
96  if (mIsComputeWindow)
97  {
98  XDestroyWindow(mDisplay, mWindow);
99  }
100 }
unsigned long mWindow
Definition: GteGLXEngine.h:53
_XDisplay * mDisplay
Definition: GteGLXEngine.h:52
bool mIsComputeWindow
Definition: GteGLXEngine.h:55
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
unsigned int mXSize
Definition: GteBaseEngine.h:95
GLXEngine(_XDisplay *display, unsigned long window, __GLXcontextRec *context, int xSize, int ySize, bool saveDriverInfo, int requiredMajor=4, int requiredMinor=3)
virtual ~GLXEngine()
virtual void MakeActive() override
#define LogError(message)
Definition: GteLogger.h:92
virtual bool Initialize(int requiredMajor, int requiredMinor, bool saveDriverInfo)
std::shared_ptr< WindowType > Create(typename WindowType::Parameters &parameters)
virtual bool Initialize(int requiredMajor, int requiredMinor, bool saveDriverInfo) override
virtual bool IsActive() const override
unsigned int mYSize
Definition: GteBaseEngine.h:95
virtual void DisplayColorBuffer(unsigned int syncInterval) override
__GLXcontextRec * mImmediate
Definition: GteGLXEngine.h:54
GTE_IMPEXP WindowSystem TheWindowSystem


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00