MaterialX 1.39.1
Loading...
Searching...
No Matches
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
11
13
14#include <MaterialXRenderHw/SimpleWindow.h>
15
16#if defined(__APPLE__)
17#include <OpenGL/gl.h>
18#elif defined(__linux__) || defined(__FreeBSD__)
19#include <GL/glx.h>
20#endif
21
22MATERIALX_NAMESPACE_BEGIN
23
25#if defined(_WIN32)
26using HardwareContextHandle = HGLRC;
27#elif defined(__linux__) || defined(__FreeBSD__)
28using HardwareContextHandle = GLXContext;
29#else
31#endif
32
34using SimpleWindowPtr = std::shared_ptr<class SimpleWindow>;
35
37using GLContextPtr = std::shared_ptr<class GLContext>;
38
41class MX_RENDERGLSL_API GLContext
42{
43 public:
46 {
47 return GLContextPtr(new GLContext(window, context));
48 }
49
51 virtual ~GLContext();
52
55 {
56 return _contextHandle;
57 }
58
60 bool isValid() const
61 {
62 return _isValid;
63 }
64
67
68 protected:
69 // Create the base context. A OpenGL context to share with can be passed in.
71
72 // Simple window
73 SimpleWindowPtr _window;
74
75 // Context handle
76 HardwareContextHandle _contextHandle;
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
90MATERIALX_NAMESPACE_END
91
92#endif
void * HardwareContextHandle
Platform dependent definition of a hardware context.
Definition: GLContext.h:30
std::shared_ptr< class GLContext > GLContextPtr
GLContext shared pointer.
Definition: GLContext.h:37
std::shared_ptr< class SimpleWindow > SimpleWindowPtr
SimpleWindow shared pointer.
Definition: GLContext.h:34
Macros for declaring imported and exported symbols.
An OpenGL context singleton.
Definition: GLContext.h:42
int makeCurrent()
Make the context "current" before execution of OpenGL operations.
bool isValid() const
Return if context is valid.
Definition: GLContext.h:60
virtual ~GLContext()
Default destructor.
static GLContextPtr create(SimpleWindowPtr window, HardwareContextHandle context={})
Create a new context.
Definition: GLContext.h:45
HardwareContextHandle contextHandle() const
Return OpenGL context handle.
Definition: GLContext.h:54