MaterialX 1.38.2
GLContext.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_GLCONTEXT_H
7#define MATERIALX_GLCONTEXT_H
8
11
13
14#include <MaterialXRenderHw/SimpleWindow.h>
15
16#if defined(__APPLE__)
17#include <OpenGL/gl.h>
18#elif defined(__linux__)
19#include <MaterialXRenderGlsl/External/GLew/glxew.h>
20#endif
21
22namespace MaterialX
23{
24
26#if defined(_WIN32)
27using HardwareContextHandle = HGLRC;
28#elif defined(__linux__)
29using HardwareContextHandle = GLXContext;
30#else
32#endif
33
35using SimpleWindowPtr = std::shared_ptr<class SimpleWindow>;
36
38using GLContextPtr = std::shared_ptr<class GLContext>;
39
42class MX_RENDERGLSL_API GLContext
43{
44 public:
46 static GLContextPtr create(SimpleWindowPtr window, HardwareContextHandle context = {})
47 {
48 return GLContextPtr(new GLContext(window, context));
49 }
50
52 virtual ~GLContext();
53
56 {
57 return _contextHandle;
58 }
59
61 bool isValid() const
62 {
63 return _isValid;
64 }
65
67 int makeCurrent();
68
69 protected:
70 // Create the base context. A OpenGL context to share with can be passed in.
71 GLContext(SimpleWindowPtr window, HardwareContextHandle context = 0);
72
73 // Simple window
74 SimpleWindowPtr _window;
75
76 // Context handle
77 HardwareContextHandle _contextHandle;
78
79 // Flag to indicate validity
80 bool _isValid;
81
82#if defined(__linux__)
83 // An X window used by context operations
84 Window _xWindow;
85
86 // An X display used by context operations
87 Display* _xDisplay;
88#endif
89};
90
91} // namespace MaterialX
92
93#endif
std::shared_ptr< class GLContext > GLContextPtr
GLContext shared pointer.
Definition: GLContext.h:38
void * HardwareContextHandle
Platform dependent definition of a hardware context.
Definition: GLContext.h:31
Macros for declaring imported and exported symbols.
An OpenGL context singleton.
Definition: GLContext.h:43
bool isValid() const
Return if context is valid.
Definition: GLContext.h:61
static GLContextPtr create(SimpleWindowPtr window, HardwareContextHandle context={})
Create a new context.
Definition: GLContext.h:46
HardwareContextHandle contextHandle() const
Return OpenGL context handle.
Definition: GLContext.h:55