HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLContext.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_GLCONTEXT_H
7 #define MATERIALX_GLCONTEXT_H
8 
9 /// @file
10 /// OpenGL context class
11 
13 
15 
16 #if defined(__APPLE__)
17 #include <OpenGL/gl.h>
18 #elif defined(__linux__) || defined(__FreeBSD__)
19 #include <GL/glx.h>
20 #endif
21 
23 
24 /// Platform dependent definition of a hardware context
25 #if defined(_WIN32)
26 using HardwareContextHandle = HGLRC;
27 #elif defined(__linux__) || defined(__FreeBSD__)
28 using HardwareContextHandle = GLXContext;
29 #else
30 using HardwareContextHandle = void*;
31 #endif
32 
33 /// SimpleWindow shared pointer
34 using SimpleWindowPtr = std::shared_ptr<class SimpleWindow>;
35 
36 /// GLContext shared pointer
37 using GLContextPtr = std::shared_ptr<class GLContext>;
38 
39 /// @class GLContext
40 /// An OpenGL context singleton
42 {
43  public:
44  /// Create a new context
46  {
47  return GLContextPtr(new GLContext(window, context));
48  }
49 
50  /// Default destructor
51  virtual ~GLContext();
52 
53  /// Return OpenGL context handle
55  {
56  return _contextHandle;
57  }
58 
59  /// Return if context is valid
60  bool isValid() const
61  {
62  return _isValid;
63  }
64 
65  /// Make the context "current" before execution of OpenGL operations
66  int makeCurrent();
67 
68  protected:
69  // Create the base context. A OpenGL context to share with can be passed in.
70  GLContext(SimpleWindowPtr window, HardwareContextHandle context = 0);
71 
72  // Simple window
74 
75  // Context handle
77 
78  // Flag to indicate validity
79  bool _isValid;
80 
81 #if defined(__linux__) || defined(__FreeBSD__)
82  // An X window used by context operations
83  Window _xWindow;
84 
85  // An X display used by context operations
86  Display* _xDisplay;
87 #endif
88 };
89 
91 
92 #endif
bool _isValid
Definition: GLContext.h:79
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
static GLContextPtr create(SimpleWindowPtr window, HardwareContextHandle context={})
Create a new context.
Definition: GLContext.h:45
HardwareContextHandle _contextHandle
Definition: GLContext.h:76
std::shared_ptr< class SimpleWindow > SimpleWindowPtr
SimpleWindow shared pointer.
Definition: GLContext.h:34
void * HardwareContextHandle
Platform dependent definition of a hardware context.
Definition: GLContext.h:30
#define MX_RENDERGLSL_API
Definition: Export.h:18
HardwareContextHandle contextHandle() const
Return OpenGL context handle.
Definition: GLContext.h:54
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
SimpleWindowPtr _window
Definition: GLContext.h:73
bool isValid() const
Return if context is valid.
Definition: GLContext.h:60
std::shared_ptr< class GLContext > GLContextPtr
GLContext shared pointer.
Definition: GLContext.h:37